Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
WorldPalette.cs
浏览该文件的文档.
1using Engine;
4
5namespace Game {
6 public class WorldPalette {
7 public const int MaxColors = 16;
8 public const int MaxNameLength = 16;
9
10 public static readonly Color[] DefaultColors = [
11 new(255, 255, 255),
12 new(181, 255, 255),
13 new(255, 181, 255),
14 new(160, 181, 255),
15 new(255, 240, 160),
16 new(181, 255, 181),
17 new(255, 181, 160),
18 new(181, 181, 181),
19 new(112, 112, 112),
20 new(32, 112, 112),
21 new(112, 32, 112),
22 new(26, 52, 128),
23 new(87, 54, 31),
24 new(24, 116, 24),
25 new(136, 32, 32),
26 new(24, 24, 24)
27 ];
28
29 public Color[] Colors;
30 public string[] Names;
31 public const string fName = "WorldPalette";
32
33 public WorldPalette() {
34 Colors = DefaultColors.ToArray();
35 Names = LanguageControl.jsonNode[fName]["Colors"].AsArray().Select(x => x.ToString()).ToArray();
36 }
37
38 public WorldPalette(ValuesDictionary valuesDictionary) {
39 string[] array = valuesDictionary.GetValue("Colors", new string(';', 15)).Split(';');
40 if (array.Length != MaxColors) {
41 throw new InvalidOperationException(LanguageControl.Get(fName, 0));
42 }
43 Colors = array.Select((s, i) => !string.IsNullOrEmpty(s) ? HumanReadableConverter.ConvertFromString<Color>(s) : DefaultColors[i])
44 .ToArray();
45 string[] array2 = valuesDictionary.GetValue("Names", new string(';', 15)).Split(';');
46 if (array2.Length != MaxColors) {
47 throw new InvalidOperationException(LanguageControl.Get(fName, 1));
48 }
49 Names = array2.Select((s, i) => !string.IsNullOrEmpty(s) ? s : LanguageControl.GetWorldPalette(i)).ToArray();
50 string[] names = Names;
51 int num = 0;
52 while (true) {
53 if (num < names.Length) {
54 if (!VerifyColorName(names[num])) {
55 break;
56 }
57 num++;
58 continue;
59 }
60 return;
61 }
62 throw new InvalidOperationException(LanguageControl.Get(fName, 2));
63 }
64
66 ValuesDictionary valuesDictionary = new();
67 string value = string.Join(
68 ";",
69 Colors.Select((c, i) => !(c == DefaultColors[i]) ? HumanReadableConverter.ConvertToString(c) : string.Empty)
70 );
71 string value2 = string.Join(";", Names.Select((n, i) => !(n == LanguageControl.Get(fName, i)) ? n : string.Empty));
72 valuesDictionary.SetValue("Colors", value);
73 valuesDictionary.SetValue("Names", value2);
74 return valuesDictionary;
75 }
76
77 public void CopyTo(WorldPalette palette) {
78 palette.Colors = Colors.ToArray();
79 palette.Names = Names.ToArray();
80 }
81
82 public static bool VerifyColorName(string name) {
83 if (name.Length < 1
84 || name.Length > MaxNameLength) {
85 return false;
86 }
87 foreach (char c in name) {
88 if (!char.IsLetterOrDigit(c)
89 && c != '-'
90 && c != ' ') {
91 return false;
92 }
93 }
94 return true;
95 }
96 }
97}
static object ConvertFromString(Type type, string data)
static string GetWorldPalette(int index)
static string Get(string className, int key)
获取在当前语言类名键对应的字符串
void CopyTo(WorldPalette palette)
static bool VerifyColorName(string name)
WorldPalette(ValuesDictionary valuesDictionary)
ValuesDictionary Save()
static readonly Color[] DefaultColors