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 <noreply@anthropic.com>
This commit is contained in:
parent
e4422deb48
commit
a2ce650d6c
29 changed files with 195 additions and 82 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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": {
|
||||
|
|
|
|||
|
|
@ -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": {
|
||||
|
|
|
|||
|
|
@ -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 @@
|
|||
</span>
|
||||
</div>
|
||||
<nav class="game-utilities" aria-label="Game options">
|
||||
{#if canUndo}<button
|
||||
class="utility-button undo-move"
|
||||
title="Undo my move"
|
||||
aria-label="Undo my move"
|
||||
onclick={() => store.undo()}><UtilityIcon name="undo" /></button
|
||||
>{/if}
|
||||
<button
|
||||
class="utility-button team-toggle"
|
||||
aria-label="Your expedition"
|
||||
|
|
|
|||
|
|
@ -41,6 +41,9 @@ try {
|
|||
} catch {
|
||||
game = initGame(3, {}, "first-light");
|
||||
}
|
||||
// Like BGS in games against bots: undo returns to the game before the last move made
|
||||
// from the interface, discarding teammate actions played after it.
|
||||
const undoPoints: State[] = [];
|
||||
let teammateTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
store.autoTeammates = localStorage.getItem("fuji-auto-teammates") === "true";
|
||||
function availableSeats() {
|
||||
|
|
@ -77,6 +80,7 @@ if (import.meta.hot)
|
|||
});
|
||||
function publish() {
|
||||
localStorage.setItem("fuji-dev-v1", JSON.stringify(game));
|
||||
store.undoAvailable = undoPoints.length > 0;
|
||||
store.receive(stripSecret(game, store.seat));
|
||||
store.chat.setState({
|
||||
canSend: true,
|
||||
|
|
@ -89,7 +93,17 @@ function publish() {
|
|||
scheduleTeammate();
|
||||
}
|
||||
store.send = (move) => {
|
||||
const previous = game;
|
||||
game = applyMove(game, move, store.seat!);
|
||||
undoPoints.push(previous);
|
||||
undoPoints.splice(0, undoPoints.length - 100);
|
||||
publish();
|
||||
};
|
||||
store.undo = () => {
|
||||
const previous = undoPoints.pop();
|
||||
if (!previous) return;
|
||||
game = previous;
|
||||
store.error = "";
|
||||
publish();
|
||||
};
|
||||
store.selectSeat = (seat) => {
|
||||
|
|
@ -99,6 +113,7 @@ store.selectSeat = (seat) => {
|
|||
};
|
||||
store.restart = (players, seed, difficulty, scenario = 1, skillAssignment = "random") => {
|
||||
game = initGame(players, { difficulty, scenario, skillAssignment }, seed);
|
||||
undoPoints.length = 0;
|
||||
store.seat = 0;
|
||||
store.chat.replace([]);
|
||||
store.chat.setDraft("");
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<script lang="ts">
|
||||
let { name }: { name: "chat" | "help" | "journal" | "fullscreen" | "exit-fullscreen" } = $props();
|
||||
let { name }: { name: "chat" | "help" | "journal" | "fullscreen" | "exit-fullscreen" | "undo" } = $props();
|
||||
</script>
|
||||
|
||||
<svg
|
||||
|
|
@ -19,6 +19,9 @@
|
|||
<path d="M9.5 9a2.5 2.5 0 0 1 5 0c0 2-2.5 2-2.5 4m0 3v.1" />
|
||||
{:else if name === "journal"}
|
||||
<path d="M5 3h14v18H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2ZM7 3v18m4-13h5m-5 4h5m-5 4h3" />
|
||||
{:else if name === "undo"}
|
||||
<path d="M9 3.5 4 8.5l5 5" />
|
||||
<path d="M4 8.5h10.5a6 6 0 0 1 0 12H10" />
|
||||
{:else if name === "exit-fullscreen"}
|
||||
<path d="M3 8h5V3m8 0v5h5M3 16h5v5m8 0v-5h5" />
|
||||
{:else}
|
||||
|
|
|
|||
|
|
@ -88,6 +88,12 @@ export class Store {
|
|||
this.savePreference("colorBlind", value);
|
||||
}
|
||||
send: (move: Move) => void = () => {};
|
||||
// BGS lets the only human of a game against bots take back their last saved move;
|
||||
// it then sends the earlier state.
|
||||
undoAvailable = $state(false);
|
||||
undo: () => void = () => {};
|
||||
/** Counts earlier states received (an undo), so local drafts can be discarded. */
|
||||
rewinds = $state(0);
|
||||
selectSeat: (seat: number) => void = () => {};
|
||||
restart: (players: number, seed: string, difficulty: number, scenario?: number, skillAssignment?: string) => void =
|
||||
() => {};
|
||||
|
|
@ -105,12 +111,9 @@ export class Store {
|
|||
}
|
||||
receive(s: View) {
|
||||
const previous = this.received;
|
||||
const reset =
|
||||
!previous ||
|
||||
this.receivedSeat !== this.seat ||
|
||||
s.revision < previous.revision ||
|
||||
s.log.length < previous.log.length ||
|
||||
document.hidden;
|
||||
const rewound = !!previous && (s.revision < previous.revision || s.log.length < previous.log.length);
|
||||
const reset = !previous || this.receivedSeat !== this.seat || rewound || document.hidden;
|
||||
if (rewound) this.rewinds++;
|
||||
this.received = s;
|
||||
this.receivedSeat = this.seat;
|
||||
this.state = s;
|
||||
|
|
|
|||
|
|
@ -1287,5 +1287,6 @@
|
|||
"+{p0} bars if kept": "+{p0} bars if kept",
|
||||
"· gain {p0} bar": "· gain {p0} bar",
|
||||
"{p0} · +{p1} bar if kept": "{p0} · +{p1} bar if kept",
|
||||
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept"
|
||||
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept",
|
||||
"Undo my move": "Fortryd mit træk"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1287,5 +1287,6 @@
|
|||
"+{p0} bars if kept": "+{p0} bars if kept",
|
||||
"· gain {p0} bar": "· gain {p0} bar",
|
||||
"{p0} · +{p1} bar if kept": "{p0} · +{p1} bar if kept",
|
||||
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept"
|
||||
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept",
|
||||
"Undo my move": "Zug zurücknehmen"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1287,5 +1287,6 @@
|
|||
"+{p0} bars if kept": "+{p0} bars if kept",
|
||||
"· gain {p0} bar": "· gain {p0} bar",
|
||||
"{p0} · +{p1} bar if kept": "{p0} · +{p1} bar if kept",
|
||||
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept"
|
||||
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept",
|
||||
"Undo my move": "Αναίρεση κίνησης"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1287,5 +1287,6 @@
|
|||
"+{p0} bars if kept": "+{p0} bars if kept",
|
||||
"· gain {p0} bar": "· gain {p0} bar",
|
||||
"{p0} · +{p1} bar if kept": "{p0} · +{p1} bar if kept",
|
||||
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept"
|
||||
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept",
|
||||
"Undo my move": "Undo my move"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1287,5 +1287,6 @@
|
|||
"+{p0} bars if kept": "+{p0} خوراکی با نگه داشتن تاسها",
|
||||
"· gain {p0} bar": "· دریافت {p0} خوراکی",
|
||||
"{p0} · +{p1} bar if kept": "{p0} · +{p1} خوراکی با نگه داشتن تاسها",
|
||||
"{p0} · +{p1} bars if kept": "{p0} · +{p1} خوراکی با نگه داشتن تاسها"
|
||||
"{p0} · +{p1} bars if kept": "{p0} · +{p1} خوراکی با نگه داشتن تاسها",
|
||||
"Undo my move": "بازگرداندن حرکت"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1287,5 +1287,6 @@
|
|||
"+{p0} bars if kept": "+{p0} bars if kept",
|
||||
"· gain {p0} bar": "· gain {p0} bar",
|
||||
"{p0} · +{p1} bar if kept": "{p0} · +{p1} bar if kept",
|
||||
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept"
|
||||
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept",
|
||||
"Undo my move": "Annuler mon coup"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1287,5 +1287,6 @@
|
|||
"+{p0} bars if kept": "+{p0} bars if kept",
|
||||
"· gain {p0} bar": "· gain {p0} bar",
|
||||
"{p0} · +{p1} bar if kept": "{p0} · +{p1} bar if kept",
|
||||
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept"
|
||||
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept",
|
||||
"Undo my move": "अपनी चाल वापस लें"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1287,5 +1287,6 @@
|
|||
"+{p0} bars if kept": "+{p0} bars if kept",
|
||||
"· gain {p0} bar": "· gain {p0} bar",
|
||||
"{p0} · +{p1} bar if kept": "{p0} · +{p1} bar if kept",
|
||||
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept"
|
||||
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept",
|
||||
"Undo my move": "Annulla la mossa"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1287,5 +1287,6 @@
|
|||
"+{p0} bars if kept": "+{p0} bars if kept",
|
||||
"· gain {p0} bar": "· gain {p0} bar",
|
||||
"{p0} · +{p1} bar if kept": "{p0} · +{p1} bar if kept",
|
||||
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept"
|
||||
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept",
|
||||
"Undo my move": "내 수 되돌리기"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1287,5 +1287,6 @@
|
|||
"+{p0} bars if kept": "+{p0} bars if kept",
|
||||
"· gain {p0} bar": "· gain {p0} bar",
|
||||
"{p0} · +{p1} bar if kept": "{p0} · +{p1} bar if kept",
|
||||
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept"
|
||||
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept",
|
||||
"Undo my move": "Zet ongedaan maken"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1287,5 +1287,6 @@
|
|||
"+{p0} bars if kept": "+{p0} bars if kept",
|
||||
"· gain {p0} bar": "· gain {p0} bar",
|
||||
"{p0} · +{p1} bar if kept": "{p0} · +{p1} bar if kept",
|
||||
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept"
|
||||
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept",
|
||||
"Undo my move": "Cofnij ruch"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1287,5 +1287,6 @@
|
|||
"+{p0} bars if kept": "+{p0} bars if kept",
|
||||
"· gain {p0} bar": "· gain {p0} bar",
|
||||
"{p0} · +{p1} bar if kept": "{p0} · +{p1} bar if kept",
|
||||
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept"
|
||||
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept",
|
||||
"Undo my move": "Desfazer jogada"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1287,5 +1287,6 @@
|
|||
"+{p0} bars if kept": "+{p0} bars if kept",
|
||||
"· gain {p0} bar": "· gain {p0} bar",
|
||||
"{p0} · +{p1} bar if kept": "{p0} · +{p1} bar if kept",
|
||||
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept"
|
||||
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept",
|
||||
"Undo my move": "Anulează mutarea"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1287,5 +1287,6 @@
|
|||
"+{p0} bars if kept": "+{p0} bars if kept",
|
||||
"· gain {p0} bar": "· gain {p0} bar",
|
||||
"{p0} · +{p1} bar if kept": "{p0} · +{p1} bar if kept",
|
||||
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept"
|
||||
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept",
|
||||
"Undo my move": "Отменить ход"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1287,5 +1287,6 @@
|
|||
"+{p0} bars if kept": "+{p0} bars if kept",
|
||||
"· gain {p0} bar": "· gain {p0} bar",
|
||||
"{p0} · +{p1} bar if kept": "{p0} · +{p1} bar if kept",
|
||||
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept"
|
||||
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept",
|
||||
"Undo my move": "Hoàn tác nước đi"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1287,5 +1287,6 @@
|
|||
"+{p0} bars if kept": "+{p0} bars if kept",
|
||||
"· gain {p0} bar": "· gain {p0} bar",
|
||||
"{p0} · +{p1} bar if kept": "{p0} · +{p1} bar if kept",
|
||||
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept"
|
||||
"{p0} · +{p1} bars if kept": "{p0} · +{p1} bars if kept",
|
||||
"Undo my move": "撤回我的行動"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,11 +10,12 @@ import { mountTutorial } from "./tutorial";
|
|||
|
||||
registerViewer<View, Move>(
|
||||
"fuji",
|
||||
({ target, move, openPlayer, hoverPlayer, leavePlayer, updatePreference, replaceLog }) => {
|
||||
({ target, move, openPlayer, hoverPlayer, leavePlayer, updatePreference, replaceLog, undo }) => {
|
||||
const store = new Store();
|
||||
store.send = move;
|
||||
store.clickPlayer = openPlayer;
|
||||
store.savePreference = updatePreference;
|
||||
store.undo = undo;
|
||||
const app = mount(App, { target, props: { store } });
|
||||
const removeCards = installPlayerCards(target, { hoverPlayer, leavePlayer });
|
||||
const thumbnail = createBoardThumbnail(target);
|
||||
|
|
@ -48,6 +49,9 @@ registerViewer<View, Move>(
|
|||
onAvatars(avatars) {
|
||||
store.avatars = avatars;
|
||||
},
|
||||
onUndoAvailable(available) {
|
||||
store.undoAvailable = available;
|
||||
},
|
||||
onError(error) {
|
||||
store.error = error instanceof Error ? error.message : String(error);
|
||||
store.waiting = false;
|
||||
|
|
|
|||
|
|
@ -1,42 +0,0 @@
|
|||
diff --git a/dist/chat-viewport.js b/dist/chat-viewport.js
|
||||
index 84fdef2bdf411584349a54362663a379d6778808..e322c2a25c0456ada442bbbff2d49494d0db952b 100644
|
||||
--- a/dist/chat-viewport.js
|
||||
+++ b/dist/chat-viewport.js
|
||||
@@ -74,6 +74,11 @@ export function bindChatViewport(list, options) {
|
||||
chat.markRead(latest.dataset.messageId);
|
||||
}
|
||||
}
|
||||
+ function updateFollowing() {
|
||||
+ if (list.clientHeight && initialized && list.scrollTop !== programmedScroll) {
|
||||
+ following = list.scrollHeight - list.scrollTop - list.clientHeight <= 1;
|
||||
+ }
|
||||
+ }
|
||||
function refresh() {
|
||||
if (disposed || frame !== undefined) {
|
||||
return;
|
||||
@@ -81,11 +86,13 @@ export function bindChatViewport(list, options) {
|
||||
frame = win.requestAnimationFrame(() => {
|
||||
frame = undefined;
|
||||
if (list.clientHeight && chat.snapshot.open && (options.isVisible?.() ?? true)) {
|
||||
+ // Observers can run before the scroll event from a small wheel or touch movement.
|
||||
+ updateFollowing();
|
||||
if (scrollToUnread) {
|
||||
const row = rows().find((element) => chat.snapshot.unreadIds.includes(element.dataset.messageId ?? ""));
|
||||
if (row) {
|
||||
list.scrollTop += row.getBoundingClientRect().top - list.getBoundingClientRect().top;
|
||||
- following = list.scrollHeight - list.scrollTop - list.clientHeight < 32;
|
||||
+ following = list.scrollHeight - list.scrollTop - list.clientHeight <= 1;
|
||||
}
|
||||
else {
|
||||
following = true;
|
||||
@@ -103,9 +110,7 @@ export function bindChatViewport(list, options) {
|
||||
});
|
||||
}
|
||||
function scroll() {
|
||||
- if (list.clientHeight && initialized && list.scrollTop !== programmedScroll) {
|
||||
- following = list.scrollHeight - list.scrollTop - list.clientHeight < 32;
|
||||
- }
|
||||
+ updateFollowing();
|
||||
refresh();
|
||||
}
|
||||
const resize = new ResizeObserver(refresh);
|
||||
|
|
@ -1 +0,0 @@
|
|||
The protocol 0.6.1 patch backports the [shared chat scrolling fix](https://codeberg.org/boardgamers/boardgamers/commit/7b4e1ff6). It prevents slow wheel and touch gestures from snapping back to the newest message. Remove the patch when upgrading to a protocol release containing that fix.
|
||||
13
pnpm-lock.yaml
generated
13
pnpm-lock.yaml
generated
|
|
@ -4,9 +4,6 @@ settings:
|
|||
autoInstallPeers: true
|
||||
excludeLinksFromLockfile: false
|
||||
|
||||
patchedDependencies:
|
||||
'@boardgamers/protocol@0.6.1': 4ec4a210cf846eebd6d902b2952c029dbcde5ed288f88dba1f9362a8a9caa953
|
||||
|
||||
importers:
|
||||
|
||||
.:
|
||||
|
|
@ -37,8 +34,8 @@ importers:
|
|||
packages/viewer:
|
||||
dependencies:
|
||||
'@boardgamers/protocol':
|
||||
specifier: 0.6.1
|
||||
version: 0.6.1(patch_hash=4ec4a210cf846eebd6d902b2952c029dbcde5ed288f88dba1f9362a8a9caa953)
|
||||
specifier: 0.10.0
|
||||
version: 0.10.0
|
||||
fuji-engine:
|
||||
specifier: workspace:*
|
||||
version: link:../engine
|
||||
|
|
@ -64,8 +61,8 @@ importers:
|
|||
|
||||
packages:
|
||||
|
||||
'@boardgamers/protocol@0.6.1':
|
||||
resolution: {integrity: sha512-/SdqqYrRUNizjGqQygR4kxTZqCOqWfj190Uj/YHI8i0pD4eNXGofZJd2QhkB63n0iSRHMvJJRJReadof151wBg==}
|
||||
'@boardgamers/protocol@0.10.0':
|
||||
resolution: {integrity: sha512-U+nOK8xeQANvjzwacHirBW+ItDf9AOmHLtkoyTI/XYFCOpL6lPsEgCbmcxnmkXv2a1/lgtVN3WpSERHUqkQkXw==}
|
||||
|
||||
'@jridgewell/gen-mapping@0.3.13':
|
||||
resolution: {integrity: sha512-2kkt/7niJ6MgEPxF0bYdQ6etZaA+fQvDcLKckhy1yIQOzaoKjBBjSj63/aLVjYE3qhRt5dvM+uUyfCg6UKCBbA==}
|
||||
|
|
@ -634,7 +631,7 @@ packages:
|
|||
|
||||
snapshots:
|
||||
|
||||
'@boardgamers/protocol@0.6.1(patch_hash=4ec4a210cf846eebd6d902b2952c029dbcde5ed288f88dba1f9362a8a9caa953)':
|
||||
'@boardgamers/protocol@0.10.0':
|
||||
dependencies:
|
||||
zod: 4.6.2
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,4 @@
|
|||
packages:
|
||||
- packages/*
|
||||
minimumReleaseAgeExclude:
|
||||
- "@boardgamers/protocol@0.2.2 || 0.3.0 || 0.3.1 || 0.3.3 || 0.4.0 || 0.4.2 || 0.5.0 || 0.6.0 || 0.6.1"
|
||||
|
||||
patchedDependencies:
|
||||
"@boardgamers/protocol@0.6.1": patches/@boardgamers__protocol@0.6.1.patch
|
||||
- "@boardgamers/protocol@0.2.2 || 0.3.0 || 0.3.1 || 0.3.3 || 0.4.0 || 0.4.2 || 0.5.0 || 0.6.0 || 0.6.1 || 0.10.0"
|
||||
|
|
|
|||
104
tests/undo-smoke.mjs
Normal file
104
tests/undo-smoke.mjs
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
// "Undo my move": BGS offers it to the only human of a game against bots (protocol 0.10.0).
|
||||
import { serveAssets } from "./asset-server.mjs";
|
||||
const assetBase = await serveAssets("packages/viewer/dist");
|
||||
import assert from "node:assert/strict";
|
||||
import { chromium } from "playwright";
|
||||
import { initGame, moveAI, activePlayers, stripSecret } from "../packages/engine/dist/index.js";
|
||||
let game = initGame(3, { skillAssignment: "fixed" }, "undo-smoke");
|
||||
while (game.phase !== "reroll")
|
||||
game = moveAI(
|
||||
game,
|
||||
activePlayers(game).find((i) => !(game.phase === "planning" && game.players[i].ready))
|
||||
);
|
||||
// After a teammate's reroll, the local player's own choices are unchanged.
|
||||
const earlier = stripSecret(game, 0);
|
||||
const later = stripSecret(moveAI(game, 1), 0);
|
||||
assert(later.revision > earlier.revision && later.log.length > earlier.log.length);
|
||||
assert.deepEqual(later.players[0], earlier.players[0]);
|
||||
|
||||
const browser = await chromium.launch({ headless: true, executablePath: process.env.FUJI_CHROMIUM_EXECUTABLE });
|
||||
try {
|
||||
for (const width of [1400, 390]) {
|
||||
const page = await browser.newPage({ viewport: { width, height: 900 } });
|
||||
const errors = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.setContent('<meta name="viewport" content="width=device-width, initial-scale=1"><div id="app"></div>');
|
||||
await page.addStyleTag({ url: assetBase + "/fuji-viewer.css" });
|
||||
await page.addScriptTag({ url: assetBase + "/fuji-viewer.iife.js" });
|
||||
await page.evaluate((state) => {
|
||||
window.events = [];
|
||||
window.logs = [];
|
||||
window.bridge = fuji.launch("#app");
|
||||
for (const name of ["undo", "move"]) bridge.on(name, (payload) => events.push({ name, payload }));
|
||||
bridge.on("replaceLog", (lines) => logs.push(lines));
|
||||
bridge.emit("preferences", { sound: false });
|
||||
bridge.emit("player", { index: 0 });
|
||||
bridge.emit("state", state);
|
||||
bridge.emit("chat:state", { canSend: true });
|
||||
}, later);
|
||||
const undo = page
|
||||
.getByRole("navigation", { name: "Game options" })
|
||||
.getByRole("button", { name: "Undo my move", exact: true });
|
||||
const emit = (name, payload) => page.evaluate(([name, payload]) => bridge.emit(name, payload), [name, payload]);
|
||||
const gone = (selector, message) =>
|
||||
page
|
||||
.waitForFunction((selector) => !document.querySelector(selector), selector, { timeout: 5000 })
|
||||
.catch(() => assert.fail(message));
|
||||
const hidden = (message) => gone(".undo-move", message);
|
||||
await page.locator(".personal .die").first().waitFor();
|
||||
assert.equal(await undo.count(), 0, "hidden until BGS offers undo");
|
||||
|
||||
await emit("undo:available", true);
|
||||
await undo.waitFor();
|
||||
assert.equal(await undo.getAttribute("title"), "Undo my move");
|
||||
assert.equal(
|
||||
await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth),
|
||||
true,
|
||||
`header overflows at ${width}px`
|
||||
);
|
||||
const box = await undo.boundingBox();
|
||||
assert(box && box.x >= 0 && box.x + box.width <= width, "undo control must stay on screen");
|
||||
|
||||
// A selection made on the later position must not survive the undo.
|
||||
await page.locator(".personal .die:not([disabled])").first().click();
|
||||
assert.equal(await page.locator(".personal .die.chosen").count(), 1);
|
||||
await undo.click();
|
||||
assert.deepEqual(await page.evaluate(() => events), [{ name: "undo", payload: undefined }]);
|
||||
await emit("state", earlier);
|
||||
await gone(".personal .die.chosen", "the earlier state must clear local selections");
|
||||
assert.equal((await page.evaluate(() => logs.at(-1))).length, earlier.log.length);
|
||||
assert.equal(await page.getByRole("button", { name: "Skip to latest" }).isVisible(), false);
|
||||
assert.equal(await page.locator(".teammate").nth(1).locator(".ready-label").textContent(), "Can act");
|
||||
await undo.waitFor();
|
||||
|
||||
// Hidden while a move awaits the next state, for spectators and in analysis.
|
||||
await page.locator("button.finish-dice, .mobile-dock button").filter({ visible: true }).first().click();
|
||||
assert.equal((await page.evaluate(() => events)).at(-1).name, "move");
|
||||
await hidden("hidden while a move is pending");
|
||||
await emit("state", earlier);
|
||||
await undo.waitFor();
|
||||
await page.evaluate((state) => {
|
||||
bridge.emit("player", {});
|
||||
bridge.emit("state", state);
|
||||
}, stripSecret(game));
|
||||
await hidden("hidden for spectators");
|
||||
await page.evaluate((state) => {
|
||||
bridge.emit("player", { index: 0 });
|
||||
bridge.emit("state", state);
|
||||
}, earlier);
|
||||
await undo.waitFor();
|
||||
await emit("preferences", { sound: false, analysis: true });
|
||||
await hidden("hidden in analysis");
|
||||
await emit("preferences", { sound: false, locale: "fr" });
|
||||
await page.getByRole("button", { name: "Annuler mon coup", exact: true }).waitFor();
|
||||
|
||||
await emit("undo:available", false);
|
||||
await hidden("hidden when BGS withdraws undo");
|
||||
assert.equal((await page.evaluate(() => events)).filter((e) => e.name === "undo").length, 1);
|
||||
assert.deepEqual(errors, []);
|
||||
await page.close();
|
||||
}
|
||||
console.log("Undo my move: offered only while available and interactive, requests undo, resets drafts on rewind.");
|
||||
} finally {
|
||||
await browser.close();
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue