-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSPDSettings.cs
More file actions
540 lines (445 loc) · 13.6 KB
/
SPDSettings.cs
File metadata and controls
540 lines (445 loc) · 13.6 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
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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
using System;
using System.Globalization;
using Newtonsoft.Json.Linq;
using watabou.utils;
using watabou.noosa.audio;
using spdd.scenes;
using spdd.messages;
namespace spdd
{
public class SPDSettings
{
private static JObject data = new JObject();
public const string DEFAULT_PREFS_FILE = "settings.json";
public static void Load()
{
try
{
var str = FileUtils.Read(DEFAULT_PREFS_FILE);
data = JObject.Parse(str);
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
public static bool Contains(string key)
{
return data.ContainsKey(key);
}
public static int GetInt(string key, int defValue)
{
return GetInt(key, defValue, int.MinValue, int.MaxValue);
}
public static int GetInt(string key, int defValue, int min, int max)
{
try
{
var token = data.GetValue(key);
if (token == null)
return defValue;
int value = token.ToObject<int>();
if (value < min || value > max)
{
value = GameMath.Clamp(value, min, max);
Put(key, value);
return value;
}
else
{
return value;
}
}
catch (Exception)
{
//ShatteredPixelDungeon.reportException(e);
Put(key, defValue);
return defValue;
}
}
public static long GetLong(string key, long defValue)
{
return GetLong(key, defValue, long.MinValue, long.MaxValue);
}
public static long GetLong(string key, long defValue, long min, long max)
{
try
{
var token = data.GetValue(key);
if (token == null)
return defValue;
long value = token.ToObject<long>();
if (value < min || value > max)
{
long val = GameMath.Clamp(min, value, max);
Put(key, val);
return val;
}
else
{
return value;
}
}
catch (Exception)
{
//ShatteredPixelDungeon.reportException(e);
Put(key, defValue);
return defValue;
}
}
public static bool GetBoolean(string key, bool defValue)
{
try
{
var token = data.GetValue(key);
if (token == null)
return defValue;
bool value = token.ToObject<bool>();
return value;
}
catch (Exception)
{
//ShatteredPixelDungeon.reportException(e);
Put(key, defValue);
return defValue;
}
}
public static string GetString(string key, string defValue)
{
try
{
var token = data.GetValue(key);
if (token == null)
return defValue;
string value = token.ToObject<string>();
if (string.IsNullOrEmpty(value))
return defValue;
return value;
}
catch (Exception)
{
//ShatteredPixelDungeon.reportException(e);
Put(key, defValue);
return defValue;
}
}
public static void Put(string key, int value)
{
data[key] = value;
Flush();
}
public static void Put(string key, long value)
{
data[key] = value;
Flush();
}
public static void Put(string key, bool value)
{
data[key] = value;
Flush();
}
public static void Put(string key, string value)
{
data[key] = value;
Flush();
}
public static void Flush()
{
FileUtils.Write(DEFAULT_PREFS_FILE, data.ToString());
}
//Version info
public const string KEY_VERSION = "version";
public static void Version(int value)
{
Put(KEY_VERSION, value);
}
public static int Version()
{
return GetInt(KEY_VERSION, 0);
}
//Graphics
public const string KEY_FULLSCREEN = "fullscreen";
public const string KEY_LANDSCAPE = "landscape";
public const string KEY_POWER_SAVER = "power_saver";
public const string KEY_SCALE = "scale";
public const string KEY_ZOOM = "zoom";
public const string KEY_BRIGHTNESS = "brightness";
public const string KEY_GRID = "visual_grid";
public static void Fullscreen(bool value)
{
Put(KEY_FULLSCREEN, value);
ShatteredPixelDungeonDash.UpdateSystemUI();
}
public static bool Fullscreen()
{
return GetBoolean(KEY_FULLSCREEN, false);
}
public static void Landscape(bool value)
{
Put(KEY_LANDSCAPE, value);
((ShatteredPixelDungeonDash)ShatteredPixelDungeonDash.instance).UpdateDisplaySize();
}
//can return null because we need to directly handle the case of landscape not being set
// as there are different defaults for different devices
public static bool? Landscape()
{
if (Contains(KEY_LANDSCAPE))
{
return GetBoolean(KEY_LANDSCAPE, false);
}
else
{
return null;
}
}
public static void PowerSaver(bool value)
{
Put(KEY_POWER_SAVER, value);
((ShatteredPixelDungeonDash)ShatteredPixelDungeonDash.instance).UpdateDisplaySize();
}
public static bool PowerSaver()
{
return GetBoolean(KEY_POWER_SAVER, false);
}
public static void Scale(int value)
{
Put(KEY_SCALE, value);
}
public static int Scale()
{
return GetInt(KEY_SCALE, 0);
}
public static void Zoom(int value)
{
Put(KEY_ZOOM, value);
}
public static int Zoom()
{
return GetInt(KEY_ZOOM, 0);
}
public static void Brightness(int value)
{
Put(KEY_BRIGHTNESS, value);
GameScene.UpdateFog();
}
public static int Brightness()
{
return GetInt(KEY_BRIGHTNESS, 0, -1, 1);
}
public static void VisualGrid(int value)
{
Put(KEY_GRID, value);
GameScene.UpdateMap();
}
public static int VisualGrid()
{
return GetInt(KEY_GRID, 0, -1, 2);
}
//Interface
public const string KEY_QUICKSLOTS = "quickslots";
public const string KEY_FLIPTOOLBAR = "flipped_ui";
public const string KEY_FLIPTAGS = "flip_tags";
public const string KEY_BARMODE = "toolbar_mode";
//public static void QuickSlots(int value)
//{
// Put(KEY_QUICKSLOTS, value);
//}
//
//public static int QuickSlots()
//{
// return GetInt(KEY_QUICKSLOTS, 4, 0, 4);
//}
public static void FlipToolbar(bool value)
{
Put(KEY_FLIPTOOLBAR, value);
}
public static bool FlipToolbar()
{
return GetBoolean(KEY_FLIPTOOLBAR, false);
}
public static void FlipTags(bool value)
{
Put(KEY_FLIPTAGS, value);
}
public static bool FlipTags()
{
return GetBoolean(KEY_FLIPTAGS, false);
}
public static void ToolbarMode(string value)
{
Put(KEY_BARMODE, value);
}
public static string ToolbarMode()
{
return GetString(KEY_BARMODE, PixelScene.Landscape() ? "GROUP" : "SPLIT");
}
//Game State
public const string KEY_LAST_CLASS = "last_class";
public const string KEY_CHALLENGES = "challenges";
public const string KEY_INTRO = "intro";
//public const string KEY_SUPPORT_NAGGED = "support_nagged";
public static void Intro(bool value)
{
Put(KEY_INTRO, value);
}
public static bool Intro()
{
return GetBoolean(KEY_INTRO, true);
}
public static void LastClass(int value)
{
Put(KEY_LAST_CLASS, value);
}
public static int LastClass()
{
return GetInt(KEY_LAST_CLASS, 0, 0, 3);
}
public static void Challenges(int value)
{
Put(KEY_CHALLENGES, value);
}
public static int Challenges()
{
return GetInt(KEY_CHALLENGES, 0, 0, spdd.Challenges.MAX_VALUE);
}
//public static void SupportNagged(bool value)
//{
// Put(KEY_SUPPORT_NAGGED, value);
//}
//
//public static bool SupportNagged()
//{
// return GetBoolean(KEY_SUPPORT_NAGGED, false);
//}
//Audio
public const string KEY_MUSIC = "music";
public const string KEY_MUSIC_VOL = "music_vol";
public const string KEY_SOUND_FX = "soundfx";
public const string KEY_SFX_VOL = "sfx_vol";
public static void Music(bool value)
{
watabou.noosa.audio.Music.Instance.Enable(value);
Put(KEY_MUSIC, value);
}
public static bool Music()
{
return GetBoolean(KEY_MUSIC, true);
}
public static void MusicVol(int value)
{
watabou.noosa.audio.Music.Instance.Volume(value * value / 100f);
Put(KEY_MUSIC_VOL, value);
}
public static int MusicVol()
{
return GetInt(KEY_MUSIC_VOL, 10, 0, 10);
}
public static void SoundFx(bool value)
{
Sample.Instance.Enable(value);
Put(KEY_SOUND_FX, value);
}
public static bool SoundFx()
{
return GetBoolean(KEY_SOUND_FX, true);
}
public static void SFXVol(int value)
{
Sample.Instance.Volume(value * value / 100f);
Put(KEY_SFX_VOL, value);
}
public static int SFXVol()
{
return GetInt(KEY_SFX_VOL, 10, 0, 10);
}
//Languages and Font
public const string KEY_LANG = "language";
public const string KEY_SYSTEMFONT = "system_font";
public static void Language(Languages lang)
{
Put(KEY_LANG, lang.Code());
}
public static Languages Language()
{
string code = GetString(KEY_LANG, null);
if (code == null)
{
return Languages.MatchLocale(CultureInfo.CurrentCulture);
}
else
{
return Languages.MatchCode(code);
}
}
public static void SystemFont(bool value)
{
Put(KEY_SYSTEMFONT, value);
}
public static bool SystemFont()
{
return GetBoolean(KEY_SYSTEMFONT,
(Language() == Languages.KOREAN || Language() == Languages.CHINESE || Language() == Languages.JAPANESE));
}
//Connectivity
public const string KEY_NEWS = "news";
public const string KEY_UPDATES = "updates";
public const string KEY_WIFI = "wifi";
public const string KEY_NEWS_LAST_READ = "news_last_read";
public static void News(bool value)
{
Put(KEY_NEWS, value);
}
public static bool News()
{
return GetBoolean(KEY_NEWS, true);
}
public static void Updates(bool value)
{
Put(KEY_UPDATES, value);
}
public static bool Updates()
{
return GetBoolean(KEY_UPDATES, true);
}
public static void WiFi(bool value)
{
Put(KEY_WIFI, value);
}
public static bool WiFi()
{
return GetBoolean(KEY_WIFI, true);
}
public static void NewsLastRead(long lastRead)
{
Put(KEY_NEWS_LAST_READ, lastRead);
}
public static long NewsLastRead()
{
return GetLong(KEY_NEWS_LAST_READ, 0);
}
//Window management (desktop only atm)
public const string KEY_WINDOW_WIDTH = "window_width";
public const string KEY_WINDOW_HEIGHT = "window_height";
public const string KEY_WINDOW_MAXIMIZED = "window_maximized";
public static void WindowResolution(Point p)
{
Put(KEY_WINDOW_WIDTH, p.x);
Put(KEY_WINDOW_HEIGHT, p.y);
}
public static Point WindowResolution()
{
return new Point(
GetInt(KEY_WINDOW_WIDTH, 960, 480, int.MaxValue),
GetInt(KEY_WINDOW_HEIGHT, 640, 320, int.MaxValue)
);
}
public static void WindowMaximized(bool value)
{
Put(KEY_WINDOW_MAXIMIZED, value);
}
public static bool WindowMaximized()
{
return GetBoolean(KEY_WINDOW_MAXIMIZED, false);
}
}
}