From 70d37401ee9f02e1e2782623eaa45634c6d2fa84 Mon Sep 17 00:00:00 2001 From: Ward Coombes Date: Fri, 9 Jan 2026 16:11:55 -0500 Subject: [PATCH] update selection state machine --- frontend/src/events.js | 6 ------ frontend/src/gamestate.js | 37 +++++++++++++++++++++---------------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/frontend/src/events.js b/frontend/src/events.js index ef10a86ca..e1dcde106 100644 --- a/frontend/src/events.js +++ b/frontend/src/events.js @@ -333,13 +333,7 @@ const parseCubeOptions = () => { }; const clickPack = (card) => { - if (!App.state.gameState.isPick(card.cardId)) { App.state.gameState.updateCardPick(card.cardId, App.state.picksPerPack); - } else if (App.state.gameState.isSelectionReady(App.state.picksPerPack, App.state.game.burnsPerPack)) { - App.state.gameState.resetPack(); - App.update(); - App.send("confirmSelection"); - } }; const hash = () => { diff --git a/frontend/src/gamestate.js b/frontend/src/gamestate.js index 3dae85462..92382b015 100644 --- a/frontend/src/gamestate.js +++ b/frontend/src/gamestate.js @@ -192,15 +192,17 @@ class GameState extends EventEmitter { } updateCardPick(cardId, picksPerPack) { - if (this.#pickCardIds.length == picksPerPack) { - this.#pickCardIds.shift(); - } - - if (this.isBurn(cardId)) { - remove(this.#burnCardIds, id => id === cardId); - } + if(this.#pickCardIds.includes(cardId)){ + // if the card is already picked, remove it + remove(this.#pickCardIds, id => id === cardId); + } else if(this.#pickCardIds.length < picksPerPack){ + // if the card had not been picked yet, pick it and remove burn if any + if (this.isBurn(cardId)) { + remove(this.#burnCardIds, id => id === cardId); + } + this.#pickCardIds.push(cardId); + } - this.#pickCardIds.push(cardId); this.updState(); this.updateSelection(); } @@ -216,15 +218,18 @@ class GameState extends EventEmitter { return false; } - if (this.#burnCardIds.length == burnsPerPack) { - this.#burnCardIds.shift(); - } - - if (this.isPick(cardId)) { - remove(this.#pickCardIds, id => id === cardId); - } + if(this.#burnCardIds.includes(cardId)){ + // if the card is already burned, remove it + remove(this.#burnCardIds, id => id === cardId); + } else if(this.#burnCardIds.length < burnsPerPack) { + // if the card is not burned, remove it from pick if any and burn it + if (this.isPick(cardId)) { + remove(this.#pickCardIds, id => id === cardId); + } + + this.#burnCardIds.push(cardId); + } - this.#burnCardIds.push(cardId); this.updState(); this.updateSelection(); }