Skip to content

Commit

Permalink
Rename box storage slot flag fetch
Browse files Browse the repository at this point in the history
`IsSlotX` is a little ambiguous; `IsBoxSlotX` much better.
  • Loading branch information
kwsch committed Jun 29, 2024
1 parent bcb4e83 commit 496c66b
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion PKHeX.Core/Editing/Saves/Slots/Info/SlotInfoBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace PKHeX.Core;
public sealed record SlotInfoBox(int Box, int Slot) : ISlotInfo
{
public StorageSlotType Type => StorageSlotType.Box;
public bool CanWriteTo(SaveFile sav) => sav.HasBox && !sav.IsSlotLocked(Box, Slot);
public bool CanWriteTo(SaveFile sav) => sav.HasBox && !sav.IsBoxSlotLocked(Box, Slot);
public WriteBlockedMessage CanWriteTo(SaveFile sav, PKM pk) => WriteBlockedMessage.None;

public bool WriteTo(SaveFile sav, PKM pk, PKMImportSetting setting = PKMImportSetting.UseDefault)
Expand Down
2 changes: 1 addition & 1 deletion PKHeX.Core/PKM/Util/EntitySorting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public static IEnumerable<PKM> BubbleUp(this IEnumerable<PKM> list, SaveFile sav
var ctr = start;
foreach (var x in list)
{
while (sav.IsSlotOverwriteProtected(ctr))
while (sav.IsBoxSlotOverwriteProtected(ctr))
ctr++;
bool isMatch = check(ctr);
var arr = isMatch ? matches : failures;
Expand Down
2 changes: 1 addition & 1 deletion PKHeX.Core/Saves/SAV7.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public override int PartyCount
protected set => Data[Party + (6 * SIZE_PARTY)] = (byte)value;
}

public override StorageSlotSource GetSlotFlags(int index)
public override StorageSlotSource GetBoxSlotFlags(int index)
{
int team = Array.IndexOf(TeamSlots, index);
if (team < 0)
Expand Down
2 changes: 1 addition & 1 deletion PKHeX.Core/Saves/SAV7b.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ protected override void SetPKM(PKM pk, bool isParty = false)
public override int PartyCount { get => Blocks.Storage.PartyCount; protected set => Blocks.Storage.PartyCount = value; }
protected override void SetPartyValues(PKM pk, bool isParty) => base.SetPartyValues(pk, true);

public override StorageSlotSource GetSlotFlags(int index)
public override StorageSlotSource GetBoxSlotFlags(int index)
{
var result = StorageSlotSource.None;
var header = Blocks.Storage.PokeListInfo;
Expand Down
2 changes: 1 addition & 1 deletion PKHeX.Core/Saves/SAV8BS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private void ReloadBattleTeams()
BoxLayout.LoadBattleTeams();
}

public override StorageSlotSource GetSlotFlags(int index)
public override StorageSlotSource GetBoxSlotFlags(int index)
{
int team = Array.IndexOf(TeamSlots, index);
if (team < 0)
Expand Down
2 changes: 1 addition & 1 deletion PKHeX.Core/Saves/SAV8SWSH.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public override int PartyCount
public int GetRecordOffset(int recordID) => Records.GetRecordOffset(recordID);
public int RecordCount => Record8.RecordCount;

public override StorageSlotSource GetSlotFlags(int index)
public override StorageSlotSource GetBoxSlotFlags(int index)
{
int team = Array.IndexOf(TeamIndexes.TeamSlots, index);
if (team < 0)
Expand Down
2 changes: 1 addition & 1 deletion PKHeX.Core/Saves/SAV9SV.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public override int PartyCount
//public int GetRecordOffset(int recordID) => Records.GetRecordOffset(recordID);
//public int RecordCount => Record9.RecordCount;

public override StorageSlotSource GetSlotFlags(int index)
public override StorageSlotSource GetBoxSlotFlags(int index)
{
int team = Array.IndexOf(TeamIndexes.TeamSlots, index);
if (team < 0)
Expand Down
26 changes: 13 additions & 13 deletions PKHeX.Core/Saves/SaveFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ public int SetBoxData(IList<PKM> value, int box, int index = 0)
int skipped = 0;
for (int slot = 0; slot < BoxSlotCount; slot++)
{
var flags = GetSlotFlags(box, slot);
var flags = GetBoxSlotFlags(box, slot);
if (!flags.IsOverwriteProtected())
SetBoxSlotAtIndex(value[index + slot], box, slot);
else
Expand Down Expand Up @@ -469,12 +469,12 @@ public void AddBoxData(IList<PKM> data, int box, int index)
/// Slot indexes that are protected from overwriting.
/// </summary>
protected virtual IList<int>[] SlotPointers => [ TeamSlots ];
public virtual StorageSlotSource GetSlotFlags(int index) => StorageSlotSource.None;
public StorageSlotSource GetSlotFlags(int box, int slot) => GetSlotFlags((box * BoxSlotCount) + slot);
public bool IsSlotLocked(int box, int slot) => GetSlotFlags(box, slot).HasFlag(StorageSlotSource.Locked);
public bool IsSlotLocked(int index) => GetSlotFlags(index).HasFlag(StorageSlotSource.Locked);
public bool IsSlotOverwriteProtected(int box, int slot) => GetSlotFlags(box, slot).IsOverwriteProtected();
public bool IsSlotOverwriteProtected(int index) => GetSlotFlags(index).IsOverwriteProtected();
public virtual StorageSlotSource GetBoxSlotFlags(int index) => StorageSlotSource.None;
public StorageSlotSource GetBoxSlotFlags(int box, int slot) => GetBoxSlotFlags((box * BoxSlotCount) + slot);
public bool IsBoxSlotLocked(int box, int slot) => GetBoxSlotFlags(box, slot).HasFlag(StorageSlotSource.Locked);
public bool IsBoxSlotLocked(int index) => GetBoxSlotFlags(index).HasFlag(StorageSlotSource.Locked);
public bool IsBoxSlotOverwriteProtected(int box, int slot) => GetBoxSlotFlags(box, slot).IsOverwriteProtected();
public bool IsBoxSlotOverwriteProtected(int index) => GetBoxSlotFlags(index).IsOverwriteProtected();

private const int StorageFullValue = -1;
public bool IsStorageFull => NextOpenBoxSlot() == StorageFullValue;
Expand Down Expand Up @@ -506,7 +506,7 @@ private bool IsRegionOverwriteProtected(int min, int max)
{
foreach (int slotIndex in arrays)
{
if (!GetSlotFlags(slotIndex).IsOverwriteProtected())
if (!GetBoxSlotFlags(slotIndex).IsOverwriteProtected())
continue;
if (min <= slotIndex && slotIndex < max)
return true;
Expand All @@ -529,7 +529,7 @@ public bool IsAnySlotLockedInBox(int BoxStart, int BoxEnd)
{
foreach (int slotIndex in arrays)
{
if (!GetSlotFlags(slotIndex).HasFlag(StorageSlotSource.Locked))
if (!GetBoxSlotFlags(slotIndex).HasFlag(StorageSlotSource.Locked))
continue;
if (min <= slotIndex && slotIndex < max)
return true;
Expand Down Expand Up @@ -678,7 +678,7 @@ public int SortBoxes(int BoxStart = 0, int BoxEnd = -1, Func<IEnumerable<PKM>, i
if (BoxEnd >= BoxStart)
Section = Section.Take(BoxSlotCount * (BoxEnd - BoxStart + 1));

Func<int, bool> skip = IsSlotOverwriteProtected;
Func<int, bool> skip = IsBoxSlotOverwriteProtected;
Section = Section.Where((_, i) => !skip(start + i));
var method = sortMethod ?? ((z, _) => z.OrderBySpecies());
var Sorted = method(Section, start);
Expand Down Expand Up @@ -728,7 +728,7 @@ public int ClearBoxes(int BoxStart = 0, int BoxEnd = -1, Func<PKM, bool>? delete
{
for (int p = 0; p < BoxSlotCount; p++)
{
if (IsSlotOverwriteProtected(i, p))
if (IsBoxSlotOverwriteProtected(i, p))
continue;
var ofs = GetBoxSlotOffset(i, p);
if (!IsPKMPresent(storage[ofs..]))
Expand Down Expand Up @@ -765,7 +765,7 @@ public int ModifyBoxes(Action<PKM> action, int BoxStart = 0, int BoxEnd = -1)
{
for (int s = 0; s < BoxSlotCount; s++)
{
if (IsSlotOverwriteProtected(b, s))
if (IsBoxSlotOverwriteProtected(b, s))
continue;
var ofs = GetBoxSlotOffset(b, s);
var dest = storage[ofs..];
Expand Down Expand Up @@ -814,7 +814,7 @@ private bool SetConcatenatedBinary(ReadOnlySpan<byte> data, int expectLength, in
var entryLength = SIZE_BOXSLOT;
for (int i = 0, ctr = start; i < data.Length; i += entryLength)
{
if (IsSlotOverwriteProtected(ctr))
if (IsBoxSlotOverwriteProtected(ctr))
continue;
var src = data.Slice(i, entryLength);
var arr = src.ToArray();
Expand Down
4 changes: 2 additions & 2 deletions PKHeX.Core/Saves/Storage/SAV4Ranch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public sealed class SAV4Ranch : BulkStorage, ISaveFileRevision
public override string Extension => ".bin";

protected override RK4 GetPKM(byte[] data) => new(data);
public override StorageSlotSource GetSlotFlags(int index) => index >= SlotCount ? StorageSlotSource.Locked : StorageSlotSource.None;
protected override bool IsSlotSwapProtected(int box, int slot) => IsSlotOverwriteProtected(box, slot);
public override StorageSlotSource GetBoxSlotFlags(int index) => index >= SlotCount ? StorageSlotSource.Locked : StorageSlotSource.None;
protected override bool IsSlotSwapProtected(int box, int slot) => IsBoxSlotOverwriteProtected(box, slot);
public override bool IsPKMPresent(ReadOnlySpan<byte> data) => EntityDetection.IsPresentSAV4Ranch(data);

private readonly GameVersion _version;
Expand Down
2 changes: 1 addition & 1 deletion PKHeX.Core/Saves/Util/SaveExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static int ImportPKMs(this SaveFile sav, IEnumerable<PKM> compat, bool ov
{
if (overwrite)
{
while (sav.IsSlotOverwriteProtected(index))
while (sav.IsBoxSlotOverwriteProtected(index))
++index;

// The above will return false if out of range. We need to double-check.
Expand Down
2 changes: 1 addition & 1 deletion PKHeX.Drawing.PokeSprite/Util/SpriteUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private static Bitmap GetSprite(PKM pk, SaveFile sav, int box, int slot, bool fl
}
if (inBox) // in box
{
var flags = sav.GetSlotFlags(box, slot);
var flags = sav.GetBoxSlotFlags(box, slot);

// Indicate any battle box teams & according locked state.
int team = flags.IsBattleTeam();
Expand Down
2 changes: 1 addition & 1 deletion PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,7 @@ private static int ImportGroup(IEnumerable<PKM> data, SaveFile sav, int box, PKM
foreach (var x in data)
{
var i = index++;
if (sav.IsSlotOverwriteProtected(box, i))
if (sav.IsBoxSlotOverwriteProtected(box, i))
{
slotSkipped++;
continue;
Expand Down
2 changes: 1 addition & 1 deletion PKHeX.WinForms/Subforms/PKM Editors/BatchEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ private void ProcessSAV(IList<SlotCache> data, IReadOnlyList<StringInstruction>
continue;
}

if (entry.Source is SlotInfoBox info && SAV.GetSlotFlags(info.Box, info.Slot).IsOverwriteProtected())
if (entry.Source is SlotInfoBox info && SAV.GetBoxSlotFlags(info.Box, info.Slot).IsOverwriteProtected())
editor.AddSkipped();
else if (!BatchEditing.IsFilterMatchMeta(filterMeta, entry))
editor.AddSkipped();
Expand Down

0 comments on commit 496c66b

Please sign in to comment.