-
Notifications
You must be signed in to change notification settings - Fork 0
/
Configuration.cs
46 lines (40 loc) · 1.31 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
using TShockAPI;
using Terraria.ID;
using Newtonsoft.Json;
namespace MiniEvent
{
public class Config
{
public double EventCooldown { get; set; }
public short RewardItem { get; set; }
public int RewardStack { get; set; }
public short TargetNPC { get; set;}
public List<Config> EventSettings = new List<Config>();
public static Config Read(string path)
{
if (!File.Exists(path))
{
Config config = new Config();
config.EventSettings.Add(new Config()
{
EventCooldown = 600,
RewardItem = ItemID.LifeCrystal,
RewardStack = 3,
TargetNPC = NPCID.TravellingMerchant
});
}
var json = File.ReadAllText(path);
return JsonConvert.DeserializeObject<Config>(json);
}
public static void Write(string path, Config config)
{
var json = JsonConvert.SerializeObject(config, Formatting.Indented);
File.WriteAllText(path, json);
}
public static void Reload(string path, ref Config config)
{
config = Config.Read(path);
TShock.Log.ConsoleInfo($"Reloaded config file at {path}");
}
}
}