2022-11-25 01:42:17 +00:00
|
|
|
using System;
|
|
|
|
|
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
2023-12-04 04:13:20 +00:00
|
|
|
public sealed class BoxLayout9(SAV9SV sav, SCBlock block) : SaveBlock<SAV9SV>(sav, block.Data), IBoxDetailName
|
2022-11-25 01:42:17 +00:00
|
|
|
{
|
|
|
|
public const int BoxCount = 32;
|
|
|
|
|
|
|
|
private const int StringMaxLength = SAV6.LongStringLength / 2;
|
|
|
|
|
|
|
|
private static int GetBoxNameOffset(int box) => SAV6.LongStringLength * box;
|
2024-03-04 05:13:16 +00:00
|
|
|
private Span<byte> GetBoxNameSpan(int box) => Data.Slice(GetBoxNameOffset(box), SAV6.LongStringLength);
|
2022-11-25 01:42:17 +00:00
|
|
|
|
|
|
|
public string GetBoxName(int box)
|
|
|
|
{
|
|
|
|
var span = GetBoxNameSpan(box);
|
|
|
|
if (System.Buffers.Binary.BinaryPrimitives.ReadUInt16LittleEndian(span) == 0)
|
2024-03-04 05:13:16 +00:00
|
|
|
return BoxDetailNameExtensions.GetDefaultBoxName(box);
|
2022-11-25 01:42:17 +00:00
|
|
|
return SAV.GetString(span);
|
|
|
|
}
|
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
public void SetBoxName(int box, ReadOnlySpan<char> value)
|
2022-11-25 01:42:17 +00:00
|
|
|
{
|
|
|
|
var span = GetBoxNameSpan(box);
|
2023-01-22 04:02:33 +00:00
|
|
|
SAV.SetString(span, value, StringMaxLength, StringConverterOption.ClearZero);
|
2022-11-25 01:42:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public string this[int i]
|
|
|
|
{
|
|
|
|
get => GetBoxName(i);
|
|
|
|
set => SetBoxName(i, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public int CurrentBox
|
|
|
|
{
|
|
|
|
get => SAV.GetValue<byte>(SaveBlockAccessor9SV.KCurrentBox);
|
|
|
|
set => SAV.SetValue(SaveBlockAccessor9SV.KCurrentBox, (byte)value);
|
|
|
|
}
|
|
|
|
}
|