-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathSlotColoring.cs
169 lines (146 loc) · 3.84 KB
/
SlotColoring.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
165
166
167
168
169
using System.Collections.Generic;
using static LootValue.Globals;
namespace LootValue
{
public struct LootValueConfigColor
{
public int UpperBound { get; set; }
public string HexColor { get; set; }
public LootValueConfigColor(string values)
{
values = values.Substring(1, values.Length-2);
string[] split = values.Split(':');
if (int.TryParse(split[0], out int upperBound))
UpperBound = upperBound;
else
UpperBound = int.MaxValue;
HexColor = split[1];
}
public LootValueConfigColor(int upperbound, string hexColor)
{
UpperBound = upperbound;
HexColor = hexColor;
}
public override string ToString()
{
return $"[{UpperBound}:{HexColor}]";
}
}
internal static class SlotColoring
{
public static readonly List<LootValueConfigColor> DefaultColors = new List<LootValueConfigColor>()
{
new LootValueConfigColor(5000, "#ff0000"),
new LootValueConfigColor(7500, "#ffa500"),
new LootValueConfigColor(10000, "#ffff00"),
new LootValueConfigColor(15000, "#00ff00"),
new LootValueConfigColor(20000, "#00ffff"),
new LootValueConfigColor(int.MaxValue, "#ff00ff")
};
public static List<LootValueConfigColor> Colors = new List<LootValueConfigColor>();
static SlotColoring()
{
Colors.AddRange(DefaultColors);
}
public static void ReadColors(string configString)
{
if (CheckConfigStringFormat(configString))
{
Colors.Clear();
string[] bounds = configString.Split(',');
foreach (string bound in bounds)
{
var t = new LootValueConfigColor(bound);
Colors.Add(t);
}
}
else
{
string msg = $"Custom colors string format was invalid. Load default colors";
logger.LogWarning(msg);
NotificationManagerClass.DisplayWarningNotification(msg);
UseDefaultColors();
}
}
public static void UseDefaultColors()
{
Colors.Clear();
Colors.AddRange(DefaultColors);
}
private static bool CheckConfigStringFormat(string configString)
{
string[] bounds = configString.Split(',');
for (int i = 0; i < bounds.Length; i++)
{
string bound = bounds[i];
if (!bound.StartsWith("["))
{
string msg = $"Custom color format failed. Entry #{i} must start with an [";
logger.LogWarning(msg);
NotificationManagerClass.DisplayWarningNotification(msg);
return false;
}
if (!bound.EndsWith("]"))
{
string msg = $"Custom color format failed. Entry #{i} must end with an ]";
logger.LogWarning(msg);
NotificationManagerClass.DisplayWarningNotification(msg);
return false;
}
string[] values = bound.Substring(1, bound.Length - 2).Split(':');
if (values.Length == 2)
{
if (!int.TryParse(values[0], out int value))
{
if (i == bounds.Length - 1)
continue;
else
{
string msg = $"Custom color format failed. Entry #{i} has invalid upper bound";
logger.LogWarning(msg);
NotificationManagerClass.DisplayWarningNotification(msg);
return false;
}
}
}
else
{
string msg = $"Custom color format failed. Entry #{i} is missing element";
logger.LogWarning(msg);
NotificationManagerClass.DisplayWarningNotification(msg);
return false;
}
}
return true;
}
private enum ESlotColor
{
Red,
Orange,
Yellow,
Green,
Lightblue,
Pink
}
static Dictionary<ESlotColor, string> slotColors { get; } = new Dictionary<ESlotColor, string>()
{
{ ESlotColor.Red, "#ff0000" },
{ ESlotColor.Orange, "#ffa500" },
{ ESlotColor.Yellow, "#ffff00" },
{ ESlotColor.Green, "#00ff00" },
{ ESlotColor.Lightblue, "#00ffff" },
{ ESlotColor.Pink, "#ff00ff" }
};
public static string GetColorFromValuePerSlots(int valuePerSlot)
{
foreach(var bound in Colors)
{
if (valuePerSlot < bound.UpperBound)
{
return bound.HexColor;
}
}
return "#ff00ff";
}
}
}