diff --git a/app/[gameID]/page.tsx b/app/[gameID]/page.tsx index f105de1..04fc86a 100644 --- a/app/[gameID]/page.tsx +++ b/app/[gameID]/page.tsx @@ -5,22 +5,10 @@ import { useParams } from 'next/navigation'; import { socket } from '@/socket'; import Card from '@/components/Card'; +import { cardMap, layout } from '@/constants/tarokka'; import type { GameUpdate, ClientUpdate, StandardGameCard, TarokkaGameCard } from '@/types'; -// map our five cards to their appropriate -// locations in a 3x3 grid -// █1█ -// 042 -// █3█ -const cardMap = { - 3: 0, - 1: 1, - 5: 2, - 7: 3, - 4: 4, -}; - export default function GamePage() { const { gameID: gameIDParam } = useParams(); @@ -77,7 +65,13 @@ export default function GamePage() { .map(arrangeCards) .map((card, index) => (
- {card && flipCard(cardMap[index])} />} + {card && ( + flipCard(cardMap[index])} + /> + )}
))} diff --git a/components/Card.tsx b/components/Card.tsx index 077ffc6..2ad11a7 100644 --- a/components/Card.tsx +++ b/components/Card.tsx @@ -1,4 +1,5 @@ 'use client'; +import { useState, useEffect, useRef } from 'react'; import { StandardGameCard, TarokkaGameCard } from '@/types'; import tarokkaCards from '@/constants/tarokkaCards'; @@ -7,25 +8,77 @@ const cardBack = tarokkaCards.find((card) => card.back)!; type CardProps = { card: StandardGameCard | TarokkaGameCard; + position: { text: string }; flipAction: () => void; }; -export default function Card({ card: { aria, flipped, url }, flipAction }: CardProps) { +export default function Card({ card: { aria, flipped, url }, position, flipAction }: CardProps) { + const [showTooltip, setShowTooltip] = useState(false); + const [tooltipPos, setTooltipPos] = useState({ x: 0, y: 0 }); + const longPressTimeout = useRef(null); + const delayTimeout = useRef(null); + + const handleMouseMove = (e: React.MouseEvent) => { + setTooltipPos({ x: e.clientX, y: e.clientY }); + }; + + const handleMouseEnter = () => { + delayTimeout.current = setTimeout(() => { + setShowTooltip(true); + }, 1000); + }; + + const handleMouseLeave = () => { + clearTimeout(delayTimeout.current!); + setShowTooltip(false); + }; + + const handleTouchStart = () => { + longPressTimeout.current = setTimeout(() => { + setShowTooltip(true); + }, 1000); + }; + + const handleTouchEnd = () => { + clearTimeout(longPressTimeout.current!); + setShowTooltip(false); + }; + return ( -
+ <>
-
- Card Back -
-
- {aria} +
+
+ Card Back +
+
+ {aria} +
-
+
+ {position.text} +
+ ); } diff --git a/constants/tarokka.ts b/constants/tarokka.ts new file mode 100644 index 0000000..46e7ab8 --- /dev/null +++ b/constants/tarokka.ts @@ -0,0 +1,47 @@ +import { Layout } from '@/types'; + +// map our five cards to their appropriate +// locations in a 3x3 grid +// 012 █1█ +// 345 -> 042 +// 678 █3█ +export const cardMap: Record = { + 3: 0, + 1: 1, + 5: 2, + 7: 3, + 4: 4, +}; + +export const layout: Layout[] = [ + { + id: 'tome', + deck: 'low', + name: 'Tome of Strahd', + text: 'This card tells of history. Knowledge of the ancient will help you better understand your enemy.', + }, + { + id: 'ravenkind', + deck: 'low', + name: 'Holy Symbol of Ravenkind', + text: 'This card tells of a powerful force for good and protection, a holy symbol of great hope.', + }, + { + id: 'sunsword', + deck: 'low', + name: 'Sunsword', + text: 'This is a card of power and strength. It tells of a weapon of vengeance: a sword of sunlight.', + }, + { + id: 'ally', + deck: 'high', + name: 'Strahd’s Enemy', + text: 'This card sheds light on one who will help you greatly in the battle against darkness.', + }, + { + id: 'strahd', + deck: 'high', + name: 'Strahd', + text: 'Your enemy is a creature of darkness, whose powers are beyond mortality. This card will lead you to him!', + }, +]; diff --git a/types/index.ts b/types/index.ts index dbce119..008da02 100644 --- a/types/index.ts +++ b/types/index.ts @@ -78,3 +78,10 @@ export interface ClientUpdate { gameID: string; cardIndex: number; } + +export interface Layout { + id: string; + deck: string; + name: string; + text: string; +}