From a2ce650d6c0044efef8e8d7254e87080a6f22ea5 Mon Sep 17 00:00:00 2001 From: coyotte508 Date: Thu, 8 Oct 2026 11:38:06 +0200 Subject: [PATCH] Offer "Undo my move" in games against bots BGS lets the only human of a game against bots take back their last saved move (protocol 0.10.0). The header utilities show an undo control while BGS reports it available to the seated player, except in analysis and while a move awaits the next state; it asks BGS to undo, which then sends the earlier state. A state that goes backwards stops playback and discards local selections (dice, equipment forms, lava warnings). The local harness offers the same control after each move made from the interface. Upgrade @boardgamers/protocol from 0.6.1 to 0.10.0 (older versions drop undo:available) and remove the 0.6.1 chat scrolling patch: 0.10.0 ships the same fix. Co-Authored-By: Claude Opus 5.5 --- docs/bgs-integration.md | 4 + package.json | 2 +- packages/viewer/package.json | 2 +- packages/viewer/src/App.svelte | 15 ++- packages/viewer/src/dev.ts | 15 +++ packages/viewer/src/lib/UtilityIcon.svelte | 5 +- packages/viewer/src/lib/store.svelte.ts | 15 +-- packages/viewer/src/localization/da.json | 3 +- packages/viewer/src/localization/de.json | 3 +- packages/viewer/src/localization/el.json | 3 +- packages/viewer/src/localization/en.json | 3 +- packages/viewer/src/localization/fa.json | 3 +- packages/viewer/src/localization/fr.json | 3 +- packages/viewer/src/localization/hi.json | 3 +- packages/viewer/src/localization/it.json | 3 +- packages/viewer/src/localization/ko.json | 3 +- packages/viewer/src/localization/nl.json | 3 +- packages/viewer/src/localization/pl.json | 3 +- packages/viewer/src/localization/pt-BR.json | 3 +- packages/viewer/src/localization/ro.json | 3 +- packages/viewer/src/localization/ru.json | 3 +- packages/viewer/src/localization/vi.json | 3 +- packages/viewer/src/localization/zh-TW.json | 3 +- packages/viewer/src/viewer.ts | 6 +- patches/@boardgamers__protocol@0.6.1.patch | 42 -------- patches/README.md | 1 - pnpm-lock.yaml | 13 +-- pnpm-workspace.yaml | 5 +- tests/undo-smoke.mjs | 104 ++++++++++++++++++++ 29 files changed, 195 insertions(+), 82 deletions(-) delete mode 100644 patches/@boardgamers__protocol@0.6.1.patch delete mode 100644 patches/README.md create mode 100644 tests/undo-smoke.mjs diff --git a/docs/bgs-integration.md b/docs/bgs-integration.md index 1b4772a..69058cd 100644 --- a/docs/bgs-integration.md +++ b/docs/bgs-integration.md @@ -41,6 +41,10 @@ Fuji has a shared win/loss. The wrapper gives all players the same ranking and r `colorBlind` is the platform’s shared color-blind preference, false by default. It is stored on the BGS account and used across supported games. The viewer reads the platform `preferences` event and emits `update:preference` with `{ name: "colorBlind", value: boolean }` when changed in Help. It adds color names to dice and color initials to map requirement symbols without changing game state. The local harness persists the same setting in localStorage. The draft registration declares the checkbox so the platform shows its shared control. Incoming preference updates must not write back to the host. +## Undo against bots + +When a single human plays with bots, BGS sends `undo:available` (protocol 0.10.0). While it is true, the header shows **Undo my move** to the seated player, except in analysis and while a move awaits the next state. The control emits `undo`; BGS then sends the earlier state. The viewer stops playback and discards local selections when a state goes backwards. The local harness offers the same control after each move made from the interface. + ## Automatic movement resolution Starting a movement resolves it immediately when no Gatherer has usable bars. Otherwise only the Gatherer(s) are active: each submits one `help` action with `count` from zero to their remaining stock. The last decision applies movement, eruption triggers and stamina automatically. Injury choices still belong to the injured player. The journal snapshots revealed and matching dice with text fallbacks for the platform log. Start a new local game when testing this flow; historical development saves using manual resolution are not migrated. diff --git a/package.json b/package.json index 987edd2..84fa6f5 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "fmt": "oxfmt", "fmt:check": "oxfmt --check", "simulate": "pnpm --filter fuji-engine build && node scripts/simulate.mjs", - "test:browser": "node tests/browser-smoke.mjs && node tests/bgs-bundle-smoke.mjs && node tests/presentation-smoke.mjs && node tests/chat-smoke.mjs && node tests/mobile-readiness-smoke.mjs && node tests/chat-tabs-smoke.mjs && node tests/chat-mentions-smoke.mjs && node tests/protocol-lifecycle-smoke.mjs && node tests/tutorial-browser.mjs && node tests/analysis-chat-browser.mjs && node tests/localization-browser.mjs", + "test:browser": "node tests/browser-smoke.mjs && node tests/bgs-bundle-smoke.mjs && node tests/presentation-smoke.mjs && node tests/chat-smoke.mjs && node tests/mobile-readiness-smoke.mjs && node tests/chat-tabs-smoke.mjs && node tests/chat-mentions-smoke.mjs && node tests/protocol-lifecycle-smoke.mjs && node tests/undo-smoke.mjs && node tests/tutorial-browser.mjs && node tests/analysis-chat-browser.mjs && node tests/localization-browser.mjs", "test:locales": "node scripts/check-locales.mjs packages/viewer/src/localization && node --test scripts/localization.test.mjs" }, "devDependencies": { diff --git a/packages/viewer/package.json b/packages/viewer/package.json index f5252bd..3e6d5c1 100644 --- a/packages/viewer/package.json +++ b/packages/viewer/package.json @@ -11,7 +11,7 @@ "test:tutorial": "node --test src/tutorial/*.spec.ts" }, "dependencies": { - "@boardgamers/protocol": "0.6.1", + "@boardgamers/protocol": "0.10.0", "fuji-engine": "workspace:*" }, "devDependencies": { diff --git a/packages/viewer/src/App.svelte b/packages/viewer/src/App.svelte index fc6c6e5..966c0ba 100644 --- a/packages/viewer/src/App.svelte +++ b/packages/viewer/src/App.svelte @@ -54,6 +54,10 @@ ); const seat = $derived(store.seat); const me = $derived(seat === undefined ? undefined : s?.players[seat]); + // Offered by BGS in games against bots; hidden for spectators, in analysis and while a move is pending. + const canUndo = $derived( + store.undoAvailable && seat !== undefined && !store.analysis && !store.waiting && !s?.outcome + ); let inspected = $state(""); let dangerousRoute = $state(""); let acceptedLavaRisk = $state(""); @@ -237,7 +241,10 @@ let decision = ""; let decisionScreen = ""; $effect(() => { + // After an undo, selections made on the later state are discarded. + const rewinds = store.rewinds; const context = JSON.stringify([ + rewinds, seat, s?.round, s?.phase, @@ -249,7 +256,7 @@ ]); const player = me; untrack(() => { - const screen = `${seat}:${s?.round}:${s?.phase}`; + const screen = `${rewinds}:${seat}:${s?.round}:${s?.phase}`; if (screen !== decisionScreen) { decisionScreen = screen; dangerousRoute = ""; @@ -504,6 +511,12 @@