-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathScriptAction.cs
93 lines (79 loc) · 2.98 KB
/
ScriptAction.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
using Microsoft.Xna.Framework;
using Rampastring.Tools;
using System;
using System.Collections.Generic;
using TSMapEditor.Models.Enums;
namespace TSMapEditor.CCEngine
{
public class ScriptActionPresetOption
{
public int Value;
public string Text;
public Color? Color;
public ScriptActionPresetOption()
{
}
public ScriptActionPresetOption(int value, string text, Color? color = null)
{
Value = value;
Text = text;
Color = color;
}
public string GetOptionText()
{
if (string.IsNullOrEmpty(Text))
return Value.ToString();
else
return Value + " - " + Text;
}
}
public class ScriptAction
{
public ScriptAction(int id)
{
ID = id;
}
public int ID { get; set; }
public string Name { get; set; } = "Unknown action";
public string Description { get; set; } = "No description";
public string ParamDescription { get; set; } = "Use 0";
public TriggerParamType ParamType { get; set; } = TriggerParamType.Unknown;
public List<ScriptActionPresetOption> PresetOptions { get; } = new List<ScriptActionPresetOption>(0);
public bool UseWindowSelection { get; set; } = false;
public void ReadIniSection(IniSection iniSection)
{
ID = iniSection.GetIntValue("IDOverride", ID);
Name = iniSection.GetStringValue(nameof(Name), Name);
Description = iniSection.GetStringValue(nameof(Description), Description);
ParamDescription = iniSection.GetStringValue(nameof(ParamDescription), ParamDescription);
UseWindowSelection = iniSection.GetBooleanValue(nameof(UseWindowSelection), UseWindowSelection);
if (Enum.TryParse(iniSection.GetStringValue(nameof(ParamType), "Unknown"), out TriggerParamType result))
{
ParamType = result;
}
int i = 0;
while (true)
{
string key = "Option" + i;
if (!iniSection.KeyExists(key))
break;
string value = iniSection.GetStringValue(key, null);
if (string.IsNullOrWhiteSpace(value))
{
Logger.Log($"Invalid {key}= in ScriptAction " + iniSection.SectionName);
break;
}
int commaIndex = value.IndexOf(',');
if (commaIndex < 0)
{
Logger.Log($"Invalid {key}= in ScriptAction " + iniSection.SectionName);
break;
}
int presetValue = Conversions.IntFromString(value.Substring(0, commaIndex), 0);
string presetText = value.Substring(commaIndex + 1);
PresetOptions.Add(new ScriptActionPresetOption(presetValue, presetText));
i++;
}
}
}
}