From 870c607b9dfb7f4bb14f031cd8f7d1277dfe638b Mon Sep 17 00:00:00 2001 From: otivm Date: Tue, 28 Apr 2026 05:09:26 +0000 Subject: [PATCH] =?UTF-8?q?Add=20onNewGame=20lifecycle=20handler=20?= =?UTF-8?q?=E2=80=94=20marks=20session=20abandoned,=20starts=20fresh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.jsx | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index acb55b6..2c166bd 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -6,7 +6,6 @@ import Map from './screens/Map.jsx' import './App.css' const TOKEN_KEY = 'otivm_token' -const SCREENS = ['ledger', 'map'] export default function App() { const [state, setState] = useState(null) @@ -40,6 +39,32 @@ export default function App() { await saveState(token, newState) } + // Session abandonment — forward-looking lifecycle handler. + // Does not delete the old save. Appends a terminal event so the record + // is complete. The old save becomes a historical artefact on disk. + // In the Simulator this event will have social and ecological consequences + // for the clan — a Constructor who stops participating leaves a gap. + // For now: mark abandoned, generate new token, bootstrap fresh in-place. + async function onNewGame() { + if (state && token) { + const abandoned = { + ...state, + events: [ + ...(state.events || []), + { type: 'session_abandoned', route_id: null, timestamp_utc: new Date().toISOString() }, + ], + } + await saveState(token, abandoned) + } + const newTok = generateToken() + localStorage.setItem(TOKEN_KEY, newTok) + setToken(newTok) + const fresh = createState(newTok) + setState(fresh) + await saveState(newTok, fresh) + setScreen('ledger') + } + if (loading) { return (
@@ -69,7 +94,7 @@ export default function App() {
- +