Skip to content

Keep melded permanents intact across a snapshot - #11421

Open
cuinhellcat wants to merge 1 commit into
Card-Forge:masterfrom
cuinhellcat:snapshot-meld-fix
Open

Keep melded permanents intact across a snapshot#11421
cuinhellcat wants to merge 1 commit into
Card-Forge:masterfrom
cuinhellcat:snapshot-meld-fix

Conversation

@cuinhellcat

Copy link
Copy Markdown

Follow-up to a review question on #11416 ("Does this break things like meld?"). It does not — but checking turned up that snapshots break meld already, in both directions, on master and independently of that PR.

Problem

A melded permanent is two cards. The front half sits on the battlefield in its Meld state; the back half is held in PlayerZoneBattlefield.meldedCards, not in the zone's card list. forEachCardInGame walks that collection, so both halves reach copyGameState — which places every card by zone type alone and drops both into the card list.

That breaks a meld whichever way the restore goes:

  • Snapshot taken while melded — the back half comes back loose on the battlefield. One permanent becomes two.
  • Snapshot taken before the meld — the back half is added to the card list but never taken out of meldedCards, so it is both melded and on the battlefield, with the front half still pointing at it through meldedWith.

Fix

Put a card the snapshot holds as melded back into the melded collection, take it out of there when the snapshot does not hold it that way, and carry meldedWith and the back-side flag across with the rest of the card state.

Reproduction

Bruna, the Fading Light and Gisela, the Broken Blade, melded the way MeldEffect does:

  • snapshot → meld → restore: before the change the back half stays in getMeldedCards() and the front half keeps its meldedWith; after it, both halves are loose again and the link is cleared.
  • meld → snapshot → restore: before the change the battlefield holds two permanents; after it, one, with the back half still melded.

Notes

  • Independent of Fix NPE when restoring a snapshot taken before a card was created #11416 — this reproduces on unmodified master, and the two changes do not touch the same lines.
  • No test added, per the note in CONTRIBUTING about agent-added tests. Both directions above exist as tests that fail before the change and pass after; say the word and I will add them, since meld has few other guards.
  • Forge's desktop suite (279 tests) passes with the change.

AI disclosure

Written with Claude Code (Claude Opus 5), as requested in CONTRIBUTING; the agent is also recorded as co-author on the commit.

A melded permanent is two cards: the front half on the battlefield in
its Meld state, and the back half held in PlayerZoneBattlefield's melded
collection rather than in its card list. forEachCardInGame walks that
collection, so both halves reach copyGameState — which then puts each of
them in the card list, because it only ever looks at the zone type.

Restoring therefore broke a meld in both directions. A snapshot taken
while melded came back as two separate permanents, the back half loose
on the battlefield. A snapshot taken before the meld left the back half
in the melded collection, so it was both melded and on the battlefield,
with the front half still pointing at it.

Place a card that the snapshot holds as melded back into the melded
collection, take it out of there when the snapshot does not, and carry
meldedWith and the back-side flag along.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@Jetz72 Jetz72 added the Experimental Restore Relating to the state-based Undo/Restore feature. label Jul 27, 2026
cuinhellcat pushed a commit to cuinhellcat/forge that referenced this pull request Jul 27, 2026
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Experimental Restore Relating to the state-based Undo/Restore feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants