From a595033bc255ca1a172a0aded0eb73eb82f1b2d8 Mon Sep 17 00:00:00 2001 From: Kurt Date: Tue, 1 Sep 2026 22:10:21 -0500 Subject: [PATCH] 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. --- .../Editing/Bulk/Base/StringInstruction.cs | 1 + PKHeX.Core/Editing/Saves/Slots/SlotEditor.cs | 3 +- .../Subforms/PKM Editors/BatchEditor.cs | 47 ++++--------------- 3 files changed, 13 insertions(+), 38 deletions(-) diff --git a/PKHeX.Core/Editing/Bulk/Base/StringInstruction.cs b/PKHeX.Core/Editing/Bulk/Base/StringInstruction.cs index 56310389b..86a3e908c 100644 --- a/PKHeX.Core/Editing/Bulk/Base/StringInstruction.cs +++ b/PKHeX.Core/Editing/Bulk/Base/StringInstruction.cs @@ -136,6 +136,7 @@ public void SetRandomRange(ReadOnlySpan 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; } } diff --git a/PKHeX.Core/Editing/Saves/Slots/SlotEditor.cs b/PKHeX.Core/Editing/Saves/Slots/SlotEditor.cs index db22ac4dc..876159ed2 100644 --- a/PKHeX.Core/Editing/Saves/Slots/SlotEditor.cs +++ b/PKHeX.Core/Editing/Saves/Slots/SlotEditor.cs @@ -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(); diff --git a/PKHeX.WinForms/Subforms/PKM Editors/BatchEditor.cs b/PKHeX.WinForms/Subforms/PKM Editors/BatchEditor.cs index 50e33f26f..9532fb2e4 100644 --- a/PKHeX.WinForms/Subforms/PKM Editors/BatchEditor.cs +++ b/PKHeX.WinForms/Subforms/PKM Editors/BatchEditor.cs @@ -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 GetChangelogSlots() + private IReadOnlyList 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 {