-
Notifications
You must be signed in to change notification settings - Fork 9
/
Config.cs
99 lines (87 loc) · 2.99 KB
/
Config.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
using System;
using System.IO;
using Newtonsoft.Json;
using TShockAPI;
namespace KeyChanger
{
public class Config
{
public bool UseSSC = true; // |Enabling grants legacy functionality, disabling uses the safer drop method
public bool EnableRegionExchanges = false; // |Default set to false
public bool MarketMode = false; // |Use only a general market region
//public bool EnableGoldKey = true; // |Gold Key works similar to a currency
public bool EnableTempleKey = true;
public bool EnableJungleKey = true;
public bool EnableCorruptionKey = true;
public bool EnableCrimsonKey = true;
public bool EnableHallowedKey = true;
public bool EnableFrozenKey = true;
public int[] TempleKeyItem = new int[] { 1293 }; // |Lihzahrd Power Cell
public int[] JungleKeyItem = new int[] { 1156 }; // |Piranha Gun
public int[] CorruptionKeyItem = new int[] { 1571 }; // |Scourge of the Corruptor
public int[] CrimsonKeyItem = new int[] { 1569 }; // |Vampire Knifes
public int[] HallowedKeyItem = new int[] { 1260 }; // |Rainbow Gun
public int[] FrozenKeyItem = new int[] { 1572 }; // |Frost Hydra Staff
// Those are optional; They're only needed if EnableRegionExchanges is set to true. Default is set to null,
// so that players can be informed of non-existing regions.
public string MarketRegion = null;
public string TempleRegion = null;
public string JungleRegion = null;
public string CorruptionRegion = null;
public string CrimsonRegion = null;
public string HallowedRegion = null;
public string FrozenRegion = null;
public static Config Read(string savepath = "")
{
// Default to tshock path if no path is given
if (String.IsNullOrWhiteSpace(savepath))
{
savepath = TShock.SavePath;
}
// Append the file name to the given path
savepath = Path.Combine(savepath, "KeyChangerConfig.json");
// Creates any missing folders
Directory.CreateDirectory(Path.GetDirectoryName(savepath));
try
{
Config file = new Config();
if (File.Exists(savepath))
{
// Get data from the file
file = JsonConvert.DeserializeObject<Config>(File.ReadAllText(savepath));
}
else
{
TShock.Log.ConsoleInfo("Creating config file for KeyChangerSSC...");
}
// Create or update the file to fix missing options
File.WriteAllText(savepath, JsonConvert.SerializeObject(file, Formatting.Indented));
return file;
}
catch (Exception ex)
{
TShock.Log.ConsoleError(ex.ToString());
return new Config();
}
}
public bool Write(string savepath = "")
{
if (String.IsNullOrWhiteSpace(savepath))
{
savepath = TShock.SavePath;
}
savepath = Path.Combine(savepath, "KeyChangerConfig.json");
Directory.CreateDirectory(Path.GetDirectoryName(savepath));
try
{
File.WriteAllText(savepath, JsonConvert.SerializeObject(this, Formatting.Indented));
return true;
}
catch (Exception ex)
{
TShock.Log.ConsoleError(ex.ToString());
return false;
}
}
}
}