forked from cnamqui/Custom-Monsters-Plugin--Tshock-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCustomMonsterConfig.cs
More file actions
61 lines (54 loc) · 1.61 KB
/
CustomMonsterConfig.cs
File metadata and controls
61 lines (54 loc) · 1.61 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
using System;
using System.IO;
using System.Collections.Generic;
using System.Reflection;
using System.Drawing;
using Terraria;
using TShockAPI;
using TShockAPI.DB;
using System.ComponentModel;
using System.Text;
using Newtonsoft.Json;
namespace CustomMonsters
{
public class CustomMonsterConfigFile
{
public int CustomSpawnRate = 600;
public int MaxCustomSpawns = 5;
public static CustomMonsterConfigFile Read(string path)
{
if (!File.Exists(path))
return new CustomMonsterConfigFile();
using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
{
return Read(fs);
}
}
public static CustomMonsterConfigFile Read(Stream stream)
{
using (var sr = new StreamReader(stream))
{
var cf = JsonConvert.DeserializeObject<CustomMonsterConfigFile>(sr.ReadToEnd());
if (ConfigRead != null)
ConfigRead(cf);
return cf;
}
}
public void Write(string path)
{
using (var fs = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Write))
{
Write(fs);
}
}
public void Write(Stream stream)
{
var str = JsonConvert.SerializeObject(this, Formatting.Indented);
using (var sw = new StreamWriter(stream))
{
sw.Write(str);
}
}
public static Action<CustomMonsterConfigFile> ConfigRead;
}
}