Move inventory item clearing to class

Fixes ClearItem offset being wrong
This commit is contained in:
Kurt 2021-12-13 18:31:00 -08:00
parent 57efeff0ee
commit 98713f4d7b
3 changed files with 7 additions and 5 deletions

View file

@ -99,7 +99,7 @@ namespace PKHeX.Core
for (ushort i = 0; i < (ushort)SAV.MaxItemID; i++) // even though there are 3000, just overwrite the ones that people will mess up.
{
if (!hashSet.Contains(i))
InventoryPouch8b.ClearItem(Data, InventoryPouch8b.GetItemOffset(i, Offset));
InventoryItem8b.Clear(Data, InventoryPouch8b.GetItemOffset(i, Offset));
}
}

View file

@ -4,6 +4,8 @@ namespace PKHeX.Core
{
public sealed class InventoryItem8b : InventoryItem, IItemFavorite, IItemNew
{
public const int SIZE = 0x10;
public bool IsFavorite { get; set; }
public bool IsNew { get; set; }
public ushort SortOrder { get; set; }
@ -38,6 +40,8 @@ namespace PKHeX.Core
BitConverter.GetBytes((ushort)0).CopyTo(data, offset + 0xE);
}
public static void Clear(byte[] data, int offset) => Array.Clear(data, offset, SIZE);
public override void SetNewDetails(int count)
{
base.SetNewDetails(count);

View file

@ -6,8 +6,6 @@ namespace PKHeX.Core
{
public sealed class InventoryPouch8b : InventoryPouch
{
private const int SIZE_ITEM = 0x10;
public bool SetNew { get; set; }
public InventoryPouch8b(InventoryType type, ushort[] legal, int maxCount, int offset,
@ -84,8 +82,8 @@ namespace PKHeX.Core
}
}
public static int GetItemOffset(ushort index, int baseOffset) => baseOffset + (SIZE_ITEM * index);
public static int GetItemOffset(ushort index, int baseOffset) => baseOffset + (InventoryItem8b.SIZE * index);
public static void ClearItem(byte[] data, int ofs) => Array.Clear(data, ofs, 0x10);
public void ClearItem(byte[] data, ushort index) => InventoryItem8b.Clear(data, GetItemOffset(index, Offset));
}
}