-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathModConfig.cs
167 lines (127 loc) · 6.15 KB
/
ModConfig.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
namespace DaLion.Overhaul;
#region using directives
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using StardewModdingAPI.Utilities;
#endregion using directives
/// <summary>The collection of configs for each module.</summary>
public sealed class ModConfig
{
#region module flags
/// <summary>Gets a value indicating whether the Professions module is enabled.</summary>
[JsonProperty]
public bool EnableProfessions { get; internal set; } = true;
#if DEBUG
/// <summary>Gets a value indicating whether the Combat module is enabled.</summary>
[JsonProperty]
public bool EnableCombat { get; internal set; } = true;
/// <summary>Gets a value indicating whether the Weapons module is enabled.</summary>
[JsonProperty]
public bool EnableWeapons { get; internal set; } = true;
/// <summary>Gets a value indicating whether the Slingshots module is enabled.</summary>
[JsonProperty]
public bool EnableSlingshots { get; internal set; } = true;
/// <summary>Gets a value indicating whether the Tools module is enabled.</summary>
[JsonProperty]
public bool EnableTools { get; internal set; } = true;
/// <summary>Gets a value indicating whether the Enchantments module is enabled.</summary>
[JsonProperty]
public bool EnableEnchantments { get; internal set; } = true;
/// <summary>Gets a value indicating whether the Rings module is enabled.</summary>
[JsonProperty]
public bool EnableRings { get; internal set; } = true;
/// <summary>Gets a value indicating whether the Ponds module is enabled.</summary>
[JsonProperty]
public bool EnablePonds { get; internal set; } = true;
/// <summary>Gets a value indicating whether the Taxes module is enabled.</summary>
[JsonProperty]
public bool EnableTaxes { get; internal set; } = true;
/// <summary>Gets a value indicating whether the Tweex module is enabled.</summary>
[JsonProperty]
public bool EnableTweex { get; internal set; } = true;
#elif RELEASE
/// <summary>Gets a value indicating whether the Combat module is enabled.</summary>
[JsonProperty]
public bool EnableCombat { get; internal set; } = false;
/// <summary>Gets a value indicating whether the Weapons module is enabled.</summary>
[JsonProperty]
public bool EnableWeapons { get; internal set; } = false;
/// <summary>Gets a value indicating whether the Slingshots module is enabled.</summary>
[JsonProperty]
public bool EnableSlingshots { get; internal set; } = false;
/// <summary>Gets a value indicating whether the Tools module is enabled.</summary>
[JsonProperty]
public bool EnableTools { get; internal set; } = false;
/// <summary>Gets a value indicating whether the Enchantments module is enabled.</summary>
[JsonProperty]
public bool EnableEnchantments { get; internal set; } = false;
/// <summary>Gets a value indicating whether the Rings module is enabled.</summary>
[JsonProperty]
public bool EnableRings { get; internal set; } = false;
/// <summary>Gets a value indicating whether the Ponds module is enabled.</summary>
[JsonProperty]
public bool EnablePonds { get; internal set; } = false;
/// <summary>Gets a value indicating whether the Taxes module is enabled.</summary>
[JsonProperty]
public bool EnableTaxes { get; internal set; } = false;
/// <summary>Gets a value indicating whether the Tweex module is enabled.</summary>
[JsonProperty]
public bool EnableTweex { get; internal set; } = true;
#endif
#endregion module flags
#region config sub-modules
/// <summary>Gets the Professions module config settings.</summary>
[JsonProperty]
public Modules.Professions.Config Professions { get; internal set; } = new();
/// <summary>Gets the Professions module config settings.</summary>
[JsonProperty]
public Modules.Combat.Config Combat { get; internal set; } = new();
/// <summary>Gets the Tools module config settings.</summary>
[JsonProperty]
public Modules.Tools.Config Tools { get; internal set; } = new();
/// <summary>Gets the Ponds module config settings.</summary>
[JsonProperty]
public Modules.Ponds.Config Ponds { get; internal set; } = new();
/// <summary>Gets the Taxes module config settings.</summary>
[JsonProperty]
public Modules.Taxes.Config Taxes { get; internal set; } = new();
/// <summary>Gets the Tweex module config settings.</summary>
[JsonProperty]
public Modules.Tweex.Config Tweex { get; internal set; } = new();
#endregion config sub-modules
/// <summary>Gets the key used to open the Generic Mod Config Menu directly at this mod.</summary>
[JsonProperty]
public KeybindList OpenMenuKey { get; internal set; } = KeybindList.Parse("LeftShift + F12");
/// <summary>Gets the key used to engage Debug Mode.</summary>
[JsonProperty]
public KeybindList DebugKey { get; internal set; } = KeybindList.Parse("OemQuotes, OemTilde");
/// <summary>Validates all internal configs and overwrites the user's config file if any invalid settings were found.</summary>
/// <param name="helper">Provides simplified APIs for writing mods.</param>
internal void Validate(IModHelper helper)
{
if (!this.Enumerate().Aggregate(true, (flag, config) => flag & config.Validate()))
{
helper.WriteConfig(this);
}
}
/// <summary>Enumerates all individual module <see cref="Shared.Configs.Config"/>s.</summary>
/// <returns>A <see cref="IEnumerable{T}"/> of <see cref="Shared.Configs.Config"/>s.</returns>
internal IEnumerable<Shared.Configs.Config> Enumerate()
{
yield return this.Professions;
yield return this.Combat;
yield return this.Tools;
yield return this.Ponds;
yield return this.Taxes;
yield return this.Tweex;
}
/// <summary>Logs all sub-config properties to the SMAPI console.</summary>
internal void Log()
{
Shared.Log.T($"[Config]: Current settings:\n{this}");
var message = this
.Enumerate()
.Aggregate("[Config]: Current settings:", (current, next) => current + "\n" + next);
}
}