Use shared tutorial feedback and next-chapter controls

This commit is contained in:
coyotte508 2026-09-16 09:30:38 +02:00
commit aaaaca312e
7 changed files with 44 additions and 42 deletions

10
pnpm-lock.yaml generated
View file

@ -86,8 +86,8 @@ importers:
viewer:
dependencies:
'@boardgamers/protocol':
specifier: 0.3.1
version: 0.3.1
specifier: 0.3.3
version: 0.3.3
container-engine:
specifier: workspace:../engine
version: link:../engine
@ -1042,10 +1042,10 @@ packages:
}
engines: { node: '>=6.9.0' }
'@boardgamers/protocol@0.3.1':
'@boardgamers/protocol@0.3.3':
resolution:
{
integrity: sha512-FF8OUEvAZ+BKjZZ3Ab8Dw7oQh6TJOKMNkmRHqoabeE4clSp8lMRnHGGEakZdi7DplDJpstnya2fgBk2hX82UrA==,
integrity: sha512-AS+x84WHXRudW6xt/s/5I3xYmNTQFbZEBp3V+41w0I2RirSr2fWjYnYf0p11nwTbZ6G5upivKz/sjYLtk8HOYA==,
}
'@cspotcode/source-map-support@0.8.1':
@ -11586,7 +11586,7 @@ snapshots:
'@babel/helper-string-parser': 7.29.7
'@babel/helper-validator-identifier': 7.29.7
'@boardgamers/protocol@0.3.1':
'@boardgamers/protocol@0.3.3':
dependencies:
zod: 4.6.2

View file

@ -18,7 +18,7 @@ allowBuilds:
autoInstallPeers: false
minimumReleaseAgeExclude:
- '@boardgamers/protocol@0.2.2 || 0.3.0 || 0.3.1'
- '@boardgamers/protocol@0.2.2 || 0.3.0 || 0.3.1 || 0.3.3'
# The cli-plugin-typescript fork-ts-checker shim does a bare
# require('@vue/compiler-sfc') expecting the vue-3 parse shape ({descriptor}).

View file

@ -19,7 +19,7 @@
"preview:tutorial": "node scripts/tutorial-preview.mjs"
},
"dependencies": {
"@boardgamers/protocol": "0.3.1",
"@boardgamers/protocol": "0.3.3",
"container-engine": "workspace:../engine",
"core-js": "^3.6.5",
"lodash": "^4.17.19",

View file

@ -53,18 +53,24 @@ try {
await page.locator('.tutorial-bid input').fill(heading.includes('add $2') ? '2' : '8');
await page.locator('.tutorial-bid button').click();
} else if (heading.includes('What does keeping') || heading.includes('What does selling')) {
assert.equal(await guide.getByRole('button', { name: 'Show me', exact: true }).isVisible(), false);
assert.equal(
await guide.getByRole('button', { name: 'Show area', exact: true }).isVisible(),
false
);
await page
.locator('.tutorial-actions')
.getByRole('button', { name: heading.includes('keeping') ? '$24' : '$12', exact: true })
.click();
await page.getByRole('status').filter({ hasText: 'Correct!' }).waitFor();
assert.match(
await page.locator('.tutorial-answer-feedback').innerText(),
await page.locator('.bgs-tutorial-feedback').innerText(),
heading.includes('keeping') ? /\$24 gained/ : /\$12 received/
);
} else if (heading.includes('Check all five')) {
assert.equal(await guide.getByRole('button', { name: 'Show me', exact: true }).isVisible(), false);
assert.equal(
await guide.getByRole('button', { name: 'Show area', exact: true }).isVisible(),
false
);
await page.locator('.tutorial-actions').getByRole('button', { name: '$5', exact: true }).click();
await guide.getByRole('alert').waitFor();
assert.equal(await guide.locator('.bgs-tutorial-heading strong').innerText(), heading);

View file

@ -14,7 +14,6 @@ export interface Choice {
label: string;
action: TutorialAction;
color?: string;
correct?: string;
}
export interface Lesson extends Omit<TutorialOptions<LessonState, TutorialAction>, 'move'> {
title: string;
@ -180,13 +179,15 @@ function questionStep(
title: string,
text: string,
answer: string,
hint: string
hint: string,
success: string
): TutorialStep<LessonState, TutorialAction> {
return {
id,
title,
text,
hint,
success,
complete: (state) => state.answer === answer,
validateMove: (_state, action) =>
action.kind !== 'answer'
@ -556,14 +557,16 @@ const keeping: Lesson = {
'What does keeping add?',
'The two white containers are worth $20. The orange is worth $10 because it completes your five-colour set. Keeping adds $30 in containers, but costs $6 paid to the bank. What is the net gain?',
'24',
'$30 in containers minus the $6 payment.'
'$30 in containers minus the $6 payment.',
'Correct! $30 in containers − $6 paid to the bank = $24 gained.'
),
questionStep(
'sell-value',
'What does selling earn?',
'Ada pays her $6 bid and the bank matches it. How much cash do you receive in total?',
'12',
'Add the $6 bid and the $6 bank subsidy.'
'Add the $6 bid and the $6 bank subsidy.',
'Correct! Ada’s $6 + the bank’s $6 = $12 received.'
),
actionStep(
'decline',
@ -585,10 +588,6 @@ const keeping: Lesson = {
return answers.map((answer) => ({
label: `$${answer}`,
action: { kind: 'answer', answer },
correct:
step === 'keep-value'
? 'Correct! $30 in containers − $6 paid to the bank = $24 gained.'
: 'Correct! Ada’s $6 + the bank’s $6 = $12 received.',
}));
}
return step === 'decline' ? [choice('Keep cargo · pay $6', { name: MoveName.Decline, data: true })] : [];
@ -611,14 +610,16 @@ const scoring: Lesson = {
'Check all five colours first',
'The orange row says $5/10: each orange scores $10 if you have all five colours on your island, or $5 otherwise. Check this before removing any containers. You have all five colours. What is each orange worth?',
'10',
'All five colours are present, so use the higher value on the card.'
'All five colours are present, so use the higher value on the card.',
'Correct! All five colours are present, so each orange scores $10.'
),
questionStep(
'discard',
'Which entire colour is removed?',
'At final scoring, remove every container of your most numerous island colour. All containers of that colour score $0, regardless of their card value. If colours tie, remove your $5/10 colour if it is tied; otherwise the game removes the lowest-valued tied colour. Which colour must you remove here?',
Color.Black,
'You have 3 dark green, 2 white, and 1 of each other colour. Remove the colour with the most containers.'
'You have 3 dark green, 2 white, and 1 of each other colour. Remove the colour with the most containers.',
'Correct! Remove all 3 dark-green containers. All three score $0.'
),
actionStep(
'finish',
@ -637,14 +638,12 @@ const scoring: Lesson = {
return ['5', '10'].map((answer) => ({
label: `$${answer}`,
action: { kind: 'answer', answer },
correct: 'Correct! All five colours are present, so each orange scores $10.',
}));
if (step === 'discard')
return colors.map((color) => ({
label: colorName(color),
color,
action: { kind: 'answer', answer: color },
correct: 'Correct! Remove all 3 dark-green containers. All three score $0.',
}));
return step === 'finish' ? [choice('Done · score the game', pass)] : [];
},

View file

@ -9,7 +9,7 @@ import Game from '../components/Game.vue';
import { colorName, colors, lessons, LessonState, TutorialAction } from './lessons';
import './tutorial.css';
export const mountTutorial: TutorialMount = async (target, { chapter, onProgress }) => {
export const mountTutorial: TutorialMount = async (target, { chapter, onProgress, nextChapter }) => {
const found = lessons.find((entry) => entry.id === chapter);
if (!found) throw Error('Unknown Container chapter');
const lesson = found;
@ -22,15 +22,11 @@ export const mountTutorial: TutorialMount = async (target, { chapter, onProgress
}
const top = element('div', 'tutorial-top');
const guide = element('div', 'tutorial-guide');
const feedback = element('p', 'tutorial-answer-feedback');
feedback.setAttribute('role', 'status');
feedback.setAttribute('aria-atomic', 'true');
feedback.hidden = true;
const controls = element('div', 'tutorial-actions');
controls.dataset.tutorial = 'lesson-actions';
controls.setAttribute('aria-label', 'Lesson actions');
const left = element('div');
left.append(feedback, guide, controls);
left.append(guide, controls);
const summary = element('aside', 'tutorial-summary');
const gameHost = element('div', 'tutorial-game');
const result = element('section', 'tutorial-result');
@ -265,17 +261,6 @@ export const mountTutorial: TutorialMount = async (target, { chapter, onProgress
let controlStep = -1;
function renderControls(snapshot: TutorialSnapshot<LessonState>) {
const step = lesson.steps[snapshot.step]?.id ?? '';
const answeredStep = lesson.steps[snapshot.step - 1]?.id ?? '';
const answered =
snapshot.state.answer === undefined
? undefined
: lesson
.choices(snapshot.state, answeredStep)
.find(
(choice) => choice.action.kind === 'answer' && choice.action.answer === snapshot.state.answer
);
feedback.textContent = answered?.correct ?? '';
feedback.hidden = !feedback.textContent || !!snapshot.error;
// Preserve the typed bid and focus when validation reports an error.
if (controlStep !== snapshot.step) {
controls.replaceChildren();
@ -351,7 +336,7 @@ export const mountTutorial: TutorialMount = async (target, { chapter, onProgress
app.$forceUpdate();
renderControls(snapshot);
});
const removeGuide = mountTutorialGuide(guide, controller);
const removeGuide = mountTutorialGuide(guide, controller, { nextChapter });
return () => {
destroyed = true;
clearTimeout(animationTimer);

View file

@ -108,11 +108,11 @@
max-width: 100%;
}
.tutorial-actions[hidden],
.tutorial-answer-feedback[hidden],
.bgs-tutorial-feedback[hidden],
.tutorial-result[hidden] {
display: none;
}
.tutorial-answer-feedback {
.bgs-tutorial-feedback {
margin: 0 0 12px;
padding: 12px 16px;
border-left: 4px solid #34784c;
@ -316,3 +316,15 @@
.tutorial-business .tutorial-container {
margin: 5px 3px 0 0;
}
.bgs-tutorial-guide .bgs-tutorial-next-chapter {
height: 40px;
padding: 0 10px;
display: inline-flex;
align-items: center;
gap: 6px;
white-space: nowrap;
}
.bgs-tutorial-guide [hidden] {
display: none;
}