2026-05-26 20:02:59 -05:00
|
|
|
import { useState } from 'react'
|
|
|
|
|
import { type Page, type GameState } from './types'
|
|
|
|
|
import TitleScreen from './pages/TitleScreen'
|
|
|
|
|
import PlayerSetup from './pages/PlayerSetup'
|
|
|
|
|
import ScoreSheet from './pages/ScoreSheet'
|
|
|
|
|
import EnterScores from './pages/EnterScores'
|
|
|
|
|
|
|
|
|
|
const STORAGE_KEY = 'currentGame'
|
|
|
|
|
|
|
|
|
|
function loadGame(): GameState | null {
|
|
|
|
|
const raw = localStorage.getItem(STORAGE_KEY)
|
|
|
|
|
return raw ? (JSON.parse(raw) as GameState) : null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function saveGame(game: GameState) {
|
|
|
|
|
localStorage.setItem(STORAGE_KEY, JSON.stringify(game))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function clearGame() {
|
|
|
|
|
localStorage.removeItem(STORAGE_KEY)
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-26 19:30:46 -05:00
|
|
|
export default function App() {
|
2026-05-26 20:02:59 -05:00
|
|
|
const [page, setPage] = useState<Page>(() =>
|
|
|
|
|
loadGame() ? 'scoresheet' : 'title'
|
2026-05-26 19:30:46 -05:00
|
|
|
)
|
2026-05-26 20:02:59 -05:00
|
|
|
const [game, setGame] = useState<GameState | null>(() => loadGame())
|
|
|
|
|
|
|
|
|
|
function handleNewGame() {
|
|
|
|
|
clearGame()
|
|
|
|
|
setGame(null)
|
|
|
|
|
setPage('setup')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function handleStart() {
|
|
|
|
|
const newGame: GameState = { players: [], rounds: [] }
|
|
|
|
|
saveGame(newGame)
|
|
|
|
|
setGame(newGame)
|
|
|
|
|
setPage('scoresheet')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function handleSubmitScores() {
|
|
|
|
|
setPage('scoresheet')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (page === 'title') return <TitleScreen onNewGame={handleNewGame} />
|
|
|
|
|
if (page === 'setup') return <PlayerSetup onStart={handleStart} />
|
|
|
|
|
if (page === 'scoresheet') return <ScoreSheet onScoreRound={() => setPage('enterscores')} onNewGame={handleNewGame} />
|
|
|
|
|
if (page === 'enterscores') return <EnterScores onSubmit={handleSubmitScores} />
|
2026-05-26 19:30:46 -05:00
|
|
|
}
|