From 28767df0fb4eb4a42e03dae699b904bdda4e2c1e Mon Sep 17 00:00:00 2001 From: Kurt Date: Sat, 31 Oct 2020 11:43:57 -0700 Subject: [PATCH] Split gamesync details to interface --- PKHeX.Core/Saves/SAV6.cs | 6 ++--- PKHeX.Core/Saves/SAV7.cs | 4 +-- PKHeX.Core/Saves/SAV7b.cs | 6 ++--- PKHeX.Core/Saves/SaveFile.cs | 2 -- .../Saves/Substructures/Misc/IGameSync.cs | 11 ++++++++ .../Controls/SAV Editor/SAVEditor.cs | 25 ++++++++----------- 6 files changed, 30 insertions(+), 24 deletions(-) create mode 100644 PKHeX.Core/Saves/Substructures/Misc/IGameSync.cs diff --git a/PKHeX.Core/Saves/SAV6.cs b/PKHeX.Core/Saves/SAV6.cs index 170c49102..c68dcb3a8 100644 --- a/PKHeX.Core/Saves/SAV6.cs +++ b/PKHeX.Core/Saves/SAV6.cs @@ -5,7 +5,7 @@ namespace PKHeX.Core /// /// Generation 6 object. /// - public abstract class SAV6 : SAV_BEEF, ITrainerStatRecord, ISaveBlock6Core, IRegionOrigin + public abstract class SAV6 : SAV_BEEF, ITrainerStatRecord, ISaveBlock6Core, IRegionOrigin, IGameSync { // Save Data Attributes protected override string BAKText => $"{OT} ({Version}) - {Played.LastSavedTime}"; @@ -63,8 +63,8 @@ namespace PKHeX.Core public int Region { get => Status.SubRegion; set => Status.SubRegion = value; } public int Country { get => Status.Country; set => Status.Country = value; } public int ConsoleRegion { get => Status.ConsoleRegion; set => Status.ConsoleRegion = value; } - public override int GameSyncIDSize => MyStatus6.GameSyncIDSize; // 64 bits - public override string GameSyncID { get => Status.GameSyncID; set => Status.GameSyncID = value; } + public int GameSyncIDSize => MyStatus6.GameSyncIDSize; // 64 bits + public string GameSyncID { get => Status.GameSyncID; set => Status.GameSyncID = value; } public override int PlayedHours { get => Played.PlayedHours; set => Played.PlayedHours = value; } public override int PlayedMinutes { get => Played.PlayedMinutes; set => Played.PlayedMinutes = value; } public override int PlayedSeconds { get => Played.PlayedSeconds; set => Played.PlayedSeconds = value; } diff --git a/PKHeX.Core/Saves/SAV7.cs b/PKHeX.Core/Saves/SAV7.cs index 070de2a8a..f77a7a748 100644 --- a/PKHeX.Core/Saves/SAV7.cs +++ b/PKHeX.Core/Saves/SAV7.cs @@ -139,8 +139,8 @@ namespace PKHeX.Core public override int SID { get => MyStatus.SID; set => MyStatus.SID = value; } public override int Game { get => MyStatus.Game; set => MyStatus.Game = value; } public override int Gender { get => MyStatus.Gender; set => MyStatus.Gender = value; } - public override int GameSyncIDSize => MyStatus7.GameSyncIDSize; // 64 bits - public override string GameSyncID { get => MyStatus.GameSyncID; set => MyStatus.GameSyncID = value; } + public int GameSyncIDSize => MyStatus7.GameSyncIDSize; // 64 bits + public string GameSyncID { get => MyStatus.GameSyncID; set => MyStatus.GameSyncID = value; } public int Region { get => MyStatus.SubRegion; set => MyStatus.SubRegion = value; } public int Country { get => MyStatus.Country; set => MyStatus.Country = value; } public int ConsoleRegion { get => MyStatus.ConsoleRegion; set => MyStatus.ConsoleRegion = value; } diff --git a/PKHeX.Core/Saves/SAV7b.cs b/PKHeX.Core/Saves/SAV7b.cs index 5039303dc..436c86ddc 100644 --- a/PKHeX.Core/Saves/SAV7b.cs +++ b/PKHeX.Core/Saves/SAV7b.cs @@ -7,7 +7,7 @@ namespace PKHeX.Core /// /// Generation 7 object for games. /// - public sealed class SAV7b : SAV_BEEF + public sealed class SAV7b : SAV_BEEF, IGameSync { protected override string BAKText => $"{OT} ({Version}) - {Blocks.Played.LastSavedTime}"; public override string Filter => "savedata|*.bin"; @@ -172,7 +172,7 @@ namespace PKHeX.Core protected override bool[] MysteryGiftReceivedFlags { get => Blocks.GiftRecords.Flags; set => Blocks.GiftRecords.Flags = value; } protected override DataMysteryGift[] MysteryGiftCards { get => Blocks.GiftRecords.Records; set => Blocks.GiftRecords.Records = (WR7[])value; } - public override int GameSyncIDSize => MyStatus7b.GameSyncIDSize; // 64 bits - public override string GameSyncID { get => Blocks.Status.GameSyncID; set => Blocks.Status.GameSyncID = value; } + public int GameSyncIDSize => MyStatus7b.GameSyncIDSize; // 64 bits + public string GameSyncID { get => Blocks.Status.GameSyncID; set => Blocks.Status.GameSyncID = value; } } } diff --git a/PKHeX.Core/Saves/SaveFile.cs b/PKHeX.Core/Saves/SaveFile.cs index 955fb77d5..2de7c40a2 100644 --- a/PKHeX.Core/Saves/SaveFile.cs +++ b/PKHeX.Core/Saves/SaveFile.cs @@ -317,8 +317,6 @@ namespace PKHeX.Core // Varied Methods protected abstract void SetChecksums(); - public virtual int GameSyncIDSize { get; } = 8; - public virtual string GameSyncID { get => string.Empty; set { } } #region Daycare public bool HasDaycare => DaycareOffset > -1; diff --git a/PKHeX.Core/Saves/Substructures/Misc/IGameSync.cs b/PKHeX.Core/Saves/Substructures/Misc/IGameSync.cs new file mode 100644 index 000000000..16d32032d --- /dev/null +++ b/PKHeX.Core/Saves/Substructures/Misc/IGameSync.cs @@ -0,0 +1,11 @@ +namespace PKHeX.Core +{ + /// + /// Provides details about the save file's Game Sync identifier. + /// + public interface IGameSync + { + int GameSyncIDSize { get; } + string GameSyncID { get; set; } + } +} diff --git a/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs b/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs index b221424d9..37163e8db 100644 --- a/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs +++ b/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs @@ -462,10 +462,10 @@ namespace PKHeX.WinForms.Controls SAV.SetDaycareRNGSeed(SAV.DaycareIndex, value); SAV.Edited = true; } - else if (tb == TB_GameSync) + else if (tb == TB_GameSync && SAV is IGameSync sync) { - var value = filterText.PadLeft(SAV.GameSyncIDSize, '0'); - SAV.GameSyncID = value; + var value = filterText.PadLeft(sync.GameSyncIDSize, '0'); + sync.GameSyncID = value; SAV.Edited = true; } else if (SAV is ISecureValueStorage s) @@ -1122,23 +1122,20 @@ namespace PKHeX.WinForms.Controls TB_Secure2.Text = s.TimeStampPrevious.ToString("X16"); } - switch (sav.Generation) + if (sav is IGameSync sync) { - case 6: - case 7: - var gsid = sav.GameSyncID; - TB_GameSync.Enabled = !string.IsNullOrEmpty(gsid); - TB_GameSync.MaxLength = sav.GameSyncIDSize; - TB_GameSync.Text = (string.IsNullOrEmpty(gsid) ? 0.ToString() : gsid).PadLeft(sav.GameSyncIDSize, '0'); - break; + var gsid = sync.GameSyncID; + TB_GameSync.Enabled = !string.IsNullOrEmpty(gsid); + TB_GameSync.MaxLength = sync.GameSyncIDSize; + TB_GameSync.Text = (string.IsNullOrEmpty(gsid) ? 0.ToString() : gsid).PadLeft(sync.GameSyncIDSize, '0'); } } private void ToggleSecrets(SaveFile sav, bool hide) { - var g67 = 6 <= sav.Generation && sav.Generation <= 7; - TB_Secure1.Visible = TB_Secure2.Visible = L_Secure1.Visible = L_Secure2.Visible = sav.Exportable && g67 && !hide; - TB_GameSync.Visible = L_GameSync.Visible = sav.Exportable && g67 && !hide; + var shouldShow = sav.Exportable && !hide; + TB_Secure1.Visible = TB_Secure2.Visible = L_Secure1.Visible = L_Secure2.Visible = shouldShow && sav is ISecureValueStorage; + TB_GameSync.Visible = L_GameSync.Visible = shouldShow && sav is IGameSync; } // DragDrop