From b45ce123daea2c83b6dbe95c422654baf83a7dcc Mon Sep 17 00:00:00 2001 From: Kurt Date: Tue, 8 Mar 2022 20:58:49 -0800 Subject: [PATCH] Show rainbow bean index 14 -> 15 Clean up some API functions --- .../Saves/Substructures/Gen7/ResortSave7.cs | 42 ++++++++++++++++-- .../Substructures/Inventory/BeanPouch.cs | 43 ------------------- .../Save Editors/Gen7/SAV_Pokebean.cs | 14 +++--- 3 files changed, 45 insertions(+), 54 deletions(-) delete mode 100644 PKHeX.Core/Saves/Substructures/Inventory/BeanPouch.cs diff --git a/PKHeX.Core/Saves/Substructures/Gen7/ResortSave7.cs b/PKHeX.Core/Saves/Substructures/Gen7/ResortSave7.cs index 072a6e0df..9060e379e 100644 --- a/PKHeX.Core/Saves/Substructures/Gen7/ResortSave7.cs +++ b/PKHeX.Core/Saves/Substructures/Gen7/ResortSave7.cs @@ -10,11 +10,11 @@ public sealed class ResortSave7 : SaveBlock public const int ResortCount = 93; public int GetResortSlotOffset(int slot) => Offset + 0x16 + (slot * PokeCrypto.SIZE_6STORED); - public PKM[] ResortPKM + public PK7[] ResortPKM { get { - PKM[] data = new PKM[ResortCount]; + PK7[] data = new PK7[ResortCount]; for (int i = 0; i < data.Length; i++) { var bytes = SAV.GetData(GetResortSlotOffset(i), PokeCrypto.SIZE_6STORED); @@ -32,8 +32,10 @@ public PKM[] ResortPKM } } - public const int BEANS_MAX = 14; + public const int BEANS_MAX = 15; public Span GetBeans() => Data.AsSpan(Offset + 0x564C, BEANS_MAX); + public void ClearBeans() => GetBeans().Fill(0); + public void FillBeans(byte value = 255) => GetBeans().Fill(value); public int GetPokebeanCount(int bean_id) => GetBeans()[bean_id]; @@ -45,5 +47,39 @@ public void SetPokebeanCount(int bean_id, int count) count = 255; GetBeans()[bean_id] = (byte)count; } + + /// + /// Utility to indicate the bean pouch indexes. + /// + public static string[] GetBeanIndexNames() + { + var colors = Enum.GetNames(typeof(BeanColor7)); + return GetBeanIndexNames(colors); + } + + private static string[] GetBeanIndexNames(string[] colors) + { + // 7 regular, 7 patterned, one rainbow + var beans = new string[(colors.Length * 2) + 1]; + for (int i = 0; i < colors.Length; i++) + { + var z = colors[i]; + beans[i] = $"{z} Bean"; + beans[i + colors.Length] = $"{z} Patterned Bean"; + } + beans[^1] = "Rainbow Bean"; + return beans; + } + } + + public enum BeanColor7 : byte + { + Red, + Blue, + LightBlue, + Green, + Yellow, + Purple, + Orange, } } diff --git a/PKHeX.Core/Saves/Substructures/Inventory/BeanPouch.cs b/PKHeX.Core/Saves/Substructures/Inventory/BeanPouch.cs deleted file mode 100644 index 4c5964256..000000000 --- a/PKHeX.Core/Saves/Substructures/Inventory/BeanPouch.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; - -namespace PKHeX.Core -{ - /// - /// Reads the bean pouch data from a . - /// - public sealed class BeanPouch - { - public const int Count = 15; - public static readonly string[] BeanIndexNames = GetBeanList(); - - public static string[] GetBeanList() - { - var colors = Enum.GetNames(typeof(BeanColor)); - var beans = new List(); - // 7 regular, 7 patterned, one rainbow - beans.AddRange(colors.Select(z => $"{z} Bean")); - beans.AddRange(colors.Select(z => $"{z} Patterned Bean")); - beans.Add("Rainbow Bean"); - return beans.ToArray(); - } - - private enum BeanColor - { - Red, - Blue, - LightBlue, - Green, - Yellow, - Purple, - Orange, - } - - private readonly SAV7 SAV; - public BeanPouch(SAV7 sav) => SAV = sav; - - public Span Beans => SAV.ResortSave.GetBeans(); - public void SetCountAll(byte val) => SAV.ResortSave.GetBeans().Fill(val); - } -} diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Pokebean.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Pokebean.cs index 3936691c5..b5177ab88 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Pokebean.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Pokebean.cs @@ -13,12 +13,9 @@ public SAV_Pokebean(SaveFile sav) SAV = (SAV7)(Origin = sav).Clone(); InitializeGrid(); - Pouch = new BeanPouch(SAV); LoadValues(); } - private readonly BeanPouch Pouch; - private readonly SaveFile Origin; private readonly SAV7 SAV; @@ -26,11 +23,12 @@ private void LoadValues() { dgv.Rows.Clear(); - var beans = Pouch.Beans; + var names = ResortSave7.GetBeanIndexNames(); + var beans = SAV.ResortSave.GetBeans(); dgv.Rows.Add(beans.Length); for (int i = 0; i < beans.Length; i++) { - dgv.Rows[i].Cells[0].Value = BeanPouch.BeanIndexNames[i]; + dgv.Rows[i].Cells[0].Value = names[i]; dgv.Rows[i].Cells[1].Value = beans[i].ToString(); } } @@ -62,21 +60,21 @@ private void B_Cancel_Click(object sender, EventArgs e) private void B_All_Click(object sender, EventArgs e) { - Pouch.SetCountAll(255); + SAV.ResortSave.FillBeans(); LoadValues(); System.Media.SystemSounds.Asterisk.Play(); } private void B_None_Click(object sender, EventArgs e) { - Pouch.SetCountAll(0); + SAV.ResortSave.ClearBeans(); LoadValues(); System.Media.SystemSounds.Asterisk.Play(); } private void B_Save_Click(object sender, EventArgs e) { - var beans = Pouch.Beans; + var beans = SAV.ResortSave.GetBeans(); for (int i = 0; i < beans.Length; i++) { var cells = dgv.Rows[i].Cells;