-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSettings.cs
More file actions
210 lines (168 loc) · 8.61 KB
/
Settings.cs
File metadata and controls
210 lines (168 loc) · 8.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
using System.Collections.Generic;
using System.Linq;
using BepInEx.Configuration;
using BepInEx.Logging;
using SpawnManager.Extensions;
using SpawnManager.Managers;
namespace SpawnManager
{
public static class Settings
{
public static ConfigEntry<bool> ShowSpawnManagerButton { get; private set; } = null!;
public static ConfigEntry<string> DisabledEnemies { get; private set; } = null!;
public static ConfigEntry<string> DisabledValuables { get; private set; } = null!;
public static IDictionary<string, ConfigEntry<string>> DisabledLevelValuables { get; private set; } = new Dictionary<string, ConfigEntry<string>>();
public static ConfigEntry<string> DisabledLevels { get; private set; } = null!;
public static IDictionary<string, ConfigEntry<string>> DisabledLevelEnemies { get; private set; } = new Dictionary<string, ConfigEntry<string>>();
public static ConfigEntry<string> DisabledItems { get; private set; } = null!;
public static IDictionary<string, ConfigEntry<string>> DisabledLevelItems { get; private set; } = new Dictionary<string, ConfigEntry<string>>();
public static ConfigEntry<string> DefaultValuable { get; private set; } = null!;
public static ManualLogSource Logger { get; private set; } = null!;
private static ConfigFile Config { get; set; } = null!;
private static bool LevelsInitialized { get; set; } = false;
private static bool ValuablesInitialized { get; set; } = false;
private const string HideFromRepoConfig = "HideREPOConfig";
internal static void Initialize(ConfigFile config, ManualLogSource logger)
{
Config = config;
Logger = logger;
var setting = ShowSpawnManagerButton = Config.Bind(
"General",
"ShowSpawnManagerButton",
true,
"Set to false to hide the Spawn Manager button on the main menu.");
setting.SettingChanged += MenuModManager.OnShowSpawnManagerButtonChanged;
_ = Config.Bind(
"Do Not Use",
"Use Spawn Manager button on main menu",
0f,
"Use Spawn Manager button on main menu");
DisabledEnemies = Config.Bind(
"Enemies",
"DisabledList",
"",
new ConfigDescription("Comma-separated list of enemy names to disable. (e.g. \"Apex Predator,Headman\")", null, HideFromRepoConfig));
DefaultValuable = Config.Bind(
"Valuables",
"Default",
"Valuable Goblet",
new ConfigDescription("A single tiny valuable used to fill when there aren't enough valuables enabled in the level. (e.g. \"Valuable Diamond\")", null, HideFromRepoConfig));
DisabledValuables = Config.Bind(
"Valuables",
"DisabledList",
"",
new ConfigDescription("Comma-separated list of valuable names to disable. (e.g. \"Valuable Television,Valuable Diamond Display\")", null, HideFromRepoConfig));
DisabledLevels = Config.Bind(
"Levels",
"DisabledList",
"",
new ConfigDescription("Comma-separated list of level names to disable. (e.g. \"Level - Manor\")", null, HideFromRepoConfig));
DisabledItems = Config.Bind(
"Items",
"DisabledList",
"",
new ConfigDescription("Comma-separated list of item names to disable. (e.g. \"Cart Medium\")", null, HideFromRepoConfig));
}
internal static void InitializeEnemiesLevels()
{
// Ensure this is only run once.
if (LevelsInitialized) return;
foreach (var level in LevelManager.GetAllLevels())
{
var configBinding = Config.Bind(
"Levels", // Should be in Enemies. TODO change to Enemies if values can be transferred.
$"{level.FriendlyName()} - Disabled Enemies",
"",
new ConfigDescription("Comma-separated list of enemy names to disable in this level. (e.g. \"Apex Predator,Headman\")", null, HideFromRepoConfig));
DisabledLevelEnemies.Add(level.name, configBinding);
}
LevelsInitialized = true;
}
internal static void InitializeItemsLevels()
{
// We need to initialize this every time as LevelGenerator is run when registering with RepoLib, and more levels may have been registered after the first one.
// But we can't re-bind the same config entry, so we need to remove any that are already bound.
var levels = LevelManager.GetAllLevelsForItems()
.Where(level => !DisabledLevelItems.ContainsKey(level.name))
.ToList();
foreach (var level in levels)
{
var configBinding = Config.Bind(
"Items",
$"{level.FriendlyName()} - Disabled Items",
"",
new ConfigDescription("Comma-separated list of item names to disable in this level. (e.g. \"Cart Medium\")", null, HideFromRepoConfig));
DisabledLevelItems.Add(level.name, configBinding);
}
}
internal static void InitializeValuablesLevels()
{
// Ensure this is only run once.
if (ValuablesInitialized) return;
if (!LevelManager.RunManagerLevelVariableIsAvailable) return;
foreach (var level in LevelManager.GetAllLevels())
{
var configBinding = Config.Bind(
"Valuables",
$"{level.FriendlyName()} - Disabled Valuables",
"",
new ConfigDescription("Comma-separated list of valuable names to disable. (e.g. \"Valuable Television,Valuable Diamond Display\")", null, HideFromRepoConfig));
DisabledLevelValuables.Add(level.name, configBinding);
}
ValuablesInitialized = true;
}
public static ISet<string> GetDisabledEnemiesForLevel(string level)
{
if (DisabledLevelEnemies.TryGetValue(level, out ConfigEntry<string> disabledEnemies))
{
return new HashSet<string>(ConvertStringToList(disabledEnemies.Value));
}
return new HashSet<string>();
}
public static ISet<string> GetDisabledItemsForLevel(string level)
{
if (DisabledLevelItems.TryGetValue(level, out ConfigEntry<string> disabledItems))
{
return new HashSet<string>(ConvertStringToList(disabledItems.Value));
}
return new HashSet<string>();
}
public static ISet<string> GetDisabledValuablesForLevel(string level)
{
if (DisabledLevelValuables.TryGetValue(level, out ConfigEntry<string> disabledValuables))
{
return new HashSet<string>(ConvertStringToList(disabledValuables.Value));
}
return new HashSet<string>();
}
public static List<string> GetDisabledSettingsEntryListNames(ConfigEntry<string> settingsVariable)
{
return ConvertStringToList(settingsVariable.Value);
}
private static List<string> ConvertStringToList(string str)
{
if (string.IsNullOrEmpty(str))
return new List<string>();
return new List<string>(str.Split(',', System.StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()));
}
public static void UpdateSettingsListEntry(ConfigEntry<string> settingsVariable, string entry, bool enabled)
{
var currentList = GetDisabledSettingsEntryListNames(settingsVariable);
if (enabled)
{
currentList.Remove(entry);
}
else
{
if (!currentList.Contains(entry))
currentList.Add(entry);
}
settingsVariable.Value = string.Join(",", currentList);
}
public static bool IsSettingsListEntryEnabled(ConfigEntry<string> settingsVariable, string entry)
{
var disabledEntries = GetDisabledSettingsEntryListNames(settingsVariable);
return !disabledEntries.Contains(entry);
}
}
}