card flip animations

This commit is contained in:
Gavin McDonald
2025-04-13 10:20:45 -04:00
parent 55409766b3
commit 070e7c9cf0
3 changed files with 33 additions and 9 deletions

View File

@@ -24,3 +24,19 @@ body {
color: var(--foreground); color: var(--foreground);
font-family: Arial, Helvetica, sans-serif; font-family: Arial, Helvetica, sans-serif;
} }
.perspective {
perspective: 1000px;
}
.transform-style-preserve-3d {
transform-style: preserve-3d;
}
.backface-hidden {
backface-visibility: hidden;
}
.rotate-y-180 {
transform: rotateY(180deg);
}

View File

@@ -1,19 +1,31 @@
'use client'; 'use client';
import { StandardGameCard, TarokkaGameCard } from '@/types'; import { StandardGameCard, TarokkaGameCard } from '@/types';
import tarokkaCards from '@/constants/tarokkaCards';
const cardBack = tarokkaCards.find((card) => card.back)!;
type CardProps = { type CardProps = {
card: StandardGameCard | TarokkaGameCard; card: StandardGameCard | TarokkaGameCard;
flipAction: () => void; flipAction: () => void;
}; };
export default function Card({ card: { aria, url }, flipAction }: CardProps) { export default function Card({ card: { aria, flipped, url }, flipAction }: CardProps) {
return ( return (
<div <div
className="h-[21vh] w-[15vh] flex items-center justify-center cursor-pointer transform transition-transform duration-200 hover:scale-150 relative z-0 hover:z-10" className="relative h-[21vh] w-[15vh] cursor-pointer perspective transition-transform duration-200 hover:scale-150 z-0 hover:z-10"
onClick={flipAction} onClick={flipAction}
> >
<img className="rounded-xl" src={url} alt={aria} /> <div
className={`transition-transform duration-500 transform-style-preserve-3d ${flipped ? 'rotate-y-180' : ''}`}
>
<div className="absolute inset-0 backface-hidden">
<img src={cardBack.url} alt="Card Back" className="rounded-xl" />
</div>
<div className="absolute inset-0 backface-hidden rotate-y-180">
<img src={url} alt={aria} className="rounded-xl" />
</div>
</div>
</div> </div>
); );
} }

View File

@@ -66,12 +66,8 @@ export default class GameStore {
gameUpdate(game: GameState): GameUpdate { gameUpdate(game: GameState): GameUpdate {
const { id, cards } = game; const { id, cards } = game;
return {
id, return { id, cards };
cards: (cards as TarokkaGameCard[]).map((card: TarokkaGameCard) =>
card.flipped ? card : { ...deck.getBack(), flipped: false },
),
};
} }
deleteGame(gameID: string): void { deleteGame(gameID: string): void {