From f2ac29ff4e8e96cc5ff0834c91976fac2061ea8d Mon Sep 17 00:00:00 2001 From: Kurt Date: Fri, 5 Jul 2019 22:02:29 -0700 Subject: [PATCH] Relocate some logic slightly reduces savefile.cs footprint --- PKHeX.Core/Saves/SAV6.cs | 8 +++++++- PKHeX.Core/Saves/SAV6AO.cs | 2 ++ PKHeX.Core/Saves/SaveFile.cs | 19 ++----------------- PKHeX.Core/Saves/Util/SaveUtil.cs | 2 +- .../Controls/SAV Editor/SAVEditor.cs | 18 ++++++++---------- .../Save Editors/Gen6/SAV_SecretBase.cs | 4 ++-- 6 files changed, 22 insertions(+), 31 deletions(-) diff --git a/PKHeX.Core/Saves/SAV6.cs b/PKHeX.Core/Saves/SAV6.cs index 51468690d..5817b9798 100644 --- a/PKHeX.Core/Saves/SAV6.cs +++ b/PKHeX.Core/Saves/SAV6.cs @@ -51,13 +51,19 @@ public abstract class SAV6 : SAV_BEEF, ITrainerStatRecord protected int Trainer2 { get; set; } = int.MinValue; protected int WondercardFlags { get; set; } = int.MinValue; protected int PlayTime { get; set; } = int.MinValue; - protected int Daycare2 { get; set; } = int.MinValue; protected int LinkInfo { get; set; } = int.MinValue; protected int JPEG { get; set; } = int.MinValue; + public int SuperTrain { get; protected set; } = int.MinValue; // Accessible as SAV6 public int MaisonStats { get; protected set; } = int.MinValue; public int Accessories { get; protected set; } = int.MinValue; + public int PSS { get; protected set; } = int.MinValue; + public int SUBE { get; protected set; } = int.MinValue; + public int BerryField { get; protected set; } = int.MinValue; + + public virtual string JPEGTitle => string.Empty; + public virtual byte[] JPEGData => Array.Empty(); protected internal const int LongStringLength = 0x22; // bytes, not characters protected internal const int ShortStringLength = 0x1A; // bytes, not characters diff --git a/PKHeX.Core/Saves/SAV6AO.cs b/PKHeX.Core/Saves/SAV6AO.cs index 470995c39..7bde53223 100644 --- a/PKHeX.Core/Saves/SAV6AO.cs +++ b/PKHeX.Core/Saves/SAV6AO.cs @@ -172,6 +172,8 @@ private void Initialize() public int EonTicket { get; private set; } public int Contest { get; private set; } + private int Daycare2 { get; set; } + public int SecretBase { get; private set; } public Zukan6 Zukan { get; private set; } public Puff6 PuffBlock { get; private set; } diff --git a/PKHeX.Core/Saves/SaveFile.cs b/PKHeX.Core/Saves/SaveFile.cs index c16b6f0dd..7ba11f108 100644 --- a/PKHeX.Core/Saves/SaveFile.cs +++ b/PKHeX.Core/Saves/SaveFile.cs @@ -100,8 +100,8 @@ protected virtual byte[] GetFinalData() public bool E => Version == GameVersion.E; public bool FRLG => Version == GameVersion.FRLG; public bool RS => Version == GameVersion.RS; - public bool GSC => Version == GameVersion.GS || Version == GameVersion.C; - public bool RBY => Version == GameVersion.RBY; + public bool GSC => Generation == 2; + public bool RBY => Generation == 1; public bool GameCube => new[] { GameVersion.COLO, GameVersion.XD, GameVersion.RSBOX }.Contains(Version); public abstract int MaxMoveID { get; } @@ -114,23 +114,15 @@ protected virtual byte[] GetFinalData() // Flags public bool HasWondercards => WondercardData > -1; - public bool HasSuperTrain => SuperTrain > -1; - public bool HasBerryField => BerryField > -1; public bool HasHoF => HoF > -1; - public bool HasSecretBase => SecretBase > -1; - public bool HasPSS => PSS > -1; - public bool HasJPEG => JPEGData.Length > 0; public bool HasBox => Box > -1; public virtual bool HasParty => Party > -1; public bool HasBattleBox => BattleBox > -1; - public bool HasFused => Fused > -1; public bool HasDaycare => Daycare > -1; public virtual bool HasPokeDex => PokeDex > -1; public virtual bool HasBoxWallpapers => GetBoxWallpaperOffset(0) > -1; public virtual bool HasNamableBoxes => HasBoxWallpapers; - public bool HasPokeBlock => ORAS && !ORASDEMO; public virtual bool HasEvents => EventFlags.Length != 0; - public bool HasLink => (ORAS && !ORASDEMO) || XY; // Counts protected virtual int GiftCountMax { get; } = int.MinValue; @@ -156,12 +148,7 @@ protected virtual byte[] GetFinalData() public int GTS { get; protected set; } = int.MinValue; public int BattleBox { get; protected set; } = int.MinValue; public int Fused { get; protected set; } = int.MinValue; - public int SUBE { get; protected set; } = int.MinValue; public int PokeDex { get; protected set; } = int.MinValue; - public int SuperTrain { get; protected set; } = int.MinValue; - public int SecretBase { get; protected set; } = int.MinValue; - public int PSS { get; protected set; } = int.MinValue; - public int BerryField { get; protected set; } = int.MinValue; public int HoF { get; protected set; } = int.MinValue; // SAV Properties @@ -401,8 +388,6 @@ public virtual MysteryGiftAlbum GiftAlbum } public virtual bool BattleBoxLocked { get => false; set { } } - public virtual string JPEGTitle => string.Empty; - public virtual byte[] JPEGData => Array.Empty(); public virtual int Country { get => -1; set { } } public virtual int ConsoleRegion { get => -1; set { } } public virtual int SubRegion { get => -1; set { } } diff --git a/PKHeX.Core/Saves/Util/SaveUtil.cs b/PKHeX.Core/Saves/Util/SaveUtil.cs index 2baf97e07..a3b4c7354 100644 --- a/PKHeX.Core/Saves/Util/SaveUtil.cs +++ b/PKHeX.Core/Saves/Util/SaveUtil.cs @@ -746,7 +746,7 @@ byte[] GetSubsection(byte[] data, int start, int length = -1) /// SaveFile data to force /// Version to retrieve for /// New object. - public static SaveFile GetG3SaveOverride(SaveFile sav, GameVersion ver) + public static SAV3 GetG3SaveOverride(SaveFile sav, GameVersion ver) { switch (ver) // Reset save file info { diff --git a/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs b/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs index c2d9dd190..2bb29ad83 100644 --- a/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs +++ b/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs @@ -678,13 +678,14 @@ private void B_OUTHallofFame_Click(object sender, EventArgs e) private void B_JPEG_Click(object sender, EventArgs e) { - byte[] jpeg = SAV.JPEGData; - if (SAV.JPEGData.Length == 0) + var s6 = (SAV6)SAV; + byte[] jpeg = s6.JPEGData; + if (s6.JPEGData.Length == 0) { WinFormsUtil.Alert(MsgSaveJPEGExportFail); return; } - string filename = $"{SAV.JPEGTitle}'s picture"; + string filename = $"{s6.JPEGTitle}'s picture"; var sfd = new SaveFileDialog { FileName = filename, Filter = "JPEG|*.jpeg" }; if (sfd.ShowDialog() != DialogResult.OK) return; @@ -1004,21 +1005,18 @@ private void ToggleViewSubEditors(SaveFile sav) { PAN_BattleBox.Visible = L_BattleBox.Visible = L_ReadOnlyPBB.Visible = sav.HasBattleBox; GB_Daycare.Visible = sav.HasDaycare; - B_OpenSecretBase.Enabled = sav.HasSecretBase; + B_OpenPokeblocks.Enabled = sav is SAV6AO; + B_OpenSecretBase.Enabled = sav is SAV6AO; B_OpenPokepuffs.Enabled = sav is IPokePuff; - B_OUTPasserby.Enabled = sav.HasPSS; + B_JPEG.Visible = B_OpenLinkInfo.Enabled = B_OpenSuperTraining.Enabled = B_OUTPasserby.Enabled = sav is SAV6XY || sav is SAV6AO; B_OpenBoxLayout.Enabled = sav.HasNamableBoxes; B_OpenWondercards.Enabled = sav.HasWondercards; - B_OpenSuperTraining.Enabled = sav.HasSuperTrain; B_OpenHallofFame.Enabled = sav.HasHoF; B_OpenOPowers.Enabled = sav is IOPower; B_OpenPokedex.Enabled = sav.HasPokeDex; - B_OpenBerryField.Enabled = sav.HasBerryField && sav.XY; + B_OpenBerryField.Enabled = sav is SAV6XY; // oras undocumented B_OpenFriendSafari.Enabled = sav.XY; - B_OpenPokeblocks.Enabled = sav.HasPokeBlock; - B_JPEG.Visible = sav.HasJPEG; B_OpenEventFlags.Enabled = sav.HasEvents; - B_OpenLinkInfo.Enabled = sav.HasLink; B_CGearSkin.Enabled = sav.Generation == 5; B_OpenPokeBeans.Enabled = B_CellsStickers.Enabled = B_FestivalPlaza.Enabled = sav is SAV7; diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_SecretBase.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_SecretBase.cs index de94faeb5..303cba89a 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_SecretBase.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_SecretBase.cs @@ -10,13 +10,13 @@ namespace PKHeX.WinForms public partial class SAV_SecretBase : Form { private readonly SaveFile Origin; - private readonly SAV6 SAV; + private readonly SAV6AO SAV; public SAV_SecretBase(SaveFile sav) { InitializeComponent(); WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage); - SAV = (SAV6)(Origin = sav).Clone(); + SAV = (SAV6AO)(Origin = sav).Clone(); abilitylist = GameInfo.Strings.abilitylist; SetupComboBoxes();