Compare commits

..

2 Commits

Author SHA1 Message Date
Brian Fertig cc75ff1862 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
2026-05-19 18:17:37 -06:00
Brian Fertig 27c13a57d4 Animation improvements 2026-05-19 18:07:03 -06:00
1 changed files with 43 additions and 20 deletions

View File

@ -713,19 +713,26 @@ export default class GoFishGame extends Phaser.Scene {
const askerCard = beforeState.players[askerSeat].hand.find(c => c.rank === rank);
if (!askerCard) { onComplete(); return; }
const askerSprite = this.makeCardSprite(askerCard, askerLayout.handCenter.x, askerLayout.handCenter.y, {
faceUp: false, rotation: 0,
});
const existingSprite = this.cardObjs.get(`hand-${askerSeat}-${askerCard.id}`);
const askerSprite = existingSprite
?? this.makeCardSprite(askerCard, askerLayout.handCenter.x, askerLayout.handCenter.y, {
faceUp: askerLayout.handFaceUp, rotation: 0,
});
if (existingSprite) this.cardObjs.delete(`hand-${askerSeat}-${askerCard.id}`);
const origX = askerSprite.x;
const origY = askerSprite.y;
askerSprite.setDepth(D.banner - 4);
this.transientObjs.push(askerSprite);
// Move asker card to show zone then flip it face-up.
// Move asker card to show zone then flip it face-up (skip flip if already face-up).
this.tweens.add({
targets: askerSprite,
x: askerShow.x, y: askerShow.y,
duration: 280,
ease: 'Cubic.easeOut',
onComplete: () => this.flipCardFaceUp(askerSprite, askerCard),
onComplete: () => {
if (!askerLayout.handFaceUp) this.flipCardFaceUp(askerSprite, askerCard);
},
});
// After card is revealed, cast fishing line toward the target, then show result.
@ -739,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({
@ -750,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 };
});
@ -782,12 +794,13 @@ export default class GoFishGame extends Phaser.Scene {
this.time.delayedCall(320, () => onComplete(allSprites));
});
} else {
// Fish — flip card back face-down and return it to hand.
this.flipCardFaceDown(askerSprite);
this.time.delayedCall(340, () => {
// Fish — flip card back face-down (if needed) and return it to hand.
if (!askerLayout.handFaceUp) this.flipCardFaceDown(askerSprite);
const returnDelay = askerLayout.handFaceUp ? 80 : 340;
this.time.delayedCall(returnDelay, () => {
this.tweens.add({
targets: askerSprite,
x: askerLayout.handCenter.x, y: askerLayout.handCenter.y,
x: origX, y: origY,
duration: 280, ease: 'Cubic.easeIn',
onComplete: () => { if (askerSprite.active) askerSprite.destroy(); },
});
@ -1011,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) {