From da4d8a5d9258148fab8ba8d58f81a90df21d8d6a Mon Sep 17 00:00:00 2001 From: AdAstra-LD Date: Fri, 5 Feb 2021 16:55:29 +0100 Subject: [PATCH] Fixed script editor expanding functions even when there's no need to (UseScript_#X) --- DS_Map/Main Window.cs | 31 +++++--- DS_Map/ROMFiles/ScriptFile.cs | 120 +++++++++++++++++-------------- DS_Map/ROMToolboxDialog.cs | 2 +- DS_Map/Resources/PokeDatabase.cs | 8 +++ 4 files changed, 96 insertions(+), 65 deletions(-) diff --git a/DS_Map/Main Window.cs b/DS_Map/Main Window.cs index 66644c8..8457155 100644 --- a/DS_Map/Main Window.cs +++ b/DS_Map/Main Window.cs @@ -5140,14 +5140,19 @@ namespace DSPRE { i++; //Skip all empty lines /* Read function commands */ - List cmdList = new List(); + if (functionTextBox.Lines[i].Contains("UseScript")) { + int scriptNumber = Int16.Parse(functionTextBox.Lines[i].Substring(1 + functionTextBox.Lines[i].IndexOf('#'))); + scrFile.functions.Add(new Script(useScript: scriptNumber)); + } else { + List cmdList = new List(); - while (functionTextBox.Lines[i] != "End" && !functionTextBox.Lines[i].Contains("Return") && !functionTextBox.Lines[i].Contains("Jump F")) { - cmdList.Add(new ScriptCommand(functionTextBox.Lines[i])); - i++; + while (functionTextBox.Lines[i] != "End" && !functionTextBox.Lines[i].Contains("Return") && !functionTextBox.Lines[i].Contains("Jump F")) { + cmdList.Add(new ScriptCommand(functionTextBox.Lines[i])); + i++; + } + cmdList.Add(new ScriptCommand(functionTextBox.Lines[i])); // Add end command + scrFile.functions.Add(new Script(commandList: cmdList)); } - cmdList.Add(new ScriptCommand(functionTextBox.Lines[i])); // Add end command - scrFile.functions.Add(new Script(commandList: cmdList)); } } } @@ -5332,7 +5337,7 @@ namespace DSPRE { buffer += Environment.NewLine; /* If current script is identical to another, print UseScript instead of commands */ - if (currentScript.useScript == -1) { + if (currentScript.useScript < 0) { for (int j = 0; j < currentScript.commands.Count; j++) buffer += currentScript.commands[j].cmdName + Environment.NewLine; } else { @@ -5346,11 +5351,19 @@ namespace DSPRE { for (int i = 0; i < currentScriptFile.functions.Count; i++) { Script currentFunction = currentScriptFile.functions[i]; + /* Write Heaader */ string funcHeader = "----- " + "@Function_#" + (i + 1) + " -----" + Environment.NewLine; buffer += funcHeader; buffer += Environment.NewLine; - for (int j = 0; j < currentFunction.commands.Count; j++) - buffer += currentFunction.commands[j].cmdName + Environment.NewLine; + + /* If current function is identical to a script, print UseScript instead of commands */ + if (currentFunction.useScript < 0) { + for (int j = 0; j < currentFunction.commands.Count; j++) + buffer += currentFunction.commands[j].cmdName + Environment.NewLine; + } else { + buffer += ("UseScript_#" + currentFunction.useScript + Environment.NewLine); + } + } functionTextBox.AppendText(buffer + Environment.NewLine, Color.Blue); buffer = ""; diff --git a/DS_Map/ROMFiles/ScriptFile.cs b/DS_Map/ROMFiles/ScriptFile.cs index acf8628..41d5739 100644 --- a/DS_Map/ROMFiles/ScriptFile.cs +++ b/DS_Map/ROMFiles/ScriptFile.cs @@ -14,6 +14,8 @@ namespace DSPRE.ROMFiles { public List