Preserve tutorial completion jump and bound displayed turn progress
This commit is contained in:
parent
fa6efc71fc
commit
14b67bd98c
6 changed files with 141 additions and 17 deletions
|
|
@ -119,11 +119,12 @@ export async function mountLesson(
|
|||
)
|
||||
await play({ type: "practice-tick", ms });
|
||||
}
|
||||
let displayedFrames = [];
|
||||
let displayedFrames = [], displayedLastTurn = 12;
|
||||
const ui = mountConsole(target, {
|
||||
onDisplayedResolutionFrames(frames) {
|
||||
displayedLastTurn = tutorial.snapshot.state.game.resolution?.lastTurn ?? 12;
|
||||
displayedFrames = frames;
|
||||
updateTutorialMissionProgress(guide, frames, locale);
|
||||
updateTutorialMissionProgress(guide, frames, locale, displayedLastTurn);
|
||||
},
|
||||
tutorial: true,
|
||||
missions: [],
|
||||
|
|
@ -217,7 +218,7 @@ export async function mountLesson(
|
|||
<h1>${escape(s.title)}</h1>${tutorialMissionHeader(chapter, s.step, locale)}<p class="native-guide-text">${tutorialTextHtml(missed ? t("tutorial.destination_missed_go_back_and_plan_another_route") : s.text, locale)}</p>${chapter === "first-shot" && s.step < 2 ? `<p class="lesson-shield-note">${pictogram("shield")}<span>${t("lesson.first-shot.shield")}</span></p>` : ""}
|
||||
<div class="native-guide-controls">${transport("restart", "rewind", t("tutorial.restart_exercise"), s.busy)}${transport("previous", "left", t("tutorial.previous_step"), s.step === 0 || s.busy)}${transport("replay", "restart", t("tutorial.replay_step"), s.busy || s.step === 0)}${s.canContinue ? `<button data-guide="continue" class="primary icon-button" title="${t("tutorial.start")}" aria-label="${t("tutorial.start")}">${pictogram("right")}</button>` : ""}${s.completed && (nextChapter || (standalone && LESSONS[index + 1])) ? `<button data-guide="next" class="primary icon-label"><span>${t("tutorial.next_exercise")}</span>${pictogram("right")}</button>` : ""}</div>
|
||||
${s.error ? `<p role="alert">${escape(s.error)}</p>` : ""}`;
|
||||
updateTutorialMissionProgress(guide, displayedFrames, locale);
|
||||
updateTutorialMissionProgress(guide, displayedFrames, locale, displayedLastTurn);
|
||||
}
|
||||
const unsubscribe = tutorial.subscribe((s) => {
|
||||
if (disposed) return;
|
||||
|
|
@ -239,7 +240,11 @@ export async function mountLesson(
|
|||
previousStage = s.state.stage;
|
||||
if (!canPlay(s)) playing = false;
|
||||
if (s.step !== lastStep) {
|
||||
ui.resetTutorial();
|
||||
// Completing the forward run is guide-only: resetting here discards the
|
||||
// penultimate frame (or cancels the final frame's pending jump). Rewinds,
|
||||
// restarts and actual chapter-step changes still establish a silent board.
|
||||
if (!(s.completed && lastStep >= 0 && s.step > lastStep))
|
||||
ui.resetTutorial();
|
||||
|
||||
if (s.completed && lastStep >= 0 && s.step > lastStep &&
|
||||
!s.state.game.resolution?.outcome?.survived)
|
||||
|
|
|
|||
|
|
@ -181,7 +181,7 @@ export function createResolutionEffects(root, cue) {
|
|||
const p = { x: bounds.left - base.left + bounds.width / 2,
|
||||
y: bounds.top - base.top + bounds.height / 2, width: bounds.width, height: bounds.height };
|
||||
const jumpSound = kind => sound(kind, position);
|
||||
const duration = reduced.matches ? 900 : 2800;
|
||||
const duration = reduced.matches ? 1500 : 2800;
|
||||
const departure = reduced.matches ? 0 : 1100;
|
||||
const arrival = reduced.matches ? 0 : 1500;
|
||||
if (!reduced.matches) {
|
||||
|
|
@ -217,14 +217,14 @@ export function createResolutionEffects(root, cue) {
|
|||
later(() => star.remove(), 560);
|
||||
}
|
||||
}, departure);
|
||||
} else {
|
||||
animate(vessel, [{ filter: "brightness(1.15)" }, { filter: "brightness(1)" }], 500);
|
||||
}
|
||||
later(() => {
|
||||
jumpSound("victory");
|
||||
const seal = node("fx-jump-success", p, "#76e5c6", stage);
|
||||
seal.innerHTML = pictogram("check");
|
||||
animateTransient(seal, [
|
||||
// Reduced motion gets a steady check, not a departing/fading ship.
|
||||
if (reduced.matches) seal.style.transform = "translate(-50%,-50%)";
|
||||
else animateTransient(seal, [
|
||||
{ transform: `translate(-50%,-50%) scale(${reduced.matches ? 1 : .85})`, opacity: 0 },
|
||||
{ transform: "translate(-50%,-50%) scale(1)", opacity: 1, offset: .2 },
|
||||
{ transform: "translate(-50%,-50%) scale(1)", opacity: 1, offset: .7 },
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ export function tutorialMissionHeader(chapter, step, locale) {
|
|||
const overview = ["basics", "planning-phases"].includes(chapter)
|
||||
? missionOverview(t)
|
||||
: "";
|
||||
const scope = ["basics", "first-shot", "energy"].includes(chapter)
|
||||
? `<small class="lesson-scope">${t("timing.exercise", { turns: chapter === "energy" ? 4 : 3 })}</small>`
|
||||
const scope = ["basics", "first-shot", "energy", "planning-phases"].includes(chapter)
|
||||
? `<small class="lesson-scope">${t("timing.exercise", { turns: chapter === "planning-phases" ? 7 : chapter === "energy" ? 4 : 3 })}</small>`
|
||||
: "";
|
||||
return overview + scope;
|
||||
}
|
||||
|
|
@ -41,14 +41,14 @@ function missionOverview(t) {
|
|||
// Frames describe the *next* resolution operation. Only a captured `appear`
|
||||
// frame closes a whole turn (crew actions alone do not finish threat movement).
|
||||
// Use the displayed prefix, never the live cursor, clock, or planned cards.
|
||||
export function missionTurnProgress(frames = []) {
|
||||
const completed = new Set(frames.filter((frame) => frame.step === "appear" && frame.turn > 0).map((frame) => frame.turn));
|
||||
export function missionTurnProgress(frames = [], lastTurn = 12) {
|
||||
const completed = new Set(frames.filter((frame) => frame.step === "appear" && frame.turn > 0 && frame.turn <= lastTurn).map((frame) => frame.turn));
|
||||
const displayed = frames.at(-1);
|
||||
return { completed, current: displayed && !completed.has(displayed.turn) ? displayed.turn : 0 };
|
||||
return { completed, current: displayed && displayed.turn <= lastTurn && !completed.has(displayed.turn) ? displayed.turn : 0 };
|
||||
}
|
||||
|
||||
export function updateTutorialMissionProgress(root, frames, locale) {
|
||||
const { completed, current } = missionTurnProgress(frames);
|
||||
export function updateTutorialMissionProgress(root, frames, locale, lastTurn = 12) {
|
||||
const { completed, current } = missionTurnProgress(frames, lastTurn);
|
||||
for (const cell of root.querySelectorAll("[data-mission-turn]")) {
|
||||
const turn = Number(cell.dataset.missionTurn);
|
||||
const done = completed.has(turn);
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ function fixture({ reduced = false, animate = true } = {}) {
|
|||
classList: { add() {} }, setAttribute() {}, removeAttribute() {},
|
||||
getClientRects: () => [1],
|
||||
getBoundingClientRect() { return { left: this.x, top: 0, width: 20, height: 20 }; },
|
||||
append(child) { child.parent = this; this.children.push(child); },
|
||||
append(child) { child.parent = this; child.parentElement = this; this.children.push(child); },
|
||||
remove() { if (this.parent) this.parent.children = this.parent.children.filter(c => c !== this); this.removed = true; },
|
||||
replaceChildren() { for (const child of [...this.children]) child.remove(); },
|
||||
querySelector: () => null,
|
||||
|
|
@ -40,6 +40,7 @@ function fixture({ reduced = false, animate = true } = {}) {
|
|||
return el;
|
||||
}
|
||||
const layout = element(), ship = element(), pawn = element(100), room = element(200);
|
||||
layout.append(ship);
|
||||
pawn.dataset.crew = "0";
|
||||
const doc = { defaultView: win, hidden: false, createElement: () => element(),
|
||||
addEventListener: (name, fn) => listeners.set(name, fn), removeEventListener: name => listeners.delete(name) };
|
||||
|
|
@ -53,7 +54,7 @@ function fixture({ reduced = false, animate = true } = {}) {
|
|||
effects.afterRender(resolution, 0);
|
||||
function render() { effects.beforeRender(); pawn.x = 300; effects.afterRender(resolution, 1); }
|
||||
function frame() { const callbacks = [...raf.values()]; raf.clear(); callbacks.forEach(fn => fn()); }
|
||||
return { effects, resolution, render, frame, pawn, ship, layer: layout.children[0], animations, raf, timers, listeners, win, doc };
|
||||
return { effects, resolution, render, frame, pawn, ship, layer: layout.children[1], animations, raf, timers, listeners, win, doc };
|
||||
}
|
||||
|
||||
test("moving pawn is replaced before the first paint, then atomically handed off at finish", async () => {
|
||||
|
|
@ -145,3 +146,27 @@ test("shared transient bursts and damage labels are removed before animation can
|
|||
assert.notEqual(flash.removedAtCancel, true, "persistent board elements are not removed");
|
||||
f.effects.destroy();
|
||||
});
|
||||
|
||||
|
||||
for (const reduced of [false, true]) {
|
||||
test(`successful final transition survives guide-only updates and plays once (reduced=${reduced})`, () => {
|
||||
const f = fixture({ reduced });
|
||||
f.resolution.frames[0].step = "computer";
|
||||
f.resolution.frames[1] = { ...f.resolution.frames[0], step: "appear" };
|
||||
f.resolution.log = [];
|
||||
f.resolution.outcome = { survived: true };
|
||||
f.render();
|
||||
// A completion notification must not reset or redraw this same board.
|
||||
f.effects.afterRender(f.resolution, 1);
|
||||
f.frame(); f.frame();
|
||||
assert.equal(f.ship.parentElement.children.filter(el => el.className === "ship-jump-effects").length, 1);
|
||||
assert.equal(f.animations.filter(a => a.element === f.ship).length, reduced ? 0 : 1);
|
||||
f.effects.afterRender(f.resolution, 1);
|
||||
assert.equal(f.raf.size, 0, "duplicate final snapshot cannot schedule another jump");
|
||||
f.effects.reset();
|
||||
f.effects.afterRender(f.resolution, 1);
|
||||
assert.equal(f.raf.size, 0, "opening the result cannot start a jump");
|
||||
assert.equal(f.ship.parentElement.children.filter(el => el.className === "ship-jump-effects").length, 0);
|
||||
f.effects.destroy();
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,3 +95,15 @@ test("progress updates accessible labels and clears old current/completed styles
|
|||
assert.equal(group.classList.contains("progressed"), false);
|
||||
}
|
||||
});
|
||||
|
||||
test("final movement sentinel is never a completed action turn (7-turn lesson or 12-turn mission)", async () => {
|
||||
const { beginResolution, resolveAll } = await import("../src/game/resolution.js");
|
||||
for (const turns of [7, 12]) {
|
||||
const r = resolveAll(beginResolution({ crewSize: 1, seed: "sentinel", programs: [[]], threats: [], tracks: {}, turns }));
|
||||
assert.equal(r.frames.at(-1).turn, turns + 1);
|
||||
assert.deepEqual(missionTurnProgress(r.frames, r.lastTurn), { completed: new Set(Array.from({ length: turns }, (_, i) => i + 1)), current: 0 });
|
||||
assert.equal(missionTurnProgress(r.frames.slice(0, -1), r.lastTurn).current, 0);
|
||||
}
|
||||
await loadLocale("en");
|
||||
assert.ok(tutorialMissionHeader("planning-phases", 3, "en").includes(translate("en", "timing.exercise", { turns: 7 })));
|
||||
});
|
||||
|
|
|
|||
82
test/tutorial-jump.browser.mjs
Normal file
82
test/tutorial-jump.browser.mjs
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
// Optional: PLAYWRIGHT_MODULE=/path/to/playwright/index.mjs node test/tutorial-jump.browser.mjs
|
||||
// Real tutorial controller and playback, isolated server with no persistence.
|
||||
import assert from 'node:assert/strict';
|
||||
import { createPreviewServer } from '../preview/server.js';
|
||||
const { chromium } = await import(process.env.PLAYWRIGHT_MODULE || 'playwright');
|
||||
const server = createPreviewServer();
|
||||
await new Promise(resolve => server.listen(0, '127.0.0.1', resolve));
|
||||
let browser;
|
||||
try {
|
||||
browser = await chromium.launch({ headless: true });
|
||||
for (const reducedMotion of ['no-preference', 'reduce']) {
|
||||
const page = await browser.newPage({ viewport: { width: 1280, height: 900 }, reducedMotion });
|
||||
const errors = [];
|
||||
page.on('pageerror', error => errors.push(error.message));
|
||||
await page.addInitScript(() => {
|
||||
window.jumpQA = { starts: 0, finishes: 0, cancelled: 0, seals: 0 };
|
||||
const animate = Element.prototype.animate;
|
||||
Element.prototype.animate = function(frames, options) {
|
||||
const animation = animate.call(this, frames, options);
|
||||
if (this.matches('.ship-vessel') && options.duration === 2800) {
|
||||
jumpQA.starts++;
|
||||
animation.finished.then(() => jumpQA.finishes++, () => jumpQA.cancelled++);
|
||||
}
|
||||
return animation;
|
||||
};
|
||||
new MutationObserver(records => {
|
||||
for (const record of records) for (const node of record.addedNodes)
|
||||
if (node.nodeType === 1 && node.matches('.fx-jump-success')) jumpQA.seals++;
|
||||
}).observe(document, { childList: true, subtree: true });
|
||||
});
|
||||
await page.goto(`http://127.0.0.1:${server.address().port}/learn?chapter=planning-phases&locale=en`);
|
||||
await page.click('[data-guide="continue"]');
|
||||
await page.click('[data-guide="phase-clock"]');
|
||||
await page.waitForSelector('#program [data-turn="1"]:not(:disabled)');
|
||||
await page.keyboard.press('ArrowRight');
|
||||
await page.waitForTimeout(300);
|
||||
await page.click('[data-guide="phase-deadline"]');
|
||||
await page.waitForSelector('[data-guide="run"]');
|
||||
await page.keyboard.press('ArrowDown');
|
||||
await page.waitForTimeout(300);
|
||||
await page.click('[data-guide="run"]');
|
||||
await page.waitForSelector('.fx-jump-success', { timeout: 90000 });
|
||||
assert.match(await page.locator('.native-guide').innerText(), /Exercise complete/);
|
||||
assert.equal(await page.locator('[data-mission-turn].completed').count(), 7);
|
||||
assert.equal(await page.locator('[data-mission-turn="8"].completed, [data-mission-turn="8"].current').count(), 0);
|
||||
if (reducedMotion === 'reduce') {
|
||||
assert.equal(await page.locator('.ship-vessel').evaluate(el => el.getAnimations().length), 0);
|
||||
assert.equal(await page.locator('.fx-jump-success').evaluate(el => el.getAnimations().length), 0);
|
||||
}
|
||||
await page.waitForTimeout(3200);
|
||||
const expected = count => ({ starts: reducedMotion === 'reduce' ? 0 : count, finishes: reducedMotion === 'reduce' ? 0 : count, cancelled: 0, seals: count });
|
||||
assert.deepEqual(await page.evaluate(() => jumpQA), expected(1));
|
||||
// Scrubbing to a result is silent; then play the actual final transition.
|
||||
const end = Number(await page.locator('#replay-slider').getAttribute('max'));
|
||||
const scrub = value => page.locator('#replay-slider').evaluate((el, value) => {
|
||||
el.value = String(value);
|
||||
el.dispatchEvent(new Event('input', { bubbles: true }));
|
||||
el.dispatchEvent(new Event('change', { bubbles: true }));
|
||||
}, value);
|
||||
await scrub(end);
|
||||
await page.waitForTimeout(300);
|
||||
assert.deepEqual(await page.evaluate(() => jumpQA), expected(1));
|
||||
await scrub(end - 1);
|
||||
await page.click('#replay-play');
|
||||
await page.waitForSelector('.fx-jump-success');
|
||||
await page.waitForTimeout(3500);
|
||||
assert.deepEqual(await page.evaluate(() => jumpQA), expected(2));
|
||||
await page.click('#live');
|
||||
await page.waitForTimeout(500);
|
||||
assert.deepEqual(await page.evaluate(() => jumpQA), expected(2));
|
||||
await page.click('[data-guide="restart"]');
|
||||
assert.equal(await page.locator('.ship-jump-effects').count(), 0);
|
||||
assert.equal(await page.locator('[data-mission-turn].completed').count(), 0);
|
||||
assert.deepEqual(errors, []);
|
||||
console.log(`${reducedMotion}: tutorial 2 completes, jump finishes once, replay ends once, scrub/live/reset silent`);
|
||||
await page.close();
|
||||
}
|
||||
} finally {
|
||||
await browser?.close();
|
||||
server.closeAllConnections();
|
||||
await new Promise(resolve => server.close(resolve));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue