From 6346444db722cc199036b6f0c5a243ac9efcf3f2 Mon Sep 17 00:00:00 2001 From: Kurt Date: Wed, 12 Feb 2020 18:52:48 -0800 Subject: [PATCH] Extract home tracker to interface --- PKHeX.Core/Legality/BulkAnalysis.cs | 8 ++++---- PKHeX.Core/Legality/Verifiers/TransferVerifier.cs | 10 +++++----- PKHeX.Core/PKM/PK8.cs | 2 +- PKHeX.Core/PKM/Shared/IHomeTrack.cs | 13 +++++++++++++ PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs | 4 ++-- 5 files changed, 25 insertions(+), 12 deletions(-) create mode 100644 PKHeX.Core/PKM/Shared/IHomeTrack.cs diff --git a/PKHeX.Core/Legality/BulkAnalysis.cs b/PKHeX.Core/Legality/BulkAnalysis.cs index 691c2e912..3e4c1f633 100644 --- a/PKHeX.Core/Legality/BulkAnalysis.cs +++ b/PKHeX.Core/Legality/BulkAnalysis.cs @@ -82,17 +82,17 @@ private void CheckClones() Debug.Assert(cp.Format == Trainer.Generation); // Check the upload tracker to see if there's any duplication. - if (cp is PK8 pk8) + if (cp is IHomeTrack home) { - if (pk8.Tracker != 0) + if (home.Tracker != 0) { - var tracker = pk8.Tracker; + var tracker = home.Tracker; if (Trackers.TryGetValue(tracker, out var clone)) AddLine(clone, cp, "Clone detected (Duplicate Tracker).", Encounter); else Trackers.Add(tracker, cp); } - else if (pk8.GenNumber < 8) + else if (cp.GenNumber < 8) { AddLine(cp, "Missing tracker.", Encounter); } diff --git a/PKHeX.Core/Legality/Verifiers/TransferVerifier.cs b/PKHeX.Core/Legality/Verifiers/TransferVerifier.cs index 5fd85a98d..373d051ba 100644 --- a/PKHeX.Core/Legality/Verifiers/TransferVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/TransferVerifier.cs @@ -109,13 +109,13 @@ public void VerifyTransferLegalityG8(LegalityAnalysis data) { data.AddLine(GetInvalid(LTransferBad)); } - else if (data.Info.Generation < 8 && pkm is PK8 pk) + else if (data.Info.Generation < 8 && pkm.Format >= 8) { - if (!pk.GG) + if (!pkm.GG && pkm is IScaledSize s) { - if (pk.HeightScalar != 0) + if (s.HeightScalar != 0) data.AddLine(GetInvalid(LTransferBad)); - if (pk.WeightScalar != 0) + if (s.WeightScalar != 0) data.AddLine(GetInvalid(LTransferBad)); var enc = data.EncounterMatch; @@ -130,7 +130,7 @@ public void VerifyTransferLegalityG8(LegalityAnalysis data) // Tracker value is set via Transfer across HOME. // Can't validate the actual values (we aren't the server), so we can only check against zero. - if (pk.Tracker == 0) + if (pkm is IHomeTrack home && home.Tracker == 0) { data.AddLine(Get(LTransferTrackerMissing, ParseSettings.Gen8TransferTrackerNotPresent)); // To the reader: It seems like the best course of action for setting a tracker is: diff --git a/PKHeX.Core/PKM/PK8.cs b/PKHeX.Core/PKM/PK8.cs index fd5f22b8d..08f17c226 100644 --- a/PKHeX.Core/PKM/PK8.cs +++ b/PKHeX.Core/PKM/PK8.cs @@ -6,7 +6,7 @@ namespace PKHeX.Core /// Generation 8 format. public sealed class PK8 : PKM, IRibbonSetEvent3, IRibbonSetEvent4, IRibbonSetCommon3, IRibbonSetCommon4, IRibbonSetCommon6, IRibbonSetCommon7, IRibbonSetCommon8, IRibbonSetMark8, - IContestStats, IHyperTrain, IScaledSize, IGigantamax, IFavorite, IDynamaxLevel, IRibbonIndex, IHandlerLanguage, IFormArgument + IContestStats, IHyperTrain, IScaledSize, IGigantamax, IFavorite, IDynamaxLevel, IRibbonIndex, IHandlerLanguage, IFormArgument, IHomeTrack { private static readonly ushort[] Unused = { diff --git a/PKHeX.Core/PKM/Shared/IHomeTrack.cs b/PKHeX.Core/PKM/Shared/IHomeTrack.cs new file mode 100644 index 000000000..0cf40f5de --- /dev/null +++ b/PKHeX.Core/PKM/Shared/IHomeTrack.cs @@ -0,0 +1,13 @@ +namespace PKHeX.Core +{ + /// + /// Interface that exposes a for Pokémon HOME. + /// + public interface IHomeTrack + { + /// + /// Tracker for the associated + /// + ulong Tracker { get; set; } + } +} \ No newline at end of file diff --git a/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs b/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs index 3fa01f1ed..5b9f2387f 100644 --- a/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs +++ b/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs @@ -1470,10 +1470,10 @@ private void Update_ID64(object sender, EventArgs e) if (!FieldsLoaded) return; // Trim out nonhex characters - if (sender == TB_HomeTracker && Entity is PK8 pk8) + if (sender == TB_HomeTracker && Entity is IHomeTrack home) { var value = Util.GetHexValue64(TB_HomeTracker.Text); - pk8.Tracker = value; + home.Tracker = value; TB_HomeTracker.Text = value.ToString("X16"); } }