diff --git a/apps/web/src/app/arcade/matching/components/SetupPhase.tsx b/apps/web/src/app/arcade/matching/components/SetupPhase.tsx index 92a7a6b1..8a189827 100644 --- a/apps/web/src/app/arcade/matching/components/SetupPhase.tsx +++ b/apps/web/src/app/arcade/matching/components/SetupPhase.tsx @@ -1,8 +1,9 @@ 'use client' +import { useState } from 'react' import { css } from '../../../../../styled-system/css' import { useGameMode } from '../../../../contexts/GameModeContext' -import { useArcadeMemoryPairs } from '../context/ArcadeMemoryPairsContext' +import { useMemoryPairs } from '../context/MemoryPairsContext' // Add bounce animation for the start button const bounceAnimation = ` @@ -32,14 +33,87 @@ export function SetupPhase() { state, setGameType, setDifficulty, + setTurnTimer, startGame, + resumeGame, + canResumeGame, + hasConfigChanged, activePlayers: _activePlayers, - } = useArcadeMemoryPairs() + } = useMemoryPairs() const { activePlayerCount, gameMode: _globalGameMode } = useGameMode() - const handleStartGame = () => { - startGame() + // PAUSE/RESUME: Warning dialog state + const [showConfigWarning, setShowConfigWarning] = useState(false) + const [hasSeenWarning, setHasSeenWarning] = useState(false) + const [pendingConfigChange, setPendingConfigChange] = useState<{ + type: 'gameType' | 'difficulty' | 'turnTimer' + value: any + } | null>(null) + + // Check if we should show warning when changing config + const shouldShowWarning = state.pausedGamePhase && !hasSeenWarning && !hasConfigChanged + + // Config change handlers that check for paused game + const handleSetGameType = (value: typeof state.gameType) => { + if (shouldShowWarning) { + setPendingConfigChange({ type: 'gameType', value }) + setShowConfigWarning(true) + } else { + setGameType(value) + } + } + + const handleSetDifficulty = (value: typeof state.difficulty) => { + if (shouldShowWarning) { + setPendingConfigChange({ type: 'difficulty', value }) + setShowConfigWarning(true) + } else { + setDifficulty(value) + } + } + + const handleSetTurnTimer = (value: typeof state.turnTimer) => { + if (shouldShowWarning) { + setPendingConfigChange({ type: 'turnTimer', value }) + setShowConfigWarning(true) + } else { + setTurnTimer(value) + } + } + + // Apply pending config change after warning + const applyPendingChange = () => { + if (pendingConfigChange) { + switch (pendingConfigChange.type) { + case 'gameType': + setGameType(pendingConfigChange.value) + break + case 'difficulty': + setDifficulty(pendingConfigChange.value) + break + case 'turnTimer': + setTurnTimer(pendingConfigChange.value) + break + } + setHasSeenWarning(true) + setPendingConfigChange(null) + setShowConfigWarning(false) + } + } + + // Cancel config change + const cancelConfigChange = () => { + setPendingConfigChange(null) + setShowConfigWarning(false) + } + + const handleStartOrResumeGame = () => { + if (canResumeGame) { + resumeGame() + } else { + startGame() + } } const getButtonStyles = ( @@ -150,6 +224,94 @@ export function SetupPhase() { minHeight: 0, // Allow shrinking })} > + {/* PAUSE/RESUME: Config change warning */} + {showConfigWarning && ( +
+

+ ⚠️ Warning: Changing Settings Will End Current Game +

+

+ You have a paused game in progress. Changing any setting will end it and you won't be + able to resume. +

+
+ + +
+
+ )} + {/* Warning if no players */} {activePlayerCount === 0 && (