2023-03-26 06:14:50 +00:00
|
|
|
using System.Collections.Generic;
|
2019-05-14 01:42:30 +00:00
|
|
|
using System.Diagnostics;
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Storage for all <see cref="Poffin4"/> the trainer has.
|
|
|
|
/// </summary>
|
|
|
|
public sealed class PoffinCase4
|
2019-05-14 01:42:30 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
private readonly SAV4Sinnoh SAV;
|
|
|
|
private readonly int Offset;
|
|
|
|
public readonly Poffin4[] Poffins;
|
|
|
|
|
|
|
|
private const int Count = 100;
|
|
|
|
|
|
|
|
public PoffinCase4(SAV4Sinnoh sav)
|
|
|
|
{
|
|
|
|
SAV = sav;
|
|
|
|
|
|
|
|
Offset = sav.OFS_PoffinCase;
|
|
|
|
Poffins = ReadPoffins(SAV, Offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Save() => WritePoffins(SAV, Offset, Poffins);
|
|
|
|
|
|
|
|
private static Poffin4[] ReadPoffins(SAV4Sinnoh sav, int offset)
|
|
|
|
{
|
2023-03-26 22:16:12 +00:00
|
|
|
var result = new Poffin4[Count];
|
|
|
|
for (int i = 0; i < result.Length; i++)
|
|
|
|
{
|
|
|
|
var ofs = offset + (i * Poffin4.SIZE);
|
|
|
|
var span = sav.General.Slice(ofs, Poffin4.SIZE);
|
|
|
|
result[i] = new Poffin4(span.ToArray());
|
|
|
|
}
|
|
|
|
return result;
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private static void WritePoffins(SAV4Sinnoh sav, int offset, IReadOnlyList<Poffin4> poffins)
|
|
|
|
{
|
|
|
|
Debug.Assert(poffins.Count == Count);
|
|
|
|
for (int i = 0; i < poffins.Count; i++)
|
2023-03-26 06:14:50 +00:00
|
|
|
{
|
2023-03-26 22:16:12 +00:00
|
|
|
var ofs = offset + (i * Poffin4.SIZE);
|
|
|
|
var span = sav.General.Slice(ofs, Poffin4.SIZE);
|
2023-03-26 06:14:50 +00:00
|
|
|
sav.SetData(span, poffins[i].Data);
|
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void FillCase()
|
|
|
|
{
|
|
|
|
foreach (var p in Poffins)
|
|
|
|
p.SetAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void DeleteAll()
|
2019-05-14 01:42:30 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
foreach (var p in Poffins)
|
|
|
|
p.Delete();
|
2019-05-14 01:42:30 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|