Delegate handleNewGame to onNewGame prop from App.jsx

This commit is contained in:
otivm
2026-04-28 05:12:17 +00:00
parent 870c607b9d
commit a8d1831fb0

View File

@@ -12,10 +12,10 @@ import {
const CHAPTERS = ['ostia', 'capua', 'brundisium', 'carthago', 'alexandria']
export default function Game({ state, onStateChange }) {
export default function Game({ state, onStateChange, onNewGame }) {
const [selectedRoute, setSelectedRoute] = useState(null)
const [dispatch, setDispatch] = useState(null) // { routeId, startMs, durationMs }
const [otium, setOtium] = useState(null) // { startMs }
const [dispatch, setDispatch] = useState(null)
const [otium, setOtium] = useState(null)
const [message, setMessage] = useState('')
const [journal, setJournal] = useState(getSeenJournalEntries(state))
const [newEntryKey, setNewEntryKey] = useState(null)
@@ -28,7 +28,6 @@ export default function Game({ state, onStateChange }) {
msgRef.current = setTimeout(() => setMessage(''), dur)
}
// Game tick — 250ms
useEffect(() => {
tickRef.current = setInterval(() => {
const now = Date.now()
@@ -36,7 +35,6 @@ export default function Game({ state, onStateChange }) {
if (dispatch) {
const elapsed = now - dispatch.startMs
if (elapsed >= dispatch.durationMs) {
// Dispatch complete
setDispatch(null)
const entry = getNewJournalEntry(state, dispatch.routeId)
const newState = applyDispatch(state, dispatch.routeId)
@@ -93,12 +91,10 @@ export default function Game({ state, onStateChange }) {
}
function handleNewGame() {
if (!window.confirm('Abandon this ledger and start a new one?')) return
localStorage.removeItem('otium_token')
window.location.reload()
if (!window.confirm('Abandon this ledger and begin a new one?')) return
onNewGame()
}
// Progress bar values
let progressPct = 0
let progressLabel = ''
let progressSub = ''
@@ -263,11 +259,7 @@ export default function Game({ state, onStateChange }) {
<div className="token-bar">
Your save code: <span className="token-code">{state.token}</span>
<button
className="btn-new-game"
onClick={handleNewGame}
title="Clear this save and start fresh"
>
<button className="btn-new-game" onClick={handleNewGame}>
New game
</button>
</div>