From 990eb73f8a3be4af2c4e87d0071d14d1b1745b50 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sat, 7 Jul 2018 15:38:11 -0700 Subject: [PATCH] Misc simplifications recordmax is simplified --- PKHeX.Core/Saves/SAV7.cs | 4 +++- PKHeX.Core/Saves/Substructures/ITrainerStatRecord.cs | 1 + PKHeX.WinForms/Subforms/Save Editors/TrainerStat.cs | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/PKHeX.Core/Saves/SAV7.cs b/PKHeX.Core/Saves/SAV7.cs index 181aaeaf0..147571239 100644 --- a/PKHeX.Core/Saves/SAV7.cs +++ b/PKHeX.Core/Saves/SAV7.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; @@ -698,6 +699,7 @@ public override int PlayedSeconds public ulong AlolaTime { get => BitConverter.ToUInt64(Data, AdventureInfo + 0x48); set => BitConverter.GetBytes(value).CopyTo(Data, AdventureInfo + 0x48); } // Stat Records + public int RecordCount => 200; public int GetRecord(int recordID) { int ofs = GetRecordOffset(recordID); @@ -728,7 +730,7 @@ public int GetRecordOffset(int recordID) return -1; } public int GetRecordMax(int recordID) => GetRecordMax(recordID, USUM ? RecordMaxType_USUM : RecordMaxType_SM); - private static int GetRecordMax(int recordID, int[] maxes) => recordID < 200 ? RecordMax[(maxes ?? RecordMaxType_USUM)[recordID]] : 0; + private static int GetRecordMax(int recordID, IReadOnlyList maxes) => recordID < 200 ? RecordMax[maxes[recordID]] : 0; private static readonly int[] RecordMax = {999999999, 9999999, 999999, 99999, 65535, 9999, 999}; private static readonly int[] RecordMaxType_SM = { diff --git a/PKHeX.Core/Saves/Substructures/ITrainerStatRecord.cs b/PKHeX.Core/Saves/Substructures/ITrainerStatRecord.cs index 502b451a0..94b8afde5 100644 --- a/PKHeX.Core/Saves/Substructures/ITrainerStatRecord.cs +++ b/PKHeX.Core/Saves/Substructures/ITrainerStatRecord.cs @@ -6,5 +6,6 @@ public interface ITrainerStatRecord int GetRecordOffset(int recordID); int GetRecordMax(int recordID); void SetRecord(int recordID, int value); + int RecordCount { get; } } } diff --git a/PKHeX.WinForms/Subforms/Save Editors/TrainerStat.cs b/PKHeX.WinForms/Subforms/Save Editors/TrainerStat.cs index e6a021724..90f816e4e 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/TrainerStat.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/TrainerStat.cs @@ -20,7 +20,7 @@ public void LoadRecords(ITrainerStatRecord sav, Dictionary records) SAV = sav; RecordList = records; CB_Stats.Items.Clear(); - for (int i = 0; i < 200; i++) + for (int i = 0; i < sav.RecordCount; i++) { if (!RecordList.TryGetValue(i, out string name)) name = $"{i:D3}";