This repository was archived by the owner on Apr 9, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdvancedConfigManager.cs
More file actions
69 lines (55 loc) · 2.13 KB
/
AdvancedConfigManager.cs
File metadata and controls
69 lines (55 loc) · 2.13 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
using System.Text.Json;
using UnityEngine;
namespace MasterHell.Config
{
public class AdvancedConfigManager : ConfigManager
{
private const string CONFIG_PATH = "UserData/JesusHack/Config.json";
private const string NICKNAMES_FILE_PATH = "UserData/JesusHack/NickNames.txt";
public override Config Load(string configPath)
{
Directory.CreateDirectory(Path.GetDirectoryName(CONFIG_PATH));
if (File.Exists(CONFIG_PATH))
{
try
{
var json = File.ReadAllText(CONFIG_PATH);
return JsonSerializer.Deserialize<Config?>(json, new JsonSerializerOptions
{
Converters = { new RectJsonConverter() }
}) ?? new Config();
}
catch { }
}
return Save(new Config(), CONFIG_PATH);
}
public override Config Save(Config config, string configPath)
{
var json = JsonSerializer.Serialize(config, new JsonSerializerOptions
{
WriteIndented = true,
Converters = { new RectJsonConverter() }
});
File.WriteAllText(CONFIG_PATH, json);
return config;
}
public string[] LoadNicknamesFromFile()
{
string[] userNicknames = ["Jesus", "MasterHell", "KolovraTT_", "Slendys", "VACAT1ON",
"DIPSYYY", "Henry", "BlackHub", "Klayvers", "Wanderer"];
if (File.Exists(NICKNAMES_FILE_PATH))
{
userNicknames = File.ReadAllLines(NICKNAMES_FILE_PATH);
return userNicknames;
}
File.WriteAllLines(NICKNAMES_FILE_PATH, userNicknames);
return userNicknames;
}
public KeyCode TryParseKeyCode(string keyName, KeyCode defaultValue = KeyCode.None)
{
if (Enum.TryParse(keyName, true, out KeyCode result))
return result;
return defaultValue;
}
}
}