diff --git a/packages/viewer/src/lib/VictoryPetals.svelte b/packages/viewer/src/lib/VictoryPetals.svelte
new file mode 100644
index 0000000..7d36bf7
--- /dev/null
+++ b/packages/viewer/src/lib/VictoryPetals.svelte
@@ -0,0 +1,93 @@
+
+
+{#if visible}
+
+ {#each petals as petal, i}
+
+ {/each}
+
+{/if}
+
+
diff --git a/packages/viewer/src/tutorial/first-steps.ts b/packages/viewer/src/tutorial/first-steps.ts
index c68b708..1ea9fe0 100644
--- a/packages/viewer/src/tutorial/first-steps.ts
+++ b/packages/viewer/src/tutorial/first-steps.ts
@@ -128,7 +128,7 @@ export const firstSteps: TutorialOptions
= {
{
id: "welcome",
title: "Escape together",
- text: "Help everyone reach the village before the lava catches anyone. You control the gold explorer; Mika and Ren are scripted teammates. Preparation is done — let’s plan your first move.",
+ text: "Help everyone reach the village before the lava catches anyone. You control the gold explorer; Mika and Ren are scripted teammates. Preparation is done. Let’s plan your first move.",
target: "board",
},
{
diff --git a/packages/viewer/src/tutorial/lessons.spec.ts b/packages/viewer/src/tutorial/lessons.spec.ts
index 25121f9..532281d 100644
--- a/packages/viewer/src/tutorial/lessons.spec.ts
+++ b/packages/viewer/src/tutorial/lessons.spec.ts
@@ -2,7 +2,15 @@ import { test } from "node:test";
import assert from "node:assert/strict";
import { createTutorial } from "@boardgamers/protocol/tutorial";
import { applyMove, cell, paths, stripSecret, terrain, threatened } from "fuji-engine";
-import { equipmentLesson, terrainLesson, lavaLesson, BONUS_TILE, ERUPTION_TILE } from "./lessons.ts";
+import {
+ equipmentLesson,
+ terrainLesson,
+ lavaLesson,
+ BONUS_TILE,
+ ERUPTION_TILE,
+ winLesson,
+ WIN_DESTINATION,
+} from "./lessons.ts";
test("equipment teaches a legal turn and private loan, with cards discarded once", async () => {
const c = await createTutorial(equipmentLesson);
@@ -105,3 +113,23 @@ test("automatic movement cannot save a plan caught by the extra plus normal erup
assert.equal(c.snapshot.canContinue, false);
assert.equal(c.snapshot.completed, true, c.snapshot.error);
});
+
+test("all three explorers reach the village and win before another eruption", async () => {
+ const c = await createTutorial(winLesson);
+ assert.ok(c.snapshot.state.players.every((p) => !cell(c.snapshot.state, p.position).lava));
+ assert.ok(threatened(c.snapshot.state).includes("3,2"), "The next wave threatens their starting position");
+ await c.continue();
+ assert.equal(await c.play({ action: "plan", path: ["3,2", "4,2", WIN_DESTINATION] }), true, c.snapshot.error);
+ assert.equal(await c.play({ action: "ready" }), true, c.snapshot.error);
+ assert.equal(c.snapshot.state.phase, "reroll");
+ assert.equal(await c.play({ action: "finishRerolls" }), true, c.snapshot.error);
+ assert.equal(c.snapshot.state.phase, "equipment");
+ assert.equal(await c.play({ action: "ready" }), true, c.snapshot.error);
+ assert.equal(c.snapshot.state.outcome, "won");
+ assert.ok(
+ c.snapshot.state.players.every((p) => terrain(cell(c.snapshot.state, p.position).terrain).kind === "village")
+ );
+ assert.equal(c.snapshot.state.log.filter((e) => e.journey?.moved).length, 3);
+ assert.equal(c.snapshot.state.log.filter((e) => e.animation?.kind === "eruption").length, 0);
+ assert.equal(c.snapshot.completed, true);
+});
diff --git a/packages/viewer/src/tutorial/lessons.ts b/packages/viewer/src/tutorial/lessons.ts
index 0ac919e..a9256c8 100644
--- a/packages/viewer/src/tutorial/lessons.ts
+++ b/packages/viewer/src/tutorial/lessons.ts
@@ -5,9 +5,7 @@ import { firstSteps, firstStepsState, lessonMove, DESTINATION } from "./first-st
const only =
(...actions: string[]) =>
(_state: State, move: Move) =>
- actions.includes(move.action)
- ? undefined
- : "Follow this step's highlighted action. Choose Retry step to try again.";
+ actions.includes(move.action) ? undefined : "Follow this step's highlighted action. Use Replay step to try again.";
function setTerrain(state: State, id: string, type: number) {
const target = cell(state, id);
@@ -167,7 +165,7 @@ export const terrainLesson: TutorialOptions = {
{
id: "first-roll",
title: "Spend the first reroll",
- text: "Keep the four matching dice (1, 2, 2, 1). Select both 6s — the fifth and sixth dice — and reroll them together. This spends one reroll, leaving one more.",
+ text: "Keep the four matching dice (1, 2, 2, 1). Select both 6s (dice 5 and 6) and reroll them together. This spends one reroll, leaving one more.",
target: "dice",
complete: (s) => s.players[0]!.rerolls === 1,
validateMove: (_s, m) =>
@@ -278,4 +276,102 @@ export const lavaLesson: TutorialOptions = {
},
};
-export const lessons = [firstSteps, equipmentLesson, terrainLesson, lavaLesson];
+export const WIN_DESTINATION = "4,1";
+export function winState() {
+ let state = firstStepsState();
+ state.round = 5;
+ state.initOptions.autoMovement = true;
+ state.initOptions.autoProgress = false;
+ // Use the garden as one of this prepared map's five village tiles.
+ cell(state, "4,0").terrain = 31;
+ for (let wave = 0; wave < 4; wave++) {
+ const next = threatened(state);
+ for (const c of state.board) if (next.includes(c.id)) c.lava = true;
+ }
+ state.players.forEach((player, seat) => {
+ player.position = "3,2";
+ player.path = [player.position];
+ player.dice.forEach((die) => {
+ die.face = [6, 1, 5][seat]!;
+ });
+ });
+ for (const [seat, path] of [
+ [1, ["3,2", "4,2", "4,1", "4,0"]],
+ [2, ["3,2", "4,2"]],
+ ] as const) {
+ state = applyMove(state, { action: "plan", path: [...path] }, seat);
+ state = applyMove(state, { action: "ready" }, seat);
+ }
+ return state;
+}
+
+function winMove(state: State, move: Move) {
+ let next = applyMove(state, move, 0);
+ for (const seat of [1, 2]) {
+ if (next.phase === "reroll" && !next.players[seat]!.ready) {
+ next = applyMove(next, { action: "finishRerolls" }, seat);
+ }
+ if (state.phase === "equipment" && next.phase === "equipment" && !next.players[seat]!.ready) {
+ next = applyMove(next, { action: "ready" }, seat);
+ }
+ }
+ return next;
+}
+
+export const winLesson: TutorialOptions = {
+ game: "fuji",
+ id: "village",
+ version: 1,
+ initialState: winState,
+ move: winMove,
+ steps: [
+ {
+ id: "welcome",
+ title: "One last journey",
+ text: "The lava is close and the village is within reach. Mika has chosen Village garden and Ren has chosen Blossom square. Help all three explorers get to safety. Reaching the village alone does not win the game.",
+ target: "board",
+ },
+ {
+ id: "destination",
+ title: "Choose Village street",
+ text: "Choose the highlighted Village street, two spaces away. It counts 4s and 6s, so your six 6s are a strong match. Each explorer must choose a different destination.",
+ target: `tile:${WIN_DESTINATION}`,
+ complete: (s) => s.players[0]!.path.at(-1) === WIN_DESTINATION,
+ validateMove: (_s, m) =>
+ m.action === "plan" && Array.isArray(m.path) && m.path.length === 3 && m.path.at(-1) === WIN_DESTINATION
+ ? undefined
+ : "Choose Village street via Blossom square.",
+ },
+ {
+ id: "confirm",
+ title: "Confirm your destination",
+ text: "Mika and Ren are ready. Confirm your route to begin the dice phase.",
+ target: "confirm",
+ complete: (s) => s.phase === "reroll",
+ validateMove: only("ready"),
+ },
+ {
+ id: "keep",
+ title: "Keep these strong dice",
+ text: "All your dice count at Village street. Keep them and finish rerolling. Your teammates keep the dice that suit their own destinations.",
+ target: "finish-rerolls",
+ complete: (s) => s.phase === "equipment",
+ validateMove: only("finishRerolls"),
+ },
+ {
+ id: "escape",
+ title: "Bring everyone home",
+ text: "Choose Ready to reveal. The game compares the dice and moves everyone in order. Watch all three explorers enter the village.",
+ target: "confirm",
+ complete: (s) => s.outcome === "won",
+ validateMove: only("ready"),
+ },
+ ],
+ completion: {
+ title: "Everyone escaped!",
+ text: "You, Mika and Ren all reached the village. The whole team wins immediately, before another eruption. That is the goal: bring everyone home together.",
+ target: "board",
+ },
+};
+
+export const lessons = [firstSteps, equipmentLesson, terrainLesson, lavaLesson, winLesson];
diff --git a/packages/viewer/src/tutorial/tutorial.css b/packages/viewer/src/tutorial/tutorial.css
index 93b6ee1..1136560 100644
--- a/packages/viewer/src/tutorial/tutorial.css
+++ b/packages/viewer/src/tutorial/tutorial.css
@@ -32,12 +32,23 @@
display: flex;
gap: 8px;
flex-wrap: wrap;
- align-items: start;
+ align-items: center;
}
-.bgs-tutorial-resets {
+.bgs-tutorial-playback,
+.bgs-tutorial-help {
display: flex;
- gap: 8px;
- margin-left: auto;
+ align-items: center;
+ flex-wrap: nowrap;
+ gap: 6px;
+}
+.bgs-tutorial-guide .bgs-tutorial-transport {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ padding: 0;
+ width: 36px;
+ height: 36px;
+ flex: 0 0 36px;
}
.bgs-tutorial-guide button {
min-height: 32px;
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index c9b5217..e7ce3d9 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -34,8 +34,8 @@ importers:
packages/viewer:
dependencies:
'@boardgamers/protocol':
- specifier: 0.3.0
- version: 0.3.0
+ specifier: 0.3.1
+ version: 0.3.1
fuji-engine:
specifier: workspace:*
version: link:../engine
@@ -61,8 +61,8 @@ importers:
packages:
- '@boardgamers/protocol@0.3.0':
- resolution: {integrity: sha512-9XI2+XK5RPdDM709Vh+uqHchr1cxe0DrtxLSvIMhhyDFaM0EutCQAuJkySQvKmdXTHizHxag+mNu4eaKx5Affw==}
+ '@boardgamers/protocol@0.3.1':
+ resolution: {integrity: sha512-FF8OUEvAZ+BKjZZ3Ab8Dw7oQh6TJOKMNkmRHqoabeE4clSp8lMRnHGGEakZdi7DplDJpstnya2fgBk2hX82UrA==}
'@jridgewell/gen-mapping@0.3.13':
resolution: {integrity: sha512-2kkt/7niJ6MgEPxF0bYdQ6etZaA+fQvDcLKckhy1yIQOzaoKjBBjSj63/aLVjYE3qhRt5dvM+uUyfCg6UKCBbA==}
@@ -631,7 +631,7 @@ packages:
snapshots:
- '@boardgamers/protocol@0.3.0':
+ '@boardgamers/protocol@0.3.1':
dependencies:
zod: 4.6.2
diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml
index c89643f..0329c1c 100644
--- a/pnpm-workspace.yaml
+++ b/pnpm-workspace.yaml
@@ -1,4 +1,4 @@
packages:
- packages/*
minimumReleaseAgeExclude:
- - "@boardgamers/protocol@0.2.2 || 0.3.0"
+ - "@boardgamers/protocol@0.2.2 || 0.3.0 || 0.3.1"
diff --git a/tests/tutorial-browser.mjs b/tests/tutorial-browser.mjs
index fe6a5d9..f46470c 100644
--- a/tests/tutorial-browser.mjs
+++ b/tests/tutorial-browser.mjs
@@ -11,6 +11,7 @@ async function recordPresentation(page) {
positions: Array.from(document.querySelectorAll(".traveler"), (el) => el.style.transform),
lava: document.querySelectorAll(".location.lava").length,
complete: document.querySelector(".bgs-tutorial-heading strong")?.textContent === "Chapter complete",
+ celebrating: !!document.querySelector(".victory-petals"),
};
if (JSON.stringify(frame) !== JSON.stringify(frames.at(-1))) frames.push(frame);
};
@@ -48,10 +49,13 @@ async function finishRound(page) {
const server = createServer(async (req, res) => {
if (req.url === "/fuji-viewer.iife.js" || req.url === "/fuji-viewer.css") {
- res.setHeader("content-type", req.url.endsWith("css") ? "text/css" : "text/javascript");
+ res.setHeader(
+ "content-type",
+ req.url.endsWith("css") ? "text/css; charset=utf-8" : "text/javascript; charset=utf-8"
+ );
res.end(await readFile(new URL(`../packages/viewer/dist${req.url}`, import.meta.url)));
} else {
- res.setHeader("content-type", "text/html");
+ res.setHeader("content-type", "text/html; charset=utf-8");
res.end(
`
`
);
@@ -60,11 +64,12 @@ const server = createServer(async (req, res) => {
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
const url = `http://127.0.0.1:${server.address().port}`;
const browser = await chromium.launch({ headless: true, executablePath: process.env.FUJI_CHROMIUM_EXECUTABLE });
+const chapterFilter = process.env.FUJI_TUTORIAL_CHAPTER;
try {
for (const viewport of [
{ width: 1440, height: 1000 },
{ width: 390, height: 844 },
- ]) {
+ ].filter(() => !chapterFilter || chapterFilter === "first-steps")) {
const context = await browser.newContext({ viewport, reducedMotion: "reduce" });
const page = await context.newPage();
const errors = [];
@@ -109,19 +114,21 @@ try {
() => document.querySelector(".bgs-tutorial-heading strong")?.textContent === "Chapter complete"
);
assert.match(await guide.innerText(), /You reached Hilltop lookout/);
- assert.equal(await guide.getByRole("button", { name: "Continue", exact: true }).isVisible(), false);
+ assert.equal(await guide.getByRole("button", { name: "Continue", exact: true }).isEnabled(), false);
await page.reload();
await page.waitForFunction(
() => document.querySelector(".bgs-tutorial-heading strong")?.textContent === "Chapter complete"
);
- await guide.getByRole("button", { name: "Restart chapter", exact: true }).click();
+ await guide.getByRole("button", { name: "Back to start", exact: true }).click();
await step(1);
assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth + 1));
assert.deepEqual(errors, []);
await context.close();
}
for (const width of [1440, 390]) {
- for (const chapter of ["equipment", "terrain-bonuses", "lava"]) {
+ for (const chapter of ["equipment", "terrain-bonuses", "lava"].filter(
+ (id) => !chapterFilter || chapterFilter === id
+ )) {
const page = await browser.newPage({ viewport: { width, height: 900 }, reducedMotion: "reduce" });
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
@@ -198,7 +205,7 @@ try {
assert.match(await page.locator('[data-tutorial="journal"]').innerText(), /Mika was caught by the lava/);
}
await guide.getByText("Chapter complete", { exact: true }).waitFor();
- assert.equal(await guide.getByRole("button", { name: "Continue", exact: true }).isVisible(), false);
+ assert.equal(await guide.getByRole("button", { name: "Continue", exact: true }).isEnabled(), false);
if (chapter === "terrain-bonuses") {
assert.match(await page.locator('[data-tutorial="equipment:rope"]').innerText(), /Available now/);
}
@@ -209,8 +216,84 @@ try {
await page.close();
}
}
+ for (const { width, reducedMotion } of [
+ { width: 1440, reducedMotion: "reduce" },
+ { width: 390, reducedMotion: "reduce" },
+ { width: 1440, reducedMotion: "no-preference" },
+ { width: 390, reducedMotion: "no-preference" },
+ ].filter(() => !chapterFilter || chapterFilter === "village")) {
+ const page = await browser.newPage({ viewport: { width, height: 900 }, reducedMotion });
+ await page.goto(`${url}/?chapter=village`);
+ const guide = page.locator(".bgs-tutorial-guide");
+ await guide.getByRole("button", { name: "Continue", exact: true }).click();
+ await guide.getByText("2/5 · Choose Village street", { exact: true }).waitFor();
+ await page.locator('[data-tutorial="tile:4,1"]').click();
+ await guide.getByText("3/5 · Confirm your destination", { exact: true }).waitFor();
+ const confirm = () => page.locator('[data-tutorial="confirm"]:visible').first().click();
+ await confirm();
+ await guide.getByText("4/5 · Keep these strong dice", { exact: true }).waitFor();
+ await guide.getByRole("button", { name: "Previous step", exact: true }).click();
+ await guide.getByText("3/5 · Confirm your destination", { exact: true }).waitFor();
+ await page.reload();
+ await guide.getByText("3/5 · Confirm your destination", { exact: true }).waitFor();
+ await confirm();
+ await guide.getByText("4/5 · Keep these strong dice", { exact: true }).waitFor();
+ await page.locator('[data-tutorial="finish-rerolls"]:visible').first().click();
+ await guide.getByText("5/5 · Bring everyone home", { exact: true }).waitFor();
+ assert.equal(await page.locator(".victory-petals").count(), 0);
+ await recordPresentation(page);
+ await confirm();
+ await guide.getByText("Chapter complete", { exact: true }).waitFor();
+ if (reducedMotion === "no-preference") await page.locator(".victory-petals").waitFor();
+ const frames = await page.evaluate(() => window.readTutorialFrames());
+ for (const seat of [0, 1, 2]) {
+ assert.notEqual(frames[0].positions[seat], frames.at(-1).positions[seat]);
+ assert.ok(
+ frames.some((f) => !f.complete && f.positions[seat] === frames.at(-1).positions[seat]),
+ "Moves are shown before chapter completion"
+ );
+ }
+ assert.equal(frames[0].lava, frames.at(-1).lava, "Victory needs no further lava wave");
+ assert.match(await guide.innerText(), /whole team wins immediately/);
+ const bounds = await guide
+ .locator(".bgs-tutorial-playback button")
+ .evaluateAll((buttons) => buttons.map((b) => b.getBoundingClientRect().top));
+ assert.equal(new Set(bounds).size, 1, "Playback controls stay on one row");
+ assert.equal(await page.evaluate(() => document.documentElement.scrollWidth > innerWidth + 1), false);
+ if (reducedMotion === "no-preference") {
+ await page.locator(".victory-petals").waitFor();
+ assert.equal(await page.locator(".victory-petals .petal").count(), 36);
+ assert.ok(
+ frames.some((f) => f.celebrating),
+ "The victory starts the petal effect"
+ );
+ assert.equal(await page.locator(".victory-petals").evaluate((el) => getComputedStyle(el).pointerEvents), "none");
+ assert.ok(
+ frames
+ .filter((f) => f.celebrating)
+ .every((f) => JSON.stringify(f.positions) === JSON.stringify(frames.at(-1).positions)),
+ "Petals follow every explorer's movement"
+ );
+ await page.waitForTimeout(1600);
+ await page.screenshot({ path: `/tmp/fuji-victory-petals-${width}.png` });
+ await page.locator(".victory-petals").waitFor({ state: "detached", timeout: 7000 });
+ } else {
+ assert.equal(await page.locator(".victory-petals").count(), 0, "Respect reduced motion");
+ }
+ await page.screenshot({ path: `/tmp/fuji-village-${width}.png`, fullPage: true });
+ await page.reload();
+ await guide.getByText("Chapter complete", { exact: true }).waitFor();
+ assert.equal(
+ await page.locator(".victory-petals").count(),
+ 0,
+ "Refreshing a finished game does not celebrate again"
+ );
+ await page.close();
+ }
console.log(
- "Fuji tutorials: all four chapters complete on desktop/mobile, with reload, equipment, lava and visible dice logs."
+ chapterFilter
+ ? `Fuji tutorial ${chapterFilter}: desktop/mobile checks passed.`
+ : "Fuji tutorials: all five chapters complete on desktop/mobile, with reload, equipment, lava and visible dice logs."
);
} finally {
await browser.close();