refactoring

This commit is contained in:
Gavin McDonald
2025-06-26 13:59:27 -04:00
parent 1c28a603b7
commit 12ae8dd6d8
4 changed files with 58 additions and 56 deletions

View File

@@ -1,43 +1,37 @@
'use client';
import { useState } from 'react';
import { useAppContext } from '@/app/AppContext';
import TiltCard from '@/components/TiltCard';
import ToolTip from '@/components/ToolTip';
import StackTheDeck from '@/components/StackTheDeck';
import tarokkaCards from '@/constants/tarokkaCards';
import getCardInfo from '@/tools/getCardInfo';
import getURL from '@/tools/getURL';
import { Layout, Settings, TarokkaGameCard } from '@/types';
import tarokkaCards from '@/constants/tarokkaCards';
import { layout } from '@/constants/tarokka';
import { Settings, TarokkaGameCard } from '@/types';
const cardBack = tarokkaCards.find((card) => card.back)!;
type CardProps = {
dm: boolean;
card: TarokkaGameCard;
position: Layout;
cardIndex: number;
settings: Settings;
flipAction: () => void;
redrawAction: () => void;
selectAction: () => void;
};
export default function Card({
dm,
card,
position,
settings,
flipAction,
redrawAction,
selectAction,
}: CardProps) {
export default function Card({ dm, card, cardIndex, settings }: CardProps) {
const [tooltip, setTooltip] = useState<React.ReactNode>(null);
const { flipCard, redraw, setSelectCardIndex } = useAppContext();
const { aria, flipped } = card;
const position = layout[cardIndex];
const handleClick = () => {
if (dm) {
flipAction();
flipCard(cardIndex);
}
};
@@ -84,8 +78,8 @@ export default function Card({
/>
{dm && !flipped && (
<StackTheDeck
onRedraw={redrawAction}
onSelect={() => selectAction()}
onRedraw={() => redraw(cardIndex)}
onSelect={() => setSelectCardIndex(cardIndex)}
onHover={setTooltip}
/>
)}

View File

@@ -0,0 +1,30 @@
'use client';
import { useAppContext } from '@/app/AppContext';
import Card from '@/components/Card';
import { cardMap } from '@/constants/tarokka';
import type {} from '@/types';
export default function TarokkaGrid() {
const { gameData } = useAppContext();
const { dmID, cards, settings } = gameData;
const isDM = !!dmID;
// map our five Tarokka cards to their proper locations in a 3x3 grid
// common deck cards: left, top, and right
// high deck cards: bottom and center
const arrangeCards = (_cell: unknown, index: number) => cards[cardMap[index]];
return (
<div className="grid grid-cols-3 grid-rows-3 gap-8 w-fit mx-auto">
{Array.from({ length: 9 })
.map(arrangeCards)
.map((card, index) => (
<div key={index} className="aspect-[2/3]}">
{card && <Card dm={isDM} card={card} cardIndex={cardMap[index]} settings={settings} />}
</div>
))}
</div>
);
}