forked from CnCNet/WorldAlteringEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThemes.cs
More file actions
95 lines (78 loc) · 2.6 KB
/
Themes.cs
File metadata and controls
95 lines (78 loc) · 2.6 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
using Rampastring.Tools;
using System.Collections.Generic;
using System.Collections.Immutable;
using TSMapEditor.Extensions;
using TSMapEditor.Misc;
namespace TSMapEditor.Models
{
public class Theme : INIDefineable
{
public Theme(string iniName, int index)
{
ININame = iniName;
Index = index;
}
[INI(false)]
public string ININame { get; }
[INI(false)]
public int Index { get; }
public string Name { get; set; } = string.Empty;
public double Length { get; set; }
public bool Normal { get; set; }
public int Scenario { get; set; }
public int Side { get; set; }
public bool Repeat { get; set; }
public override string ToString()
{
return $"{Index} {Name}";
}
public void ReadFromSection(IniSection iniSection)
{
ReadPropertiesFromIniSection(iniSection);
}
}
public class Themes
{
public Themes(IniFileEx themeIni)
{
Initialize(themeIni);
}
public ImmutableList<Theme> List { get; private set; }
public Theme Get(int index)
{
return List.GetElementIfInRange(index);
}
public Theme Get(string name)
{
return List.Find(theme => theme.Name == name);
}
public Theme GetByININame(string iniName)
{
return List.Find(theme => theme.ININame == iniName);
}
private void Initialize(IniFileEx themeIni)
{
var themes = new List<Theme>();
const string definitionsSectionName = "Themes";
var themeDefinitions = themeIni.GetSectionKeys(definitionsSectionName);
if (themeDefinitions == null)
{
Logger.Log($"Failed to find [{definitionsSectionName}] section from {Constants.ThemeIniPath} - skipping loading themes");
return;
}
foreach (string key in themeDefinitions)
{
string themeIniName = themeIni.GetStringValue(definitionsSectionName, key, string.Empty);
if (!string.IsNullOrWhiteSpace(themeIniName))
themes.Add(new Theme(themeIniName, themes.Count));
}
foreach (var theme in themes)
{
var themeSection = themeIni.GetSection(theme.ININame);
if (themeSection != null)
theme.ReadFromSection(themeSection);
}
List = ImmutableList.Create(themes.ToArray());
}
}
}