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 (