diff --git a/packages/viewer/package.json b/packages/viewer/package.json index eb4b4e5..362c40d 100644 --- a/packages/viewer/package.json +++ b/packages/viewer/package.json @@ -16,7 +16,7 @@ "preview": "vite preview" }, "dependencies": { - "@boardgamers/protocol": "0.3.1", + "@boardgamers/protocol": "0.3.3", "outpost-engine": "workspace:*" }, "devDependencies": { diff --git a/packages/viewer/src/tutorial/lessons.ts b/packages/viewer/src/tutorial/lessons.ts index fb05c78..dbdcc4b 100644 --- a/packages/viewer/src/tutorial/lessons.ts +++ b/packages/viewer/src/tutorial/lessons.ts @@ -277,18 +277,25 @@ function actionStep( allowed(action, state) ? undefined : "Follow this step’s instructions. Use Replay step to start it again.", }; } -function question(id: string, title: string, text: string, answer: string): TutorialStep { +function question( + id: string, + title: string, + text: string, + answer: string, + explanation: string +): TutorialStep { return { - ...actionStep( - id, - title, - text, - (action) => action.kind === "answer" && action.answer === answer, - (state) => state.answer === answer, - "lesson-choices" - ), + id, + title, + text, + success: `Correct! ${explanation}`, + complete: (state) => state.answer === answer, validateMove: (_state, action) => - action.kind === "answer" && action.answer === answer ? undefined : "Not quite. Try another answer.", + action.kind !== "answer" + ? "Choose one of the answers below." + : action.answer === answer + ? undefined + : `Not quite. ${explanation}`, }; } const isMove = (action: Move["action"]) => (value: LessonAction) => @@ -315,7 +322,8 @@ export const lessons: Lesson[] = [ "credits", "Cards are your money", "You have 21 credits in four cards. Purchases consume whole cards and give no change. If you spend all 21 on a Water factory costing 20, how many credits come back?", - "0" + "0", + "You receive no change. All 21 credits are spent, even though the factory costs 20." ), actionStep( "build", @@ -418,7 +426,8 @@ export const lessons: Lesson[] = [ "price", "How much do you owe?", "You bid 60, Leo bid 50 and Ada bid 40. The price is the second-highest bid plus 1, here 51. Subtract your two Data Libraries’ 20-credit discount. How much do you pay?", - "31" + "31", + "The auction price is 51. Your 20-credit discount reduces your payment to 31." ), actionStep( "pay", @@ -450,7 +459,8 @@ export const lessons: Lesson[] = [ "limit", "How many robots can operate?", "Each Robots upgrade lets you operate as many robots as you have colonists. With three colonists and one Robots upgrade, how many robots could work? Robots do not use your colonist capacity.", - "3" + "3", + "One Robots upgrade and three colonists let you operate up to three robots. They use no colonist capacity." ), actionStep( "assign", @@ -498,7 +508,8 @@ export const lessons: Lesson[] = [ "count", "Which cards use space?", "You hold fourteen cards: ten Ore, two Water and two Research. Research and Microbiotics use no hand capacity. How many of your cards count toward the limit?", - "12" + "12", + "The ten Ore and two Water cards use 12 spaces. Both Research cards use none." ), actionStep( "discard", @@ -536,7 +547,8 @@ export const lessons: Lesson[] = [ "requirement", "What must the payment include?", "A New Chemicals factory costs 60. Is having a Research card enough, or must you spend it as part of those 60 credits?", - "Spend one Research card per factory" + "Spend one Research card per factory", + "Spend a Research card as part of each factory’s 60-credit payment. Keeping it in hand is not enough." ), actionStep( "build", @@ -591,7 +603,8 @@ export const lessons: Lesson[] = [ "space", "How much storage does it use?", "Mega Water is one physical card, but it replaces four ordinary cards. How many spaces does it count toward your hand limit?", - "4" + "4", + "One Mega card uses four spaces, just like the four production cards it replaces." ), ], choices: { space: answers("1", "4", "30") }, @@ -616,7 +629,8 @@ export const lessons: Lesson[] = [ "score", "Does saving money score points?", "You also hold a 60-credit Moon Ore card. Does keeping it in your hand add 60 VP?", - "No, only staffed factories and upgrades score" + "No, only staffed factories and upgrades score", + "Unspent cards add no VP. Points come from staffed factories and upgrades." ), actionStep( "open", @@ -641,7 +655,8 @@ export const lessons: Lesson[] = [ "round", "Is the game over immediately?", "You now have 75 VP, but Ada and Leo still have turns this round. Could another player still finish with more VP and win?", - "Yes, finish the round first" + "Yes, finish the round first", + "Everyone finishes the round. Another player can still overtake you; the highest final VP wins." ), actionStep( "finish", diff --git a/packages/viewer/src/tutorial/mount.ts b/packages/viewer/src/tutorial/mount.ts index 75ed51c..16b4cd7 100644 --- a/packages/viewer/src/tutorial/mount.ts +++ b/packages/viewer/src/tutorial/mount.ts @@ -8,7 +8,7 @@ import { ViewerStore } from "../lib/store.svelte"; import { lessons, type LessonAction } from "./lessons"; import "./tutorial.css"; -export const mountTutorial: TutorialMount = async (target, { chapter, onProgress }) => { +export const mountTutorial: TutorialMount = async (target, { chapter, onProgress, nextChapter }) => { const lesson = lessons.find((entry) => entry.id === chapter); if (!lesson) { throw Error("Unknown Outpost chapter"); @@ -124,7 +124,7 @@ export const mountTutorial: TutorialMount = async (target, { chapter, onProgress choices.hidden = !choices.childElementCount; }); await tick(); - const cleanupGuide = mountTutorialGuide(guide, controller); + const cleanupGuide = mountTutorialGuide(guide, controller, { nextChapter }); const resize = new ResizeObserver(() => { target.style.setProperty("--tutorial-height", `${top.getBoundingClientRect().height}px`); }); diff --git a/packages/viewer/src/tutorial/tutorial.css b/packages/viewer/src/tutorial/tutorial.css index 53443fb..4985a91 100644 --- a/packages/viewer/src/tutorial/tutorial.css +++ b/packages/viewer/src/tutorial/tutorial.css @@ -107,3 +107,24 @@ margin-top: 8px; } } + +.bgs-tutorial-feedback { + margin: 0 0 12px; + padding: 10px 12px; + border-left: 3px solid #54c584; + background: #193b2c; + color: #c1f3d4; + font-weight: 600; +} + +.bgs-tutorial-guide .bgs-tutorial-next-chapter { + height: 36px; + padding: 0 10px; + display: inline-flex; + align-items: center; + gap: 6px; + white-space: nowrap; +} +.bgs-tutorial-guide [hidden] { + display: none; +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a40a333..20dc7a7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -40,8 +40,8 @@ importers: packages/viewer: dependencies: '@boardgamers/protocol': - specifier: 0.3.1 - version: 0.3.1 + specifier: 0.3.3 + version: 0.3.3 outpost-engine: specifier: workspace:* version: link:../engine @@ -67,8 +67,8 @@ importers: packages: - '@boardgamers/protocol@0.3.1': - resolution: {integrity: sha512-FF8OUEvAZ+BKjZZ3Ab8Dw7oQh6TJOKMNkmRHqoabeE4clSp8lMRnHGGEakZdi7DplDJpstnya2fgBk2hX82UrA==} + '@boardgamers/protocol@0.3.3': + resolution: {integrity: sha512-AS+x84WHXRudW6xt/s/5I3xYmNTQFbZEBp3V+41w0I2RirSr2fWjYnYf0p11nwTbZ6G5upivKz/sjYLtk8HOYA==} '@jridgewell/gen-mapping@0.3.13': resolution: {integrity: sha512-2kkt/7niJ6MgEPxF0bYdQ6etZaA+fQvDcLKckhy1yIQOzaoKjBBjSj63/aLVjYE3qhRt5dvM+uUyfCg6UKCBbA==} @@ -772,7 +772,7 @@ packages: snapshots: - '@boardgamers/protocol@0.3.1': + '@boardgamers/protocol@0.3.3': dependencies: zod: 4.6.2 diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 26a7feb..b4d3983 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -1,4 +1,4 @@ packages: - "packages/*" minimumReleaseAgeExclude: - - "@boardgamers/protocol@0.3.1" + - "@boardgamers/protocol@0.3.1 || 0.3.3" diff --git a/tests/tutorial-browser.mjs b/tests/tutorial-browser.mjs index 57c5433..b579650 100644 --- a/tests/tutorial-browser.mjs +++ b/tests/tutorial-browser.mjs @@ -42,7 +42,10 @@ try { const answer = lesson.choices[entry.id].find( (choice) => !entry.validateMove(lesson.initialState(), { kind: "answer", answer: choice.answer }) ); + assert.equal(await guide.getByRole("button", { name: "Show area", exact: true }).isVisible(), false); await button(answer.label).click(); + await guide.locator(".bgs-tutorial-feedback").waitFor(); + assert.match(await guide.locator(".bgs-tutorial-feedback").innerText(), /^Correct! /); } else if (lesson.watch?.[entry.id]) { await button(lesson.watch[entry.id]).click(); } else if (entry.id === "open") { diff --git a/tests/tutorial.spec.mjs b/tests/tutorial.spec.mjs index 1e06efb..adff8ef 100644 --- a/tests/tutorial.spec.mjs +++ b/tests/tutorial.spec.mjs @@ -122,9 +122,17 @@ for (const lesson of lessons) { assert.equal(controller.snapshot.step, index + 1); validateState(controller.snapshot.state.game); const after = structuredClone(controller.snapshot.state); + const feedback = controller.snapshot.feedback; + if (entry?.kind === "answer") { + assert.match(feedback, /^Correct! /); + assert.equal(lesson.steps[index].target, undefined); + } else { + assert.equal(feedback, ""); + } controller.destroy(); controller = await createTutorial(options); assert.deepEqual(controller.snapshot.state, after); + assert.equal(controller.snapshot.feedback, feedback); assert.equal(controller.snapshot.step, index + 1); await controller.previousStep(); assert.deepEqual(controller.snapshot.state, before); @@ -179,7 +187,7 @@ test("wrong answers and unrelated moves leave the lesson unchanged", async () => await controller.continue(); const before = structuredClone(controller.snapshot.state); await controller.play(answer("1")); - assert.equal(controller.snapshot.error, "Not quite. Try another answer."); + assert.match(controller.snapshot.error, /^Not quite\. You receive no change/); assert.deepEqual(controller.snapshot.state, before); await controller.play(answer("0")); await controller.play(move({ action: "endTurn", buys: [], manned: [0, 1, 2] }));