Show rainbow bean index

14 -> 15
Clean up some API functions
This commit is contained in:
Kurt
2022-03-08 20:58:49 -08:00
parent 5359a140a6
commit b45ce123da
3 changed files with 45 additions and 54 deletions

View File

@@ -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<byte> 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;
}
/// <summary>
/// Utility to indicate the bean pouch indexes.
/// </summary>
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,
}
}

View File

@@ -1,43 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace PKHeX.Core
{
/// <summary>
/// Reads the bean pouch data from a <see cref="SAV7"/>.
/// </summary>
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<string>();
// 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<byte> Beans => SAV.ResortSave.GetBeans();
public void SetCountAll(byte val) => SAV.ResortSave.GetBeans().Fill(val);
}
}

View File

@@ -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;