-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLevel.cs
More file actions
679 lines (634 loc) · 28.7 KB
/
Level.cs
File metadata and controls
679 lines (634 loc) · 28.7 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
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Reflection;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using SharpFAI.Util;
namespace SharpFAI.Serialization
{
/// <summary>
/// 表示一个 ADOFAI 关卡,具有解析和操作功能
/// Represents an ADOFAI level with parsing and manipulation capabilities
/// </summary>
public class Level
{
/// <summary>
/// 表示关卡数据的 JSON 对象
/// JSON object representing level data
/// </summary>
public JObject root
{
get
{
_root["actions"] = actions;
_root["angleData"] = angleData;
_root["settings"] = settings;
if (decorations != null)
{
_root["decorations"] = decorations;
}
return _root;
}
}
private readonly JObject _root;
/// <summary>
/// 表示关卡设置的 JSON 对象
/// JSON object representing level settings
/// </summary>
private JObject settings{ get; }
/// <summary>
/// 表示关卡砖块角度的 JSON 数组
/// JSON array representing the angle of level tiles
/// </summary>
public JArray angleData{ get; private set; }
/// <summary>
/// 表示所有关卡事件的 JSON 数组
/// JSON array representing level actions
/// </summary>
public JArray actions{ get; }
/// <summary>
/// 表示所有关卡装饰的 JSON 数组
/// JSON array representing level decorations
/// </summary>
public JArray? decorations{ get; }
/// <summary>
/// 表示关卡砖块角度的只读列表
/// Read-only list representing the angle of level tiles
/// </summary>
public ReadOnlyCollection<double> angles { get; private set; }
/// <summary>
/// 表示关卡文件路径的字符串
/// Path to the level file
/// </summary>
public string? pathToLevel { get; }
/// <summary>
/// 反序列化后的所有事件
/// All events after deserialization
/// </summary>
public ReadOnlyCollection<BaseEvent>? deserializedEvents { get; private set; }
/// <summary>
/// 通过关卡信息字典初始化 Level 类的新实例
/// Initializes a new instance of the Level class from level information dictionary
/// </summary>
/// <param name="levelInfo">表示关卡信息的字典 / Dictionary representing level information</param>
public Level(Dictionary<string, object>? levelInfo)
{
_root = JObject.Parse(
JsonConvert.SerializeObject(levelInfo));
actions = _root["actions"].ToObject<JArray>();
if (_root.ContainsKey("angleData"))
{
angleData = _root["angleData"].ToObject<JArray>();
angles = angleData.ToObject<List<double>>().AsReadOnly();
}
else if (_root.ContainsKey("pathData"))
{
InitAngleData();
}
settings = _root["settings"].ToObject<JObject>();
if (settings["version"].Value<int>() > 10)
{
decorations = _root["decorations"].ToObject<JArray>();
}
deserializedEvents = DeserializeEvents();
}
public static bool operator ==(Level a, Level b)
{
// 处理两个对象都为 null 的情况
if (ReferenceEquals(a, b)) return true;
// 处理其中一个为 null 的情况
if (a is null || b is null) return false;
// 如果都有路径,则比较路径
if (a.pathToLevel != null && b.pathToLevel != null) return a.pathToLevel == b.pathToLevel;
// 否则比较各个属性
return JToken.DeepEquals(a._root, b._root) &&
JToken.DeepEquals(a.decorations, b.decorations) &&
JToken.DeepEquals(a.settings, b.settings) &&
JToken.DeepEquals(a.angleData, b.angleData) &&
JToken.DeepEquals(a.actions, b.actions);
}
public static bool operator !=(Level a, Level b)
{
return !(a == b);
}
/// <summary>
/// 通过文件路径加载并初始化 Level 类的新实例,使用隐式转换符
/// Initializes a new instance of the Level class by loading from a file path, using the implicit conversion operator
/// </summary>
/// <param name="pathToLevel">关卡文件路径 / Path to the level file</param>
public static implicit operator Level(string pathToLevel)
{
return new Level(SimpleJSON.DeserializeFile(pathToLevel));
}
/// <summary>
/// 隐式转换,将Level对象转换为JSON
/// Implicit conversion, converting the Level object to JSON
/// </summary>
/// <param name="level"></param>
/// <returns></returns>
public static implicit operator JObject(Level level)
{
return JObject.Parse(level.ToString());
}
/// <summary>
/// 通过文件路径加载并初始化 Level 类的新实例
/// Initializes a new instance of the Level class by loading from a file path
/// </summary>
/// <param name="pathToLevel">关卡文件路径 / Path to the level file</param>
public Level(string? pathToLevel) : this(SimpleJSON.DeserializeFile(pathToLevel))
{
this.pathToLevel = pathToLevel;
}
/// <summary>
/// 使用默认设置创建一个新关卡并可选保存到指定路径
/// Creates a new level with default settings and optionally saves it to the specified path
/// </summary>
/// <param name="savePath">保存新关卡的路径(可选)/ Path to save the new level to (optional)</param>
/// <returns>新的 Level 实例 / A new Level instance</returns>
public static Level CreateNewLevel(string? savePath = null)
{
JObject root = new();
root["angleData"] = new JArray([0,0,0,0,0,0,0,0,0,0]);
root["settings"] = JObject.FromObject(new
{
version = 14,
author = "Created Level by SharpFAI",
bpm = 100,
offset = 0,
pitch = 100
});
root["actions"] = new JArray();
root["decorations"] = new JArray();
if (savePath != null)
{
File.WriteAllText(savePath, root.ToString());
}
return new(JsonConvert.DeserializeObject<Dictionary<string,object>>(root.ToString()));
}
/// <summary>
/// 当 angleData 不存在时从路径数据初始化角度数据
/// Initializes angle data from path data when angleData is not present
/// </summary>
private void InitAngleData()
{
if (this.angles?.Any() ?? false) return;
List<TileAngle> tileAngles = _root["pathData"]
.ToObject<string>()
.ToCharArray()
.Select(c => TileAngle.AngleCharMap[c])
.ToList();
double staticAngle = 0d;
List<double> angles = [];
foreach (TileAngle angle in tileAngles) {
if (angle == TileAngle.NONE) {
angles.Add(angle.Angle);
continue;
}
staticAngle = angle.Relative ? FloatMath.GeneralizeAngle(staticAngle + 180 - angle.Angle) : angle.Angle;
angles.Add(staticAngle);
}
this.angles = angles.AsReadOnly();
_root.Remove("pathData");
angleData = JArray.FromObject(angles);
_root.Add("angleData", angleData);
}
/// <summary>
/// 获取指定类型的设置值
/// Gets a setting value with the specified type
/// </summary>
/// <typeparam name="T">要转换设置的类型 / The type to convert the setting to</typeparam>
/// <param name="setting">设置名称 / The setting name</param>
/// <returns>转换为类型 T 的设置值 / The setting value converted to type T</returns>
public T GetSetting<T>(string setting)
{
return settings[setting].ToObject<T>();
}
/// <summary>
/// 设置指定类型的设置值
/// Sets a setting value with the specified type
/// </summary>
/// <typeparam name="T">要设置的值的类型 / The type of the value to set</typeparam>
/// <param name="setting">设置名称 / The setting name</param>
/// <param name="value">要设置的值 / The value to set</param>
public void PutSetting<T>(string setting, T value)
{
settings[setting] = JToken.FromObject(value);
}
/// <summary>
/// 检查关卡中是否存在某个设置
/// Checks if a setting exists in the level
/// </summary>
/// <param name="setting">要检查的设置名称 / The setting name to check</param>
/// <returns>如果设置存在则返回 true,否则返回 false / True if the setting exists, false otherwise</returns>
public bool HasSetting(string setting)
{
return settings.ContainsKey(setting);
}
/// <summary>
/// 设置关卡的曲目
/// Sets the song for the level
/// </summary>
/// <param name="songPath">歌曲文件路径 / Path to the song file</param>
public void SetSong(string songPath)
{
PutSetting("songFilename",Path.GetFileName(songPath));
File.Copy(songPath, Path.Combine(Path.GetDirectoryName(pathToLevel), Path.GetFileName(songPath)), true);
}
/// <summary>
/// 向指定地板添加事件
/// Adds an event to the specified floor
/// </summary>
/// <param name="floor">要添加事件的地板编号 / The floor number to add the event to</param>
/// <param name="type">事件类型 / The event type</param>
/// <param name="data">事件的可选附加数据 / Optional additional data for the event</param>
public void AddEvent(int floor, EventType type, JObject data = null)
{
JObject newEvent = new JObject();
newEvent["floor"] = floor;
newEvent["eventType"] = type.ToString();
if (data != null)
{
foreach (var kvpair in data)
{
newEvent[kvpair.Key] = kvpair.Value;
}
}
actions.Add(newEvent);
_root["actions"] = actions;
}
/// <summary>
/// 添加事件
/// Adds an event
/// </summary>
/// <param name="eventInfo">要添加的事件信息 / Event information to be added</param>
public void AddEvent(BaseEvent eventInfo)
{
JObject newEvent = JObject.Parse(eventInfo.ToString());
actions.Add(newEvent);
}
/// <summary>
/// 从关卡中移除多个设置
/// Removes multiple settings from the level
/// </summary>
/// <param name="settingsToRemove">要移除的设置名称数组 / Array of setting names to remove</param>
public void RemoveSettings(params string[] settingsToRemove)
{
foreach (string setting in settingsToRemove)
{
settings.Remove(setting);
}
_root["settings"] = settings;
}
/// <summary>
/// 获取指定地板上特定类型的所有事件
/// Gets all events of a specific type on a specific floor
/// </summary>
/// <param name="floor">地板编号 / The floor number</param>
/// <param name="type">事件类型 / The event type</param>
/// <returns>符合条件的事件列表 / List of events matching the criteria</returns>
public List<JObject> GetEvents(int floor, EventType type)
{
var events = new List<JObject>();
foreach (var baseEvent in deserializedEvents)
{
if (baseEvent.Floor == floor && baseEvent.EventType == type)
{
events.Add(JObject.Parse(baseEvent.ToString()));
}
}
return events;
}
/// <summary>
/// 获取指定地板上的所有事件
/// Gets all events on a specific floor
/// </summary>
/// <param name="floor">地板编号 / The floor number</param>
/// <returns>该地板上所有事件的列表 / List of all events on the floor</returns>
public JArray GetFloorEvents(int floor)
{
var events = new JArray();
foreach (JObject action in actions)
{
if (action["floor"].Value<int>() == floor)
{
events.Add(action);
}
}
return events;
}
/// <summary>
/// 检查地板是否有任何事件
/// Checks if a floor has any events
/// </summary>
/// <param name="floor">要检查的地板编号 / The floor number to check</param>
/// <returns>如果地板有事件则返回 true,否则返回 false / True if the floor has events, false otherwise</returns>
public bool HasEvents(int floor)
{
return GetFloorEvents(floor).Any();
}
/// <summary>
/// 移除满足特定条件的事件
/// Removes events that meet a specific condition
/// </summary>
/// <param name="condition">用于判断事件是否应被移除的条件 / The condition to determine if an event should be removed</param>
public void RemoveEventsIf(Func<BaseEvent, bool> condition)
{
for (int i = 0; i < actions.Count; i++)
{
BaseEvent? a = EventJsonConverter.Deserialize<BaseEvent>(actions[i].ToString());
if (condition(a))
{
actions.RemoveAt(i);
i--;
}
}
_root["actions"] = actions;
if (decorations == null) return;
for (int i = 0; i < decorations.Count; i++)
{
BaseEvent? a = EventJsonConverter.Deserialize<BaseEvent>(decorations[i].ToString());
if (condition(a ?? BaseEvent.Empty))
{
decorations.RemoveAt(i);
i--;
}
}
_root["decorations"] = decorations;
}
/// <summary>
/// 检查地板是否有特定类型的事件
/// Checks if a floor has events of a specific type
/// </summary>
/// <param name="floor">要检查的地板编号 / The floor number to check</param>
/// <param name="type">要检查的事件类型 / The event type to check for</param>
/// <returns>如果地板有指定类型的事件则返回 true,否则返回 false / True if the floor has events of the specified type, false otherwise</returns>
public bool HasEvents(int floor, EventType type)
{
return GetEvents(floor, type).Any();
}
/// <summary>
/// 从地板中移除特定类型的事件
/// Removes events of a specific type from a floor
/// </summary>
/// <param name="floor">地板编号 / The floor number</param>
/// <param name="type">要移除的事件类型 / The event type to remove</param>
/// <param name="count">要移除的事件数量(默认:1)/ Number of events to remove (default: 1)</param>
public void RemoveFloorEvents(int floor, EventType type, int count = 1)
{
int eventsRemoved = 0;
foreach (JObject action in actions)
{
if (action["floor"].Value<int>() == floor && action["eventType"].Value<string>() == type.ToString())
actions.Remove(action);
if (++eventsRemoved == count) break;
}
_root["actions"] = actions;
}
/// <summary>
/// 向关卡添加文本装饰
/// Adds text decoration to the level
/// </summary>
/// <param name="floor">地板编号(默认:0)/ The floor number (default: 0)</param>
/// <param name="text">文本内容(默认:空)/ The text content (default: empty)</param>
/// <param name="tag">装饰标签(默认:空)/ The decoration tag (default: empty)</param>
/// <param name="relativeToScreen">是否相对于屏幕或瓦片(默认:false)/ Whether relative to screen or tile (default: false)</param>
/// <param name="data">可选的附加数据 / Optional additional data</param>
public void AddTextToDecorations(int floor = 0, string text = "", string tag = "",bool relativeToScreen = false, JObject data = null)
{
JObject newText = new JObject();
newText["decText"] = text;
newText["font"] = "Default";
if (data != null)
{
foreach (var kvpair in data)
{
newText[kvpair.Key] = kvpair.Value;
}
}
AddDecoration(floor,EventType.AddText, tag, relativeToScreen, newText);
}
/// <summary>
/// 向关卡添加装饰
/// Adds a decoration to the level
/// </summary>
/// <param name="floor">地板编号(默认:0)/ The floor number (default: 0)</param>
/// <param name="type">装饰类型(默认:AddDecoration)/ The decoration type (default: AddDecoration)</param>
/// <param name="tag">装饰标签(默认:空)/ The decoration tag (default: empty)</param>
/// <param name="relativeToScreen">是否相对于屏幕或瓦片(默认:false)/ Whether relative to screen or tile (default: false)</param>
/// <param name="data">可选的附加数据 / Optional additional data</param>
public void AddDecoration(int floor = 0, EventType type = EventType.AddDecoration, string tag = "", bool relativeToScreen = false, JObject data = null)
{
JObject newDecoration = new JObject();
if (!relativeToScreen)
{
newDecoration["floor"] = floor;
}
newDecoration["eventType"] = type.ToString();
newDecoration["tag"] = tag;
newDecoration["decorationImage"] = "";
newDecoration["relativeTo"] = relativeToScreen ? "Camera" : "Tile";
newDecoration["depth"] = -1;
if (data != null)
{
foreach (var kvpair in data)
{
newDecoration[kvpair.Key] = kvpair.Value;
}
}
decorations.Add(newDecoration);
_root["decorations"] = decorations;
}
/// <summary>
/// Saves the level to a file
/// 将关卡保存到文件
/// </summary>
/// <param name="newLevelPath">The file path to save as / 保存的文件路径 </param>
/// <param name="indent">Whether to format with indentation (default: true) / 是否使用缩进格式化(默认:true)</param>
public void Save(string? newLevelPath = null, bool indent = true)
{
if (newLevelPath == null && pathToLevel != null)
{
newLevelPath = Path.Combine(Path.GetDirectoryName(pathToLevel),"level-modified.adofai");
}
else if (newLevelPath == null && pathToLevel == null)
{
throw new ArgumentNullException(nameof(newLevelPath));
}
File.WriteAllText(newLevelPath, ToString(indent));
}
/// <summary>
/// Converts the level to JSON string representation
/// 将关卡转换为JSON字符串表示
/// </summary>
/// <param name="indent">Whether to format with indentation (default: true) / 是否使用缩进格式化(默认:true)</param>
/// <returns>JSON string representation of the level / 关卡的JSON字符串表示</returns>
public string ToString(bool indent = true)
{
_root["actions"] = actions;
_root["angleData"] = angleData;
_root["settings"] = settings;
if (decorations != null)
{
_root["decorations"] = decorations;
}
JsonSerializerSettings serializerSettings = new JsonSerializerSettings();
serializerSettings.Formatting = Formatting.Indented;
if (!indent)
{
serializerSettings.Formatting = Formatting.None;
}
return JsonConvert.SerializeObject(_root, serializerSettings);
}
/// <summary>
/// Converts the level to JSON string
/// 将关卡转换为JSON字符串
/// </summary>
/// <returns></returns>
public override string ToString()
{
return ToString(false);
}
/// <summary>
/// Gets all events of a specific type from the level
/// 从关卡中获取特定类型的所有事件
/// </summary>
/// <param name="type">The event type to search for / 要搜索的事件类型</param>
/// <returns>Array of events matching the specified type / 匹配指定类型的事件数组</returns>
public JArray GetEvents(EventType type)
{
JArray events = [];
foreach (var action in actions)
{
if (action["eventType"].Value<string>() == type.ToString())
{
events.Add(action);
}
}
return events;
}
/// <summary>
/// 获取满足指定条件的所有事件
/// Gets all events that satisfy the specified condition
/// </summary>
/// <param name="condition">用于确定事件是否应包含在列表中的委托 / Delegate to determine whether an event should be included in the list</param>
/// <returns>满足条件的事件列表 / A list of events that meet the condition</returns>
public List<BaseEvent> GetEventsIf(Func<BaseEvent, bool> condition)
{
List<BaseEvent> events = [];
for (int i = 0; i < actions.Count; i++)
{
BaseEvent @event = EventJsonConverter.Deserialize<BaseEvent>(actions[i].ToString()) ?? BaseEvent.Empty;
if (condition(@event))
{
events.Add(@event);
}
}
if (decorations == null) return events;
for (int i = 0; i < decorations.Count; i++)
{
BaseEvent @event = EventJsonConverter.Deserialize<BaseEvent>(decorations[i].ToString()) ?? BaseEvent.Empty;
if (condition(@event))
{
events.Add(@event);
}
}
return events;
}
/// <summary>
/// Deserializes level events into strongly-typed objects; optionally includes decorations when requested
/// 将关卡事件反序列化为强类型对象;可选按需包含装饰
/// </summary>
/// <param name="includeDecorations">Whether to also deserialize decorations / 是否同时反序列化装饰</param>
/// <returns>Read-only list of events in the same order as actions (and decorations if included); returns empty list when none / 只读的事件列表,顺序与 actions(以及包含时的 decorations)一致;若无事件返回空列表而非 null</returns>
public ReadOnlyCollection<BaseEvent> DeserializeEvents(bool includeDecorations = false)
{
if (deserializedEvents == null)
{
List<BaseEvent> baseEvents = [];
baseEvents.AddRange(JsonConvert.DeserializeObject<BaseEvent[]>(actions.ToString(), EventJsonConverter.GetJsonSettings()));
if (includeDecorations && decorations != null)
{
baseEvents.AddRange(JsonConvert.DeserializeObject<BaseEvent[]>(decorations.ToString(), EventJsonConverter.GetJsonSettings()));
}
deserializedEvents = baseEvents.AsReadOnly();
}
return deserializedEvents;
}
/// <summary>
/// 获取音频绝对路径
/// Get audio absolute path
/// </summary>
/// <returns>Absolute path to audio file / 音频文件的绝对路径</returns>
public string GetAudioPath()
{
if (string.IsNullOrEmpty(settings["songFilename"].ToObject<string>()))
{
throw new FileNotFoundException("Audio file not found");
}
return Path.Combine(Path.GetDirectoryName(pathToLevel), settings["songFilename"].Value<string>());
}
}
internal class TileAngle
{
public static readonly TileAngle _0 = new TileAngle('R', 0, false);
public static readonly TileAngle _15 = new TileAngle('p', 15, false);
public static readonly TileAngle _30 = new TileAngle('J', 30, false);
public static readonly TileAngle _45 = new TileAngle('E', 45, false);
public static readonly TileAngle _60 = new TileAngle('T', 60, false);
public static readonly TileAngle _75 = new TileAngle('o', 75, false);
public static readonly TileAngle _90 = new TileAngle('U', 90, false);
public static readonly TileAngle _105 = new TileAngle('q', 105, false);
public static readonly TileAngle _120 = new TileAngle('G', 120, false);
public static readonly TileAngle _135 = new TileAngle('Q', 135, false);
public static readonly TileAngle _150 = new TileAngle('H', 150, false);
public static readonly TileAngle _165 = new TileAngle('W', 165, false);
public static readonly TileAngle _180 = new TileAngle('L', 180, false);
public static readonly TileAngle _195 = new TileAngle('x', 195, false);
public static readonly TileAngle _210 = new TileAngle('N', 210, false);
public static readonly TileAngle _225 = new TileAngle('Z', 225, false);
public static readonly TileAngle _240 = new TileAngle('F', 240, false);
public static readonly TileAngle _255 = new TileAngle('V', 255, false);
public static readonly TileAngle _270 = new TileAngle('D', 270, false);
public static readonly TileAngle _285 = new TileAngle('Y', 285, false);
public static readonly TileAngle _300 = new TileAngle('B', 300, false);
public static readonly TileAngle _315 = new TileAngle('C', 315, false);
public static readonly TileAngle _330 = new TileAngle('M', 330, false);
public static readonly TileAngle _345 = new TileAngle('A', 345, false);
public static readonly TileAngle _5 = new TileAngle('5', 108, true);
public static readonly TileAngle _6 = new TileAngle('6', 252, true);
public static readonly TileAngle _7 = new TileAngle('7', 900.0 / 7.0, true);
public static readonly TileAngle _8 = new TileAngle('8', 360 - 900.0 / 7.0, true);
public static readonly TileAngle R60 = new TileAngle('t', 60, true);
public static readonly TileAngle R120 = new TileAngle('h', 120, true);
public static readonly TileAngle R240 = new TileAngle('j', 240, true);
public static readonly TileAngle R300 = new TileAngle('y', 300, true);
public static readonly TileAngle NONE = new TileAngle('!', 999, true);
public static readonly Dictionary<char, TileAngle> AngleCharMap = new Dictionary<char, TileAngle>();
static TileAngle()
{
foreach (var field in typeof(TileAngle).GetFields(BindingFlags.Public | BindingFlags.Static))
{
if (field.FieldType == typeof(TileAngle))
{
var tileAngle = (TileAngle)field.GetValue(null);
if (tileAngle != null)
{
AngleCharMap[tileAngle.CharCode] = tileAngle;
}
}
}
}
private TileAngle(char charCode, double angle, bool relative)
{
CharCode = charCode;
Angle = angle;
Relative = relative;
}
private char CharCode { get; }
public double Angle { get; }
public readonly bool Relative;
}
}