From 99ebc4786683d2617134605aca2a9f22f18b57da Mon Sep 17 00:00:00 2001 From: Kurt Date: Sat, 6 Jul 2024 01:35:50 -0500 Subject: [PATCH] Extract TrainerName const to static class Central location for where these values are defined. --- PKHeX.Core/Editing/Bulk/BatchMods.cs | 4 - PKHeX.Core/Game/Locations/LocationsHOME.cs | 32 +-- .../Legality/Encounters/Data/EncounterUtil.cs | 4 +- .../Templates/GO/EncounterSlot8GO.cs | 2 +- PKHeX.Core/PKM/SK2.cs | 3 +- PKHeX.Core/PKM/Util/TrainerName.cs | 13 ++ .../Saves/Abstractions/SimpleTrainerInfo.cs | 2 +- PKHeX.Core/Saves/SaveFile.cs | 2 +- PKHeX.Core/Saves/Util/SaveUtil.cs | 4 +- .../Saves/MemeCrypto/SwishCryptoTests.cs | 2 +- .../Simulator/ShowdownSetTests.cs | 198 ++++++++++-------- 11 files changed, 148 insertions(+), 118 deletions(-) create mode 100644 PKHeX.Core/PKM/Util/TrainerName.cs diff --git a/PKHeX.Core/Editing/Bulk/BatchMods.cs b/PKHeX.Core/Editing/Bulk/BatchMods.cs index 72eb1bbc5..520f4bb4d 100644 --- a/PKHeX.Core/Editing/Bulk/BatchMods.cs +++ b/PKHeX.Core/Editing/Bulk/BatchMods.cs @@ -58,10 +58,6 @@ public static class BatchMods new ComplexSet(nameof(PKM.MetDate), (pk, cmd) => pk.MetDate = ParseDate(cmd.PropertyValue)), new ComplexSet(nameof(PKM.EggMetDate), (pk, cmd) => pk.EggMetDate = ParseDate(cmd.PropertyValue)), - // Value Swap - new ComplexSet(nameof(PKM.EncryptionConstant), value => value == nameof(PKM.PID), (pk, _) => pk.EncryptionConstant = pk.PID), - new ComplexSet(nameof(PKM.PID), value => value == nameof(PKM.EncryptionConstant), (pk, _) => pk.PID = pk.EncryptionConstant), - // Realign to Derived Value new ComplexSet(nameof(PKM.Ability), value => value.Length == 2 && value.StartsWith(CONST_SPECIAL), (pk, cmd) => pk.RefreshAbility(Convert.ToInt16(cmd.PropertyValue[1]) - 0x30)), new ComplexSet(nameof(PKM.AbilityNumber), value => value.Length == 2 && value.StartsWith(CONST_SPECIAL), (pk, cmd) => pk.RefreshAbility(Convert.ToInt16(cmd.PropertyValue[1]) - 0x30)), diff --git a/PKHeX.Core/Game/Locations/LocationsHOME.cs b/PKHeX.Core/Game/Locations/LocationsHOME.cs index 45ba20713..f643cb00f 100644 --- a/PKHeX.Core/Game/Locations/LocationsHOME.cs +++ b/PKHeX.Core/Game/Locations/LocationsHOME.cs @@ -67,11 +67,11 @@ public static class LocationsHOME /// public static GameVersion GetVersionSWSH(GameVersion version) => version switch { - GameVersion.PLA => GameVersion.SW, - GameVersion.BD => GameVersion.SW, - GameVersion.SP => GameVersion.SH, - GameVersion.SL => GameVersion.SW, - GameVersion.VL => GameVersion.SH, + PLA => SW, + BD => SW, + SP => SH, + SL => SW, + VL => SH, _ => version, }; @@ -80,22 +80,22 @@ public static class LocationsHOME /// public static ushort GetMetSWSH(ushort loc, GameVersion version) => version switch { - GameVersion.PLA => SWLA, - GameVersion.BD => SWBD, - GameVersion.SP => SHSP, - GameVersion.SL => SWSL, - GameVersion.VL => SHVL, + PLA => SWLA, + BD => SWBD, + SP => SHSP, + SL => SWSL, + VL => SHVL, _ => loc, }; public static GameVersion GetVersionSWSHOriginal(ushort loc) => loc switch { - SWLA => GameVersion.PLA, - SWBD => GameVersion.BD, - SHSP => GameVersion.SP, - SWSL => GameVersion.SL, - SHVL => GameVersion.VL, - _ => GameVersion.SW, + SWLA => PLA, + SWBD => BD, + SHSP => SP, + SWSL => SL, + SHVL => VL, + _ => SW, }; /// diff --git a/PKHeX.Core/Legality/Encounters/Data/EncounterUtil.cs b/PKHeX.Core/Legality/Encounters/Data/EncounterUtil.cs index 14ccab1af..52c7faebb 100644 --- a/PKHeX.Core/Legality/Encounters/Data/EncounterUtil.cs +++ b/PKHeX.Core/Legality/Encounters/Data/EncounterUtil.cs @@ -68,8 +68,8 @@ public static class EncounterUtil /// Language to apply the name in public static string GetTrainerName(ITrainerInfo tr, int lang) => lang switch { - (int)LanguageID.Japanese => tr.Language == 1 ? tr.OT : "ゲーフリ", - _ => tr.Language == 1 ? "GF" : tr.OT, + (int)LanguageID.Japanese => tr.Language == 1 ? tr.OT : TrainerName.GameFreakJPN, + _ => tr.Language == 1 ? TrainerName.GameFreakINT : tr.OT, }; /// diff --git a/PKHeX.Core/Legality/Encounters/Templates/GO/EncounterSlot8GO.cs b/PKHeX.Core/Legality/Encounters/Templates/GO/EncounterSlot8GO.cs index 3723bff00..b39981964 100644 --- a/PKHeX.Core/Legality/Encounters/Templates/GO/EncounterSlot8GO.cs +++ b/PKHeX.Core/Legality/Encounters/Templates/GO/EncounterSlot8GO.cs @@ -132,7 +132,7 @@ public sealed record EncounterSlot8GO(int StartDate, int EndDate, ushort Species pk.OriginalTrainerName = tr.OT; pk.ID32 = tr.ID32; pk.OriginalTrainerGender = tr.Gender; - pk.HandlingTrainerName = "PKHeX"; + pk.HandlingTrainerName = TrainerName.ProgramINT; pk.CurrentHandler = 1; if (pk is IHandlerLanguage l) l.HandlingTrainerLanguage = 2; diff --git a/PKHeX.Core/PKM/SK2.cs b/PKHeX.Core/PKM/SK2.cs index d3ceef1cc..a5e6e976d 100644 --- a/PKHeX.Core/PKM/SK2.cs +++ b/PKHeX.Core/PKM/SK2.cs @@ -180,7 +180,8 @@ public sealed class SK2 : GBPKM, ICaughtData2 // Only copies until first 0x50 terminator, but just copy everything Nickname = Nickname, - OriginalTrainerName = IsRental ? Japanese ? "1337" : "PKHeX" : OriginalTrainerName, + OriginalTrainerName = !IsRental ? OriginalTrainerName + : Japanese ? TrainerName.GameFreakJPN : TrainerName.ProgramINT, }; private static bool IsJapanese(ReadOnlySpan data) diff --git a/PKHeX.Core/PKM/Util/TrainerName.cs b/PKHeX.Core/PKM/Util/TrainerName.cs new file mode 100644 index 000000000..131ca4cba --- /dev/null +++ b/PKHeX.Core/PKM/Util/TrainerName.cs @@ -0,0 +1,13 @@ +namespace PKHeX.Core; + +/// +/// Common trainer names used in the program. +/// +public static class TrainerName +{ + public const string GameFreakJPN = "ゲーフリ"; + public const string GameFreakINT = "GF"; + + public const string ProgramJPN = "PKHeX"; + public const string ProgramINT = "PKHeX"; +} diff --git a/PKHeX.Core/Saves/Abstractions/SimpleTrainerInfo.cs b/PKHeX.Core/Saves/Abstractions/SimpleTrainerInfo.cs index a9a324377..eb2238b13 100644 --- a/PKHeX.Core/Saves/Abstractions/SimpleTrainerInfo.cs +++ b/PKHeX.Core/Saves/Abstractions/SimpleTrainerInfo.cs @@ -5,7 +5,7 @@ namespace PKHeX.Core; /// public sealed record SimpleTrainerInfo : ITrainerInfo, IRegionOrigin { - public string OT { get; set; } = "PKHeX"; + public string OT { get; set; } = TrainerName.ProgramINT; public ushort TID16 { get; set; } = 12345; public ushort SID16 { get; set; } = 54321; public byte Gender { get; set; } diff --git a/PKHeX.Core/Saves/SaveFile.cs b/PKHeX.Core/Saves/SaveFile.cs index 79d0a0617..991c66942 100644 --- a/PKHeX.Core/Saves/SaveFile.cs +++ b/PKHeX.Core/Saves/SaveFile.cs @@ -131,7 +131,7 @@ public abstract class SaveFile : ITrainerInfo, IGameValueLimit, IGeneration, IVe public virtual uint ID32 { get; set; } public virtual ushort TID16 { get; set; } public virtual ushort SID16 { get; set; } - public virtual string OT { get; set; } = "PKHeX"; + public virtual string OT { get; set; } = TrainerName.ProgramINT; public virtual int PlayedHours { get; set; } public virtual int PlayedMinutes { get; set; } public virtual int PlayedSeconds { get; set; } diff --git a/PKHeX.Core/Saves/Util/SaveUtil.cs b/PKHeX.Core/Saves/Util/SaveUtil.cs index 5fd6e0237..29286c77e 100644 --- a/PKHeX.Core/Saves/Util/SaveUtil.cs +++ b/PKHeX.Core/Saves/Util/SaveUtil.cs @@ -806,8 +806,8 @@ public static class SaveUtil /// public static string GetSafeTrainerName(SaveFile? sav, LanguageID lang) => lang switch { - LanguageID.Japanese => sav?.Generation >= 3 ? "PKHeX" : "1337", - _ => "PKHeX", + LanguageID.Japanese => sav?.Generation >= 3 ? TrainerName.ProgramJPN : TrainerName.GameFreakJPN, + _ => TrainerName.ProgramINT, }; /// diff --git a/Tests/PKHeX.Core.Tests/Saves/MemeCrypto/SwishCryptoTests.cs b/Tests/PKHeX.Core.Tests/Saves/MemeCrypto/SwishCryptoTests.cs index 842abbf84..ddb243e52 100644 --- a/Tests/PKHeX.Core.Tests/Saves/MemeCrypto/SwishCryptoTests.cs +++ b/Tests/PKHeX.Core.Tests/Saves/MemeCrypto/SwishCryptoTests.cs @@ -14,7 +14,7 @@ public class SwishCryptoTests [Fact] public void CanMakeBlankSAV8() { - var sav = SaveUtil.GetBlankSAV(GameVersion.SW, "PKHeX"); + var sav = SaveUtil.GetBlankSAV(GameVersion.SW, TrainerName.ProgramINT); sav.Should().NotBeNull(); } } diff --git a/Tests/PKHeX.Core.Tests/Simulator/ShowdownSetTests.cs b/Tests/PKHeX.Core.Tests/Simulator/ShowdownSetTests.cs index d2c275601..ae251ba86 100644 --- a/Tests/PKHeX.Core.Tests/Simulator/ShowdownSetTests.cs +++ b/Tests/PKHeX.Core.Tests/Simulator/ShowdownSetTests.cs @@ -25,7 +25,7 @@ public class ShowdownSetTests var pk7 = new PK7 {Species = set.Species, Form = set.Form, Moves = set.Moves}; var encounters = EncounterMovesetGenerator.GenerateEncounters(pk7, set.Moves, GameVersion.MN); Assert.False(encounters.Any()); - pk7.HandlingTrainerName = "PKHeX"; + pk7.HandlingTrainerName = TrainerName.ProgramINT; encounters = EncounterMovesetGenerator.GenerateEncounters(pk7, set.Moves, GameVersion.MN); var first = encounters.FirstOrDefault(); Assert.NotNull(first); @@ -100,7 +100,7 @@ public class ShowdownSetTests public void SimulatorGetSplitBreed() { var set = new ShowdownSet(SetMunchSnorLax); - var pk7 = new PK7 { Species = set.Species, Form = set.Form, Moves = set.Moves, HandlingTrainerName = "PKHeX" }; // !! specify the HT name, we need tutors for this one + var pk7 = new PK7 { Species = set.Species, Form = set.Form, Moves = set.Moves, HandlingTrainerName = TrainerName.ProgramINT }; // !! specify the HT name, we need tutors for this one var encs = EncounterMovesetGenerator.GenerateEncounters(pk7, set.Moves, GameVersion.SN).ToList(); Assert.True(encs.Count > 0); Assert.True(encs.All(z => z.Species > 150)); @@ -117,7 +117,7 @@ public class ShowdownSetTests public void SimulatorGetVCEgg1() { var set = new ShowdownSet(SetSlowpoke12); - var pk7 = new PK7 { Species = set.Species, Form = set.Form, Moves = set.Moves, HandlingTrainerName = "PKHeX" }; + var pk7 = new PK7 { Species = set.Species, Form = set.Form, Moves = set.Moves, HandlingTrainerName = TrainerName.ProgramINT }; var encs = EncounterMovesetGenerator.GenerateEncounters(pk7, set.Moves, GameVersion.GD).ToList(); Assert.True(encs.Count > 0); @@ -209,100 +209,118 @@ public class ShowdownSetTests } private const string LowLevelElectrode = - @"BOLICHI (Electrode) -IVs: 19 HP / 16 Atk / 18 Def / 25 SpA / 19 SpD / 25 Spe -Ability: Static -Level: 3 -Hasty Nature -- Charge -- Tackle -- Screech -- Sonic Boom"; + """ + BOLICHI (Electrode) + IVs: 19 HP / 16 Atk / 18 Def / 25 SpA / 19 SpD / 25 Spe + Ability: Static + Level: 3 + Hasty Nature + - Charge + - Tackle + - Screech + - Sonic Boom + """; private const string SetDuplicateMoves = - @"Kingler-Gmax @ Master Ball -Ability: Sheer Force -Shiny: Yes -EVs: 252 Atk / 4 SpD / 252 Spe -Jolly Nature -- Crabhammer -- Rock Slide -- Rock Slide -- X-Scissor"; + """ + Kingler-Gmax @ Master Ball + Ability: Sheer Force + Shiny: Yes + EVs: 252 Atk / 4 SpD / 252 Spe + Jolly Nature + - Crabhammer + - Rock Slide + - Rock Slide + - X-Scissor + """; private const string SetROCKSMetang = - @"Metang -IVs: 20 HP / 3 Atk / 26 Def / 1 SpA / 6 SpD / 8 Spe -Ability: Clear Body -Level: 30 -Adamant Nature -- Take Down -- Confusion -- Metal Claw -- Refresh"; + """ + Metang + IVs: 20 HP / 3 Atk / 26 Def / 1 SpA / 6 SpD / 8 Spe + Ability: Clear Body + Level: 30 + Adamant Nature + - Take Down + - Confusion + - Metal Claw + - Refresh + """; private const string SetGlaceonUSUMTutor = - @"Glaceon (F) @ Assault Vest -IVs: 0 Atk -EVs: 252 HP / 252 SpA / 4 SpD -Ability: Ice Body -Shiny: Yes -Modest Nature -- Blizzard -- Water Pulse -- Shadow Ball -- Hyper Voice"; + """ + Glaceon (F) @ Assault Vest + IVs: 0 Atk + EVs: 252 HP / 252 SpA / 4 SpD + Ability: Ice Body + Shiny: Yes + Modest Nature + - Blizzard + - Water Pulse + - Shadow Ball + - Hyper Voice + """; private const string SetSmeargle = - @"Smeargle @ Focus Sash -Ability: Own Tempo -EVs: 248 HP / 8 Def / 252 Spe -Jolly Nature -- Sticky Web -- Nuzzle -- Taunt -- Whirlwind"; + """ + Smeargle @ Focus Sash + Ability: Own Tempo + EVs: 248 HP / 8 Def / 252 Spe + Jolly Nature + - Sticky Web + - Nuzzle + - Taunt + - Whirlwind + """; private const string SetCelebi = - @"Celebi @ Toxic Orb -Ability: Natural Cure -Jolly Nature -- Recover -- Heal Bell -- Safeguard -- Hold Back"; + """ + Celebi @ Toxic Orb + Ability: Natural Cure + Jolly Nature + - Recover + - Heal Bell + - Safeguard + - Hold Back + """; private const string SetNicknamedTypeNull = - @"Reliance (Type: Null) @ Eviolite -EVs: 252 HP / 4 Def / 252 SpD -Ability: Battle Armor -Careful Nature -- Facade -- Swords Dance -- Sleep Talk -- Rest"; + """ + Reliance (Type: Null) @ Eviolite + EVs: 252 HP / 4 Def / 252 SpD + Ability: Battle Armor + Careful Nature + - Facade + - Swords Dance + - Sleep Talk + - Rest + """; private const string SetMunchSnorLax = - @"Snorlax @ Choice Band -Ability: Thick Fat -Level: 50 -EVs: 84 HP / 228 Atk / 180 Def / 12 SpD / 4 Spe -Adamant Nature -- Double-Edge -- High Horsepower -- Self-Destruct -- Fire Punch"; + """ + Snorlax @ Choice Band + Ability: Thick Fat + Level: 50 + EVs: 84 HP / 228 Atk / 180 Def / 12 SpD / 4 Spe + Adamant Nature + - Double-Edge + - High Horsepower + - Self-Destruct + - Fire Punch + """; private const string SetSlowpoke12 = - @"Threat (Slowpoke) @ Eviolite -Ability: Regenerator -Shiny: Yes -EVs: 248 HP / 252 Atk / 8 SpD -Adamant Nature -- Body Slam -- Earthquake -- Belly Drum -- Iron Tail"; + """ + Threat (Slowpoke) @ Eviolite + Ability: Regenerator + Shiny: Yes + EVs: 248 HP / 252 Atk / 8 SpD + Adamant Nature + - Body Slam + - Earthquake + - Belly Drum + - Iron Tail + """; private static readonly string[] Sets = [ @@ -310,13 +328,15 @@ Adamant Nature SetNicknamedTypeNull, SetMunchSnorLax, - @"Greninja @ Choice Specs -Ability: Battle Bond -EVs: 252 SpA / 4 SpD / 252 Spe -Timid Nature -- Hydro Pump -- Spikes -- Water Shuriken -- Dark Pulse", + """ + Greninja @ Choice Specs + Ability: Battle Bond + EVs: 252 SpA / 4 SpD / 252 Spe + Timid Nature + - Hydro Pump + - Spikes + - Water Shuriken + - Dark Pulse + """, ]; }