From cc75ff18628f3488075ecc44dfb89883e5d450b9 Mon Sep 17 00:00:00 2001 From: Brian Fertig Date: Tue, 19 May 2026 18:17:37 -0600 Subject: [PATCH] fix: correct Go Fish card animation positioning and face-up state - Use existing card sprites for target hand animations to prevent duplicates - Respect `handFaceUp` layout setting when flipping target cards - Calculate precise destination coordinates for drawn cards based on hand axis and index - Simplify `animateFishDraw` signature to accept explicit destination coordinates - Fix tween completion logic to properly trigger callbacks --- public/src/games/gofish/GoFishGame.js | 37 +++++++++++++++++++-------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/public/src/games/gofish/GoFishGame.js b/public/src/games/gofish/GoFishGame.js index 12f10c7..3559dc9 100644 --- a/public/src/games/gofish/GoFishGame.js +++ b/public/src/games/gofish/GoFishGame.js @@ -746,9 +746,12 @@ export default class GoFishGame extends Phaser.Scene { : targetShow.x + (i - (n - 1) / 2) * (CARD_W + 8); const ty = isTargetVert ? targetShow.y + (i - (n - 1) / 2) * (CARD_H + 8) : targetShow.y; - const sprite = this.makeCardSprite(card, targetLayout.handCenter.x, targetLayout.handCenter.y, { - faceUp: false, rotation: 0, - }); + const existingTargetSprite = this.cardObjs.get(`hand-${targetSeat}-${card.id}`); + const sprite = existingTargetSprite + ?? this.makeCardSprite(card, targetLayout.handCenter.x, targetLayout.handCenter.y, { + faceUp: targetLayout.handFaceUp, rotation: 0, + }); + if (existingTargetSprite) this.cardObjs.delete(`hand-${targetSeat}-${card.id}`); sprite.setDepth(D.banner - 4); this.transientObjs.push(sprite); this.tweens.add({ @@ -757,7 +760,9 @@ export default class GoFishGame extends Phaser.Scene { duration: 250, delay: i * 80, ease: 'Cubic.easeOut', - onComplete: () => this.flipCardFaceUp(sprite, card), + onComplete: () => { + if (!targetLayout.handFaceUp) this.flipCardFaceUp(sprite, card); + }, }); return { sprite, tx, ty }; }); @@ -1019,27 +1024,37 @@ export default class GoFishGame extends Phaser.Scene { if (sprite) { const revealCard = askerSeat === 0 ? after.lastAsk.drawnCard : null; - this.animateFishDraw(sprite, askerSeat, revealCard, continueAfterDraw); + const drawnCard = after.lastAsk.drawnCard; + const newHand = after.players[askerSeat].hand; + const cardIndex = newHand.findIndex(c => c.id === drawnCard.id); + const askerLayout = slotLayout(this.slotForSeat[askerSeat]); + let destX, destY; + if (askerLayout.handAxis === 'x') { + destX = askerLayout.handCenter.x + (cardIndex - (newHand.length - 1) / 2) * HAND_SPREAD; + destY = askerLayout.handCenter.y; + } else { + destX = askerLayout.handCenter.x; + destY = askerLayout.handCenter.y + (cardIndex - (newHand.length - 1) / 2) * HAND_SPREAD; + } + this.animateFishDraw(sprite, revealCard, destX, destY, continueAfterDraw); } else { this.time.delayedCall(50, continueAfterDraw); } } - animateFishDraw(sprite, askerSeat, revealCard, onComplete) { - const layout = slotLayout(this.slotForSeat[askerSeat]); + animateFishDraw(sprite, revealCard, destX, destY, onComplete) { sprite.setDepth(D.banner - 4); + this.transientObjs.push(sprite); const flyToHand = () => { this.tweens.add({ targets: sprite, - x: layout.handCenter.x, y: layout.handCenter.y, + x: destX, y: destY, rotation: 0, - alpha: 0, duration: 400, ease: 'Cubic.easeIn', - onComplete: () => { if (sprite.active) sprite.destroy(); }, + onComplete: () => onComplete(), }); - this.time.delayedCall(450, onComplete); }; if (revealCard) {