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