mirror of
https://github.com/kwsch/PKHeX
synced 2024-12-24 03:13:18 +00:00
bf6c25eca7
A little bit cleaner when the logic is separated Keep an abstraction of BoxEdit to cache the current box contents. Already fetched to show sprites; any future fetches (for preview text / hover sprite) can reuse the already fetched pkm data. Should probably rewrite this stuff completely, but effort better spent elsewhere
57 lines
No EOL
1.6 KiB
C#
57 lines
No EOL
1.6 KiB
C#
using System;
|
|
|
|
namespace PKHeX.Core
|
|
{
|
|
/// <summary>
|
|
/// Represents a Box Editor that loads the contents for easy manipulation.
|
|
/// </summary>
|
|
public class BoxEdit
|
|
{
|
|
private readonly SaveFile SAV;
|
|
private readonly PKM[] CurrentContents;
|
|
|
|
public BoxEdit(SaveFile sav)
|
|
{
|
|
SAV = sav;
|
|
CurrentContents = new PKM[sav.BoxSlotCount];
|
|
}
|
|
|
|
public void LoadBox(int box)
|
|
{
|
|
if ((uint)box >= SAV.BoxCount)
|
|
throw new ArgumentOutOfRangeException(nameof(box));
|
|
|
|
SAV.AddBoxData(CurrentContents, box, 0);
|
|
CurrentBox = box;
|
|
}
|
|
|
|
public PKM this[int index]
|
|
{
|
|
get => CurrentContents[index];
|
|
set
|
|
{
|
|
CurrentContents[index] = value;
|
|
int ofs = SAV.GetBoxSlotOffset(index);
|
|
SAV.SetStoredSlot(value, ofs);
|
|
}
|
|
}
|
|
|
|
public int CurrentBox { get; private set; }
|
|
public int BoxWallpaper { get => SAV.GetBoxWallpaper(CurrentBox); set => SAV.SetBoxWallpaper(CurrentBox, value); }
|
|
public string BoxName { get => SAV.GetBoxName(CurrentBox); set => SAV.SetBoxName(CurrentBox, value); }
|
|
|
|
public int MoveLeft(bool max = false)
|
|
{
|
|
int newBox = max ? 0 : (CurrentBox + SAV.BoxCount - 1) % SAV.BoxCount;
|
|
LoadBox(newBox);
|
|
return newBox;
|
|
}
|
|
|
|
public int MoveRight(bool max = false)
|
|
{
|
|
int newBox = max ? SAV.BoxCount - 1 : (CurrentBox + 1) % SAV.BoxCount;
|
|
LoadBox(newBox);
|
|
return newBox;
|
|
}
|
|
}
|
|
} |