mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-09-08 07:37:27 -05:00
Fix slot write/batch regressions
Closes #4866: Slot Set now uses default settings instead of "None" update. `SlotEditor.cs` Closes #4865: Return entire list of party data instead of first slot. No need to filter `GetChangelogSlots`. Resolves #4867: Update Run button enabled state when finishing the applicability scan. Add a note about bad rand range (`.Species=$100,$200` causes an internal error when executed). We don't care if SetRandomRange fails.
This commit is contained in:
@@ -136,6 +136,7 @@ public void SetRandomRange(ReadOnlySpan<char> str)
|
||||
}
|
||||
else
|
||||
{
|
||||
// Let any min > max situation throw later, if user entered in a bad rand range / parse failure of max (e.g. $100).
|
||||
Random = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,8 @@ public SlotTouchResult Set(ISlotInfo slot, PKM pk, SlotTouchType type = SlotTouc
|
||||
return SlotTouchResult.FailWrite;
|
||||
|
||||
using var change = Changelog.Begin(slot);
|
||||
if (!slot.WriteTo(SAV, pk, EntityImportSettings.None))
|
||||
var settings = type != SlotTouchType.Set ? EntityImportSettings.None : default;
|
||||
if (!slot.WriteTo(SAV, pk, settings))
|
||||
return SlotTouchResult.FailWrite;
|
||||
|
||||
change.Commit();
|
||||
|
||||
@@ -204,55 +204,27 @@ private void B_Save_Click(object sender, EventArgs e)
|
||||
return;
|
||||
}
|
||||
|
||||
// Flush all modified savedata slots back to the save.
|
||||
var slots = GetChangelogSlots();
|
||||
using var change = _changelog.Begin(slots);
|
||||
var settings = default(EntityImportSettings) with { UpdateRecord = EntityImportOption.Disable };
|
||||
foreach (var slot in slots)
|
||||
{
|
||||
if (TryGetCachedSlot(slot, out var cache))
|
||||
slot.WriteTo(_sav, cache.Entity, EntityImportSettings.None);
|
||||
slot.WriteTo(_sav, cache.Entity, settings);
|
||||
}
|
||||
|
||||
change.Commit();
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
|
||||
private IReadOnlyList<ISlotInfo> GetChangelogSlots()
|
||||
private IReadOnlyList<ISlotInfo> GetChangelogSlots() => [.. _modifiedSlots];
|
||||
|
||||
private bool TryGetCachedSlot(ISlotInfo source, [NotNullWhen(true)] out SlotCache? cache)
|
||||
{
|
||||
// Party reversion captures the entire party, so multiple party slot entries only need
|
||||
// one changelog slot. Box entries remain individually addressable.
|
||||
var slots = _modifiedSlots.Where(z => z is not SlotInfoParty).ToList();
|
||||
if (_modifiedSlots.Any(z => z is SlotInfoParty))
|
||||
slots.Add(_modifiedSlots.First(z => z is SlotInfoParty));
|
||||
return slots;
|
||||
}
|
||||
|
||||
private bool TryGetCachedSlot(ISlotInfo source, out SlotCache cache)
|
||||
{
|
||||
if (_boxData is not null)
|
||||
{
|
||||
foreach (var slot in _boxData)
|
||||
{
|
||||
if (ReferenceEquals(slot.Source, source))
|
||||
{
|
||||
cache = slot;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_party is not null)
|
||||
{
|
||||
foreach (var slot in _party)
|
||||
{
|
||||
if (!ReferenceEquals(slot.Source, source))
|
||||
continue;
|
||||
cache = slot;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
cache = null!;
|
||||
return false;
|
||||
cache = _boxData?.FirstOrDefault(z => ReferenceEquals(z.Source, source))
|
||||
?? _party?.FirstOrDefault(z => ReferenceEquals(z.Source, source));
|
||||
return cache is not null;
|
||||
}
|
||||
|
||||
private void B_Cancel_Click(object sender, EventArgs e)
|
||||
@@ -329,6 +301,7 @@ private async void UpdateFilterCountDebounced()
|
||||
if (generation != _filterCountGeneration)
|
||||
return;
|
||||
L_Count.Text = result;
|
||||
UpdateButtons();
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user