mirror of
https://github.com/AdAstra-LD/DS-Pokemon-Rom-Editor.git
synced 2026-05-09 21:50:57 -05:00
- Add NSBTX and Remove NSBTX buttons also add/remove building configuration file [NSBTX Editor] - Changed format of Script Editor display - Added highlighting of 'Script', 'Function' and 'Action' keywords (only upon reloading) - Changed Endcodes database to HashSet (PokeDatabase -> ScriptEditor) - Minor refactor
86 lines
3.7 KiB
C#
86 lines
3.7 KiB
C#
using DSPRE.Resources;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Globalization;
|
||
using System.Linq;
|
||
using System.Windows.Forms;
|
||
|
||
namespace DSPRE.ROMFiles {
|
||
public class ActionContainer {
|
||
public List<ScriptAction> actionCommandsList;
|
||
public uint manualUserID;
|
||
|
||
#region Constructors (2)
|
||
public ActionContainer(uint actionNumber, List<ScriptAction> actionCommandsList = null) {
|
||
manualUserID = actionNumber;
|
||
this.actionCommandsList = actionCommandsList;
|
||
}
|
||
#endregion
|
||
}
|
||
public class ScriptAction {
|
||
|
||
#region Fields (4)
|
||
public ushort? id;
|
||
public ushort? repetitionCount;
|
||
public string name;
|
||
#endregion
|
||
|
||
public ScriptAction(ushort id, ushort? repetitionCount = null) {
|
||
this.id = id;
|
||
this.repetitionCount = repetitionCount;
|
||
|
||
if (!PokeDatabase.ScriptEditor.movementsDictIDName.TryGetValue(id, out name))
|
||
name = id.ToString("X4");
|
||
|
||
if (repetitionCount != null && id != 0x00FE)
|
||
name += " " + "0x" + ((ushort)repetitionCount).ToString("X");
|
||
}
|
||
public ScriptAction(string wholeLine, int lineNumber) {
|
||
name = wholeLine;
|
||
|
||
string[] nameParts = wholeLine.Replace("\t", "").Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); // Separate command code from parameters
|
||
/* Get command id, which is always first in the description */
|
||
|
||
try {
|
||
id = PokeDatabase.ScriptEditor.movementsDictIDName.First(x => x.Value.Equals(nameParts[0], StringComparison.InvariantCultureIgnoreCase)).Key;
|
||
} catch (InvalidOperationException) {
|
||
try {
|
||
id = UInt16.Parse(nameParts[0], NumberStyles.HexNumber, CultureInfo.InvariantCulture);
|
||
} catch (FormatException) {
|
||
string details;
|
||
if (wholeLine.Contains('@') && wholeLine.Contains('#')) {
|
||
details = "This probably means you forgot to \"End\" the Action above it.";
|
||
} else {
|
||
details = "Are you sure it's a proper Action Command?";
|
||
}
|
||
MessageBox.Show("This Script file could not be saved." +
|
||
Environment.NewLine + "Parser failed to interpret line " + lineNumber + ": \"" + wholeLine + "\"." +
|
||
Environment.NewLine + "\n" + details, "Parser error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
id = null;
|
||
return;
|
||
}
|
||
}
|
||
|
||
if (id != 0x00FE && nameParts.Length < 2 || nameParts.Length > 2) { //E.g.: End 0x2 0x40 OR LookUp
|
||
MessageBox.Show("Wrong number of parameters for action " + nameParts[0] + " at line " + lineNumber + "." + Environment.NewLine +
|
||
"Received: " + (nameParts.Length - 1) + Environment.NewLine + "Expected: 1"
|
||
+ Environment.NewLine + "\nThis Script File can not be saved.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
id = null;
|
||
} else {
|
||
if (id == 0x00FE) {
|
||
repetitionCount = 0;
|
||
} else {
|
||
NumberStyles style;
|
||
if (nameParts[1].StartsWith("0x", StringComparison.InvariantCultureIgnoreCase)) {
|
||
style = NumberStyles.HexNumber;
|
||
nameParts[1] = nameParts[1].Substring(2);
|
||
} else {
|
||
style = NumberStyles.Integer;
|
||
}
|
||
repetitionCount = ushort.Parse(nameParts[1], style);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|