forked from JavidPack/CheatSheet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Configuration.cs
169 lines (157 loc) · 4.58 KB
/
Configuration.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
using Newtonsoft.Json;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Terraria;
using Terraria.ModLoader;
namespace CheatSheet
{
internal class ConfigurationLoader
{
private static string jsonDatabaseFilenamePersonal = "CheatSheetConfig.json";
private static string jsonDatabaseFilenameServer = "CheatSheetConfig_Server.json";
internal static PersonalConfiguration personalConfiguration;
internal static ServerConfiguration serverConfiguration;
internal static void Initialized()
{
personalConfiguration = new PersonalConfiguration();
// Reset?
Directory.CreateDirectory(Main.SavePath);
string path = string.Concat(new object[]
{
Main.SavePath,
Path.DirectorySeparatorChar,
jsonDatabaseFilenamePersonal,
});
if (File.Exists(path))
{
using (StreamReader r = new StreamReader(path))
{
string json = r.ReadToEnd();
personalConfiguration = JsonConvert.DeserializeObject<PersonalConfiguration>(json);
}
}
serverConfiguration = new ServerConfiguration();
Directory.CreateDirectory(Main.SavePath);
path = string.Concat(new object[]
{
Main.SavePath,
Path.DirectorySeparatorChar,
jsonDatabaseFilenameServer,
});
if (File.Exists(path))
{
using (StreamReader r = new StreamReader(path))
{
string json = r.ReadToEnd();
serverConfiguration = JsonConvert.DeserializeObject<ServerConfiguration>(json);
}
}
}
// Saves personal settings, and if not client, saves serversettings too.
public static void SaveSetting()
{
Directory.CreateDirectory(Main.SavePath);
string path = string.Concat(new object[]
{
Main.SavePath,
Path.DirectorySeparatorChar,
jsonDatabaseFilenamePersonal,
});
string json = JsonConvert.SerializeObject(personalConfiguration, Formatting.Indented);
File.WriteAllText(path, json);
// If not MP client.
if (Main.netMode != 1)
{
Directory.CreateDirectory(Main.SavePath);
path = string.Concat(new object[]
{
Main.SavePath,
Path.DirectorySeparatorChar,
jsonDatabaseFilenameServer,
});
json = JsonConvert.SerializeObject(serverConfiguration, Formatting.Indented);
File.WriteAllText(path, json);
}
}
}
internal class PersonalConfiguration
{
public bool ItemBrowser = true;
public bool NPCBrowser = true;
public bool RecipeBrowser = true;
public bool MinionBooster = true;
public bool PaintTools = true;
public bool ExtraAccessorySlots = true;
public bool Butcher = true;
public bool Waypoints = true;
public bool SpawnRate = true;
public bool ModExtensions = true;
public bool ClearMenu = true;
public bool Vacuum = true;
public bool LightHack = true;
public bool GodMode = true;
//public bool BossDowner = true;
//public bool EventManager = true;
[JsonIgnore]
public bool HiddenTest = true;
//public int[] BannedVanillaNPCIDs {
// get {
// return Menus.NPCBrowser.filteredNPCSlots.ToArray();
// }
// set {
// Menus.NPCBrowser.filteredNPCSlots = new List<int>(value);
// }
//}
}
internal class ServerConfiguration
{
public JSONNPC[] BannedNPCs
{
get
{
return Menus.NPCBrowser.filteredNPCSlots.Select(
type => NPCLoader.GetNPC(type) == null ? new JSONNPC(null, Lang.GetNPCNameValue(type), type) : new JSONNPC(NPCLoader.GetNPC(type).mod.Name, NPCLoader.GetNPC(type).Name, 0)
).ToArray();
}
set
{
// Vanilla are saved as Name and type, type is used, name is just for reading convenience.
// Modded are stored as Classname
List<int> loaded = value.Select(
jsonnpc => jsonnpc.id != 0 ? jsonnpc.id : (ModLoader.GetMod(jsonnpc.mod)?.NPCType(jsonnpc.name) ?? -100)
).ToList();
loaded.RemoveAll(x => x == -100);
Menus.NPCBrowser.filteredNPCSlots = loaded;
Menus.NPCBrowser.needsUpdate = true;
}
}
}
//["mod"] = NPCLoader.GetNPC(type).mod.Name,
//["name"] = Main.npcName[type],
//Mod mod = ModLoader.GetMod(tag.GetString("mod"));
// int type = mod?.NPCType(tag.GetString("name")) ?? 0;
// if (type > 0)
// NPC.killCount[type] = tag.GetInt("count");
public class JSONNPC
{
public string mod;
public string name;
public int id;
public JSONNPC(string mod, string name, int id)
{
this.mod = mod;
this.name = name;
this.id = id;
if (id != 0)
{
this.mod = "Terraria";
}
}
// We only want to serialize id when name is null, meaning it's a vanilla npc. ModNPC have a guaranteed (ModName, Name) uniqueness. Name for vanilla is just convinience for editing json manually.
public bool ShouldSerializeid()
{
return mod == "Terraria";
}
}
}