From efbac28b91cba92729ea62fa08d08f6e39eb15a1 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sun, 5 Jan 2020 21:51:02 -0800 Subject: [PATCH] Rework accessors for PKMConverter trainer cache Might break downstream users, for the better. Internal behavior had to change! --- PKHeX.Core/PKM/Util/FormConverter.cs | 3 ++- PKHeX.Core/PKM/Util/PKMConverter.cs | 12 ++++++++++-- PKHeX.WinForms/MainWindow/Main.cs | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/PKHeX.Core/PKM/Util/FormConverter.cs b/PKHeX.Core/PKM/Util/FormConverter.cs index 21a6765bc..0f512e25e 100644 --- a/PKHeX.Core/PKM/Util/FormConverter.cs +++ b/PKHeX.Core/PKM/Util/FormConverter.cs @@ -44,7 +44,8 @@ public static string[] GetFormList(int species, IReadOnlyList types, IRe return GetFormsGen8(species, types, forms, genders); } - private static bool IsGG() => GameVersion.GG.Contains(PKMConverter.Trainer.Game); + // this is a hack; depends on currently loaded SaveFile's Game ID + private static bool IsGG() => GameVersion.GG.Contains(PKMConverter.Game); public static bool IsTotemForm(int species, int form, int generation = 7) { diff --git a/PKHeX.Core/PKM/Util/PKMConverter.cs b/PKHeX.Core/PKM/Util/PKMConverter.cs index a9394c42d..780fbe703 100644 --- a/PKHeX.Core/PKM/Util/PKMConverter.cs +++ b/PKHeX.Core/PKM/Util/PKMConverter.cs @@ -12,12 +12,20 @@ namespace PKHeX.Core /// public static class PKMConverter { - public static ITrainerInfo Trainer { internal get; set; } = new SimpleTrainerInfo(); - private static readonly ITrainerInfo Trainer67 = new SimpleTrainerInfo(GameVersion.SN); + public static void SetPrimaryTrainer(ITrainerInfo t) + { + Trainer = t; + if (t.ConsoleRegion != 0) + Trainer67 = t; + } + + private static ITrainerInfo Trainer { get; set; } = new SimpleTrainerInfo(); + private static ITrainerInfo Trainer67 { get; set; } = new SimpleTrainerInfo(GameVersion.SN); public static string OT_Name => Trainer.OT; public static int OT_Gender => Trainer.Gender; public static int Language => Trainer.Language; public static int Format => Trainer.Generation; + public static int Game => Trainer.Game; public static bool AllowIncompatibleConversion { private get; set; } public static void SetConsoleRegionData3DS(PKM pkm) diff --git a/PKHeX.WinForms/MainWindow/Main.cs b/PKHeX.WinForms/MainWindow/Main.cs index 8ccc48ca4..85175aa78 100644 --- a/PKHeX.WinForms/MainWindow/Main.cs +++ b/PKHeX.WinForms/MainWindow/Main.cs @@ -738,7 +738,7 @@ private bool OpenSAV(SaveFile sav, string path) PKME_Tabs.Focus(); // flush any pending changes StoreLegalSaveGameData(sav); - PKMConverter.Trainer = sav; + PKMConverter.SetPrimaryTrainer(sav); SpriteUtil.Initialize(sav); // refresh sprite generator dragout.Size = new Size(SpriteUtil.Spriter.Width, SpriteUtil.Spriter.Height);