From dbe5ea819d6e49e5eb16bf0602d41c42186f1f12 Mon Sep 17 00:00:00 2001 From: coyotte508 Date: Tue, 15 Sep 2026 21:02:51 +0200 Subject: [PATCH] Add four guided tutorials using protocol 0.3.0 --- README.md | 15 + package.json | 4 +- packages/viewer/package.json | 5 +- packages/viewer/src/App.svelte | 43 ++- packages/viewer/src/lib/Die.svelte | 3 + packages/viewer/src/lib/JournalEntry.svelte | 6 +- packages/viewer/src/lib/Landscape.svelte | 8 +- packages/viewer/src/lib/store.svelte.ts | 11 + packages/viewer/src/tutorial.ts | 67 +++++ .../viewer/src/tutorial/first-steps.spec.ts | 83 ++++++ packages/viewer/src/tutorial/first-steps.ts | 228 ++++++++++++++ packages/viewer/src/tutorial/lessons.spec.ts | 107 +++++++ packages/viewer/src/tutorial/lessons.ts | 281 ++++++++++++++++++ packages/viewer/src/tutorial/tutorial.css | 115 +++++++ packages/viewer/src/viewer.ts | 71 +++-- packages/viewer/tsconfig.json | 1 + packages/viewer/tutorial.html | 17 ++ packages/viewer/vite.config.ts | 7 +- pnpm-lock.yaml | 10 +- pnpm-workspace.yaml | 2 +- tests/bgs-bundle-smoke.mjs | 1 + tests/protocol-lifecycle-smoke.mjs | 13 + tests/tutorial-browser.mjs | 218 ++++++++++++++ 23 files changed, 1254 insertions(+), 62 deletions(-) create mode 100644 packages/viewer/src/tutorial.ts create mode 100644 packages/viewer/src/tutorial/first-steps.spec.ts create mode 100644 packages/viewer/src/tutorial/first-steps.ts create mode 100644 packages/viewer/src/tutorial/lessons.spec.ts create mode 100644 packages/viewer/src/tutorial/lessons.ts create mode 100644 packages/viewer/src/tutorial/tutorial.css create mode 100644 packages/viewer/tutorial.html create mode 100644 tests/tutorial-browser.mjs diff --git a/README.md b/README.md index 2182636..a241aae 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,21 @@ pnpm fmt The engine tests cover deterministic replay, invalid-move atomicity, private information, movement, lava, injury timing and equipment interactions. Simulation runs 150 complete expeditions across player counts and difficulty levels and verifies exact replays. Browser smoke testing covers setup, route selection, every round phase, game end, mobile overflow and the help dialog. +## Tutorial + +Open `http://127.0.0.1:5187/tutorial.html?chapter=first-steps` to play a lesson. Each chapter uses the real engine, a prepared position and scripted teammates. Progress resumes separately for each chapter; the guide offers hints and restart controls. + +`pnpm build` produces one viewer JS/CSS bundle for games and tutorials. Upload it as the viewer with global name `fuji`, then add these chapters under **Tutorial** in BGS admin (revision `2` for chapters 1–3, `5` for chapter 4): + +| ID | Title | Covers | +| ----------------- | ---------------------------------- | ------------------------------------------------------------------------------- | +| `first-steps` | Your first journey | Destinations, matching dice, rerolls, Buddy and movement. | +| `equipment` | Equipment & helping teammates | Shovel, Map, card timing, discards and private loans. | +| `terrain-bonuses` | Location bonuses & supplies | Bonus rerolls, equipment tokens and next-round availability. | +| `lava` | When two lava waves catch the team | A deliberate defeat: an extra eruption plus the normal wave catches a teammate. | + +Chapter sources: `packages/viewer/src/tutorial/first-steps.ts` and `lessons.ts`. Keep setup and teammate actions deterministic; bump the chapter revision for incompatible changes. `pnpm check` tests legal actions, lesson outcomes, hidden information and saved progress. `node tests/tutorial-browser.mjs` completes every chapter on desktop and mobile. BGS calls `fuji.launchTutorial` for local lessons and `fuji.launch` for multiplayer games. + ## Packages - `packages/engine`: pure TypeScript rules, serializable state, seeded randomness, immutable move application and `dist/wrapper.js` for BGS. diff --git a/package.json b/package.json index ece2085..716563b 100644 --- a/package.json +++ b/package.json @@ -6,11 +6,11 @@ "dev": "pnpm --filter fuji-engine build && pnpm --filter fuji-viewer dev", "build": "pnpm --filter fuji-engine build && pnpm --filter fuji-viewer build", "test": "pnpm --filter fuji-engine test", - "check": "pnpm fmt:check && pnpm build && pnpm --filter fuji-viewer check && pnpm test", + "check": "pnpm fmt:check && pnpm build && pnpm --filter fuji-viewer check && pnpm test && pnpm --filter fuji-viewer test:tutorial", "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" + "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" }, "devDependencies": { "oxfmt": "0.61.0", diff --git a/packages/viewer/package.json b/packages/viewer/package.json index e26970c..cb31d22 100644 --- a/packages/viewer/package.json +++ b/packages/viewer/package.json @@ -7,10 +7,11 @@ "scripts": { "dev": "vite --host 127.0.0.1 --port 5187 --strictPort", "build": "vite build", - "check": "svelte-check --tsconfig ./tsconfig.json" + "check": "svelte-check --tsconfig ./tsconfig.json", + "test:tutorial": "node --test src/tutorial/*.spec.ts" }, "dependencies": { - "@boardgamers/protocol": "0.2.2", + "@boardgamers/protocol": "0.3.0", "fuji-engine": "workspace:*" }, "devDependencies": { diff --git a/packages/viewer/src/App.svelte b/packages/viewer/src/App.svelte index c17b8c0..9abc756 100644 --- a/packages/viewer/src/App.svelte +++ b/packages/viewer/src/App.svelte @@ -148,6 +148,7 @@ if (tool === "knife" && !copyOptions.some((c) => c.id === copied) && copyOptions[0]) copied = copyOptions[0].id; }); const actionTool = $derived(tool === "knife" ? (copyOptions.some((c) => c.id === copied) ? copied : null) : tool); + const shovelDie = $derived(dice.length === 1 ? me?.dice.find((d) => d.id === dice[0]) : undefined); const binocularReasons = $derived.by(() => { if (actionTool !== "binoculars" || !s) return undefined; return Object.fromEntries( @@ -252,7 +253,7 @@ }); function pickDie(id: string) { - dice = dice.includes(id) ? dice.filter((x) => x !== id) : [...dice, id]; + dice = dice.includes(id) ? dice.filter((x) => x !== id) : actionTool === "shovel" ? [id] : [...dice, id]; } function chooseLocation(id: string) { if (s?.phase === "setup") return; @@ -393,7 +394,7 @@ {#snippet journalPanel(location: string)} -
+

Expedition journal

{:else}

✓ Your route is set. Waiting for the team.

{:else}

✓ Ready. Waiting for the team.

@@ -1059,8 +1065,10 @@ {:else if s.activeResolution === null}

Choose who moves next. A route that triggers extra lava is often best resolved last.

- {#if !me.resolved} store.dispatch({ action: "beginMovement" })}>Resolve my journey →{:else}

✓ Your journey is resolved.

{/if} {:else if resolvingPlayer && result}{@const criterion = terrain( cell(s, resolvingPlayer.path.at(-1)!).terrain @@ -1131,12 +1139,16 @@ location.

{danger.length}locations threatened
- {/if} {#if me && s.phase !== "setup" && !s.outcome} -
+

Your equipment

{me.cards.length} @@ -1152,6 +1164,7 @@ !s.pending && (c.id !== "knife" || copyOptions.length > 0)}
{:else if entry.dice} -
- ⚄ {entry.diceLabel ?? entry.text} +
+
⚄ {entry.diceLabel ?? entry.text}
{#each entry.dice as d}{:else}No matching dice{/each}
-
+ {:else}