Skip to content

Commit

Permalink
Allow parsing script action options from another section
Browse files Browse the repository at this point in the history
  • Loading branch information
Starkku authored Jun 17, 2024
1 parent 718cba4 commit e115f81
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
21 changes: 16 additions & 5 deletions src/TSMapEditor/CCEngine/ScriptAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,39 +33,50 @@ public ScriptAction(int id)
public string Name { get; set; } = "Unknown action";
public string Description { get; set; } = "No description";
public string ParamDescription { get; set; } = "Use 0";
public string OptionsSectionName { get; set; } = string.Empty;
public TriggerParamType ParamType { get; set; } = TriggerParamType.Unknown;
public List<ScriptActionPresetOption> PresetOptions { get; } = new List<ScriptActionPresetOption>(0);

public void ReadIniSection(IniSection iniSection)
public void ReadIniSection(IniFile iniFile, string sectionName)
{
var iniSection = iniFile.GetSection(sectionName);
ID = iniSection.GetIntValue("IDOverride", ID);
Name = iniSection.GetStringValue(nameof(Name), Name);
Description = iniSection.GetStringValue(nameof(Description), Description);
OptionsSectionName = iniSection.GetStringValue(nameof(OptionsSectionName), OptionsSectionName);
ParamDescription = iniSection.GetStringValue(nameof(ParamDescription), ParamDescription);
if (Enum.TryParse(iniSection.GetStringValue(nameof(ParamType), "Unknown"), out TriggerParamType result))
{
ParamType = result;
}

var optionsSection = iniSection;
string extraDesc = string.Empty;
if (!string.IsNullOrEmpty(OptionsSectionName) && iniFile.SectionExists(OptionsSectionName))
{
optionsSection = iniFile.GetSection(OptionsSectionName);
extraDesc = $"(Options section: {OptionsSectionName}) ";
}

int i = 0;
while (true)
{
string key = "Option" + i;

if (!iniSection.KeyExists(key))
if (!optionsSection.KeyExists(key))
break;

string value = iniSection.GetStringValue(key, null);
string value = optionsSection.GetStringValue(key, null);
if (string.IsNullOrWhiteSpace(value))
{
Logger.Log($"Invalid {key}= in ScriptAction " + iniSection.SectionName);
Logger.Log($"Invalid {key}= in ScriptAction {extraDesc}" + iniSection.SectionName);
break;
}

int commaIndex = value.IndexOf(',');
if (commaIndex < 0)
{
Logger.Log($"Invalid {key}= in ScriptAction " + iniSection.SectionName);
Logger.Log($"Invalid {key}= in ScriptAction {extraDesc}" + iniSection.SectionName);
break;
}

Expand Down
6 changes: 4 additions & 2 deletions src/TSMapEditor/Models/EditorConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,11 @@ private void ReadScriptActions()

for (int i = 0; i < sections.Count; i++)
{
if (sections[i].StartsWith("$"))
continue;

var scriptAction = new ScriptAction(i);
var scriptSection = iniFile.GetSection(sections[i]);
scriptAction.ReadIniSection(scriptSection);
scriptAction.ReadIniSection(iniFile, sections[i]);

if (ScriptActions.ContainsKey(scriptAction.ID))
{
Expand Down

0 comments on commit e115f81

Please sign in to comment.