-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathPluginConfig.cs
306 lines (253 loc) · 14.7 KB
/
PluginConfig.cs
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
using System;
using System.Collections;
using System.ComponentModel;
using BepInEx.Configuration;
namespace Bulldozer
{
public enum BuryVeinMode
{
[Description("Use game setting for raise/lower. Note that the raise/lower checkbox must be enabled for this to have an impact")]
Tool,
[Description("Always bury veins, ignoring game setting. Note that the raise/lower checkbox must be enabled for this to have an impact")]
Bury,
[Description("Always raise veins, ignoring game setting. Note that the raise/lower checkbox must be enabled for this to have an impact")]
Raise
}
public enum FoundationDecorationMode
{
[Description("Use game setting for brushType (whatever selected in game is what will be used)")]
Tool,
[Description("Ignore game setting, always use painted foundation (brushType: 1)")]
Paint,
[Description("Ignore game setting, always use painted foundation (brushType: 2)")]
Decorate,
[Description("Ignore game setting, always use 'no decoration' mode (brushType: 7)")]
Clear,
}
public enum OperationMode
{
[Description("Full cheat mode, resource not consumed")]
FullCheat,
[Description("Consume available resource and continue")]
HalfCheat,
[Description("Consume available resources, halt when empty")]
Honest
}
public static class PluginConfig
{
public static ConfigEntry<int> workItemsPerFrame;
public static ConfigEntry<int> maxInitMsPerFrame;
public static ConfigEntry<bool> useActionBuildTearDown;
public static ConfigEntry<int> factoryTeardownRunTimePerFrame;
public static ConfigEntry<OperationMode> soilPileConsumption;
public static ConfigEntry<OperationMode> foundationConsumption;
public static ConfigEntry<int> maxLatitude;
public static ConfigEntry<int> minLatitude;
// used to make UI checkbox values persistent
public static ConfigEntry<bool> addGuideLines;
public static ConfigEntry<bool> alterVeinState;
public static ConfigEntry<bool> destroyFactoryAssemblers;
public static ConfigEntry<bool> addGuideLinesEquator;
public static ConfigEntry<bool> addGuideLinesMeridian;
public static ConfigEntry<bool> addGuideLinesTropic;
public static ConfigEntry<bool> addGuideLinesPoles;
public static ConfigEntry<int> minorMeridianInterval;
public static ConfigEntry<int> guideLinesEquatorColor;
public static ConfigEntry<int> guideLinesTropicColor;
public static ConfigEntry<int> guideLinesMeridianColor;
public static ConfigEntry<int> guideLinesMinorMeridianColor;
public static ConfigEntry<int> guideLinesPoleColor;
public static ConfigEntry<bool> enableRegionColor;
public static ConfigEntry<string> regionColors;
public static ConfigEntry<BuryVeinMode> buryVeinMode;
public static ConfigEntry<FoundationDecorationMode> foundationDecorationMode;
public static ConfigEntry<bool> guideLinesOnly;
public static ConfigEntry<bool> removeVegetation;
public static ConfigEntry<bool> deleteFactoryTrash;
public static ConfigEntry<bool> disableTechRequirement;
public static ConfigEntry<bool> skipDestroyingStations;
public static ConfigEntry<bool> featureFastDelete;
public static ConfigEntry<string> originalReformButtonPosition;
public static ConfigFile PluginConfigFile;
public static void InitConfig(ConfigFile configFile)
{
PluginConfigFile = configFile;
minLatitude = configFile.Bind("Control", "Min Latitude", -90,
new ConfigDescription("Minimum latitude to work on. Set equal to Max Latitude to apply to entire planet",
new AcceptableValueRange<int>(-90, 90)));
maxLatitude = configFile.Bind("Control", "Max Latitude", 90,
new ConfigDescription("Max latitude to work on, set min and max to the same value to apply to entire planet",
new AcceptableValueRange<int>(-90, 90)));
minLatitude.SettingChanged += OnMinLatitudeChange;
maxLatitude.SettingChanged += OnMaxLatitudeChange;
workItemsPerFrame = configFile.Bind("Performance", "WorkItemsPerFrame", 1,
new ConfigDescription("Number of actions attempted per Frame. Default value is 1 (minimum since 0 would not do anything other than queue up work). " +
"Larger values might make the job complete more quickly, but will also slow your system down noticeably",
new AcceptableValueRange<int>(1, 25), "configEditOnly"));
maxInitMsPerFrame = configFile.Bind("Performance", "MaxInitMsPerFrame", 50,
new ConfigDescription("How long to let init run per frame",
new AcceptableValueRange<int>(5, 250), "configEditOnly"));
useActionBuildTearDown = configFile.Bind("Performance", "UseActionBuildTearDown", true,
new ConfigDescription("Method to use for teardown. Disabled causes exceptions sometimes but might run a little faster",
null, "configEditOnly"));
factoryTeardownRunTimePerFrame = configFile.Bind("Performance", "Teardown MS Per Frame", 500,
new ConfigDescription(
"How long in ms to let the teardown task run per update. Note that 1000 ms means your game will be running at 1 UPS, but at 1 UPS the UI should still let you halt the task (click button again)\r\n" +
"Larger values might make the job complete more quickly, but will also slow your system down noticeably",
new AcceptableValueRange<int>(20, 3000), "configEditOnly"));
soilPileConsumption = configFile.Bind("Cheatiness", "SoilPileConsumption", OperationMode.FullCheat,
"Controls whether bulldozing consumes and or requires available soil pile");
foundationConsumption = configFile.Bind("Cheatiness", "FoundationConsumption", OperationMode.Honest,
"Controls whether bulldozing consumes and or requires available foundation pile");
disableTechRequirement = configFile.Bind("Cheatiness", "DisableTechRequirement", false,
"Enable/disable tech requirement for using mod");
buryVeinMode = configFile.Bind("Veins", "BuryVeinMode", BuryVeinMode.Tool, "No impact if raise/lower checkbox is not set");
addGuideLinesEquator = configFile.Bind("Decoration", "AddGuideLinesEquator", true,
"Enable/disable equator guideline individually. No effect if AddGuideLines is disabled");
addGuideLinesMeridian = configFile.Bind("Decoration", "AddGuideLinesMeridian", true,
"Enable/disable of the meridian guidelines individually. No effect if AddGuideLines is disabled");
addGuideLinesTropic = configFile.Bind("Decoration", "AddGuideLinesTropic", true,
"Enable/disable of the tropic guidelines individually. No effect if AddGuideLines is disabled");
addGuideLinesPoles = configFile.Bind("Decoration", "AddGuideLinesPoles", false,
"Enable/disable painting polar areas. No effect if AddGuideLines is disabled. Poles are considered first 2 tropics");
minorMeridianInterval = configFile.Bind("Decoration", "MinorMeridianInterval", 0,
new ConfigDescription(
"Paint meridians starting at 0 and incrementing by this value. E.g., a value of 10 would add a meridian line every 10 degrees 18, 36 total. 0 to disable",
new AcceptableValueRange<int>(0, 89), "meridians"));
guideLinesEquatorColor = configFile.Bind("CustomColors", "Equator Color", 7,
new ConfigDescription("Index of color in palette to paint equator. Default is green", new AcceptableValueRange<int>(0, 31), "color"));
guideLinesMeridianColor = configFile.Bind("CustomColors", "Meridian Color", 12,
new ConfigDescription("Index of color in palette to paint major meridian lines", new AcceptableValueRange<int>(0, 31), "color"));
guideLinesMinorMeridianColor = configFile.Bind("CustomColors", "Minor Meridian Color", 3,
new ConfigDescription("Index of color in palette to paint minor meridian lines", new AcceptableValueRange<int>(0, 31), "color"));
guideLinesTropicColor = configFile.Bind("CustomColors", "Tropic Color", 2,
new ConfigDescription("Index of color in palette to paint tropic lines", new AcceptableValueRange<int>(0, 31), "color"));
guideLinesPoleColor = configFile.Bind("CustomColors", "Pole Color", 1,
new ConfigDescription("Index of color in palette to paint poles", new AcceptableValueRange<int>(0, 31), "color"));
enableRegionColor = configFile.Bind("CustomColors", "Enable Region Color", false,
"Enable painting colors based on coordinates");
regionColors = configFile.Bind("UIOnly", "Region Colors JSON", "", "Not for editing, use UI to define values");
guideLinesOnly = configFile.Bind("Decoration", "GuideLinesOnly",false,
"Only add guidelines, don't pave entire planet");
foundationDecorationMode = configFile.Bind("Decoration", "FoundationDecorationMode", FoundationDecorationMode.Tool,
"Change to have a permanent setting instead of tracking the game's current config");
deleteFactoryTrash = configFile.Bind("Destruction", "DeleteFactoryTrash", false,
"Erase all items littered while destroying factory items");
removeVegetation = configFile.Bind("Destruction", "RemoveVegetation", true,
"Erase vegetation");
skipDestroyingStations = configFile.Bind("Destruction", "SkipDestroyingStations", false,
"Enable/disable teardown of logistics stations");
// Config edit only, but just in case it needs to be turned off at some point in the future
featureFastDelete = configFile.Bind("Destruction", "Enable Fast Delete", true,
new ConfigDescription("Enable Raptor's fast delete for factory teardown", null, "configEditOnly"));
alterVeinState = configFile.Bind("UIOnly", "AlterVeinState", false,
new ConfigDescription("Don't edit, use UI checkbox. By default, veins will not be lowered or raised. Enabling takes much longer",
null, "uiEditOnly"));
destroyFactoryAssemblers = configFile.Bind("UIOnly", "DestroyFactoryAssemblers", false,
"Don't edit, use UI checkbox. Destroy all factory machines (labs, assemblers, etc). It can be very slow so if you get bored waiting and want to delete stuff yourself, make sure to stop the bulldoze process.");
addGuideLines = configFile.Bind("UIOnly", "AddGuideLines", true,
"Don't edit, this property backs the checkbox in the UI. If enabled painted lines at certain points on planet will be added");
originalReformButtonPosition = configFile.Bind("UIOnly", "OriginalReformButtonPosition", "0,0",
"Track where the button was before we started messing with it");
#if RELEASE
originalReformButtonPosition.Value = "0,0";
#endif
}
private static void OnMaxLatitudeChange(object sender, EventArgs e)
{
if (sender is ConfigEntry<int> entry && minLatitude.Value > entry.Value)
{
minLatitude.Value = maxLatitude.Value;
}
}
private static void OnMinLatitudeChange(object sender, EventArgs e)
{
if (sender is ConfigEntry<int> entry && maxLatitude.Value < entry.Value)
{
maxLatitude.Value = entry.Value;
}
}
public static string GetCurrentVeinsRaiseState()
{
var reformTool = GameMain.mainPlayer?.controller.actionBuild.reformTool;
if (reformTool == null)
{
return "UNKNOWN";
}
var bury = buryVeinMode.Value == BuryVeinMode.Tool ? reformTool.buryVeins : buryVeinMode.Value == BuryVeinMode.Bury;
return bury ? "bury" : "restore";
}
public static void ResetConfigWindowOptionsToDefault()
{
foreach (var configDefinition in PluginConfigFile.Keys)
{
// edit config to tweak performance config settings
if (configDefinition.Section == "UIOnly")
{
continue;
}
var configEntry = PluginConfigFile[configDefinition];
if (((IList)configEntry.Description.Tags).Contains("configEditOnly"))
{
continue;
}
configEntry.BoxedValue = configEntry.DefaultValue;
}
}
public static bool LatitudeOutOfBounds(float latInDegrees)
{
if (!IsLatConstrained())
return false;
return maxLatitude.Value <= latInDegrees || minLatitude.Value >= latInDegrees;
}
public static bool IsLatConstrained()
{
if (maxLatitude.Value == minLatitude.Value)
return false;
return maxLatitude.Value != 90 || minLatitude.Value != -90;
}
public static bool NeedReformIndexProvider()
{
if (IsLatConstrained())
return true;
if (enableRegionColor.Value)
return true;
if (guideLinesOnly.Value)
return true;
if (!addGuideLines.Value)
return false;
return (addGuideLinesEquator.Value
|| addGuideLinesMeridian.Value
|| addGuideLinesPoles.Value
|| addGuideLinesTropic.Value
|| minorMeridianInterval.Value > 0);
}
public static string GetLatRangeString()
{
// $"{Degrees}° {Minutes}' {Direction}";
var minlat = minLatitude.Value;
var latDir = "° N";
if (minlat < 0)
{
minlat = -minlat;
latDir = "° S";
}
else if (minlat == 0)
{
latDir = "° ";
}
var maxlat = maxLatitude.Value;
var maxLatDir = "° N";
if (maxlat < 0)
{
maxlat = -maxlat;
maxLatDir = "° S";
}
else if (maxlat == 0)
{
maxLatDir = "° ";
}
return $"{minlat}{latDir} - {maxlat}{maxLatDir}";
}
}
}