-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
Configuration.cs
164 lines (152 loc) · 4.87 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
using Newtonsoft.Json;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Terraria;
using Terraria.ModLoader.Config;
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, ConfigManager.serializerSettings);
if (personalConfiguration == null)
personalConfiguration = new PersonalConfiguration();
}
}
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, ConfigManager.serializerSettings);
}
}
}
// 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, ConfigManager.serializerSettings);
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,
});
// ReferenceDefaultsPreservingResolver messed up with ServerConfiguration serialization.
// TODO: Migrate to regular ModConfig stuff, make proper way of initializing ModConfig saves in-game for tMod.
json = JsonConvert.SerializeObject(serverConfiguration, new JsonSerializerSettings {
Formatting = Formatting.Indented,
DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate,
ObjectCreationHandling = ObjectCreationHandling.Replace,
NullValueHandling = NullValueHandling.Ignore,
});
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 NPCDefinition[] BannedNPCs {
get {
return Menus.NPCBrowser.filteredNPCSlots.Select(type => new NPCDefinition(type)).ToArray();
}
set {
// This will forget unloaded modnpc.
List<int> loaded = value.Where(x => x != null && x.Mod != null && !x.IsUnloaded).Select(npc => npc.Type).Distinct().ToList();
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";
}
}
*/
}