add trainer param to parametertype enum

This commit is contained in:
KalaayPT 2025-08-09 17:38:30 +02:00
parent 2657ffd47e
commit c3fb90bcf8
4 changed files with 54 additions and 11 deletions

View File

@ -93,6 +93,7 @@ namespace DSPRE.Editors
ScriptDatabase.InitializePokemonNames();
ScriptDatabase.InitializeItemNames();
ScriptDatabase.InitializeMoveNames();
ScriptDatabase.InitializeTrainerNames();
SetupScriptEditorTextAreas();
/* Extract essential NARCs sub-archives*/
Helpers.statusLabelMessage("Setting up Script Editor...");
@ -123,6 +124,7 @@ namespace DSPRE.Editors
" " + String.Join(" ", ScriptDatabase.itemNames.Values) +
" " + String.Join(" ", ScriptDatabase.moveNames.Values) +
" " + String.Join(" ", ScriptDatabase.soundNames.Values) +
" " + String.Join(" ", ScriptDatabase.trainerNames.Values) +
" " + ScriptFile.ContainerTypes.Script.ToString() +
" " + ScriptFile.ContainerTypes.Function.ToString() +
" " + ScriptFile.ContainerTypes.Action.ToString() +

View File

@ -164,7 +164,8 @@ namespace DSPRE.ROMFiles {
if (!nameParts[i + 1].StartsWith("SEQ_")
&& !nameParts[i + 1].StartsWith("SPECIES_")
&& !nameParts[i + 1].StartsWith("ITEM_")
&& !nameParts[i + 1].StartsWith("MOVE_")) {
&& !nameParts[i + 1].StartsWith("MOVE_")
&& !nameParts[i + 1].StartsWith("TRAINER_")) {
nameParts[i + 1] = nameParts[i + 1].PurgeSpecial(ScriptFile.specialChars);
}
@ -221,10 +222,18 @@ namespace DSPRE.ROMFiles {
}
else
{
MessageBox.Show($"Argument {paramToCheck} couldn't be parsed as a valid Condition, Overworld ID, Direction ID, Pokemon, Item, Move, Sound, Script, Function or Action number.\n\n" +
var trainer = ScriptDatabase.trainerNames.FirstOrDefault(x => x.Value.IgnoreCaseEquals(paramToCheck));
if (!string.IsNullOrWhiteSpace(trainer.Value))
{
result = trainer.Key;
}
else
{
MessageBox.Show($"Argument {paramToCheck} couldn't be parsed as a valid Condition, Overworld ID, Direction ID, Pokemon, Item, Move, Sound, Trainer, Script, Function or Action number.\n\n" +
$"Line {lineNumber}: {wholeLine}", "Invalid identifier", MessageBoxButtons.OK, MessageBoxIcon.Error);
id = null;
return;
id = null;
return;
}
}
}
}
@ -362,27 +371,38 @@ namespace DSPRE.ROMFiles {
{
return sound.Value;
}
var trainer = ScriptDatabase.trainerNames.FirstOrDefault(x =>
x.Value.IgnoreCaseEquals(parameter));
if (!string.IsNullOrWhiteSpace(trainer.Value))
{
return trainer.Value;
}
string closestItem = FindClosestMatch(parameter, ScriptDatabase.itemNames.Values);
if (!string.IsNullOrWhiteSpace(closestItem))
{
throw new ArgumentException($"'{parameter}' is not a valid Item name.\nDid you mean {closestItem}?");
throw new ArgumentException($"'{parameter}' is not a valid Item.\nDid you mean {closestItem}?");
}
string closestPokemon = FindClosestMatch(parameter, ScriptDatabase.pokemonNames.Values);
if (!string.IsNullOrWhiteSpace(closestPokemon))
{
throw new ArgumentException($"'{parameter}' is not a valid Pokemon name.\nDid you mean {closestPokemon}?");
throw new ArgumentException($"'{parameter}' is not a valid Pokemon.\nDid you mean {closestPokemon}?");
}
string closestMove = FindClosestMatch(parameter, ScriptDatabase.moveNames.Values);
if (!string.IsNullOrWhiteSpace(closestMove))
{
throw new ArgumentException($"'{parameter}' is not a valid Move name.\nDid you mean {closestMove}?");
throw new ArgumentException($"'{parameter}' is not a valid Move.\nDid you mean {closestMove}?");
}
string closestSound = FindClosestMatch(parameter, ScriptDatabase.soundNames.Values);
if (!string.IsNullOrWhiteSpace(closestSound))
{
throw new ArgumentException($"'{parameter}' is not a valid Sound name.\nDid you mean {closestSound}?");
}
string closestTrainer = FindClosestMatch(parameter, ScriptDatabase.trainerNames.Values);
if (!string.IsNullOrWhiteSpace(closestTrainer))
{
throw new ArgumentException($"'{parameter}' is not a valid Trainer.\nDid you mean {closestTrainer}?");
}
return parameter;
}

View File

@ -1,5 +1,6 @@
using DSPRE;
using DSPRE.Resources;
using DSPRE.ROMFiles;
using System;
using System.Collections.Generic;
using System.IO;
@ -216,6 +217,7 @@ namespace DSPRE.Resources {
public static Dictionary<ushort, string> itemNames = new Dictionary<ushort, string>();
public static Dictionary<ushort, string> moveNames = new Dictionary<ushort, string>();
public static Dictionary<ushort, string> soundNames = new Dictionary<ushort, string>();
public static Dictionary<ushort, string> trainerNames = new Dictionary<ushort, string>();
public static Dictionary<ushort, string> movementsDictIDName = new Dictionary<ushort, string>();
public static Dictionary<ushort, int> commandsWithRelativeJump = new Dictionary<ushort, int>()
@ -244,7 +246,7 @@ namespace DSPRE.Resources {
public static void InitializePokemonNames()
{
string[] names = RomInfo.GetPokemonNames();
string[] names = GetPokemonNames();
pokemonNames = names.Select((name, index) => new { name, index })
.ToDictionary(
x => (ushort)x.index,
@ -253,7 +255,7 @@ namespace DSPRE.Resources {
}
public static void InitializeItemNames()
{
string[] names = RomInfo.GetItemNames();
string[] names = GetItemNames();
itemNames = names.Select((name, index) => new { name, index })
.ToDictionary(
x => (ushort)x.index,
@ -262,13 +264,27 @@ namespace DSPRE.Resources {
}
public static void InitializeMoveNames()
{
string[] names = RomInfo.GetAttackNames();
string[] names = GetAttackNames();
moveNames = names.Select((name, index) => new { name, index })
.ToDictionary(
x => (ushort)x.index,
x => "MOVE_" + x.name.ToUpper().Replace(' ', '_')
);
}
public static void InitializeTrainerNames()
{
string[] names = GetSimpleTrainerNames();
trainerNames = Enumerable.Range(0, names.Length)
.ToDictionary(
index => (ushort)index,
index => index == 0
? "TRAINER_NONE"
: $"TRAINER_{names[index]}_{index:D3}"
.ToUpper()
.Replace(' ', '_')
.Replace("&", "AND")
);
}
}
}

View File

@ -19,7 +19,8 @@ public class ScriptParameter {
Pokemon,
Item,
Move,
Sound
Sound,
Trainer
}
public static ParameterType ParseTypeString(string typeStr)
@ -104,6 +105,10 @@ public class ScriptParameter {
if (ScriptDatabase.moveNames.TryGetValue((ushort)value, out string moveName))
return $"{moveName}";
break;
case ParameterType.Trainer:
if (ScriptDatabase.trainerNames.TryGetValue((ushort)value, out string trainerName))
return $"{trainerName}";
break;
case ParameterType.Function:
return $"Function#{value}";
//case ParameterType.Variable: