-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtendedAdminConfig.cs
More file actions
116 lines (92 loc) · 3.59 KB
/
ExtendedAdminConfig.cs
File metadata and controls
116 lines (92 loc) · 3.59 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
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using Newtonsoft.Json;
using CommonLibrary.Native;
namespace ExtendedAdmin
{
public class ExtendedAdminConfig
{
[Description("Raffle starting pot")]
public int RaffleStartPot = 100;
[Description("Minutes between raffles")]
public int RaffleDuration = 60;
[Description("The odds of winning the raffle")]
public int RaffleOdds = 65535;
[Description("The cost of a raffle ticket")]
public int RaffleTicketCost = 100;
[Description("Time between raffle updates (minutes)")]
public int RaffleUpdateDuration = 10;
[Description("Maximum number of raffle tickets")]
public int MaxRaffleTickets = 500;
[Description("Ticket percentage kept")]
public float RaffleTicketsKept = 75f;
[Description("The group players that are in prison are part of.")]
public string PrisonGroup = "Prison";
[Description("The name of the prison warp")]
public string PrisonWarp = "prison";
[Description("Shards deducted when sent to prison")]
public int PrisonShards = 5000;
[Description("The name of the bank region")]
public string BankRegion = "Bank";
public static ExtendedAdminConfig Read(string path)
{
if (!File.Exists(path))
return new ExtendedAdminConfig();
using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
{
return Read(fs);
}
}
public static ExtendedAdminConfig Read(Stream stream)
{
using (var sr = new StreamReader(stream))
{
var cf = JsonConvert.DeserializeObject<ExtendedAdminConfig>(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<ExtendedAdminConfig> ConfigRead;
static void DumpDescriptions()
{
var sb = new StringBuilder();
var defaults = new ExtendedAdminConfig();
foreach (var field in defaults.GetType().GetFields())
{
if (field.IsStatic)
continue;
var name = field.Name;
var type = field.FieldType.Name;
var descattr = field.GetCustomAttributes(false).FirstOrDefault(o => o is DescriptionAttribute) as DescriptionAttribute;
var desc = descattr != null && !string.IsNullOrWhiteSpace(descattr.Description) ? descattr.Description : "None";
var def = field.GetValue(defaults);
sb.AppendLine("## {0} ".SFormat(name));
sb.AppendLine("**Type:** {0} ".SFormat(type));
sb.AppendLine("**Description:** {0} ".SFormat(desc));
sb.AppendLine("**Default:** \"{0}\" ".SFormat(def));
sb.AppendLine();
}
File.WriteAllText("ConfigDescriptions.txt", sb.ToString());
}
}
}