From 77d75ece951542e7f69e496051c7d7a8a9f73279 Mon Sep 17 00:00:00 2001 From: coyotte508 Date: Sat, 31 Oct 2026 17:56:01 +0100 Subject: [PATCH] Teach programming with a reachable ship destination and movement choices --- README.md | 2 +- bgs/tutorial.js | 3 ++- preview/app.js | 15 ++++++++++++--- preview/icons.js | 1 + preview/style.css | 23 +++++++++++++++++++---- src/tutorial-controller.js | 8 ++++---- src/tutorials.js | 11 +++++++++++ test/tutorial-controller.test.js | 23 +++++++++++++++++++++++ 8 files changed, 73 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 90948c6..f109e99 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ npm test npm run dev ``` -Open . Start with **Flight school / École de vol**: eight exercises use the real engine. Start with **Planning turns**: one crew member, two movement cards, and an empty turn. Arrange the cards, try the start/pause practice clock, then watch each turn execute. The later exercises have editable programs and a teammate already maintaining the computer; they cover firing, energy, malfunctions, battlebots/interceptors, double actions, phasing and specializations. +Open . Start with **Flight school / École de vol**: eight exercises use the real engine. Start with **Planning turns**: one crew member, a highlighted destination, two movement actions, and an empty turn. Choose left, right or a deck change to reach the destination; try the start/pause practice clock, then watch each turn execute. A missed destination can be retried. The later exercises have editable programs and a teammate already maintaining the computer; they cover firing, energy, malfunctions, battlebots/interceptors, double actions, phasing and specializations. For a full mission, expand **Local session / Session locale**. Select 1–5 humans, the crew, mission, threat pools and optional modules. In solo, you control four androids and have access to the full action deck. In multiplayer testing, open another tab with `?seat=1`, etc. Readiness lasts two minutes; everyone must be ready together. The local mission starts after a three-second countdown. If someone misses the window, the crew keeps waiting. Select a card half, then a turn. Advance individual phases to lock previous turns, or let the shared clock do so. After programming, the captain can resolve one step at a time or finish the mission; everyone can inspect the replay and log. diff --git a/bgs/tutorial.js b/bgs/tutorial.js index 2e86ad1..38c4a1c 100644 --- a/bgs/tutorial.js +++ b/bgs/tutorial.js @@ -61,9 +61,10 @@ export async function mountLesson(target, { chapter = "basics", locale = "en", o const label = [t("Découvrir", "Discover"), t("Préparer", "Plan"), t("Exécuter", "Execute")]; const transport = (action, icon, title, disabled = false) => ``; function renderGuide(s) { + const missed = LESSONS[index].basics && s.step === 2 && completedTurns(s.state) >= 3 && !s.completed; guide.innerHTML = `
${escape(LESSONS[index].title[locale === "fr" ? 0 : 1])}
${standalone ? `${t("Partie locale", "Local game")}` : ''}${transport("sound", soundOn ? "speaker" : "muted", soundOn ? t("Couper les sons", "Mute sounds") : t("Activer les sons", "Enable sounds"))}
-

${escape(s.title)}

${escape(s.text)}

+

${escape(s.title)}

${escape(missed ? t("Destination manquée. Revenez préparer un autre trajet.", "Destination missed. Go back and plan another route.") : s.text)}

${transport("restart", "rewind", t("Recommencer l’exercice", "Restart exercise"), s.busy)}${transport("previous", "left", t("Étape précédente", "Previous step"), s.step === 0 || s.busy)}${transport("replay", "restart", t("Rejouer cette étape", "Replay step"), s.busy || s.step === 0)}${s.canContinue ? `` : ''}${s.completed && (nextChapter || standalone && LESSONS[index + 1]) ? `` : ''}${s.saved ? "✓" : ""}
${s.error ? `

${escape(s.error)}

` : ''}`; } diff --git a/preview/app.js b/preview/app.js index 3b5b383..c3ab083 100644 --- a/preview/app.js +++ b/preview/app.js @@ -389,6 +389,15 @@ export function mountConsole(root, host = null) { crewLabel: (id) => view.players[id]?.name ?? `${t("Androïde", "Android")} ${id + 1}`, }); + if (basic && view.tutorial.targetStation) { + const goal = $("#ship").querySelector(`[data-station="${view.tutorial.targetStation}"]`); + if (goal) { + const reached = view.stage === "resolution" && ship.crew[0].station === view.tutorial.targetStation; + goal.classList.add("tutorial-destination"); + goal.classList.toggle("destination-reached", reached); + goal.insertAdjacentHTML("beforeend", `${pictogram(reached ? "check" : "destination")}`); + } + } $("#resources").innerHTML = `${symbol("fuel", `${t("Combustible", "Fuel")} : ${ship.fuel}`, `${ship.fuel}`)}${symbol("rocket", `${t("Roquettes", "Rockets")} : ${ship.rockets}`, `${ship.rockets}`)}${symbol("computer", t("Ordinateur", "Computer") + " · " + ship.computer.map((x, i) => `${t("Phase", "Phase")} ${i + 1} : ${x ? t("entretenu", "maintained") : t("à entretenir", "not maintained")}`).join(" · "), ship.computer.map((x, i) => `${i + 1}`).join(""))}${symbol("bots", `${t("Robots de combat · Escouades disponibles", "Battlebots · Available squads")} : ${ship.bots.filter((b) => b.owner === null && b.station && !b.disabled).length}`, `${ship.bots.filter((b) => b.owner === null && b.station && !b.disabled).length}${t("escouades", "squads")}`)}${ship.crew .filter((p) => p.space) @@ -531,12 +540,12 @@ export function mountConsole(root, host = null) { ]; const grouped = []; for (const card of hand) { - if (basic && !card.sides.some(side => side.length === 1 && ["red", "blue"].includes(side[0]))) continue; + if (basic && !card.sides.some(side => side.length === 1 && ["red", "blue", "lift"].includes(side[0]))) continue; const same = grouped.find( (c) => c.kind === "normal" && card.kind === "normal" && - JSON.stringify(basic ? c.sides.filter(side => side.length === 1 && ["red", "blue"].includes(side[0])) : c.sides) === JSON.stringify(basic ? card.sides.filter(side => side.length === 1 && ["red", "blue"].includes(side[0])) : card.sides), + JSON.stringify(basic ? c.sides.filter(side => side.length === 1 && ["red", "blue", "lift"].includes(side[0])) : c.sides) === JSON.stringify(basic ? card.sides.filter(side => side.length === 1 && ["red", "blue", "lift"].includes(side[0])) : card.sides), ); if (same) same.count++; else grouped.push({ ...card, count: 1 }); @@ -579,7 +588,7 @@ export function mountConsole(root, host = null) { ) .map( (c) => - `
${c.count > 1 ? `×${c.count}` : ""}${c.sides.map((side, index) => basic && !(side.length === 1 && ["red", "blue"].includes(side[0])) ? "" : ``).join("")}
`, + `
${c.count > 1 ? `×${c.count}` : ""}${c.sides.map((side, index) => basic && !(side.length === 1 && ["red", "blue", "lift"].includes(side[0])) ? "" : ``).join("")}
`, ) .join("") : ""; diff --git a/preview/icons.js b/preview/icons.js index fca06df..972aecf 100644 --- a/preview/icons.js +++ b/preview/icons.js @@ -35,6 +35,7 @@ const paths = { step: "m5 4 11 8L5 20V4Zm14 0v16", forward: "m2 5 9 7-9 7V5Zm10 0 9 7-9 7V5Z", restart: "M4 10a8 8 0 1 1 1 8M4 3v7h7", + destination: "M5 21V3m0 0h14l-3 4 3 4H5", check: "m4 12 5 5L20 6", close: "m5 5 14 14M5 19 19 5", cards: "M7 7h13v15H7zM4 18H2V2h13v2", diff --git a/preview/style.css b/preview/style.css index 770d983..52d7e9e 100644 --- a/preview/style.css +++ b/preview/style.css @@ -2264,7 +2264,7 @@ input:not([type="checkbox"]):not([type="range"]) { .training-ship .deck-upper .station { min-height: 88px; } -.training-ship .deck-upper .occupants { +.training-ship .occupants { align-items: center; min-height: 50px; padding: 8px 0; @@ -2277,7 +2277,7 @@ input:not([type="checkbox"]):not([type="range"]) { min-height: 88px; } .training-ship .deck-lower .occupants { - display: none; + display: flex; } .training-ship .crew-pawn > svg.equipment-art { width: 36px; @@ -2358,9 +2358,8 @@ input:not([type="checkbox"]):not([type="range"]) { .native-tutorial.learning-basics #program { display: flex; gap: 12px; border-left: 3px solid #e6b66b; padding: 12px; background: #101e28; } .native-tutorial.learning-basics #program .slot { flex: 0 0 72px; min-height: 90px; } .native-tutorial.learning-basics #program .slot.current { border-color: #74e8bd; box-shadow: 0 0 0 2px #74e8bd55; } -.native-tutorial.learning-basics #hand { grid-template-columns: repeat(2, 80px); } +.native-tutorial.learning-basics #hand { grid-template-columns: repeat(3, 80px); } .native-tutorial.learning-basics #hand .card { min-height: 68px; } -.native-tutorial.learning-basics #hand .copies, .native-tutorial.learning-basics #program-crew, .native-tutorial.learning-basics .crew-tabs, .native-tutorial.learning-basics #player-help, @@ -2393,3 +2392,19 @@ input:not([type="checkbox"]):not([type="range"]) { .training-ship .deck-upper .station, .training-ship .deck-lower .station { min-height: 104px; } + +.native-tutorial.learning-basics .training-ship .deck-lower { opacity: 1; } +.training-ship .station.tutorial-destination { + border: 2px dashed #e8c984; + background: #e8c98418; +} +.destination-marker { position: absolute; right: 10px; bottom: 10px; color: #e8c984; } +.training-ship .station.destination-reached { border-style: solid; border-color: #74e8bd; background: #74e8bd18; } +.destination-reached .destination-marker { color: #74e8bd; } +.native-tutorial.learning-basics #hand .card > button { + display: flex; + align-items: center; + justify-content: center; + min-height: 68px; + width: 100%; +} diff --git a/src/tutorial-controller.js b/src/tutorial-controller.js index 795e804..9eac6e1 100644 --- a/src/tutorial-controller.js +++ b/src/tutorial-controller.js @@ -13,7 +13,7 @@ export function createLessonTutorial(id, { locale = "en", storage, onProgress } if (!lesson) throw Error("Unknown lesson"); const t = (fr, en) => locale === "fr" ? fr : en; return createTutorial({ - game: "space-alert", id, version: 2, storage, onProgress, + game: "space-alert", id, version: lesson.basics ? 3 : 2, storage, onProgress, initialState: () => createLesson(id, 1000), move(state, move) { if (move.type === "practice-phase") { @@ -39,12 +39,12 @@ export function createLessonTutorial(id, { locale = "en", storage, onProgress } { id: "discover", title: lesson.title[locale === "fr" ? 0 : 1], text: lesson.basics ? t("Préparez vos actions, puis regardez-les s’exécuter. Commençons sans menace, avec un seul androïde.", "Plan your actions, then watch them execute. Start without threats, with one android.") : lesson.instructions.map(p => p[locale === "fr" ? 0 : 1]).join("\n\n") }, { id: "plan", title: t("Préparer le programme", "Plan the program"), - text: lesson.basics ? t("Placez deux flèches dans le programme. Le vaisseau attend. La troisième case reste vide : attendre.", "Place two arrows in the program. The ship waits. The third slot stays empty: wait.") : t("Programmez les cartes sur le vaisseau, puis terminez la programmation. Le chrono est facultatif ici.", "Program cards on the ship, then finish planning. The clock is optional here."), + text: lesson.basics ? t("Rejoignez la salle marquée en deux actions. La troisième case reste vide : attendre.", "Reach the marked room in two actions. Leave the third slot empty: wait.") : t("Programmez les cartes sur le vaisseau, puis terminez la programmation. Le chrono est facultatif ici.", "Program cards on the ship, then finish planning. The clock is optional here."), complete: state => state.stage === "resolution" }, { id: "execute", title: t("Exécuter les tours", "Run the turns"), text: t("Programme verrouillé. Avancez la résolution avec ▶. Les équipiers agissent ensemble, puis les menaces.", "Program locked. Advance resolution with ▶. Crew act together, then threats."), - complete: state => lesson.basics ? completedTurns(state) >= 3 : !!state.game.resolution?.outcome }, + complete: state => lesson.basics ? completedTurns(state) >= 3 && state.game.resolution.ship.crew[0].station === state.tutorial.targetStation : !!state.game.resolution?.outcome }, ], - completion: { title: t("Exercice terminé", "Exercise complete"), text: lesson.basics ? t("Le chrono sert à préparer. Les tours exécutent ensuite votre programme. Une case vide signifie attendre.", "The clock is for planning. Turns then execute your program. An empty slot means wait.") : t("Rejouez pour comparer un autre programme, ou passez à la suite.", "Replay to compare another program, or move on.") }, + completion: { title: t("Exercice terminé", "Exercise complete"), text: lesson.basics ? t("Destination atteinte ! Votre programme vous y a conduit.", "Destination reached! Your program took you there.") : t("Rejouez pour comparer un autre programme, ou passez à la suite.", "Replay to compare another program, or move on.") }, }); } diff --git a/src/tutorials.js b/src/tutorials.js index 330fc07..fcd2da6 100644 --- a/src/tutorials.js +++ b/src/tutorials.js @@ -197,6 +197,7 @@ export function createLesson(id, now) { title: l.title, instructions: l.instructions, basics: !!l.basics, + targetStation: l.basics ? "blue-lower" : undefined, clockRunning: false, }; s.game.tracks = Object.fromEntries( @@ -219,5 +220,15 @@ export function createLesson(id, now) { s.game.programs[1][turn - 1] = { cards: [{ id, side }] }; s.game.slotVersions[1][turn - 1]++; } + if (l.basics) { + // A small physical hand makes spending and reusing actions visible. + const remaining = { red: 2, blue: 2, lift: 2 }; + s.game.hands[0] = s.game.hands[0].filter(id => { + const action = s.game.cards[id].sides.find(side => side.length === 1 && remaining[side[0]] > 0)?.[0]; + if (!action) return false; + remaining[action]--; + return true; + }); + } return s; } diff --git a/test/tutorial-controller.test.js b/test/tutorial-controller.test.js index 1c3056e..9172606 100644 --- a/test/tutorial-controller.test.js +++ b/test/tutorial-controller.test.js @@ -53,3 +53,26 @@ test("practice clock advances planning only; resolution remains untimed", async assert.equal(completedTurns(t.snapshot.state), 0); t.destroy(); }); + +for (const route of [["blue", "lift"], ["lift", "blue"], ["blue", "red"], ["red", "lift"]]) { + test(`navigation lesson checks the resolved destination: ${route.join(", ")}`, async () => { + const t = await createLessonTutorial("basics"); + await t.continue(); + await place(t, 1, route[0]); + await place(t, 2, route[1]); + assert.equal(t.snapshot.completed, false); + await t.play({ type: "practice-phase" }); + await t.play({ type: "practice-phase" }); + for (let i = 0; i < 30 && completedTurns(t.snapshot.state) < 3; i++) + assert.equal(await t.play({ type: "resolve" }), true, t.snapshot.error); + const succeeds = route.includes("blue") && route.includes("lift"); + assert.equal(t.snapshot.completed, succeeds); + assert.equal(t.snapshot.state.game.resolution.ship.crew[0].station === "blue-lower", succeeds); + if (!succeeds) { + await t.previousStep(); + assert.equal(t.snapshot.state.stage, "programming"); + assert.equal(t.snapshot.step, 1); + } + t.destroy(); + }); +}