/** * dashboard-client-game.ts — verbatim JS chunk: game-mode, achievements, perf, tabs. * * Extracted from html.ts (PR0 split) — ZERO behavior change. Third of three * chunks concatenated into the dashboard IIFE (core → repos → game). Shares * the closure with core + repos. */ /** Game-mode settings, leaderboards, achievements, perf tab, tab switching. */ export function dashboardClientGameJs(): string { return `// --- Game-mode settings strip (S32) ------------------------------------- // Polls GET /api/game-state and applies the row to the settings controls + // the document theme. On any control change, PUTs a partial patch back. The // dashboard server is a detached child with no MegaRuntime ref, so it reads / // writes the game_state SQLite row directly; the in-process MegaRuntime picks // up the change via its fs.watch cache-eviction watcher (S32). var gmCheckbox = document.getElementById('set-game-mode'); var gmTheme = document.getElementById('set-theme'); var gmTui = document.getElementById('set-tui-mode'); function applyGameState(gs) { if (!gs) return; if (gs.theme) document.documentElement.dataset.theme = gs.theme; if (gmCheckbox) gmCheckbox.checked = !!gs.game_mode_on; if (gmTheme) gmTheme.value = gs.theme || 'transparent'; if (gmTui) gmTui.value = gs.tui_display_mode || 'full'; } function pollGameState() { fetch('/api/game-state').then(function(r) { return r.json(); }).then(applyGameState).catch(function() {}); // guardrails-allow PREVENT-PI-004: browser-side fetch in dashboard HTML template (not Node runtime) } function putGameState(patch) { fetch('/api/game-state', { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(patch) }).then(function(r) { return r.json(); }).then(applyGameState).catch(function() {}); // guardrails-allow PREVENT-PI-004: browser-side fetch in dashboard HTML template (not Node runtime) } if (gmCheckbox) gmCheckbox.addEventListener('change', function() { putGameState({ game_mode_on: gmCheckbox.checked }); }); if (gmTheme) gmTheme.addEventListener('change', function() { putGameState({ theme: gmTheme.value }); }); // P3: client-side theme cycling (no new endpoint). Reads the already-fetched //