-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathModSettings.cs
More file actions
281 lines (234 loc) · 11 KB
/
Copy pathModSettings.cs
File metadata and controls
281 lines (234 loc) · 11 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
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
using Newtonsoft.Json;
using System;
using System.IO;
namespace DigimonNOAccess
{
/// <summary>
/// Centralized settings storage with JSON persistence.
/// All configurable mod values are exposed as static properties.
/// Call Initialize() early in Main.OnInitializeMelon() before any handler reads settings.
/// </summary>
public static class ModSettings
{
private static string _settingsPath;
// --- General ---
private static bool _readVoicedText = false;
public static bool ReadVoicedText
{
get => _readVoicedText;
set
{
_readVoicedText = value;
DialogTextPatch.AlwaysReadText = value;
}
}
public static bool SpeakMovieSubtitles { get; set; } = true;
// --- Text to speech (Prism) ---
// Engine is stored by Prism's stable registry ID, not by name or index.
// 0 means "let Prism pick the best available".
public static ulong SpeechEngineId { get; set; } = 0;
public static string SpeechVoice { get; set; } = "";
public static int SpeechRatePercent { get; set; } = 50;
public static int SpeechVolumePercent { get; set; } = 100;
public static bool SpeakOnlyWhenFocused { get; set; } = true;
// --- Audio Navigation: Detection Ranges ---
public static float ItemRange { get; set; } = 80f;
public static float NpcRange { get; set; } = 80f;
public static float EnemyRange { get; set; } = 100f;
public static float TransitionRange { get; set; } = 60f;
public static float FacilityRange { get; set; } = 80f;
// --- Audio Navigation: Base Volumes ---
public static float NearestVolume { get; set; } = 0.8f;
public static float BackgroundVolume { get; set; } = 0.15f;
// --- Audio Navigation: Per-type Volumes (0.0 to 1.0) ---
public static float ItemVolume { get; set; } = 1.0f;
public static float NpcVolume { get; set; } = 1.0f;
public static float EnemyVolume { get; set; } = 1.0f;
public static float TransitionVolume { get; set; } = 1.0f;
public static float FacilityVolume { get; set; } = 1.0f;
// --- Pathfinding beacon ---
// The beacon conveys distance through how fast it repeats, not how loud it is,
// so this is a flat volume rather than a range.
public static float PathfinderVolume { get; set; } = 0.45f;
// --- Audio Navigation: Per-type Enable/Disable ---
public static bool ItemsEnabled { get; set; } = true;
public static bool NpcsEnabled { get; set; } = true;
public static bool EnemiesEnabled { get; set; } = true;
public static bool TransitionsEnabled { get; set; } = true;
public static bool FacilitiesEnabled { get; set; } = true;
// --- Audio Navigation: Max Simultaneous Sounds ---
public static int MaxItemSounds { get; set; } = 3;
public static int MaxNpcSounds { get; set; } = 3;
public static int MaxEnemySounds { get; set; } = 3;
public static int MaxTransitionSounds { get; set; } = 2;
public static int MaxFacilitySounds { get; set; } = 2;
// --- Battle ---
public static bool AnnounceBattleBuffs { get; set; } = true;
// --- Gameplay: Care Mechanics ---
public static bool DisableHunger { get; set; } = false;
public static bool DisableToilet { get; set; } = false;
public static bool DisableFatigue { get; set; } = false;
public static bool DisableSickness { get; set; } = false;
public static void Initialize(string modFolderPath)
{
_settingsPath = Path.Combine(modFolderPath, "settings.json");
Load();
DebugLogger.Log($"[ModSettings] Initialized, path: {_settingsPath}");
}
public static void Load()
{
try
{
if (!File.Exists(_settingsPath))
{
DebugLogger.Log("[ModSettings] No settings file found, using defaults");
Save();
return;
}
string json = File.ReadAllText(_settingsPath);
var data = JsonConvert.DeserializeObject<SettingsData>(json);
if (data == null)
{
DebugLogger.Warning("[ModSettings] Failed to deserialize settings, using defaults");
return;
}
ApplyFromData(data);
DebugLogger.Log("[ModSettings] Settings loaded successfully");
}
catch (Exception ex)
{
DebugLogger.Error($"[ModSettings] Error loading settings: {ex.Message}");
}
}
public static void Save()
{
try
{
var data = CreateData();
string json = JsonConvert.SerializeObject(data, Formatting.Indented);
File.WriteAllText(_settingsPath, json);
}
catch (Exception ex)
{
DebugLogger.Error($"[ModSettings] Error saving settings: {ex.Message}");
}
}
private static void ApplyFromData(SettingsData data)
{
ReadVoicedText = data.ReadVoicedText;
SpeakMovieSubtitles = data.SpeakMovieSubtitles;
SpeechEngineId = data.SpeechEngineId;
SpeechVoice = data.SpeechVoice ?? "";
SpeechRatePercent = data.SpeechRatePercent;
SpeechVolumePercent = data.SpeechVolumePercent;
SpeakOnlyWhenFocused = data.SpeakOnlyWhenFocused;
ItemRange = data.ItemRange;
NpcRange = data.NpcRange;
EnemyRange = data.EnemyRange;
TransitionRange = data.TransitionRange;
FacilityRange = data.FacilityRange;
NearestVolume = data.NearestVolume;
BackgroundVolume = data.BackgroundVolume;
ItemVolume = data.ItemVolume;
NpcVolume = data.NpcVolume;
EnemyVolume = data.EnemyVolume;
TransitionVolume = data.TransitionVolume;
FacilityVolume = data.FacilityVolume;
PathfinderVolume = data.PathfinderVolume;
ItemsEnabled = data.ItemsEnabled;
NpcsEnabled = data.NpcsEnabled;
EnemiesEnabled = data.EnemiesEnabled;
TransitionsEnabled = data.TransitionsEnabled;
FacilitiesEnabled = data.FacilitiesEnabled;
MaxItemSounds = data.MaxItemSounds;
MaxNpcSounds = data.MaxNpcSounds;
MaxEnemySounds = data.MaxEnemySounds;
MaxTransitionSounds = data.MaxTransitionSounds;
MaxFacilitySounds = data.MaxFacilitySounds;
AnnounceBattleBuffs = data.AnnounceBattleBuffs;
DisableHunger = data.DisableHunger;
DisableToilet = data.DisableToilet;
DisableFatigue = data.DisableFatigue;
DisableSickness = data.DisableSickness;
}
private static SettingsData CreateData()
{
return new SettingsData
{
ReadVoicedText = ReadVoicedText,
SpeakMovieSubtitles = SpeakMovieSubtitles,
SpeechEngineId = SpeechEngineId,
SpeechVoice = SpeechVoice,
SpeechRatePercent = SpeechRatePercent,
SpeechVolumePercent = SpeechVolumePercent,
SpeakOnlyWhenFocused = SpeakOnlyWhenFocused,
ItemRange = ItemRange,
NpcRange = NpcRange,
EnemyRange = EnemyRange,
TransitionRange = TransitionRange,
FacilityRange = FacilityRange,
NearestVolume = NearestVolume,
BackgroundVolume = BackgroundVolume,
ItemVolume = ItemVolume,
NpcVolume = NpcVolume,
EnemyVolume = EnemyVolume,
TransitionVolume = TransitionVolume,
FacilityVolume = FacilityVolume,
PathfinderVolume = PathfinderVolume,
ItemsEnabled = ItemsEnabled,
NpcsEnabled = NpcsEnabled,
EnemiesEnabled = EnemiesEnabled,
TransitionsEnabled = TransitionsEnabled,
FacilitiesEnabled = FacilitiesEnabled,
MaxItemSounds = MaxItemSounds,
MaxNpcSounds = MaxNpcSounds,
MaxEnemySounds = MaxEnemySounds,
MaxTransitionSounds = MaxTransitionSounds,
MaxFacilitySounds = MaxFacilitySounds,
AnnounceBattleBuffs = AnnounceBattleBuffs,
DisableHunger = DisableHunger,
DisableToilet = DisableToilet,
DisableFatigue = DisableFatigue,
DisableSickness = DisableSickness,
};
}
private class SettingsData
{
public bool ReadVoicedText { get; set; } = false;
public bool SpeakMovieSubtitles { get; set; } = true;
public ulong SpeechEngineId { get; set; } = 0;
public string SpeechVoice { get; set; } = "";
public int SpeechRatePercent { get; set; } = 50;
public int SpeechVolumePercent { get; set; } = 100;
public bool SpeakOnlyWhenFocused { get; set; } = true;
public float ItemRange { get; set; } = 80f;
public float NpcRange { get; set; } = 80f;
public float EnemyRange { get; set; } = 100f;
public float TransitionRange { get; set; } = 60f;
public float FacilityRange { get; set; } = 80f;
public float NearestVolume { get; set; } = 0.8f;
public float BackgroundVolume { get; set; } = 0.15f;
public float ItemVolume { get; set; } = 1.0f;
public float NpcVolume { get; set; } = 1.0f;
public float EnemyVolume { get; set; } = 1.0f;
public float TransitionVolume { get; set; } = 1.0f;
public float FacilityVolume { get; set; } = 1.0f;
public float PathfinderVolume { get; set; } = 0.45f;
public bool ItemsEnabled { get; set; } = true;
public bool NpcsEnabled { get; set; } = true;
public bool EnemiesEnabled { get; set; } = true;
public bool TransitionsEnabled { get; set; } = true;
public bool FacilitiesEnabled { get; set; } = true;
public int MaxItemSounds { get; set; } = 3;
public int MaxNpcSounds { get; set; } = 3;
public int MaxEnemySounds { get; set; } = 3;
public int MaxTransitionSounds { get; set; } = 2;
public int MaxFacilitySounds { get; set; } = 2;
public bool AnnounceBattleBuffs { get; set; } = true;
public bool DisableHunger { get; set; } = false;
public bool DisableToilet { get; set; } = false;
public bool DisableFatigue { get; set; } = false;
public bool DisableSickness { get; set; } = false;
}
}
}