From 9f8642f7d2eb7d45ca51c4cb4843e9319c8bdbc5 Mon Sep 17 00:00:00 2001 From: Kurt Date: Fri, 6 Aug 2021 15:35:49 -0700 Subject: [PATCH] Hide Generation/Game setters behind mutation method --- .../ByGeneration/EncounterGenerator12.cs | 3 +-- PKHeX.Core/Legality/Structures/LegalInfo.cs | 15 ++++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/PKHeX.Core/Legality/Encounters/Generator/ByGeneration/EncounterGenerator12.cs b/PKHeX.Core/Legality/Encounters/Generator/ByGeneration/EncounterGenerator12.cs index 520bcca1a..2cd23660b 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/ByGeneration/EncounterGenerator12.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/ByGeneration/EncounterGenerator12.cs @@ -17,8 +17,7 @@ internal static IEnumerable GetEncounters12(PKM pkm, LegalInfo i { foreach (var z in GenerateFilteredEncounters12(pkm)) { - info.Generation = z.Generation; - info.Game = z.Version; + info.StoreMetadata(z.Version, z.Generation); yield return z; } } diff --git a/PKHeX.Core/Legality/Structures/LegalInfo.cs b/PKHeX.Core/Legality/Structures/LegalInfo.cs index 4d120aa0c..f9021b874 100644 --- a/PKHeX.Core/Legality/Structures/LegalInfo.cs +++ b/PKHeX.Core/Legality/Structures/LegalInfo.cs @@ -11,10 +11,10 @@ public sealed class LegalInfo : IGeneration private readonly PKM pkm; /// The generation of games the originated from. - public int Generation { get; internal set; } + public int Generation { get; private set; } /// The Game the originated from. - public GameVersion Game { get; internal set; } + public GameVersion Game { get; private set; } /// The matched Encounter details for the . public IEncounterable EncounterMatch @@ -78,10 +78,15 @@ public LegalInfo(PKM pk, List parse) { pkm = pk; Parse = parse; + StoreMetadata((GameVersion)pk.Version, pkm.Generation); + } - // Store repeatedly accessed values - Game = (GameVersion)pkm.Version; - Generation = pkm.Generation; + internal void StoreMetadata(GameVersion game, int gen) + { + // We can call this method at the start for any Gen3+ encounter iteration. + // We need to call this for each Gen1/2 encounter as Version is not stored for those origins. + Game = game; + Generation = gen; } /// List of all near-matches that were rejected for a given reason.