Skip to content

Send P2P delete-element when token is dropped in the bin #273

@arasaka-net

Description

@arasaka-net

Dragging a token into the token bin removes it from the local DOM but never sends a sendDeleteMessage, so the opponent still sees the token on their board.

Context
The P2P protocol includes a delete-element message type that is correctly used when a card is deleted via the Delete key (keyboard.js:49). However, the token bin deletion path in the ungrab handler of createToken calls tokenElement.remove() without notifying the peer. In a multiplayer game this means binned tokens persist on the opponent's screen indefinitely, creating a desynchronized board state. The fix is to call sendDeleteMessage(tokenElement.id) before removing the element, matching the pattern already established in keyboard.js.

Affected Files

  • src/scripts/token.js:36 — Add sendDeleteMessage(tokenElement.id) before tokenElement.remove()
  • src/scripts/token.js:2 — Import sendDeleteMessage from ./p2p.js
  • src/scripts/token.test.js — Add test verifying sendDeleteMessage is called when token lands in the bin

Requirements

  • When a token is dragged into the token bin and released, sendDeleteMessage is called with the token's id before the element is removed from the DOM
  • sendDeleteMessage is imported from ./p2p.js in token.js
  • A unit test in token.test.js confirms that sendDeleteMessage is invoked when isPointWithinElement returns true for the token bin during ungrab
  • Existing token tests continue to pass

Verification

  • npm test -- --reporter=verbose src/scripts/token.test.js
  • npm run lint
  • grep -n 'sendDeleteMessage' src/scripts/token.js

Not In Scope

  • Do not add P2P sync for token flipping or stacking — those are separate issues
  • Do not refactor the ungrab handler beyond adding the send call
  • Do not modify p2p.js receive-side handling

Evidence

  • src/scripts/token.js:36tokenElement.remove() is called when the token overlaps the bin, but no sendDeleteMessage call precedes it
  • src/scripts/keyboard.js:49-50 — Card deletion correctly calls sendDeleteMessage(selectedCard.id) before selectedCard.remove(), establishing the expected pattern
  • src/scripts/token.js:1-3sendDeleteMessage is not imported — only sendCreateMessage is imported from ./p2p.js

Arasaka Queue Planning Division.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions