diff --git a/src/main.ts b/src/main.ts index 6715fee..310ca7b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,16 +1,28 @@ import './style.css' import { load, newGame, save } from './state' import { tick } from './engine' -import { render } from './ui' +import { render, refresh } from './ui' import { toggleHelp } from './help' const app = document.querySelector('#app')! const state = load() ?? newGame() +// User actions (deploy/uninstall/buy/fix/prestige) change the DOM's shape, +// so they get a full rebuild for instant feedback. function scheduleRender() { render(app, state, scheduleRender) } +// The passive per-tick refresh only patches values that drift on their own +// (points/rate, background crashes, new log lines) - it never recreates +// the deploy form or any button, so it can't step on an in-flight click or +// reset a select the player is mid-choice on. +function scheduleRefresh() { + if (!refresh(app, state, scheduleRender)) scheduleRender() +} + +scheduleRender() + let last = performance.now() // Passive UI refresh - user actions call scheduleRender() directly for // instant feedback, so this only needs to be fast enough to reflect the @@ -25,12 +37,7 @@ function loop(now: number) { } function renderLoop() { - // Skip the rebuild while a