Improve Space Alert tutorials, ship UI and table career continuity
This commit is contained in:
parent
c430c032e9
commit
28a302e911
24 changed files with 1353 additions and 325 deletions
24
README.md
24
README.md
|
|
@ -13,10 +13,12 @@ npm test
|
|||
npm run dev
|
||||
```
|
||||
|
||||
Open <http://127.0.0.1:5250>. Start with **Flight school / École de vol**: seven untimed exercises use the real engine, with editable programs and a teammate already maintaining the computer. The examples cover firing, energy, malfunctions, battlebots/interceptors, double actions, phasing and specializations.
|
||||
Open <http://127.0.0.1:5250>. 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.
|
||||
|
||||
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.
|
||||
|
||||
Training starts with its clock paused. **Start practice clock** and **Pause clock** control time only in training; normal missions retain their shared, continuous clock. You can also advance lesson phases explicitly.
|
||||
|
||||
The local seat selector, “Ready all” and “Next announcement” buttons are development tools. This host has **no authentication** and deliberately listens only on `127.0.0.1`. It is not an online multiplayer deployment. Use external voice for cooperation; browser speech synthesis is optional and communications-blackout silence relies on the players.
|
||||
|
||||
## Implemented
|
||||
|
|
@ -48,7 +50,7 @@ No publisher artwork, scanned cards, rulebook files or official voice recordings
|
|||
|
||||
## Build for BGS
|
||||
|
||||
The BGS integration requires the published `@boardgamers/protocol` **0.8.x** package:
|
||||
The BGS integration requires the published `@boardgamers/protocol` **0.10.0** package:
|
||||
|
||||
```sh
|
||||
npm install
|
||||
|
|
@ -67,3 +69,21 @@ npm run build
|
|||
```
|
||||
|
||||
Upload the generated engine tarball and `dist/viewer.js` through BGS admin. Use the metadata in [`bgs/gameinfo.json`](bgs/gameinfo.json): engine entry `bgs/engine.js`, viewer global `SpaceAlert`, game-managed time control, and no Elo. Keep the version private during playtesting. BGS assigns uploaded asset URLs; the example intentionally has no viewer URL. See [the integration notes](docs/realtime-host.md) for clock, table and career behavior.
|
||||
|
||||
|
||||
### Playable tutorials
|
||||
|
||||
Open `/learn?chapter=basics&locale=fr` on the local preview server. Lessons use
|
||||
`@boardgamers/protocol/tutorial` for validated action history, checkpoints,
|
||||
previous/replay/restart controls, and browser-local progress. The BGS viewer
|
||||
registers the same `mountLesson` through `launchTutorial`; chapter metadata still
|
||||
needs configuring when the viewer is published. Nothing has been published by
|
||||
this local change.
|
||||
|
||||
Tutorials mount the ordinary console, ship, card controls and program slots.
|
||||
The first chapter hides unrelated systems, card sides and crew members. Both
|
||||
ship decks retain the same room height. Resolution is untimed and uses the
|
||||
ordinary resolution controls; the planning clock never drives individual turns.
|
||||
The speaker toggle enables short synthesized action cues (off initially).
|
||||
|
||||
[BGS playable tutorial API](https://codeberg.org/boardgamers/boardgamers/src/branch/main/apps/docs/docs/guide/tutorials.md)
|
||||
|
|
|
|||
|
|
@ -118,22 +118,26 @@ export function init(players, expansions, options, seed, creator, context) {
|
|||
if (progress && progress.version !== 1)
|
||||
throw Error("Unsupported Space Alert career version");
|
||||
const previous = progress?.data?.explorers ?? {};
|
||||
const explorers = Object.fromEntries(
|
||||
playerIds
|
||||
.filter((id) => options.careers || previous[id])
|
||||
.map((id, i) => [
|
||||
id,
|
||||
previous[id]
|
||||
? structuredClone(previous[id])
|
||||
: createExplorer(id, `Explorer ${i + 1}`),
|
||||
]),
|
||||
);
|
||||
// A table career survives games its owner sits out.
|
||||
const explorers = {
|
||||
...structuredClone(previous),
|
||||
...Object.fromEntries(
|
||||
playerIds
|
||||
.filter((id) => options.careers || previous[id])
|
||||
.map((id, i) => [
|
||||
id,
|
||||
previous[id]
|
||||
? structuredClone(previous[id])
|
||||
: createExplorer(id, `Explorer ${i + 1}`),
|
||||
]),
|
||||
),
|
||||
};
|
||||
if (Object.values(explorers).some((e) => e.activeRun))
|
||||
throw Error("Previous explorers have not returned from their mission");
|
||||
if (
|
||||
options.careers &&
|
||||
campaignLimit &&
|
||||
Object.values(explorers).some((e) => e.level < 2)
|
||||
playerIds.some((id) => explorers[id].level < 2)
|
||||
)
|
||||
throw Error("Career explorers need level 2 before a campaign");
|
||||
const state = createSession(
|
||||
|
|
@ -379,7 +383,9 @@ export function stripSecret(state, seat, context) {
|
|||
const id = state.bgs.playerIds[seat];
|
||||
view.careerIds = state.bgs.playerIds;
|
||||
view.explorers = (
|
||||
state.bgs.settings.careers ? Object.values(state.bgs.explorers) : []
|
||||
state.bgs.settings.careers
|
||||
? state.bgs.playerIds.map((id) => state.bgs.explorers[id])
|
||||
: []
|
||||
).map((e) => ({
|
||||
...e,
|
||||
activeRun: !!e.activeRun,
|
||||
|
|
|
|||
128
bgs/tutorial.js
Normal file
128
bgs/tutorial.js
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
import { createLessonTutorial, completedTurns } from "../src/tutorial-controller.js";
|
||||
import { LESSONS } from "../src/tutorials.js";
|
||||
import { snapshot } from "../src/view.js";
|
||||
import { mountConsole } from "../preview/app.js";
|
||||
import { pictogram } from "../preview/icons.js";
|
||||
import { createSoundDesign } from "../preview/sound.js";
|
||||
import html from "../preview/index.html";
|
||||
import css from "../preview/style.css";
|
||||
|
||||
export async function mountLesson(target, { chapter = "basics", locale = "en", onProgress, nextChapter, standalone = false } = {}) {
|
||||
const t = (fr, en) => locale === "fr" ? fr : en;
|
||||
const index = LESSONS.findIndex(l => l.id === chapter);
|
||||
if (index < 0) throw Error("Unknown tutorial chapter");
|
||||
const sound = createSoundDesign();
|
||||
let soundOn = false, disposed = false, lastStep = -1, lastTurn = 0, lastTick = performance.now();
|
||||
let storage;
|
||||
try { storage = window.localStorage; } catch {}
|
||||
const tutorial = await createLessonTutorial(chapter, { locale, storage, onProgress });
|
||||
target.innerHTML = html.split("<body>")[1].split('<script type="module"')[0].split("</body>")[0];
|
||||
const style = document.createElement("style");
|
||||
style.textContent = css;
|
||||
target.prepend(style);
|
||||
target.classList.add("native-tutorial");
|
||||
const guide = document.createElement("section");
|
||||
guide.className = "native-guide";
|
||||
target.querySelector("#basics-guide").before(guide);
|
||||
if (chapter === "basics") {
|
||||
target.querySelector("#planning").append(target.querySelector("#basics-guide"));
|
||||
target.querySelector("#ship").classList.add("training-ship");
|
||||
}
|
||||
const goChapter = id => {
|
||||
if (standalone) location.assign(`/learn?chapter=${encodeURIComponent(id)}&locale=${encodeURIComponent(locale)}`);
|
||||
};
|
||||
const play = async move => {
|
||||
if (!await tutorial.play(move)) throw Error(tutorial.snapshot.error || t("Action indisponible", "Action unavailable"));
|
||||
};
|
||||
async function tick() {
|
||||
const now = performance.now();
|
||||
const ms = Math.floor(now - lastTick);
|
||||
lastTick = now;
|
||||
if (tutorial.snapshot.state.tutorial.clockRunning && tutorial.snapshot.state.stage === "programming")
|
||||
await play({ type: "practice-tick", ms });
|
||||
}
|
||||
const ui = mountConsole(target, {
|
||||
tutorial: true, missions: [],
|
||||
command: play,
|
||||
openLesson: goChapter,
|
||||
async tutorialPost(path, body) {
|
||||
if (path === "/api/lesson-clock") {
|
||||
await tick();
|
||||
await play({ type: "practice-clock", running: body.running });
|
||||
lastTick = performance.now();
|
||||
} else if (path === "/api/lesson-next") await play({ type: "practice-phase" });
|
||||
else throw Error("Unsupported tutorial action");
|
||||
},
|
||||
cue: (kind, pan) => sound.cue(kind, pan),
|
||||
});
|
||||
ui.setPreferences({ locale });
|
||||
ui.setPlayer(0);
|
||||
const escape = value => String(value).replace(/[&<>"']/g, c => ({ '&':'&', '<':'<', '>':'>', '"':'"', "'":''' })[c]);
|
||||
const label = [t("Découvrir", "Discover"), t("Préparer", "Plan"), t("Exécuter", "Execute")];
|
||||
const transport = (action, icon, title, disabled = false) => `<button data-guide="${action}" class="quiet icon-button" title="${title}" aria-label="${title}" ${disabled ? 'disabled' : ''}>${pictogram(icon)}</button>`;
|
||||
function renderGuide(s) {
|
||||
guide.innerHTML = `<div class="native-guide-top"><span>${escape(LESSONS[index].title[locale === "fr" ? 0 : 1])}</span><div class="native-guide-tools">${standalone ? `<a href="/">${t("Partie locale", "Local game")}</a>` : ''}${transport("sound", soundOn ? "speaker" : "muted", soundOn ? t("Couper les sons", "Mute sounds") : t("Activer les sons", "Enable sounds"))}</div></div>
|
||||
<nav class="basics-stages" aria-label="${t("Étapes", "Steps")}">${label.map((name, i) => `<button data-guide-step="${i}" class="quiet ${Math.min(s.step, 2) === i ? 'active' : ''}" ${i > s.step || s.busy ? 'disabled' : ''} ${s.step === i ? 'aria-current="step"' : ''}><span class="step-number">${i + 1}</span><span>${name}</span></button>`).join('')}</nav>
|
||||
<h1>${escape(s.title)}</h1><p class="native-guide-text">${escape(s.text)}</p>
|
||||
<div class="native-guide-controls">${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 ? `<button data-guide="continue" class="primary icon-button" title="${t("Commencer", "Start")}" aria-label="${t("Commencer", "Start")}">${pictogram("right")}</button>` : ''}${s.completed && (nextChapter || standalone && LESSONS[index + 1]) ? `<button data-guide="next" class="primary icon-label"><span>${t("Exercice suivant", "Next exercise")}</span>${pictogram("right")}</button>` : ''}<small title="${t("Progression enregistrée", "Progress saved")}" aria-label="${t("Progression enregistrée", "Progress saved")}">${s.saved ? "✓" : ""}</small></div>
|
||||
${s.error ? `<p role="alert">${escape(s.error)}</p>` : ''}`;
|
||||
}
|
||||
const unsubscribe = tutorial.subscribe(s => {
|
||||
if (disposed) return;
|
||||
if (s.step !== lastStep) {
|
||||
ui.resetTutorial();
|
||||
|
||||
if (s.completed && lastStep >= 0 && s.step > lastStep) sound.cue("complete");
|
||||
lastStep = s.step;
|
||||
}
|
||||
const turn = completedTurns(s.state);
|
||||
if (turn > lastTurn && lastTurn >= 0 && !s.completed) {
|
||||
const action = s.state.game.programs[0][turn - 1]?.cards?.[0];
|
||||
const actions = action ? s.state.game.cards[action.id]?.sides[action.side] : [];
|
||||
sound.cue(actions?.length ? "turn" : "wait", actions?.includes("red") ? -.5 : actions?.includes("blue") ? .5 : 0);
|
||||
}
|
||||
lastTurn = turn;
|
||||
const view = snapshot(s.state, 0);
|
||||
view.tutorial = { ...s.state.tutorial, nativeStep: s.step };
|
||||
view.explorers = [];
|
||||
view.careerIds = [];
|
||||
target.dataset.tutorialStep = String(s.step);
|
||||
target.dataset.tutorialStage = s.state.stage;
|
||||
ui.render(view);
|
||||
renderGuide(s);
|
||||
});
|
||||
const onClick = async event => {
|
||||
const button = event.target.closest("button");
|
||||
if (!button || tutorial.snapshot.busy) return;
|
||||
const action = button.dataset.guide;
|
||||
if (action === "sound") {
|
||||
soundOn = !soundOn; sound.enable(soundOn); sound.cue("select"); renderGuide(tutorial.snapshot); return;
|
||||
}
|
||||
if (!action && button.dataset.guideStep === undefined) return;
|
||||
ui.resetTutorial();
|
||||
lastTurn = -1;
|
||||
sound.cue("back");
|
||||
if (button.dataset.guideStep !== undefined) {
|
||||
const step = Number(button.dataset.guideStep);
|
||||
while (tutorial.snapshot.step > step) await tutorial.previousStep();
|
||||
} else if (action === "continue") await tutorial.continue();
|
||||
else if (action === "previous") await tutorial.previousStep();
|
||||
else if (action === "replay") await tutorial.restartStep();
|
||||
else if (action === "restart") await tutorial.restart();
|
||||
else if (action === "next") {
|
||||
if (nextChapter) nextChapter.open();
|
||||
else goChapter(LESSONS[index + 1].id);
|
||||
}
|
||||
|
||||
lastTick = performance.now();
|
||||
};
|
||||
guide.addEventListener("click", onClick);
|
||||
const ticker = setInterval(() => {
|
||||
if (!tutorial.snapshot.busy) void tick().catch(() => {});
|
||||
}, 5000);
|
||||
return () => {
|
||||
disposed = true; clearInterval(ticker); unsubscribe(); tutorial.destroy(); ui.destroy(); sound.destroy();
|
||||
guide.removeEventListener("click", onClick);
|
||||
target.classList.remove("native-tutorial");
|
||||
};
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
import { mountLesson } from "./tutorial.js";
|
||||
import { registerViewer } from "@boardgamers/protocol/viewer";
|
||||
import { mountConsole } from "../preview/app.js";
|
||||
import html from "../preview/index.html";
|
||||
|
|
@ -55,12 +56,15 @@ registerViewer("SpaceAlert", (context) => {
|
|||
settings: state.bgs.settings,
|
||||
};
|
||||
view.careerIds = state.bgs.playerIds;
|
||||
view.explorers = Object.values(state.bgs.explorers).map((e) => ({
|
||||
...e,
|
||||
activeRun: !!e.activeRun,
|
||||
eligible: [],
|
||||
editable: false,
|
||||
}));
|
||||
view.explorers = state.bgs.playerIds
|
||||
.map((id) => state.bgs.explorers[id])
|
||||
.filter(Boolean)
|
||||
.map((e) => ({
|
||||
...e,
|
||||
activeRun: !!e.activeRun,
|
||||
eligible: [],
|
||||
editable: false,
|
||||
}));
|
||||
}
|
||||
ui.render(view);
|
||||
if (pending && view.nextSequence > pending.sequence) {
|
||||
|
|
@ -100,4 +104,4 @@ registerViewer("SpaceAlert", (context) => {
|
|||
}
|
||||
},
|
||||
};
|
||||
});
|
||||
}, { tutorial: mountLesson });
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ For the current audit of the complete standard inventory, see [components](compo
|
|||
|
||||
1. **Timing:** readiness, shared start, autonomous deadlines, reconnect and per-player phase locks implemented and tested. Untimed tutorials use explicit host clock advances without changing normal mission timing.
|
||||
2. **Local play:** private physical cards, Android/solo rules, ship resolution, all threat cards, all specialization abilities, scoring, campaigns and local explorer persistence implemented.
|
||||
3. **Teaching/viewer:** seven untimed guided exercises use the actual engine. FR/EN controls and effect descriptions, threat details, replay, native scrolling and journal available. Official names remain English; original visual symbols are placeholders for any later licensed artwork.
|
||||
3. **Teaching/viewer:** eight guided exercises, starting with a focused plan/execute introduction and a pausable practice clock, use the actual engine. FR/EN controls and effect descriptions, threat details, replay, native scrolling and journal available. Official names remain English; original visual symbols are placeholders for any later licensed artwork.
|
||||
4. **Rules validation:** deterministic fixtures cover critical interactions, and every threat terminates and replays from serialized state. This is not exhaustive proof of all combinations; human playtests remain necessary before claiming release readiness.
|
||||
5. **BGS release:** the private-playtest adapter is implemented; see [integration and deployment](realtime-host.md). Public release awaits human playtesting. Careers currently persist within a table, and voice remains external.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# BGS integration
|
||||
|
||||
The adapter is in `bgs/engine.js`; the hosted viewer is `bgs/viewer.js`. It uses BGS protocol 0.8 and the platform's durable engine wakeups. The standalone development server remains useful for rule tests, but is not the online host.
|
||||
The adapter is in `bgs/engine.js`; the hosted viewer is `bgs/viewer.js`. It uses the published BGS protocol 0.10.0 package and the platform's durable engine wakeups. The standalone development server remains useful for rule tests, but is not the online host.
|
||||
|
||||
## Clock and commands
|
||||
|
||||
|
|
@ -20,6 +20,8 @@ BGS **Play again** creates a new game record with fresh randomness, the same res
|
|||
|
||||
BGS carries only the versioned `tableProgress` checkpoint into the next game's `init`; full game states are never copied. The adapter keeps career totals, achievements and the latest mission summary, keyed by account ID. Older summaries stay with their original replays. `migrateTableProgress` rejects unknown schemas. Cancellation clears an unfinished run without awarding experience; disabling careers preserves earned progress.
|
||||
|
||||
Careers survive games their owner sits out, including games with careers disabled. Only the current crew appears in the live career panel.
|
||||
|
||||
Careers are **table-local**, not account-wide profiles. Moving to another table starts a separate career. There is no global campaign directory or cross-table character synchronization. The game version is retained between games; retired versions ask players to create a new table.
|
||||
|
||||
## Results and limitations
|
||||
|
|
|
|||
238
package-lock.json
generated
238
package-lock.json
generated
|
|
@ -1,245 +1,31 @@
|
|||
{
|
||||
"name": "@boardgamers/space-alert",
|
||||
"version": "0.1.4",
|
||||
"version": "0.1.5",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@boardgamers/space-alert",
|
||||
"version": "0.1.4",
|
||||
"version": "0.1.5",
|
||||
"license": "AGPL-3.0-only",
|
||||
"devDependencies": {
|
||||
"@boardgamers/protocol": "0.8.1",
|
||||
"@boardgamers/protocol": "0.10.0",
|
||||
"esbuild": "^0.28.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=24"
|
||||
}
|
||||
},
|
||||
"../boardgamers-mono/node_modules/.pnpm/@types+node@24.11.0/node_modules/@types/node": {
|
||||
"version": "24.11.0",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"undici-types": "~7.16.0"
|
||||
}
|
||||
},
|
||||
"../boardgamers-mono/node_modules/.pnpm/oxfmt@0.61.0_svelte@5.56.8_@typescript-eslint+types@8.56.1_/node_modules/oxfmt": {
|
||||
"version": "0.61.0",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"tinypool": "2.1.0"
|
||||
},
|
||||
"bin": {
|
||||
"oxfmt": "bin/oxfmt"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^20.19.0 || >=22.12.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/Boshen"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@oxfmt/binding-android-arm-eabi": "0.61.0",
|
||||
"@oxfmt/binding-android-arm64": "0.61.0",
|
||||
"@oxfmt/binding-darwin-arm64": "0.61.0",
|
||||
"@oxfmt/binding-darwin-x64": "0.61.0",
|
||||
"@oxfmt/binding-freebsd-x64": "0.61.0",
|
||||
"@oxfmt/binding-linux-arm-gnueabihf": "0.61.0",
|
||||
"@oxfmt/binding-linux-arm-musleabihf": "0.61.0",
|
||||
"@oxfmt/binding-linux-arm64-gnu": "0.61.0",
|
||||
"@oxfmt/binding-linux-arm64-musl": "0.61.0",
|
||||
"@oxfmt/binding-linux-ppc64-gnu": "0.61.0",
|
||||
"@oxfmt/binding-linux-riscv64-gnu": "0.61.0",
|
||||
"@oxfmt/binding-linux-riscv64-musl": "0.61.0",
|
||||
"@oxfmt/binding-linux-s390x-gnu": "0.61.0",
|
||||
"@oxfmt/binding-linux-x64-gnu": "0.61.0",
|
||||
"@oxfmt/binding-linux-x64-musl": "0.61.0",
|
||||
"@oxfmt/binding-openharmony-arm64": "0.61.0",
|
||||
"@oxfmt/binding-win32-arm64-msvc": "0.61.0",
|
||||
"@oxfmt/binding-win32-ia32-msvc": "0.61.0",
|
||||
"@oxfmt/binding-win32-x64-msvc": "0.61.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"svelte": "^5.0.0",
|
||||
"vite-plus": "*"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"svelte": {
|
||||
"optional": true
|
||||
},
|
||||
"vite-plus": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"../boardgamers-mono/node_modules/.pnpm/oxlint-tsgolint@0.16.0/node_modules/oxlint-tsgolint": {
|
||||
"version": "0.16.0",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"tsgolint": "bin/tsgolint.js"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@oxlint-tsgolint/darwin-arm64": "0.16.0",
|
||||
"@oxlint-tsgolint/darwin-x64": "0.16.0",
|
||||
"@oxlint-tsgolint/linux-arm64": "0.16.0",
|
||||
"@oxlint-tsgolint/linux-x64": "0.16.0",
|
||||
"@oxlint-tsgolint/win32-arm64": "0.16.0",
|
||||
"@oxlint-tsgolint/win32-x64": "0.16.0"
|
||||
}
|
||||
},
|
||||
"../boardgamers-mono/node_modules/.pnpm/oxlint@1.51.0_oxlint-tsgolint@0.16.0/node_modules/oxlint": {
|
||||
"version": "1.51.0",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"oxlint": "bin/oxlint"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^20.19.0 || >=22.12.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/Boshen"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@oxlint/binding-android-arm-eabi": "1.51.0",
|
||||
"@oxlint/binding-android-arm64": "1.51.0",
|
||||
"@oxlint/binding-darwin-arm64": "1.51.0",
|
||||
"@oxlint/binding-darwin-x64": "1.51.0",
|
||||
"@oxlint/binding-freebsd-x64": "1.51.0",
|
||||
"@oxlint/binding-linux-arm-gnueabihf": "1.51.0",
|
||||
"@oxlint/binding-linux-arm-musleabihf": "1.51.0",
|
||||
"@oxlint/binding-linux-arm64-gnu": "1.51.0",
|
||||
"@oxlint/binding-linux-arm64-musl": "1.51.0",
|
||||
"@oxlint/binding-linux-ppc64-gnu": "1.51.0",
|
||||
"@oxlint/binding-linux-riscv64-gnu": "1.51.0",
|
||||
"@oxlint/binding-linux-riscv64-musl": "1.51.0",
|
||||
"@oxlint/binding-linux-s390x-gnu": "1.51.0",
|
||||
"@oxlint/binding-linux-x64-gnu": "1.51.0",
|
||||
"@oxlint/binding-linux-x64-musl": "1.51.0",
|
||||
"@oxlint/binding-openharmony-arm64": "1.51.0",
|
||||
"@oxlint/binding-win32-arm64-msvc": "1.51.0",
|
||||
"@oxlint/binding-win32-ia32-msvc": "1.51.0",
|
||||
"@oxlint/binding-win32-x64-msvc": "1.51.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"oxlint-tsgolint": ">=0.15.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"oxlint-tsgolint": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"../boardgamers-mono/node_modules/.pnpm/playwright@1.62.1/node_modules/playwright": {
|
||||
"version": "1.62.1",
|
||||
"dev": true,
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"playwright-core": "1.62.1"
|
||||
},
|
||||
"bin": {
|
||||
"playwright": "cli.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"fsevents": "2.3.2"
|
||||
}
|
||||
},
|
||||
"../boardgamers-mono/node_modules/.pnpm/typescript@7.0.2/node_modules/typescript": {
|
||||
"version": "7.0.2",
|
||||
"dev": true,
|
||||
"license": "Apache-2.0",
|
||||
"bin": {
|
||||
"tsc": "bin/tsc"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16.20.0"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@typescript/typescript-aix-ppc64": "7.0.2",
|
||||
"@typescript/typescript-darwin-arm64": "7.0.2",
|
||||
"@typescript/typescript-darwin-x64": "7.0.2",
|
||||
"@typescript/typescript-freebsd-arm64": "7.0.2",
|
||||
"@typescript/typescript-freebsd-x64": "7.0.2",
|
||||
"@typescript/typescript-linux-arm": "7.0.2",
|
||||
"@typescript/typescript-linux-arm64": "7.0.2",
|
||||
"@typescript/typescript-linux-loong64": "7.0.2",
|
||||
"@typescript/typescript-linux-mips64el": "7.0.2",
|
||||
"@typescript/typescript-linux-ppc64": "7.0.2",
|
||||
"@typescript/typescript-linux-riscv64": "7.0.2",
|
||||
"@typescript/typescript-linux-s390x": "7.0.2",
|
||||
"@typescript/typescript-linux-x64": "7.0.2",
|
||||
"@typescript/typescript-netbsd-arm64": "7.0.2",
|
||||
"@typescript/typescript-netbsd-x64": "7.0.2",
|
||||
"@typescript/typescript-openbsd-arm64": "7.0.2",
|
||||
"@typescript/typescript-openbsd-x64": "7.0.2",
|
||||
"@typescript/typescript-sunos-x64": "7.0.2",
|
||||
"@typescript/typescript-win32-arm64": "7.0.2",
|
||||
"@typescript/typescript-win32-x64": "7.0.2"
|
||||
}
|
||||
},
|
||||
"../boardgamers-mono/node_modules/.pnpm/zod@4.3.6/node_modules/zod": {
|
||||
"version": "4.3.6",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/colinhacks"
|
||||
}
|
||||
},
|
||||
"../boardgamers-mono/packages/protocol": {
|
||||
"name": "@boardgamers/protocol",
|
||||
"version": "0.8.1",
|
||||
"node_modules/@boardgamers/protocol": {
|
||||
"version": "0.10.0",
|
||||
"resolved": "https://registry.npmjs.org/@boardgamers/protocol/-/protocol-0.10.0.tgz",
|
||||
"integrity": "sha512-U+nOK8xeQANvjzwacHirBW+ItDf9AOmHLtkoyTI/XYFCOpL6lPsEgCbmcxnmkXv2a1/lgtVN3WpSERHUqkQkXw==",
|
||||
"dev": true,
|
||||
"license": "AGPL-3.0-only",
|
||||
"dependencies": {
|
||||
"zod": "^4.3.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "catalog:",
|
||||
"oxfmt": "catalog:",
|
||||
"oxlint": "^1.51.0",
|
||||
"oxlint-tsgolint": "^0.16.0",
|
||||
"playwright": "1.62.1",
|
||||
"typescript": "catalog:"
|
||||
}
|
||||
},
|
||||
"../boardgamers-mono/packages/protocol/node_modules/@types/node": {
|
||||
"resolved": "../boardgamers-mono/node_modules/.pnpm/@types+node@24.11.0/node_modules/@types/node",
|
||||
"link": true
|
||||
},
|
||||
"../boardgamers-mono/packages/protocol/node_modules/oxfmt": {
|
||||
"resolved": "../boardgamers-mono/node_modules/.pnpm/oxfmt@0.61.0_svelte@5.56.8_@typescript-eslint+types@8.56.1_/node_modules/oxfmt",
|
||||
"link": true
|
||||
},
|
||||
"../boardgamers-mono/packages/protocol/node_modules/oxlint": {
|
||||
"resolved": "../boardgamers-mono/node_modules/.pnpm/oxlint@1.51.0_oxlint-tsgolint@0.16.0/node_modules/oxlint",
|
||||
"link": true
|
||||
},
|
||||
"../boardgamers-mono/packages/protocol/node_modules/oxlint-tsgolint": {
|
||||
"resolved": "../boardgamers-mono/node_modules/.pnpm/oxlint-tsgolint@0.16.0/node_modules/oxlint-tsgolint",
|
||||
"link": true
|
||||
},
|
||||
"../boardgamers-mono/packages/protocol/node_modules/playwright": {
|
||||
"resolved": "../boardgamers-mono/node_modules/.pnpm/playwright@1.62.1/node_modules/playwright",
|
||||
"link": true
|
||||
},
|
||||
"../boardgamers-mono/packages/protocol/node_modules/typescript": {
|
||||
"resolved": "../boardgamers-mono/node_modules/.pnpm/typescript@7.0.2/node_modules/typescript",
|
||||
"link": true
|
||||
},
|
||||
"../boardgamers-mono/packages/protocol/node_modules/zod": {
|
||||
"resolved": "../boardgamers-mono/node_modules/.pnpm/zod@4.3.6/node_modules/zod",
|
||||
"link": true
|
||||
},
|
||||
"node_modules/@boardgamers/protocol": {
|
||||
"resolved": "../boardgamers-mono/packages/protocol",
|
||||
"link": true
|
||||
},
|
||||
"node_modules/@esbuild/aix-ppc64": {
|
||||
"version": "0.28.2",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.28.2.tgz",
|
||||
|
|
@ -719,6 +505,16 @@
|
|||
"@esbuild/win32-ia32": "0.28.2",
|
||||
"@esbuild/win32-x64": "0.28.2"
|
||||
}
|
||||
},
|
||||
"node_modules/zod": {
|
||||
"version": "4.6.7",
|
||||
"resolved": "https://registry.npmjs.org/zod/-/zod-4.6.7.tgz",
|
||||
"integrity": "sha512-g8W2D2kU6a8untc053fX1uVBKzM7yqAxW/3zwk83+6RyF2+SKOuV+c0wBDhUwzV1PaGapmZH+rmcUzPf+3CGwg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/colinhacks"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@boardgamers/space-alert",
|
||||
"version": "0.1.4",
|
||||
"version": "0.1.5",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"description": "Space Alert and The New Frontier: deterministic game engine and local playtest",
|
||||
|
|
@ -19,7 +19,7 @@
|
|||
"url": "git+https://github.com/boardgamers/space-alert.git"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@boardgamers/protocol": "0.8.1",
|
||||
"@boardgamers/protocol": "0.10.0",
|
||||
"esbuild": "^0.28.2"
|
||||
},
|
||||
"exports": {
|
||||
|
|
|
|||
180
preview/app.js
180
preview/app.js
|
|
@ -1,3 +1,4 @@
|
|||
import { basicsView } from "./basics.js";
|
||||
import { mountNavigation } from "./navigation.js";
|
||||
import { pictogram, shipLocator, specializationIcons } from "./icons.js";
|
||||
import { createTacticalView } from "./tactical.js";
|
||||
|
|
@ -44,8 +45,20 @@ export function mountConsole(root, host = null) {
|
|||
replayFrame = null,
|
||||
sound = false,
|
||||
combine = false,
|
||||
lastSpoken = 0;
|
||||
lastSpoken = 0,
|
||||
basicsStarted = false,
|
||||
basicsPicked = false;
|
||||
const t = (fr, en) => (locale === "fr" ? fr : en);
|
||||
const actionWords = (text) =>
|
||||
text.replace(
|
||||
/\b[ABC]\b/g,
|
||||
(key) =>
|
||||
({
|
||||
A: t("Armes", "Weapons"),
|
||||
B: t("Énergie", "Energy"),
|
||||
C: t("Systèmes", "Systems"),
|
||||
})[key],
|
||||
);
|
||||
const navigation = mountNavigation(root, {
|
||||
locale: () => locale,
|
||||
hosted: !!host,
|
||||
|
|
@ -81,16 +94,16 @@ export function mountConsole(root, host = null) {
|
|||
const specialName = (n) => names[n]?.[locale === "fr" ? 0 : 1] ?? n;
|
||||
const label = (a) =>
|
||||
({
|
||||
A: t("A · Tirer ou réparer l’arme", "A · Fire or repair weapon"),
|
||||
A: t("Armes · Tirer ou réparer (A)", "Weapons · Fire or repair (A)"),
|
||||
B: t(
|
||||
"B · Transférer l’énergie ou réparer",
|
||||
"B · Transfer energy or repair",
|
||||
"Énergie · Transférer ou réparer (B)",
|
||||
"Energy · Transfer or repair (B)",
|
||||
),
|
||||
C: t(
|
||||
"C · Système de la station ou réparation",
|
||||
"C · Station system or repair",
|
||||
"Systèmes · Utiliser ou réparer (C)",
|
||||
"Systems · Operate or repair (C)",
|
||||
),
|
||||
bots: t("Attaquer avec les robots", "Battlebot attack"),
|
||||
bots: t("Robot de combat · Attaquer", "Battlebot · Attack"),
|
||||
red: t("Aller à gauche", "Move left"),
|
||||
blue: t("Aller à droite", "Move right"),
|
||||
lift: t("Changer de pont", "Change deck"),
|
||||
|
|
@ -113,6 +126,9 @@ export function mountConsole(root, host = null) {
|
|||
if (a.startsWith("teleport:"))
|
||||
return `<span class="teleport-action" style="--zone:var(--${esc(a.slice(9).split("-")[0])})">${pictogram("teleport")}${shipLocator([a.slice(9)])}</span>`;
|
||||
const actionIcon = {
|
||||
A: "A",
|
||||
B: "B",
|
||||
C: "C",
|
||||
bots: "bots",
|
||||
red: "left",
|
||||
blue: "right",
|
||||
|
|
@ -282,6 +298,21 @@ export function mountConsole(root, host = null) {
|
|||
if (crew >= view.crewSize) crew = seat;
|
||||
root.lang = locale;
|
||||
localizeSetup();
|
||||
const basic = !!view.tutorial?.basics;
|
||||
root.classList.toggle("learning-basics", basic);
|
||||
$("#basics-guide").hidden = !basic;
|
||||
if (basic)
|
||||
$("#basics-guide").innerHTML = basicsView(view, locale, {
|
||||
started: basicsStarted || view.tutorial.nativeStep > 0,
|
||||
picked: basicsPicked,
|
||||
shipMarkup: shipCutaway({
|
||||
ship: { ...view.game.ship, crew: [view.game.ship.crew[0]] },
|
||||
selectedCrew: 0,
|
||||
canPlan: false,
|
||||
isAndroid: () => true,
|
||||
crewLabel: () => t("Androïde 1", "Android 1"),
|
||||
}),
|
||||
});
|
||||
const g = view.game,
|
||||
own = view.players[seat] ?? {
|
||||
ready: true,
|
||||
|
|
@ -325,9 +356,10 @@ export function mountConsole(root, host = null) {
|
|||
)
|
||||
.join(" ");
|
||||
$("#lesson-guide").hidden = !view.tutorial;
|
||||
$("#lesson-guide").innerHTML = view.tutorial
|
||||
? `<ol>${view.tutorial.instructions.map((p) => `<li>${esc(p[locale === "fr" ? 0 : 1])}</li>`).join("")}</ol>${view.stage === "programming" ? `<button id="lesson-next" class="icon-label">${pictogram(view.phase === 1 ? "step" : "lock")}<span>${view.phase === 1 ? t("Phase 2", "Phase 2") : t("Terminer la programmation", "Finish programming")}</span></button>` : ""} <button data-lesson="${view.tutorial.id}" class="quiet icon-button" title="${t("Recommencer", "Restart")}" aria-label="${t("Recommencer", "Restart")}">${pictogram("restart")}</button>`
|
||||
: "";
|
||||
$("#lesson-guide").innerHTML =
|
||||
view.tutorial && !basic
|
||||
? `<ol>${view.tutorial.instructions.map((p) => `<li>${esc(actionWords(p[locale === "fr" ? 0 : 1]))}</li>`).join("")}</ol><div class="lesson-actions">${view.stage === "programming" ? `<button id="lesson-clock" class="icon-label">${pictogram(view.tutorial.clockRunning ? "pause" : "clock")}<span>${view.tutorial.clockRunning ? t("Mettre le chrono en pause", "Pause clock") : t("Lancer le chrono d’entraînement", "Start practice clock")}</span></button><button id="lesson-next" class="icon-label">${pictogram(view.phase === 1 ? "step" : "lock")}<span>${view.phase === 1 ? t("Phase 2", "Phase 2") : t("Terminer la programmation", "Finish programming")}</span></button>` : ""} <button data-lesson="${view.tutorial.id}" class="quiet icon-button" title="${t("Recommencer", "Restart")}" aria-label="${t("Recommencer", "Restart")}">${pictogram("restart")}</button></div>`
|
||||
: "";
|
||||
$("#comms").innerHTML = symbol(
|
||||
view.communicationsAvailable ? "comms" : "muted",
|
||||
view.communicationsAvailable
|
||||
|
|
@ -346,18 +378,19 @@ export function mountConsole(root, host = null) {
|
|||
: "";
|
||||
if (ship) {
|
||||
$("#ship").innerHTML = shipCutaway({
|
||||
ship,
|
||||
ship: basic ? { ...ship, crew: [ship.crew[0]] } : ship,
|
||||
selectedCrew: crew,
|
||||
canPlan:
|
||||
view.stage === "programming" &&
|
||||
!basic && view.stage === "programming" &&
|
||||
seat >= 0 &&
|
||||
(g?.solo || crew === seat || crew >= view.players.length) &&
|
||||
!own.finishedPlanning,
|
||||
isAndroid: (id) => g.solo || id >= view.players.length,
|
||||
crewLabel: (id) =>
|
||||
view.players[id]?.name ?? `${t("Androïde", "Android")} ${id + 1}`,
|
||||
});
|
||||
$("#resources").innerHTML =
|
||||
`${symbol("fuel", `${t("Combustible", "Fuel")} : ${ship.fuel}`, `<b>${ship.fuel}</b>`)}${symbol("rocket", `${t("Roquettes", "Rockets")} : ${ship.rockets}`, `<b>${ship.rockets}</b>`)}${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) => `<span class="computer-phase ${x ? "maintained" : ""}">${i + 1}</span>`).join(""))}${symbol("bots", `${t("Robots disponibles", "Available battlebots")} : ${ship.bots.filter((b) => b.owner === null && b.station && !b.disabled).length}`, `<b>${ship.bots.filter((b) => b.owner === null && b.station && !b.disabled).length}</b>`)}${ship.crew
|
||||
`${symbol("fuel", `${t("Combustible", "Fuel")} : ${ship.fuel}`, `<b>${ship.fuel}</b>`)}${symbol("rocket", `${t("Roquettes", "Rockets")} : ${ship.rockets}`, `<b>${ship.rockets}</b>`)}${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) => `<span class="computer-phase ${x ? "maintained" : ""}">${i + 1}</span>`).join(""))}${symbol("bots", `${t("Robots de combat · Escouades disponibles", "Battlebots · Available squads")} : ${ship.bots.filter((b) => b.owner === null && b.station && !b.disabled).length}`, `<b>${ship.bots.filter((b) => b.owner === null && b.station && !b.disabled).length}</b><small>${t("escouades", "squads")}</small>`)}${ship.crew
|
||||
.filter((p) => p.space)
|
||||
.map((p) =>
|
||||
symbol(
|
||||
|
|
@ -427,15 +460,15 @@ export function mountConsole(root, host = null) {
|
|||
ownPhase =
|
||||
g?.solo || crew >= view.players.length ? view.phase : own.planningPhase;
|
||||
$("#program").innerHTML = (g?.programs[crew] ?? [])
|
||||
.slice(0, view.mission.phaseEndsMs.length === 2 ? 7 : 12)
|
||||
.slice(0, basic ? 3 : view.mission.phaseEndsMs.length === 2 ? 7 : 12)
|
||||
.map((slot) => {
|
||||
const editable =
|
||||
planning &&
|
||||
(!basic || slot.turn < 3) && planning &&
|
||||
canOwn &&
|
||||
!own.finishedPlanning &&
|
||||
phaseFor(slot.turn) === ownPhase;
|
||||
const description = `T+${slot.turn} · ${slot.cards.map((c) => (c.sides ? c.sides[c.side].map(label).join(" → ") : c.category === "movement" ? t("Déplacement", "Movement") : t("Action", "Action"))).join(" + ") || t("Vide", "Empty")}`;
|
||||
return `<button class="slot ${phaseFor(slot.turn) < ownPhase ? "locked" : ""} ${phaseFor(slot.turn) > ownPhase ? "future" : ""}" data-turn="${slot.turn}" ${editable ? "" : "disabled"} title="${esc(description)}" aria-label="${esc(description)}"><span class="turn">T+${slot.turn} ${phaseFor(slot.turn) < ownPhase ? pictogram("lock") : ""}</span><span class="action">${slot.cards.map((c) => (c.sides ? c.sides[c.side].map(icon).join(" ") : pictogram(c.category === "movement" ? "move" : "cards"))).join(" + ") || "·"}</span></button>`;
|
||||
return `<button class="slot ${basic && resolution && slot.turn === (resolution.step === "damage" ? resolution.turn : Math.max(0, resolution.turn - 1)) ? "current" : ""} ${phaseFor(slot.turn) < ownPhase ? "locked" : ""} ${phaseFor(slot.turn) > ownPhase ? "future" : ""}" data-turn="${slot.turn}" ${editable ? "" : "disabled"} title="${esc(description)}" aria-label="${esc(description)}"><span class="turn">T+${slot.turn} ${phaseFor(slot.turn) < ownPhase ? pictogram("lock") : ""}</span><span class="action">${slot.cards.map((c) => (c.sides ? c.sides[c.side].map(icon).join(" ") : pictogram(c.category === "movement" ? "move" : "cards"))).join(" + ") || pictogram("wait")}</span></button>`;
|
||||
})
|
||||
.join("");
|
||||
$("#player-help").textContent = planning
|
||||
|
|
@ -473,7 +506,7 @@ export function mountConsole(root, host = null) {
|
|||
: planning
|
||||
? `${g?.solo ? "" : button("advance-phase", t("Phase suivante →", "Next phase →"), own.finishedPlanning || own.planningPhase >= view.mission.phaseEndsMs.length)}${button("finish-planning", t("Verrouiller mon programme", "Lock my program"), own.finishedPlanning || view.phase < view.mission.phaseEndsMs.length)}${g.dataCredits ? button("draw", `${t("Piocher", "Draw")} +${g.dataCredits}`) : ""}${g.androidDataCredits ? button("draw-android", t("Carte androïde", "Android card") + ` +${g.androidDataCredits}`, !g.canDrawAndroid) : ""}`
|
||||
: view.stage === "resolution"
|
||||
? `${button("resolve", t("Étape suivante →", "Next step →"), seat !== 0 || !!resolution?.outcome, 'class="primary"')}${button("resolve-all", t("Résoudre la mission", "Resolve mission"), seat !== 0 || !!resolution?.outcome)}`
|
||||
? `<button data-command="resolve" class="primary icon-button" title="${t("Étape de résolution suivante", "Next resolution step")}" aria-label="${t("Étape de résolution suivante", "Next resolution step")}" ${seat !== 0 || !!resolution?.outcome ? "disabled" : ""}>${pictogram("step")}</button><button data-command="resolve-all" class="quiet icon-button" title="${t("Résoudre la mission", "Resolve mission")}" aria-label="${t("Résoudre la mission", "Resolve mission")}" ${seat !== 0 || !!resolution?.outcome ? "disabled" : ""}>${pictogram("right")}${pictogram("right")}</button>`
|
||||
: view.stage === "cancelled"
|
||||
? '<button id="open-setup">' +
|
||||
t("Nouvelle session", "New session") +
|
||||
|
|
@ -498,11 +531,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;
|
||||
const same = grouped.find(
|
||||
(c) =>
|
||||
c.kind === "normal" &&
|
||||
card.kind === "normal" &&
|
||||
JSON.stringify(c.sides) === JSON.stringify(card.sides),
|
||||
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),
|
||||
);
|
||||
if (same) same.count++;
|
||||
else grouped.push({ ...card, count: 1 });
|
||||
|
|
@ -545,7 +579,7 @@ export function mountConsole(root, host = null) {
|
|||
)
|
||||
.map(
|
||||
(c) =>
|
||||
`<div class="card ${c.kind}">${c.count > 1 ? `<span class="copies">×${c.count}</span>` : ""}${c.sides.map((side, index) => `<button data-card="${esc(c.id)}" data-side="${index}" class="${selected.some((s) => s.id === c.id && s.side === index) ? "selected" : ""}" aria-pressed="${selected.some((s) => s.id === c.id && s.side === index)}" title="${esc(side.map(label).join(" → "))}" aria-label="${esc(side.map(label).join(" → "))}">${side.map(icon).join(" · ")}</button>`).join("")}</div>`,
|
||||
`<div class="card ${c.kind}">${c.count > 1 ? `<span class="copies">×${c.count}</span>` : ""}${c.sides.map((side, index) => basic && !(side.length === 1 && ["red", "blue"].includes(side[0])) ? "" : `<button data-card="${esc(c.id)}" data-side="${index}" class="${selected.some((s) => s.id === c.id && s.side === index) ? "selected" : ""}" aria-pressed="${selected.some((s) => s.id === c.id && s.side === index)}" title="${esc(side.map(label).join(" → "))}" aria-label="${esc(side.map(label).join(" → "))}">${side.map(icon).join(" · ")}</button>`).join("")}</div>`,
|
||||
)
|
||||
.join("")
|
||||
: "";
|
||||
|
|
@ -554,7 +588,7 @@ export function mountConsole(root, host = null) {
|
|||
? ["all", "A", "B", "C", "bots", "move"]
|
||||
.map(
|
||||
(f) =>
|
||||
`<button data-filter="${f}" class="quiet icon-button" aria-pressed="${handFilter === f}" title="${esc(f === "all" ? t("Toutes les cartes", "All cards") : f === "move" ? t("Déplacements", "Movement") : label(f))}" aria-label="${esc(f === "all" ? t("Toutes les cartes", "All cards") : f === "move" ? t("Déplacements", "Movement") : label(f))}">${f === "all" ? pictogram("cards") : f === "bots" ? pictogram("bots") : f === "move" ? pictogram("move") : f}</button>`,
|
||||
`<button data-filter="${f}" class="quiet icon-button" aria-pressed="${handFilter === f}" title="${esc(f === "all" ? t("Toutes les cartes", "All cards") : f === "move" ? t("Déplacements", "Movement") : label(f))}" aria-label="${esc(f === "all" ? t("Toutes les cartes", "All cards") : f === "move" ? t("Déplacements", "Movement") : label(f))}">${f === "all" ? pictogram("cards") : f === "bots" ? pictogram("bots") : f === "move" ? pictogram("move") : pictogram(f)}</button>`,
|
||||
)
|
||||
.join("")
|
||||
: "";
|
||||
|
|
@ -601,7 +635,7 @@ export function mountConsole(root, host = null) {
|
|||
["reactor", t("Réacteur", "Reactor")],
|
||||
["fuel", t("Combustible", "Fuel")],
|
||||
["computer", t("Ordinateur", "Computer")],
|
||||
["bots", t("Robots", "Battlebots")],
|
||||
["bots", t("Robots de combat", "Battlebots")],
|
||||
["android", t("Androïde", "Android")],
|
||||
["interceptor", t("Intercepteurs", "Interceptors")],
|
||||
["observation", t("Observation", "Visual confirmation")],
|
||||
|
|
@ -722,6 +756,7 @@ export function mountConsole(root, host = null) {
|
|||
$("#career-seats").addEventListener("change", setupSpecialists);
|
||||
async function localPost(path, body) {
|
||||
if (host) {
|
||||
if (host.tutorialPost) return host.tutorialPost(path, body);
|
||||
if (path === "/api/campaign-next") return command("campaign-next", body);
|
||||
if (path === "/api/career") {
|
||||
if (body.id && body.id !== view.careerIds[seat])
|
||||
|
|
@ -858,7 +893,9 @@ export function mountConsole(root, host = null) {
|
|||
if (host) {
|
||||
if (target !== seat || seat < 0)
|
||||
throw Error("Only your own seat can send commands");
|
||||
return host.command({ type, sequence: view.nextSequence, ...extra });
|
||||
const result = await host.command({ type, sequence: view.nextSequence, ...extra });
|
||||
if (type === "program") host.cue?.("place");
|
||||
return result;
|
||||
}
|
||||
const s =
|
||||
target === seat
|
||||
|
|
@ -907,15 +944,92 @@ export function mountConsole(root, host = null) {
|
|||
navigation.openPanel("setup");
|
||||
return;
|
||||
}
|
||||
if (el.id === "basics-start" || el.dataset.basicsPick) {
|
||||
host?.cue?.("select");
|
||||
if (el.id === "basics-start") basicsStarted = true;
|
||||
else
|
||||
basicsPicked =
|
||||
basicsPicked === el.dataset.basicsPick
|
||||
? false
|
||||
: el.dataset.basicsPick;
|
||||
rerender();
|
||||
return;
|
||||
}
|
||||
if (el.dataset.basicsTurn) {
|
||||
const turn = Number(el.dataset.basicsTurn);
|
||||
if (turn > 2) return;
|
||||
perform(async () => {
|
||||
if (!basicsPicked) {
|
||||
await command("remove", {
|
||||
crew: 0,
|
||||
turn,
|
||||
slotVersion: view.game.programs[0][turn - 1].revision,
|
||||
});
|
||||
return;
|
||||
}
|
||||
const action = basicsPicked;
|
||||
const card = view.game.hand.find((c) =>
|
||||
c.sides.some((s) => s.length === 1 && s[0] === action),
|
||||
);
|
||||
if (!card) throw Error(t("Carte indisponible", "Card unavailable"));
|
||||
basicsPicked = false;
|
||||
await command("program", {
|
||||
crew: 0,
|
||||
turn,
|
||||
slotVersion: view.game.programs[0][turn - 1].revision,
|
||||
cards: [
|
||||
{
|
||||
id: card.id,
|
||||
side: card.sides.findIndex(
|
||||
(s) => s.length === 1 && s[0] === action,
|
||||
),
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (el.id === "lesson-clock") {
|
||||
perform(() =>
|
||||
localPost("/api/lesson-clock", {
|
||||
running: !view.tutorial.clockRunning,
|
||||
}),
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (el.id === "basics-plan") {
|
||||
if (view.stage === "resolution") perform(async () => {
|
||||
basicsStarted = true;
|
||||
basicsPicked = false;
|
||||
await localPost("/api/lesson-back", {});
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (el.id === "basics-run" || el.id === "basics-execute") {
|
||||
if (view.stage === "resolution") return;
|
||||
perform(async () => {
|
||||
while (view.stage === "programming")
|
||||
await localPost("/api/lesson-next", {});
|
||||
host?.cue?.("start");
|
||||
rerender();
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (el.dataset.lesson) {
|
||||
if (host?.tutorial) { host.openLesson(el.dataset.lesson); return; }
|
||||
if (!host) { location.assign(`/learn?chapter=${encodeURIComponent(el.dataset.lesson)}&locale=${locale}`); return; }
|
||||
perform(async () => {
|
||||
seat = 0;
|
||||
crew = 0;
|
||||
selected = [];
|
||||
replayFrame = null;
|
||||
basicsStarted = false;
|
||||
basicsPicked = false;
|
||||
await localPost("/api/lesson", { lesson: el.dataset.lesson });
|
||||
navigation.closePanel();
|
||||
$("#lesson-guide").scrollIntoView({ block: "start" });
|
||||
$(
|
||||
view.tutorial?.basics ? "#basics-guide" : "#lesson-guide",
|
||||
).scrollIntoView({ block: "start" });
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
|
@ -1042,6 +1156,7 @@ export function mountConsole(root, host = null) {
|
|||
return;
|
||||
}
|
||||
if (el.dataset.card) {
|
||||
host?.cue?.("select");
|
||||
const choice = { id: el.dataset.card, side: Number(el.dataset.side) };
|
||||
if (e.shiftKey || combine)
|
||||
selected = [
|
||||
|
|
@ -1212,7 +1327,8 @@ export function mountConsole(root, host = null) {
|
|||
intervals.push(
|
||||
setInterval(() => {
|
||||
if (!view) return;
|
||||
const now = view.serverNow + performance.now() - received;
|
||||
const paused = view.tutorial && !view.tutorial.clockRunning;
|
||||
const now = view.serverNow + (paused ? 0 : performance.now() - received);
|
||||
const end =
|
||||
view.stage === "presence"
|
||||
? view.players[seat]?.readyUntil
|
||||
|
|
@ -1221,8 +1337,13 @@ export function mountConsole(root, host = null) {
|
|||
: view.stage === "programming"
|
||||
? view.missionStartAt + view.mission.phaseEndsMs.at(-1)
|
||||
: now;
|
||||
$("#clock").textContent = view.tutorial
|
||||
? t("Libre", "Untimed")
|
||||
const practiceTime = $("[data-practice-time]");
|
||||
if (practiceTime)
|
||||
practiceTime.textContent =
|
||||
duration(Math.max(0, (end ?? now) - now)) +
|
||||
(paused ? t(" · en pause", " · paused") : "");
|
||||
$("#clock").textContent = paused
|
||||
? t("En pause", "Paused")
|
||||
: view.stage === "presence" && !view.players[seat]?.ready
|
||||
? t("En attente", "Waiting")
|
||||
: duration((end ?? now) - now);
|
||||
|
|
@ -1259,6 +1380,7 @@ export function mountConsole(root, host = null) {
|
|||
})();
|
||||
}
|
||||
return {
|
||||
resetTutorial() { basicsPicked = false; basicsStarted = false; selected = []; replayFrame = null; key = ""; },
|
||||
render(next) {
|
||||
if (host && next.bgs?.settings) {
|
||||
$("#mission").value = next.bgs.settings.mission ?? next.mission.id;
|
||||
|
|
@ -1272,7 +1394,11 @@ export function mountConsole(root, host = null) {
|
|||
if (host) $("#connection").textContent = "";
|
||||
},
|
||||
setPlayer(index) {
|
||||
seat = index ?? -1;
|
||||
const nextSeat = index ?? -1;
|
||||
// BGS repeats player information during state/presence updates. Only an
|
||||
// actual seat change should discard the locally selected android/cards.
|
||||
if (seat === nextSeat) return;
|
||||
seat = nextSeat;
|
||||
crew = Math.max(0, seat);
|
||||
selected = [];
|
||||
rerender();
|
||||
|
|
|
|||
97
preview/basics.js
Normal file
97
preview/basics.js
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
import { pictogram } from "./icons.js";
|
||||
// A focused view over the real lesson state, not a separate game simulation.
|
||||
export function basicsView(view, locale, { started, picked, shipMarkup }) {
|
||||
const t = (fr, en) => (locale === "fr" ? fr : en);
|
||||
const slots = view.game.programs[0];
|
||||
const placed = slots.slice(0, 2).filter((s) => s.cards.length).length;
|
||||
const r = view.game.resolution;
|
||||
const turn = r?.step === "damage" ? r.turn : Math.max(0, (r?.turn ?? 0) - 1);
|
||||
const playing = view.stage === "resolution";
|
||||
if (view.tutorial.nativeStep !== undefined) {
|
||||
const control = (id, glyph, description, disabled = false) => `<button id="${id}" class="primary icon-button" title="${description}" aria-label="${description}" ${disabled ? "disabled" : ""}>${pictogram(glyph)}</button>`;
|
||||
if (view.tutorial.nativeStep === 0) return "";
|
||||
if (playing) return "";
|
||||
return `<div class="practice-readiness" role="status" aria-label="${placed}/2 ${t("actions placées", "actions placed")}"><span>${pictogram("cards")} ${placed}/2</span><span class="ready-dots" aria-hidden="true">${[0,1].map(i => `<i class="${i < placed ? "filled" : ""}"></i>`).join("")}</span>${control("basics-run", "step", t("Exécuter le programme", "Run program"), placed !== 2)}</div><div class="practice-clock"><div><strong data-practice-time></strong><small>${t("Préparation", "Planning")}</small></div>${control("lesson-clock", view.tutorial.clockRunning ? "pause" : "clock", view.tutorial.clockRunning ? t("Pause", "Pause") : t("Lancer le chrono", "Start clock"))}</div>`;
|
||||
}
|
||||
const intro = !started && !placed && !playing;
|
||||
const ready = placed === 2;
|
||||
const direction = (n) => {
|
||||
const c = slots[n - 1].cards[0];
|
||||
return c?.sides[c.side][0];
|
||||
};
|
||||
const actionLabel = (a) =>
|
||||
a === "blue"
|
||||
? t("À droite", "Move right")
|
||||
: a === "red"
|
||||
? t("À gauche", "Move left")
|
||||
: t("Attendre", "Wait");
|
||||
const heading = intro
|
||||
? t(
|
||||
"Vous décidez d’abord. Vous agissez ensuite.",
|
||||
"Plan first. Act afterward.",
|
||||
)
|
||||
: playing
|
||||
? turn >= 3
|
||||
? t("Vous venez de jouer trois tours.", "You just played three turns.")
|
||||
: turn === 0 ? t("Lecture du programme", "Playing the program") : t(`Tour ${turn} exécuté`, `Turn ${turn} carried out`)
|
||||
: ready && !picked
|
||||
? t("Essayez le chrono.", "Try the clock.")
|
||||
: placed === 0
|
||||
? t("Choisissez où aller.", "Choose where to go.")
|
||||
: t(
|
||||
"Choisissez votre deuxième action.",
|
||||
"Choose your second action.",
|
||||
);
|
||||
const explanation = intro
|
||||
? t(
|
||||
"Dans Space Alert, tout le monde prépare ses actions en même temps. Puis le vaisseau exécute les programmes, tour après tour. Ici, commençons avec un seul équipier, sans menace.",
|
||||
"In Space Alert, everyone plans their actions at the same time. Then the ship carries out those plans, turn by turn. Start here with one crew member and no threats.",
|
||||
)
|
||||
: playing
|
||||
? [
|
||||
t("La préparation est terminée. Les actions vont maintenant se jouer dans l’ordre.", "Planning is finished. Actions now play in order."),
|
||||
t(
|
||||
"La première carte est exécutée. Regardez votre nouvelle position ; la deuxième carte attend son tour.",
|
||||
"The first card has played. Look at your position; the second card is still waiting.",
|
||||
),
|
||||
t(
|
||||
"La deuxième carte est exécutée. Une flèche vers le bord du vaisseau vous laisse sur place. Chaque case est un tour, pas une seconde.",
|
||||
"The second card has played. Moving beyond the edge of the ship leaves you in place. Each slot is a turn, not a second.",
|
||||
),
|
||||
t(
|
||||
"La case 3 est vide : vous restez sur place. En mission, tous les équipiers exécutent leur case 1, puis leur case 2, etc.",
|
||||
"Slot 3 is empty: you stay put. In a mission, every crew member carries out slot 1, then slot 2, and so on.",
|
||||
),
|
||||
][Math.min(turn, 3)]
|
||||
: ready && !picked
|
||||
? t(
|
||||
"Le chrono limite le temps pour préparer les cartes. Il ne déplace pas l’équipier. Vous pouvez le lancer et le mettre en pause ici ; en mission, il continue pour tout le monde.",
|
||||
"The clock limits how long you have to arrange cards. It does not move your crew member. Here you can start and pause it; in a mission it keeps running for everyone.",
|
||||
)
|
||||
: picked
|
||||
? t(
|
||||
"Choisissez le tour 1 ou 2. Vous pouvez aussi remplacer une carte déjà posée.",
|
||||
"Choose turn 1 or 2. You can also replace a card already there.",
|
||||
)
|
||||
: t(
|
||||
"Choisissez une flèche, puis un tour. Vous pouvez remplacer ou retirer vos cartes.",
|
||||
"Choose an arrow, then a turn. You can replace or remove your cards.",
|
||||
);
|
||||
const btn = (id, text) =>
|
||||
`<button id="${id}" class="primary">${text}</button>`;
|
||||
return `<div class="basics-top"><span>${t("PREMIERS PAS · SANS MENACE", "FIRST STEPS · NO THREATS")}</span><button data-lesson="basics" class="quiet">${t("Recommencer", "Restart")}</button></div>
|
||||
<nav class="basics-stages" aria-label="${t("Étapes de l’exercice", "Lesson steps")}"><button id="basics-plan" class="quiet ${!playing ? "active" : ""}" ${!playing ? 'aria-current="step"' : ''} ${playing && !view.tutorial.canReturnToPlanning ? 'disabled' : ''}><span class="step-number">1</span><span>${t("Préparer", "Plan")}</span></button><button id="basics-execute" class="quiet ${playing ? "active" : ""}" ${playing ? 'aria-current="step"' : ''} ${!playing && !ready ? 'disabled' : ''}><span class="step-number">2</span><span>${t("Exécuter les tours", "Run the turns")}</span></button></nav>
|
||||
<h1>${heading}</h1><p class="basics-explanation" role="status">${explanation}</p>
|
||||
<div class="training-ship ship cutaway" aria-label="${t("Le vaisseau · position réelle de l’androïde 1", "The ship · android 1’s actual position")}">${shipMarkup}</div>
|
||||
${
|
||||
intro
|
||||
? btn(
|
||||
"basics-start",
|
||||
t("Essayer avec deux cartes", "Try with two cards"),
|
||||
)
|
||||
: `<div class="basics-program-heading">${pictogram("cards")}<span>${t("Programme", "Program")}</span>${pictogram("right")}</div><div class="basics-program program">${[1, 2, 3].map((n) => `<button title="${t("Tour", "Turn")} ${n} · ${actionLabel(direction(n))}" aria-label="${t("Tour", "Turn")} ${n} · ${actionLabel(direction(n))}" data-basics-turn="${n}" ${playing || (!picked && !slots[n - 1].cards.length) || n === 3 ? "disabled" : ""} class="slot ${playing && n === turn ? "current" : ""}"><span class="turn">T+${n}</span><strong class="action">${pictogram(direction(n) === "blue" ? "right" : direction(n) === "red" ? "left" : "wait")}</strong></button>`).join("")}</div>
|
||||
${!playing ? `<div class="practice-readiness" role="status"><progress value="${placed}" max="2"></progress><span title="${t("Actions de l’exercice placées", "Practice actions placed")}" aria-label="${placed}/2 ${t("actions de l’exercice placées", "practice actions placed")}">${pictogram("cards")} ${placed}/2</span></div><div class="basics-card-area"><div class="basics-card-choices">${["red", "blue"].map((action) => `<button title="${actionLabel(action)}" aria-label="${actionLabel(action)}" data-basics-pick="${action}" aria-pressed="${picked === action}" class="basics-card ${picked === action ? "selected" : ""}"><strong>${pictogram(action === "blue" ? "right" : "left")}</strong></button>`).join("")}</div></div>` : ""}
|
||||
${!playing && ready ? `<div class="practice-clock"><div><strong data-practice-time></strong><small>${t("pour préparer · exercice sans danger", "to plan · safe practice")}</small></div><button id="lesson-clock" class="icon-button" title="${view.tutorial.clockRunning ? t("Mettre en pause", "Pause clock") : t("Lancer le chrono", "Start clock")}" aria-label="${view.tutorial.clockRunning ? t("Mettre en pause", "Pause clock") : t("Lancer le chrono", "Start clock")}">${pictogram(view.tutorial.clockRunning ? "pause" : "clock")}</button></div><button id="basics-run" class="primary icon-button" title="${t("Exécuter le programme", "Run program")}" aria-label="${t("Exécuter le programme", "Run program")}">${pictogram("step")}</button>` : ""}
|
||||
${playing ? (turn < 3 ? `<button data-command="resolve" class="primary icon-button" title="${t("Étape de résolution suivante", "Next resolution step")}" aria-label="${t("Étape de résolution suivante", "Next resolution step")}">${pictogram("step")}</button>` : `<div class="basics-complete"><p>${t("Préparer sous un chrono et exécuter les tours sont deux moments différents. Ensuite, vous apprendrez à utiliser une arme.", "Planning against a clock and carrying out turns are two different parts of the game. Next, learn to use a weapon.")}</p><button data-lesson="first-shot" class="primary">${t("Suite : votre premier tir", "Next: your first shot")}</button></div>`) : ""}`
|
||||
}`;
|
||||
}
|
||||
|
|
@ -1,12 +1,16 @@
|
|||
// Shared silhouettes keep the ship, cards and controls visually consistent.
|
||||
const paths = {
|
||||
wait: "M6 3h12M6 21h12M7 3v4l5 5-5 5v4m10-18v4l-5 5 5 5v4",
|
||||
clock: "M2 12a10 10 0 1 0 20 0 10 10 0 1 0-20 0Zm10-6v6l4 2",
|
||||
pause: "M7 4h3v16H7zM14 4h3v16h-3z",
|
||||
journal: "M5 3h14v18H5zM9 7h6M9 11h6M9 15h4",
|
||||
training: "m3 9 9-6 9 6-9 6-9-6Zm4 3v6l5 3 5-3v-6",
|
||||
ship: "m4 20 4-11L20 4l-5 12-11 4Zm4-11 7 7M3 15l6 6",
|
||||
crew: "M8 8a4 4 0 1 0 8 0 4 4 0 1 0-8 0ZM4 21v-3a8 8 0 0 1 16 0v3",
|
||||
guide: "M4 4h6l2 2 2-2h6v16h-6l-2 2-2-2H4V4Zm8 2v16",
|
||||
bots: "M7 9V7a5 5 0 0 1 10 0v2H7Zm2-3h6M6 10h12v8H6zM10 13h4M3 11v6m18-6v6M8 18v3H5m11-3v3h3",
|
||||
android: "M5 7h14v13H5zM12 3v4M10 3h4M8 11h1m6 0h1M8 16h8M2 10v6m20-6v6",
|
||||
bots: "m5 4 7-2 7 2v9l-7 4-7-4V4ZM8 8h2m4 0h2M9 12h6M4 21l2-6m14 6-2-6M9 17v4m6-4v4",
|
||||
|
||||
laser: "M3 14h8v6H3zM6 14V9h4v5M9 9l8-6M14 10l7-5M17 13l5-4",
|
||||
pulse:
|
||||
"M9 12a3 3 0 1 0 6 0 3 3 0 1 0-6 0ZM6 6a8.5 8.5 0 0 0 0 12m12-12a8.5 8.5 0 0 1 0 12M3 3a13 13 0 0 0 0 18m18-18a13 13 0 0 1 0 18",
|
||||
|
|
@ -15,7 +19,8 @@ const paths = {
|
|||
fuel: "M7 3h8v3H7zM5 6h14v15H5zM5 10h4m6 0h4M13 11l-4 5h3l-1 4 5-6h-3v-3Z",
|
||||
computer: "M3 3h18v13H3zM8 21h8m-4-5v5M6 7l3 2-3 2m6 1h5",
|
||||
observation:
|
||||
"M2 12s4-7 10-7 10 7 10 7-4 7-10 7S2 12 2 12Zm7 0a3 3 0 1 0 6 0 3 3 0 1 0-6 0Z",
|
||||
"M2 13 5 4h4l2 9m2 0 2-9h4l3 9M11 12h2M11 17h2M1 16a5 5 0 1 0 10 0 5 5 0 1 0-10 0Zm12 0a5 5 0 1 0 10 0 5 5 0 1 0-10 0Z",
|
||||
systems: "M3 6h18M3 12h18M3 18h18M7 3v6m10 0v6M9 15v6",
|
||||
rocket:
|
||||
"M9 15C7 7 13 2 21 3c1 8-4 14-12 12ZM9 9H5l-3 6h6m7 0v4l-6 3v-6M5 18l-3 4m13-14h2v2h-2z",
|
||||
interceptor: "m12 2 3 9 7 5v3l-8-3v5h-4v-5l-8 3v-3 7-5 3-9Z",
|
||||
|
|
@ -26,6 +31,7 @@ const paths = {
|
|||
lift: "M8 21V3L3 8m14-5v18l5-5",
|
||||
move: "M3 12h18M8 7l-5 5 5 5m8-10 5 5-5 5",
|
||||
lock: "M6 10h12v11H6zM8 10V6a4 4 0 0 1 8 0v4m-4 5v2",
|
||||
rewind: "M5 4v16m14-16L8 12l11 8V4Z",
|
||||
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",
|
||||
|
|
@ -63,30 +69,31 @@ export const specializationIcons = {
|
|||
};
|
||||
|
||||
export function pictogram(name) {
|
||||
return `<svg class="pictogram" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="${paths[name] ?? paths.star}"/></svg>`;
|
||||
return `<svg class="pictogram" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="${paths[{ A: "laser", B: "reactor", C: "systems", battlebots: "bots" }[name] ?? name] ?? paths.star}"/></svg>`;
|
||||
}
|
||||
|
||||
// A miniature of the actual six-room plan, readable without colour.
|
||||
export function shipLocator(stations, incomingZone = null) {
|
||||
const zones = ["red", "white", "blue"];
|
||||
const incoming = zones.includes(incomingZone);
|
||||
const offset = incoming ? 22 : 0;
|
||||
const offset = 0;
|
||||
const x = zones.indexOf(incomingZone) * 20 + 13;
|
||||
return `<svg class="ship-locator" viewBox="0 0 66 ${36 + offset}" aria-hidden="true" focusable="false">${incoming ? `<path class="incoming-arrow" d="M33 2v5L${x} 15v5m-4-5 4 5 4-5"/>` : ""}<path class="locator-hull" d="m7 ${2 + offset} 52 0 6 6v20l-6 6H7l-6-6v-20Z"/>${["upper", "lower"].flatMap((deck, row) => zones.map((zone, col) => `<rect x="${5 + col * 20}" y="${6 + row * 13 + offset}" width="16" height="10" rx="1" class="${stations.includes(`${zone}-${deck}`) ? "located" : ""}"/>`)).join("")}</svg>`;
|
||||
return `<svg class="ship-locator" viewBox="0 0 66 ${incoming ? 58 : 36}" aria-hidden="true" focusable="false">${incoming ? `<path class="incoming-arrow" d="M33 56v-5L${x} 43v-5m-4 5 4-5 4 5"/>` : ""}<path class="locator-hull" d="m7 ${2 + offset} 52 0 6 6v20l-6 6H7l-6-6v-20Z"/>${["upper", "lower"].flatMap((deck, row) => zones.map((zone, col) => `<rect x="${5 + col * 20}" y="${6 + row * 13 + offset}" width="16" height="10" rx="1" class="${stations.includes(`${zone}-${deck}`) ? "located" : ""}"/>`)).join("")}</svg>`;
|
||||
}
|
||||
|
||||
// Large, flat equipment drawings stay readable on the cutaway's smallest rooms.
|
||||
// Colours, silhouettes and action letters provide independent visual cues.
|
||||
// Shared steel, teal and amber materials match the shield and reactor artwork.
|
||||
const equipment = {
|
||||
laser: `<path fill="#79949f" d="M12 48h40l6 10H6z"/><circle cx="32" cy="42" r="14" fill="#dbe7dd"/><path fill="#e6b66b" d="M20 29h24v18H20z"/><path fill="#dbe7dd" d="M23 8h7v28h-7zm13 0h7v28h-7z"/><path stroke="#ff806c" stroke-width="4" d="M26 3v11m14-11v11"/><path stroke="#243947" d="M26 41h13"/>`,
|
||||
"light-laser": `<path fill="#79949f" d="M15 47h34l5 11H10z"/><circle cx="32" cy="40" r="14" fill="#dbe7dd"/><path fill="#e6b66b" d="M23 28h18v17H23z"/><path fill="#dbe7dd" d="M28 7h8v29h-8z"/><path stroke="#ff806c" stroke-width="4" d="M32 2v11"/>`,
|
||||
pulse: `<path fill="#79949f" d="M14 46h36l6 11H8z"/><path fill="#dbe7dd" d="M23 36h18v16H23z"/><circle cx="32" cy="28" r="12" fill="#c7a1ff"/><path stroke="#c7a1ff" fill="none" stroke-width="3" d="M16 12a23 23 0 0 0 0 32m32-32a23 23 0 0 1 0 32"/><path stroke="#f2e6ff" d="M25 28h14m-7-7v14"/>`,
|
||||
android: `<path stroke="#dbe7dd" stroke-width="4" d="M32 5v10m-5-10h10"/><path fill="currentColor" d="M13 15h38v40H13z"/><path fill="#285469" d="M19 22h26v16H19z"/><path fill="#a4f2f1" stroke="none" d="M23 27h5v5h-5zm13 0h5v5h-5z"/><path stroke="#285469" stroke-width="3" d="M23 46h18"/><path fill="#79949f" d="M5 25h8v20H5zm46 0h8v20h-8z"/>`,
|
||||
battlebots: `<path fill="#79949f" d="M12 28h40v22H12zM6 30h6v17H6zm46 0h6v17h-6zM19 49h9v10H15v-5h4zm17 0h9v5h4v5H36z"/><path fill="#dbe7dd" d="M18 25v-7a14 14 0 0 1 28 0v7zM17 28h30v22H17z"/><path fill="#285469" d="M22 15h20v7H22z"/><path stroke="#a4f2f1" stroke-width="3" d="M25 18h14"/><path fill="#e6b66b" d="M25 34h14v9H25z"/>`,
|
||||
observation: `<path fill="#79949f" d="M8 34 15 8h12l3 26m4 0 3-26h12l7 26"/><path fill="#dbe7dd" d="M25 25h14v17H25z"/><circle cx="17" cy="43" r="14" fill="#dbe7dd"/><circle cx="47" cy="43" r="14" fill="#dbe7dd"/><circle cx="17" cy="43" r="9" fill="#285469"/><circle cx="47" cy="43" r="9" fill="#285469"/><path stroke="#a4f2f1" stroke-width="3" d="m12 45 6-7m24 7 6-7"/><path stroke="#e6b66b" stroke-width="4" d="M16 12h9m14 0h9"/>`,
|
||||
laser: `<path fill="#79949f" d="M12 48h40l6 10H6z"/><circle cx="32" cy="42" r="14" fill="#dbe7dd"/><path fill="#e6b66b" d="M20 29h24v18H20z"/><path fill="#dbe7dd" d="M23 8h7v28h-7zm13 0h7v28h-7z"/><path stroke="#e6b66b" stroke-width="4" d="M26 3v11m14-11v11"/><path stroke="#243947" d="M26 41h13"/>`,
|
||||
"light-laser": `<path fill="#79949f" d="M15 47h34l5 11H10z"/><circle cx="32" cy="40" r="14" fill="#dbe7dd"/><path fill="#e6b66b" d="M23 28h18v17H23z"/><path fill="#dbe7dd" d="M28 7h8v29h-8z"/><path stroke="#e6b66b" stroke-width="4" d="M32 2v11"/>`,
|
||||
pulse: `<path fill="#79949f" d="M14 46h36l6 11H8z"/><path fill="#dbe7dd" d="M23 36h18v16H23z"/><circle cx="32" cy="28" r="12" fill="#59cedc"/><path stroke="#59cedc" fill="none" stroke-width="3" d="M16 12a23 23 0 0 0 0 32m32-32a23 23 0 0 1 0 32"/><path stroke="#b7edf0" d="M25 28h14m-7-7v14"/>`,
|
||||
shield: `<path fill="#447286" d="M10 44h44v12H10z"/><path fill="#b7edf0" d="M23 44h18v11H23z"/><path fill="#3b8f9e" stroke="#b4f7f5" d="M32 5 53 13v14c0 13-12 20-21 24-9-4-21-11-21-24V13z"/><path fill="#a4f2f1" stroke="none" d="m33 14-12 17h9l-1 11 13-19h-9z"/>`,
|
||||
reactor: `<path fill="#7f97a0" d="M14 11h36v45H14z"/><path fill="#e6b66b" d="M22 6h20v52H22z"/><path fill="#ffe9a3" stroke="none" d="M26 12h12v9H26zm0 13h12v9H26zm0 13h12v9H26z"/><path stroke="#dbe7dd" stroke-width="5" d="M14 20H7m7 20H7m43-20h7m-7 20h7"/><path fill="#dbe7dd" d="M18 3h28v7H18zm0 49h28v8H18z"/>`,
|
||||
computer: `<path fill="#dbe7dd" d="M7 8h50v33H7z"/><path fill="#285469" d="M12 13h40v23H12z"/><path stroke="#91eff1" stroke-width="3" d="m17 20 5 4-5 4m12 0h15"/><path fill="#7f97a0" d="M13 41h38l8 14H5z"/><path stroke="#dbe7dd" d="M19 47h26m-19 5h12"/>`,
|
||||
battlebots: `<path fill="#7f97a0" d="M19 43h10v16H17zm16 0h10l2 16H35zM7 25h10v23H7zm40 0h10v23H47z"/><path fill="#dbe7dd" d="M17 23h30v23H17zM21 6h22v18H21z"/><path fill="#59cedc" d="M24 11h16v6H24z"/><path fill="#e6b66b" d="M25 28h14v10H25z"/><path stroke="#dbe7dd" d="M24 3h16"/>`,
|
||||
interceptor: `<path fill="#dbe7dd" d="m32 4 8 24 17 15v9l-21-7v14h-8V45L7 52v-9l17-15z"/><path fill="#59cedc" d="m32 16 4 14h-8z"/><path stroke="#e6b66b" stroke-width="4" d="m18 41 7-5m21 5-7-5"/>`,
|
||||
observation: `<path fill="#dbe7dd" d="M4 32s10-19 28-19 28 19 28 19-10 19-28 19S4 32 4 32Z"/><circle cx="32" cy="32" r="13" fill="#59cedc"/><circle cx="32" cy="32" r="6" fill="#183447"/><circle cx="36" cy="27" r="3" fill="#f0fcff" stroke="none"/>`,
|
||||
rocket: `<path fill="#e6b66b" d="m24 34-13 12v12l17-9m12-15 13 12v12l-17-9"/><path fill="#dbe7dd" d="M24 49V22Q24 9 32 3q8 6 8 19v27z"/><path fill="#e6b66b" d="M24 23h16v9H24z"/><path fill="#59cedc" d="m27 52 5 9 5-9z"/>`,
|
||||
fuel: `<path fill="#dbe7dd" d="M22 5h20v8H22zM15 13h34v44H15z"/><path fill="#e6b66b" d="M21 22h22v26H21z"/><path fill="#fff0b8" stroke="none" d="m34 24-11 14h8l-2 9 13-17h-9z"/>`,
|
||||
fighter: `<path fill="#81959f" d="M23 13h18v20H23z"/><path fill="#dbe7dd" d="m27 12-4 16L6 39v10l20-7 6 17 6-17 20 7V39L41 28l-4-16z"/><path fill="#cc917b" d="m8 40 15-10-2 8-13 6zm48 0L41 30l2 8 13 6z"/><path fill="#6fced6" d="m32 27 4 11-4 7-4-7z"/><path stroke="#a9d8dc" stroke-width="4" d="M27 8v7m10-7v7"/>`,
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@
|
|||
<div id="ready-controls" class="controls"></div>
|
||||
</section>
|
||||
<div id="error" role="alert"></div>
|
||||
<section id="basics-guide" hidden></section>
|
||||
<section id="lesson-guide" hidden></section>
|
||||
<div class="flight-layout">
|
||||
<section class="tactical">
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { pictogram, specializationIcons } from "./icons.js";
|
||||
import { pictogram, specializationIcons, equipmentPicture } from "./icons.js";
|
||||
|
||||
const navIcons = {
|
||||
journal: "journal",
|
||||
|
|
@ -55,7 +55,10 @@ export function mountNavigation(root, { locale, hosted }) {
|
|||
button.type = "button";
|
||||
button.textContent = option.textContent;
|
||||
if (select.id === "program-crew") {
|
||||
button.innerHTML = pictogram(option.dataset.kind);
|
||||
button.innerHTML =
|
||||
option.dataset.kind === "android"
|
||||
? equipmentPicture("android")
|
||||
: pictogram(option.dataset.kind);
|
||||
const name = document.createElement("span");
|
||||
name.textContent = option.dataset.shortLabel;
|
||||
button.append(name);
|
||||
|
|
|
|||
|
|
@ -33,11 +33,14 @@ import {
|
|||
} from "../src/session.js";
|
||||
|
||||
export function createPreviewServer({ clock = Date.now, storagePath } = {}) {
|
||||
let lessonPlanning = null;
|
||||
let offset = 0,
|
||||
explorers = {},
|
||||
careerIds = [];
|
||||
const trustedClock = () =>
|
||||
state?.tutorial && state.stage === "programming"
|
||||
state?.tutorial &&
|
||||
!state.tutorial.clockRunning &&
|
||||
state.stage === "programming"
|
||||
? state.observedAt
|
||||
: clock() + offset;
|
||||
let state = createSession(
|
||||
|
|
@ -52,6 +55,7 @@ export function createPreviewServer({ clock = Date.now, storagePath } = {}) {
|
|||
const saved = JSON.parse(readFileSync(storagePath, "utf8"));
|
||||
if (saved.schema === 2) {
|
||||
state = saved.state;
|
||||
lessonPlanning = saved.lessonPlanning ?? null;
|
||||
offset = saved.offset ?? 0;
|
||||
explorers = saved.explorers ?? {};
|
||||
careerIds = saved.careerIds ?? [];
|
||||
|
|
@ -67,7 +71,7 @@ export function createPreviewServer({ clock = Date.now, storagePath } = {}) {
|
|||
mkdirSync(dirname(storagePath), { recursive: true });
|
||||
writeFileSync(
|
||||
storagePath + ".tmp",
|
||||
JSON.stringify({ schema: 2, state, offset, explorers, careerIds }),
|
||||
JSON.stringify({ schema: 2, state, offset, explorers, careerIds, lessonPlanning }),
|
||||
{
|
||||
mode: 0o600,
|
||||
},
|
||||
|
|
@ -127,7 +131,7 @@ export function createPreviewServer({ clock = Date.now, storagePath } = {}) {
|
|||
}
|
||||
function viewFor(seat) {
|
||||
const view = snapshot(state, seat);
|
||||
view.tutorial = state.tutorial;
|
||||
view.tutorial = state.tutorial ? { ...state.tutorial, canReturnToPlanning: !!lessonPlanning } : undefined;
|
||||
view.careerIds = careerIds;
|
||||
view.explorers = Object.values(explorers).map((e) => ({
|
||||
...e,
|
||||
|
|
@ -140,8 +144,15 @@ export function createPreviewServer({ clock = Date.now, storagePath } = {}) {
|
|||
function schedule() {
|
||||
clearTimeout(timer);
|
||||
settleCareers();
|
||||
if (state.tutorial?.basics && state.stage === "programming" && state.phase === 1)
|
||||
lessonPlanning = structuredClone(state);
|
||||
persist();
|
||||
if (state.tutorial && state.stage === "programming") return;
|
||||
if (
|
||||
state.tutorial &&
|
||||
!state.tutorial.clockRunning &&
|
||||
state.stage === "programming"
|
||||
)
|
||||
return;
|
||||
const at = nextWakeup(state);
|
||||
if (at === null) return;
|
||||
timer = setTimeout(
|
||||
|
|
@ -189,6 +200,8 @@ export function createPreviewServer({ clock = Date.now, storagePath } = {}) {
|
|||
"/api/career",
|
||||
"/api/lesson",
|
||||
"/api/lesson-next",
|
||||
"/api/lesson-clock",
|
||||
"/api/lesson-back",
|
||||
"/api/campaign-next",
|
||||
].includes(url.pathname)
|
||||
) {
|
||||
|
|
@ -211,12 +224,40 @@ export function createPreviewServer({ clock = Date.now, storagePath } = {}) {
|
|||
if (url.pathname === "/api/lesson") {
|
||||
if (careerIds.some((id) => explorers[id].activeRun))
|
||||
throw Error("Finish the current career mission first");
|
||||
lessonPlanning = null;
|
||||
state = createLesson(command.lesson, clock() + offset);
|
||||
careerIds = [];
|
||||
persisted = -1;
|
||||
schedule();
|
||||
return json(200, viewFor(0));
|
||||
}
|
||||
if (url.pathname === "/api/lesson-back") {
|
||||
if (!state.tutorial?.basics || !lessonPlanning || state.stage !== "resolution")
|
||||
throw Error("No planning checkpoint");
|
||||
const revision = state.revision + 1;
|
||||
state = structuredClone(lessonPlanning);
|
||||
state.revision = revision;
|
||||
state.tutorial.clockRunning = false;
|
||||
offset = state.observedAt - clock();
|
||||
schedule();
|
||||
return json(200, viewFor(0));
|
||||
}
|
||||
if (url.pathname === "/api/lesson-clock") {
|
||||
if (
|
||||
!state.tutorial ||
|
||||
state.stage !== "programming" ||
|
||||
typeof command.running !== "boolean"
|
||||
)
|
||||
throw Error("No active practice clock");
|
||||
state = advanceClock(state, trustedClock());
|
||||
if (state.stage !== "programming")
|
||||
throw Error("Programming has finished");
|
||||
offset = state.observedAt - clock();
|
||||
state.tutorial.clockRunning = command.running;
|
||||
state.revision++;
|
||||
schedule();
|
||||
return json(200, viewFor(seat));
|
||||
}
|
||||
if (url.pathname === "/api/lesson-next") {
|
||||
if (!state.tutorial || state.stage !== "programming")
|
||||
throw Error("No active lesson");
|
||||
|
|
@ -224,6 +265,7 @@ export function createPreviewServer({ clock = Date.now, storagePath } = {}) {
|
|||
state,
|
||||
state.missionStartAt + state.mission.phaseEndsMs[state.phase - 1],
|
||||
);
|
||||
offset = state.observedAt - clock();
|
||||
schedule();
|
||||
return json(200, viewFor(0));
|
||||
}
|
||||
|
|
@ -410,9 +452,23 @@ export function createPreviewServer({ clock = Date.now, storagePath } = {}) {
|
|||
res.end(await readFile(new URL(`.${url.pathname}`, import.meta.url)));
|
||||
return;
|
||||
}
|
||||
if (req.method === "GET" && url.pathname === "/learn") {
|
||||
res.writeHead(200, { "Content-Type": "text/html", "Cache-Control": "no-store" });
|
||||
return res.end('<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Space Alert · Entraînement</title></head><body><script type="module" src="/tutorial-bundle.js"></script></body></html>');
|
||||
}
|
||||
if (req.method === "GET" && url.pathname === "/tutorial-bundle.js") {
|
||||
const { build } = await import("esbuild");
|
||||
const bundle = await build({
|
||||
entryPoints: [fileURLToPath(new URL("tutorial-entry.js", import.meta.url))],
|
||||
bundle: true, write: false, format: "esm", loader: { ".html": "text", ".css": "text" },
|
||||
});
|
||||
res.writeHead(200, { "Content-Type": "text/javascript", "Cache-Control": "no-store" });
|
||||
return res.end(bundle.outputFiles[0].text);
|
||||
}
|
||||
const file = {
|
||||
"/": "index.html",
|
||||
"/app.js": "app.js",
|
||||
"/basics.js": "basics.js",
|
||||
"/local.js": "local.js",
|
||||
"/text.js": "text.js",
|
||||
"/navigation.js": "navigation.js",
|
||||
|
|
|
|||
41
preview/sound.js
Normal file
41
preview/sound.js
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
// Short, quiet synthesized cues; no downloads, looping soundtrack or timing authority.
|
||||
export function createSoundDesign() {
|
||||
let context;
|
||||
let enabled = false;
|
||||
function enable(value) {
|
||||
enabled = value;
|
||||
if (enabled) {
|
||||
const Audio = window.AudioContext || window.webkitAudioContext;
|
||||
if (!Audio) return;
|
||||
context ??= new Audio();
|
||||
void context.resume().catch(() => {});
|
||||
} else if (context) void context.suspend().catch(() => {});
|
||||
}
|
||||
function cue(kind, pan = 0) {
|
||||
if (!enabled || !context || context.state !== "running") return;
|
||||
const notes = {
|
||||
select: [[660, 0, .045]], place: [[440, 0, .065], [660, .06, .09]],
|
||||
start: [[330, 0, .09], [440, .1, .09], [660, .2, .14]],
|
||||
turn: [[300, 0, .07], [450, .08, .12]], wait: [[260, 0, .13]],
|
||||
complete: [[440, 0, .1], [550, .12, .1], [660, .24, .22]],
|
||||
back: [[440, 0, .07], [330, .08, .09]], error: [[180, 0, .12]],
|
||||
}[kind] ?? [];
|
||||
for (const [frequency, delay, duration] of notes) {
|
||||
const oscillator = context.createOscillator();
|
||||
const gain = context.createGain();
|
||||
const stereo = context.createStereoPanner();
|
||||
const at = context.currentTime + delay;
|
||||
oscillator.type = "sine";
|
||||
oscillator.frequency.value = frequency;
|
||||
stereo.pan.value = pan;
|
||||
gain.gain.setValueAtTime(0, at);
|
||||
gain.gain.linearRampToValueAtTime(.045, at + .008);
|
||||
gain.gain.exponentialRampToValueAtTime(.001, at + duration);
|
||||
oscillator.connect(gain).connect(stereo).connect(context.destination);
|
||||
oscillator.start(at);
|
||||
oscillator.stop(at + duration + .02);
|
||||
oscillator.onended = () => { oscillator.disconnect(); gain.disconnect(); stereo.disconnect(); };
|
||||
}
|
||||
}
|
||||
return { enable, cue, destroy() { if (context) void context.close(); } };
|
||||
}
|
||||
|
|
@ -101,7 +101,7 @@ header {
|
|||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
max-width: 1260px;
|
||||
max-width: none;
|
||||
margin: auto;
|
||||
padding: 22px 28px;
|
||||
border-bottom: 1px solid var(--line);
|
||||
|
|
@ -127,7 +127,7 @@ header {
|
|||
gap: 7px;
|
||||
}
|
||||
main {
|
||||
max-width: 1260px;
|
||||
max-width: none;
|
||||
margin: auto;
|
||||
padding: 22px 28px;
|
||||
}
|
||||
|
|
@ -186,6 +186,11 @@ h1 {
|
|||
grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
|
||||
gap: 30px;
|
||||
}
|
||||
.tactical {
|
||||
width: 100%;
|
||||
max-width: 760px;
|
||||
min-width: 0;
|
||||
}
|
||||
.section-heading {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
|
@ -312,13 +317,21 @@ h2 {
|
|||
gap: 5px;
|
||||
}
|
||||
.slot {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-width: 0;
|
||||
min-height: 64px;
|
||||
padding: 5px 3px;
|
||||
padding: 20px 3px;
|
||||
background: #101f2b;
|
||||
border-color: #344553;
|
||||
}
|
||||
.slot .turn {
|
||||
position: absolute;
|
||||
top: 7px;
|
||||
left: 3px;
|
||||
right: 3px;
|
||||
font-size: 9px;
|
||||
color: var(--muted);
|
||||
display: block;
|
||||
|
|
@ -757,7 +770,7 @@ input:not([type="checkbox"]):not([type="range"]) {
|
|||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 4px;
|
||||
max-width: 1260px;
|
||||
max-width: none;
|
||||
margin: auto;
|
||||
padding: 8px 28px;
|
||||
border-bottom: 1px solid var(--line);
|
||||
|
|
@ -1127,14 +1140,23 @@ input:not([type="checkbox"]):not([type="range"]) {
|
|||
.cutaway {
|
||||
position: relative;
|
||||
container-type: inline-size;
|
||||
padding: 0 9px;
|
||||
border-inline: 5px solid #526c79;
|
||||
border-radius: 40% 40% 18px 18px / 24px 24px 18px 18px;
|
||||
}
|
||||
.ship-hull {
|
||||
position: relative;
|
||||
padding: 0 14px 12px;
|
||||
}
|
||||
.ship-hull::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
inset: 39px 0 0;
|
||||
border: 2px solid #8296a0;
|
||||
border-top: 0;
|
||||
border-radius: 0 0 18px 18px;
|
||||
background: #172c39;
|
||||
box-shadow: inset 0 0 0 2px #263f4d;
|
||||
}
|
||||
.ship-bow {
|
||||
margin: 0 -9px;
|
||||
position: relative;
|
||||
margin: 0 -14px;
|
||||
height: 40px;
|
||||
}
|
||||
.ship-bow svg {
|
||||
|
|
@ -1145,7 +1167,7 @@ input:not([type="checkbox"]):not([type="range"]) {
|
|||
fill: none;
|
||||
}
|
||||
.ship-bow .hull-shell {
|
||||
fill: #314e5c;
|
||||
fill: #172c39;
|
||||
}
|
||||
.ship-bow .bridge-window {
|
||||
fill: #79ccd4;
|
||||
|
|
@ -1494,15 +1516,16 @@ input:not([type="checkbox"]):not([type="range"]) {
|
|||
display: grid;
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
gap: 12px;
|
||||
padding: 0 10px;
|
||||
padding: 0 14px 18px;
|
||||
}
|
||||
.ship-stern > span {
|
||||
display: flex;
|
||||
gap: 5px;
|
||||
justify-content: center;
|
||||
width: 65%;
|
||||
width: min(55%, 100px);
|
||||
margin: auto;
|
||||
padding: 6px 10px 9px;
|
||||
padding: 0 8px;
|
||||
height: 20px;
|
||||
border: 2px solid #81939a;
|
||||
border-top: 0;
|
||||
border-radius: 0 0 12px 12px;
|
||||
|
|
@ -1511,6 +1534,7 @@ input:not([type="checkbox"]):not([type="range"]) {
|
|||
.ship-stern i {
|
||||
width: 12px;
|
||||
height: 14px;
|
||||
transform: translateY(12px);
|
||||
background: #95dfe7;
|
||||
border-radius: 0 0 6px 6px;
|
||||
box-shadow: 0 3px 7px #82eff04a;
|
||||
|
|
@ -1678,13 +1702,17 @@ input:not([type="checkbox"]):not([type="range"]) {
|
|||
}
|
||||
@media (max-width: 760px) {
|
||||
.cutaway {
|
||||
margin-inline: -9px;
|
||||
padding-inline: 6px;
|
||||
border-inline-width: 3px;
|
||||
margin-inline: 0;
|
||||
}
|
||||
.ship-hull {
|
||||
padding-inline: 9px;
|
||||
}
|
||||
.ship-hull::before {
|
||||
top: 29px;
|
||||
}
|
||||
.ship-bow {
|
||||
height: 30px;
|
||||
margin-inline: -6px;
|
||||
margin-inline: -9px;
|
||||
}
|
||||
}
|
||||
/* Shared equipment inspector and threat cards. */
|
||||
|
|
@ -1771,14 +1799,14 @@ input:not([type="checkbox"]):not([type="range"]) {
|
|||
.threat-portrait {
|
||||
display: block;
|
||||
position: relative;
|
||||
height: 180px;
|
||||
height: 204px;
|
||||
background: #10212d;
|
||||
overflow: hidden;
|
||||
}
|
||||
.threat-portrait > .equipment-art {
|
||||
width: 128px;
|
||||
height: 118px;
|
||||
margin: 24px auto 0;
|
||||
margin: 66px auto 0;
|
||||
border-radius: 0;
|
||||
}
|
||||
.threat-timing {
|
||||
|
|
@ -1789,6 +1817,10 @@ input:not([type="checkbox"]):not([type="range"]) {
|
|||
white-space: nowrap;
|
||||
}
|
||||
.threat-target {
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: end;
|
||||
|
|
@ -1963,3 +1995,401 @@ input:not([type="checkbox"]):not([type="range"]) {
|
|||
height: 115px;
|
||||
}
|
||||
}
|
||||
|
||||
/* The first lesson reveals only the idea currently being taught. */
|
||||
.learning-basics .flight-layout,
|
||||
.learning-basics .mission-line,
|
||||
.learning-basics #lesson-guide,
|
||||
.learning-basics #crew,
|
||||
.learning-basics .header-tools {
|
||||
display: none !important;
|
||||
}
|
||||
#basics-guide {
|
||||
max-width: 760px;
|
||||
margin: 16px auto 60px;
|
||||
}
|
||||
.basics-top,
|
||||
.basics-stages {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
}
|
||||
.basics-top > span {
|
||||
font-size: 0.75rem;
|
||||
letter-spacing: 0.12em;
|
||||
color: #b4c8d9;
|
||||
}
|
||||
.basics-stages {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 8px;
|
||||
margin: 24px 0;
|
||||
color: #a0aabb;
|
||||
}
|
||||
.basics-stages button {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-start;
|
||||
gap: 10px;
|
||||
min-height: 52px;
|
||||
margin: 0;
|
||||
padding: 10px 12px;
|
||||
border: 0;
|
||||
border-bottom: 3px solid transparent;
|
||||
border-radius: 0;
|
||||
font-size: inherit;
|
||||
line-height: 1.3;
|
||||
text-align: left;
|
||||
}
|
||||
.basics-stages .step-number {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
width: 26px;
|
||||
height: 26px;
|
||||
flex: 0 0 26px;
|
||||
border: 1px solid currentColor;
|
||||
border-radius: 50%;
|
||||
font-size: .8rem;
|
||||
}
|
||||
.basics-stages .active {
|
||||
color: #b8ffe3;
|
||||
border-bottom-color: #74e8bd;
|
||||
background: #142b32;
|
||||
}
|
||||
#basics-guide h1 {
|
||||
font-size: clamp(1.5rem, 4vw, 2.25rem);
|
||||
line-height: 1.2;
|
||||
}
|
||||
.basics-explanation {
|
||||
max-width: 62ch;
|
||||
line-height: 1.65;
|
||||
min-height: 4.5em;
|
||||
}
|
||||
.basics-program button {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
padding: 14px 8px;
|
||||
}
|
||||
.basics-program button:disabled {
|
||||
opacity: 1;
|
||||
color: #b9c9d7;
|
||||
background: #17232e;
|
||||
cursor: default;
|
||||
}
|
||||
.basics-program button:not(:disabled),
|
||||
.basics-program button.current {
|
||||
outline: 2px solid #74e8bd;
|
||||
outline-offset: 2px;
|
||||
}
|
||||
.basics-program strong,
|
||||
.basics-card strong {
|
||||
font-size: 2.2rem;
|
||||
line-height: 1;
|
||||
}
|
||||
.basics-card-area {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
.basics-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
min-width: 165px;
|
||||
padding: 20px;
|
||||
}
|
||||
.basics-card.selected {
|
||||
outline: 3px solid #74e8bd;
|
||||
outline-offset: 3px;
|
||||
}
|
||||
.practice-clock {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
flex-wrap: wrap;
|
||||
gap: 16px;
|
||||
padding: 18px;
|
||||
margin: 20px 0;
|
||||
border: 1px solid #496071;
|
||||
border-radius: 12px;
|
||||
}
|
||||
.practice-clock strong,
|
||||
.practice-clock small {
|
||||
display: block;
|
||||
}
|
||||
.practice-clock strong {
|
||||
font-size: 1.35rem;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
#basics-run {
|
||||
width: 100%;
|
||||
}
|
||||
@media (max-width: 520px) {
|
||||
.basics-top {
|
||||
align-items: flex-start;
|
||||
}
|
||||
.basics-stages {
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
.basics-program {
|
||||
gap: 7px;
|
||||
}
|
||||
}
|
||||
|
||||
.shared-equipment-icon {
|
||||
fill: none;
|
||||
stroke: #b7e3e9;
|
||||
stroke-width: 1.7;
|
||||
stroke-linecap: round;
|
||||
stroke-linejoin: round;
|
||||
}
|
||||
.system-card .action-key {
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
}
|
||||
.action-key .pictogram {
|
||||
width: 17px;
|
||||
height: 17px;
|
||||
}
|
||||
.ship-key .pictogram {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
color: var(--gold);
|
||||
}
|
||||
#hand-filter .pictogram {
|
||||
width: 23px;
|
||||
height: 23px;
|
||||
}
|
||||
#resources .symbol-stat small {
|
||||
font-size: 0.72rem;
|
||||
}
|
||||
|
||||
/* Crew selectors and board markers share the same drawing and number treatment. */
|
||||
.crew-tabs .equipment-art {
|
||||
width: 27px;
|
||||
height: 27px;
|
||||
flex: 0 0 27px;
|
||||
color: #bfd0db;
|
||||
}
|
||||
.crew-tabs [aria-pressed="true"] .equipment-art {
|
||||
color: #ffe0a0;
|
||||
}
|
||||
.crew-pawn {
|
||||
width: auto;
|
||||
height: 30px;
|
||||
gap: 2px;
|
||||
align-items: center;
|
||||
}
|
||||
.crew-pawn > svg.equipment-art {
|
||||
width: 27px;
|
||||
height: 27px;
|
||||
fill: none;
|
||||
stroke: #162e3d;
|
||||
stroke-width: 2;
|
||||
}
|
||||
.crew-pawn > svg.pictogram {
|
||||
width: 23px;
|
||||
height: 27px;
|
||||
fill: none;
|
||||
stroke: currentColor;
|
||||
}
|
||||
.crew-pawn b {
|
||||
position: static;
|
||||
width: auto;
|
||||
min-width: 8px;
|
||||
color: currentColor;
|
||||
text-shadow: none;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.lesson-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
padding-top: 4px;
|
||||
}
|
||||
.lesson-actions > button {
|
||||
min-height: 44px;
|
||||
margin: 0;
|
||||
padding: 10px 14px;
|
||||
line-height: 22px;
|
||||
}
|
||||
.lesson-actions > .icon-button {
|
||||
width: 44px;
|
||||
padding: 10px;
|
||||
flex: 0 0 44px;
|
||||
}
|
||||
.lesson-actions .pictogram {
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
}
|
||||
.basics-card-choices {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 16px;
|
||||
}
|
||||
.basics-card-choices .basics-card {
|
||||
min-width: 135px;
|
||||
}
|
||||
.basics-program strong .pictogram,
|
||||
.basics-card strong .pictogram {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
}
|
||||
.basics-card-choices .basics-card {
|
||||
min-width: 88px;
|
||||
min-height: 80px;
|
||||
}
|
||||
|
||||
/* Teach on the real ship; reveal its systems in later lessons. */
|
||||
.training-ship {
|
||||
max-width: 530px;
|
||||
margin: 20px auto 28px;
|
||||
}
|
||||
.training-ship .systems,
|
||||
.training-ship .between-decks,
|
||||
.training-ship .ship-passage,
|
||||
.training-ship .ship-key,
|
||||
.training-ship .damage {
|
||||
display: none;
|
||||
}
|
||||
.training-ship .deck-upper .station {
|
||||
min-height: 88px;
|
||||
}
|
||||
.training-ship .deck-upper .occupants {
|
||||
align-items: center;
|
||||
min-height: 50px;
|
||||
padding: 8px 0;
|
||||
}
|
||||
.training-ship .deck-lower {
|
||||
margin-top: 10px;
|
||||
opacity: 0.25;
|
||||
}
|
||||
.training-ship .deck-lower .station {
|
||||
min-height: 88px;
|
||||
}
|
||||
.training-ship .deck-lower .occupants {
|
||||
display: none;
|
||||
}
|
||||
.training-ship .crew-pawn > svg.equipment-art {
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
}
|
||||
.training-ship .crew-pawn {
|
||||
height: 38px;
|
||||
}
|
||||
.basics-program-heading {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
margin-bottom: 10px;
|
||||
color: #b9c9d7;
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
.basics-program.program {
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
justify-content: flex-start;
|
||||
margin: 0 0 20px;
|
||||
padding: 14px;
|
||||
border-left: 3px solid #e6b66b;
|
||||
background: #101e28;
|
||||
border-radius: 0 8px 8px 0;
|
||||
}
|
||||
.basics-program button.slot {
|
||||
width: 76px;
|
||||
min-height: 90px;
|
||||
flex: 0 0 76px;
|
||||
border-radius: 6px;
|
||||
gap: 16px;
|
||||
}
|
||||
.basics-program .turn {
|
||||
font-size: 0.72rem;
|
||||
}
|
||||
.basics-card-area {
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
/* BGS checkpoint controller, with a localized guide matching the ship console. */
|
||||
.native-guide { margin: 0 0 24px; }
|
||||
.native-guide-top, .native-guide-tools, .native-guide-controls {
|
||||
display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
|
||||
}
|
||||
.native-guide-top { justify-content: space-between; color: #b4c8d9; }
|
||||
.native-guide-tools a { color: #a9d7e7; font-size: .8rem; }
|
||||
.native-guide h1 { font-size: clamp(1.4rem, 3vw, 2rem); margin: 20px 0 8px; }
|
||||
.native-guide-text { line-height: 1.6; white-space: pre-line; max-width: 65ch; }
|
||||
.native-guide-controls { margin-top: 16px; }
|
||||
.native-guide-controls small { color: #9db0bf; margin-left: auto; }
|
||||
.native-guide .basics-stages { grid-template-columns: repeat(3, 1fr); margin: 16px 0; }
|
||||
.native-tutorial .basics-top,
|
||||
.native-tutorial #basics-guide > .basics-stages,
|
||||
.native-tutorial #basics-guide > h1,
|
||||
.native-tutorial .basics-explanation,
|
||||
.native-tutorial #basics-start,
|
||||
.native-tutorial .basics-complete,
|
||||
.native-tutorial #console-nav,
|
||||
.native-tutorial .header-tools,
|
||||
.native-tutorial .mission-line,
|
||||
.native-tutorial #crew,
|
||||
.native-tutorial #lesson-guide > ol,
|
||||
.native-tutorial #lesson-guide [data-lesson] { display: none; }
|
||||
.native-tutorial #basics-guide { margin-top: 0; }
|
||||
.native-tutorial .training-ship { margin-top: 0; }
|
||||
.practice-readiness { display: flex; align-items: center; gap: 12px; margin: 12px 0; color: #b8ffe3; }
|
||||
.practice-readiness progress { width: 80px; height: 6px; accent-color: #74e8bd; }
|
||||
@media (max-width: 520px) {
|
||||
.native-guide .basics-stages { gap: 3px; }
|
||||
.native-guide .basics-stages button { flex-direction: column; gap: 6px; padding: 10px 4px; text-align: center; }
|
||||
.native-guide-controls small { width: 100%; margin: 0; }
|
||||
}
|
||||
.native-tutorial #basics-run { width: 64px; height: 48px; }
|
||||
.practice-readiness > span { display: inline-flex; align-items: center; gap: 6px; }
|
||||
.native-tutorial.learning-basics .flight-layout { display: grid !important; margin: 0; align-items: start; }
|
||||
.native-tutorial.learning-basics #planning { min-width: 0; }
|
||||
.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 .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,
|
||||
.native-tutorial.learning-basics #card-help,
|
||||
.native-tutorial.learning-basics #controls,
|
||||
.native-tutorial.learning-basics #hand-filter,
|
||||
.native-tutorial.learning-basics #resources,
|
||||
.native-tutorial.learning-basics #threats,
|
||||
.native-tutorial.learning-basics #comms,
|
||||
.native-tutorial.learning-basics #latest,
|
||||
.native-tutorial.learning-basics #replay,
|
||||
.native-tutorial.learning-basics .tactical .section-heading:has(#threat-title),
|
||||
.native-tutorial[data-tutorial-step="0"] #planning { display: none !important; }
|
||||
|
||||
.native-tutorial.learning-basics .tactical { max-width: 600px; }
|
||||
.native-tutorial.learning-basics #ship { width: 100%; max-width: 600px; margin: 0; }
|
||||
.ready-dots { display: flex; gap: 6px; }
|
||||
.ready-dots i { display: block; width: 14px; height: 18px; border: 1px solid #688999; border-radius: 3px; }
|
||||
.ready-dots i.filled { background: #74e8bd; border-color: #74e8bd; }
|
||||
.practice-readiness #basics-run { margin-left: auto; }
|
||||
@media (max-width: 720px) {
|
||||
.native-tutorial.learning-basics .flight-layout { grid-template-columns: 1fr; }
|
||||
}
|
||||
.native-tutorial.learning-basics #ship .station-title { visibility: hidden; }
|
||||
.native-tutorial.learning-basics[data-tutorial-stage="resolution"] #controls { display: flex !important; gap: 10px; }
|
||||
.native-tutorial.learning-basics[data-tutorial-stage="resolution"] #replay { display: block !important; }
|
||||
.native-tutorial.learning-basics[data-tutorial-stage="resolution"] #replay label,
|
||||
.native-tutorial.learning-basics[data-tutorial-stage="resolution"] #replay #live { display: none; }
|
||||
.native-tutorial.learning-basics[data-tutorial-step="3"] #controls { display: none !important; }
|
||||
|
||||
.training-ship .deck-upper .station,
|
||||
.training-ship .deck-lower .station { min-height: 104px; }
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { illustration, threatIllustration } from "./art.js";
|
||||
import { pictogram, shipLocator } from "./icons.js";
|
||||
import { pictogram, shipLocator, equipmentPicture } from "./icons.js";
|
||||
|
||||
export function createTacticalView({
|
||||
t,
|
||||
|
|
@ -8,6 +8,13 @@ export function createTacticalView({
|
|||
zoneName,
|
||||
playerColor = () => "",
|
||||
}) {
|
||||
const actionName = (key) =>
|
||||
({
|
||||
A: t("Armes", "Weapons"),
|
||||
B: t("Énergie", "Energy"),
|
||||
C: t("Systèmes", "Systems"),
|
||||
})[key];
|
||||
const actionWords = (text) => text.replace(/\b[ABC]\b/g, actionName);
|
||||
const meter = (value, capacity) =>
|
||||
`<span class="charge-pips" aria-hidden="true">${Array.from({ length: capacity }, (_, i) => `<i class="${i < value ? "filled" : ""}"></i>`).join("")}</span>`;
|
||||
|
||||
|
|
@ -77,15 +84,15 @@ export function createTacticalView({
|
|||
"Perform C here on turns 1–2, 4–5 and 8–9 to maintain the computer each phase and avoid delaying programs.",
|
||||
),
|
||||
"blue-upper": t(
|
||||
"C prend les robots de cette salle, ou réactive ceux que vous portez déjà.",
|
||||
"C prend les robots de combat de cette salle, ou réactive ceux que vous portez déjà.",
|
||||
"C takes this room’s battlebots, or reactivates the team you already carry.",
|
||||
),
|
||||
"red-lower": t(
|
||||
"C prend les robots de cette salle, ou réactive ceux que vous portez déjà.",
|
||||
"C prend les robots de combat de cette salle, ou réactive ceux que vous portez déjà.",
|
||||
"C takes this room’s battlebots, or reactivates the team you already carry.",
|
||||
),
|
||||
"red-upper": t(
|
||||
"Avec des robots actifs, C vous fait décoller en intercepteur. Un seul équipier peut être dans l’espace à la fois.",
|
||||
"Avec des robots de combat actifs, C vous fait décoller en intercepteur. Un seul équipier peut être dans l’espace à la fois.",
|
||||
"With active battlebots, C launches you in an interceptor. Only one crew member can be in space at a time.",
|
||||
),
|
||||
"white-lower": t(
|
||||
|
|
@ -99,15 +106,21 @@ export function createTacticalView({
|
|||
}[station];
|
||||
const flow = `<div class="energy-flow"><span>${illustration(sourceIcon)}<b>${sourceValue}</b><small>${esc(sourceName)}</small></span>${pictogram("right")}<span>${illustration(system)}<b>${s[system]}/${capacity}</b><small>${esc(energyName)}</small></span></div>`;
|
||||
const details = (key, art, text, extra = "") =>
|
||||
`<template>${key === "B" ? "" : `<div class="system-detail-art">${illustration(art)}</div>`}<p class="room-location">${esc(zoneName(zone))} · ${deck === "upper" ? t("Pont supérieur", "Upper deck") : t("Pont inférieur", "Lower deck")}</p>${extra}<p>${esc(text)}</p><p class="planning-note">${t(`Programmez ${key} à un tour où votre équipier sera dans cette salle. Une panne de ce système fait utiliser l’action pour la réparer.`, `Program ${key} on a turn when your crew member will be in this room. A malfunction of this system makes the action repair it instead.`)}</p>${canPlan ? `<button class="primary icon-label" data-pick-action="${key}"><span class="action-key">${key}</span>${t(`Voir mes cartes ${key}`, `Show my ${key} cards`)}</button>` : ""}</template>`;
|
||||
`<template>${key === "B" ? "" : `<div class="system-detail-art">${illustration(art)}</div>`}<p class="room-location">${esc(zoneName(zone))} · ${deck === "upper" ? t("Pont supérieur", "Upper deck") : t("Pont inférieur", "Lower deck")}</p>${extra}<p>${esc(actionWords(text))}</p><p class="planning-note">${t(`Programmez ${actionName(key)} à un tour où votre équipier sera dans cette salle. Une panne de ce système fait utiliser l’action pour la réparer.`, `Program ${actionName(key)} on a turn when your crew member will be in this room. A malfunction of this system makes the action repair it instead.`)}</p>${canPlan ? `<button class="primary icon-label" data-pick-action="${key}"><span class="action-key">${pictogram(key)}</span>${t(`Voir mes cartes ${actionName(key)}`, `Show my ${actionName(key)} cards`)}</button>` : ""}</template>`;
|
||||
return `<div class="systems illustrated-systems">
|
||||
<div class="system-card weapon-system"><button title="${esc(weapon)}" data-inspect="system-${station}-A" data-inspect-title="${esc(weapon)}" aria-haspopup="dialog" aria-label="${esc(`${weapon} · A · ${t("Puissance", "Power")} ${power}`)}"><span class="action-key">A</span>${illustration(weaponArt)}<span class="system-caption"><strong>${t("Tirer", "Fire")}</strong><span class="power-value">${symbol("hull", t("Puissance de tir", "Firepower"), power)}</span></span></button>${details("A", weaponArt, fireText, `<div class="weapon-facts">${symbol("hull", `${t("Puissance", "Power")} ${power}`, power)}${symbol(light ? "check" : "reactor", light ? t("Batterie autonome", "Own battery") : t("Coût : 1 énergie", "Cost: 1 energy"), light ? t("Autonome", "Own battery") : "−1")}</div>`)}</div>
|
||||
<div class="system-card energy-system ${s[system] === 0 ? "depleted" : ""}"><button data-inspect="system-${station}-B" data-inspect-title="${esc(charge)}" aria-haspopup="dialog" aria-label="${esc(`${charge} · B · ${s[system]}/${capacity}`)}"><span class="action-key">B</span>${illustration(system)}<span class="system-caption"><strong>${t("Charger", "Charge")}</strong><b class="energy-value">${s[system]}/${capacity}</b>${meter(s[system], capacity)}</span></button>${details("B", system, chargeText, flow)}</div>
|
||||
<div class="system-card special-system"><button title="${esc(c)}" data-inspect="system-${station}-C" data-inspect-title="${esc(c)}" aria-haspopup="dialog" aria-label="C · ${esc(c)}"><span class="action-key">C</span>${illustration(cIcon)}<span class="system-caption"><strong>${esc(c)}</strong></span></button>${details("C", cIcon, cText)}</div>
|
||||
<div class="system-card weapon-system"><button title="${esc(weapon)}" data-inspect="system-${station}-A" data-inspect-title="${esc(weapon)}" aria-haspopup="dialog" aria-label="${esc(`${weapon} · A · ${t("Puissance", "Power")} ${power}`)}"><span class="action-key">${pictogram("A")}</span>${illustration(weaponArt)}<span class="system-caption"><strong>${t("Tirer", "Fire")}</strong><span class="power-value">${symbol("hull", t("Puissance de tir", "Firepower"), power)}</span></span></button>${details("A", weaponArt, fireText, `<div class="weapon-facts">${symbol("hull", `${t("Puissance", "Power")} ${power}`, power)}${symbol(light ? "check" : "reactor", light ? t("Batterie autonome", "Own battery") : t("Coût : 1 énergie", "Cost: 1 energy"), light ? t("Autonome", "Own battery") : "−1")}</div>`)}</div>
|
||||
<div class="system-card energy-system ${s[system] === 0 ? "depleted" : ""}"><button data-inspect="system-${station}-B" data-inspect-title="${esc(charge)}" aria-haspopup="dialog" aria-label="${esc(`${charge} · B · ${s[system]}/${capacity}`)}"><span class="action-key">${pictogram("B")}</span>${illustration(system)}<span class="system-caption"><strong>${t("Charger", "Charge")}</strong><b class="energy-value">${s[system]}/${capacity}</b>${meter(s[system], capacity)}</span></button>${details("B", system, chargeText, flow)}</div>
|
||||
<div class="system-card special-system"><button title="${esc(c)}" data-inspect="system-${station}-C" data-inspect-title="${esc(c)}" aria-haspopup="dialog" aria-label="C · ${esc(c)}"><span class="action-key">${pictogram("C")}</span>${illustration(cIcon)}<span class="system-caption"><strong>${esc(c)}</strong></span></button>${details("C", cIcon, cText)}</div>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
function shipCutaway({ ship, selectedCrew, canPlan, crewLabel }) {
|
||||
function shipCutaway({
|
||||
ship,
|
||||
selectedCrew,
|
||||
canPlan,
|
||||
crewLabel,
|
||||
isAndroid = () => false,
|
||||
}) {
|
||||
const zones = ["red", "white", "blue"];
|
||||
const movementHelp = (lift) =>
|
||||
`<template><div class="passage-explanation">${pictogram(lift ? "lift" : "move")}</div><p>${lift ? t("Programmez une carte ↑↓ pour changer de pont dans cette zone.", "Program an ↑↓ card to change deck in this zone.") : t("Programmez une flèche gauche ou droite pour passer dans la salle voisine du même pont.", "Program a left or right arrow to enter the next room on the same deck.")}</p>${canPlan ? `<button class="primary icon-label" data-pick-action="move">${pictogram("move")}${t("Voir mes déplacements", "Show my movement cards")}</button>` : ""}</template>`;
|
||||
|
|
@ -128,8 +141,8 @@ export function createTacticalView({
|
|||
const [cIcon, c] = {
|
||||
"red-upper": ["interceptor", t("Intercepteurs", "Interceptors")],
|
||||
"white-upper": ["computer", t("Ordinateur", "Computer")],
|
||||
"blue-upper": ["bots", t("Robots", "Battlebots")],
|
||||
"red-lower": ["bots", t("Robots", "Battlebots")],
|
||||
"blue-upper": ["bots", t("Robots de combat", "Battlebots")],
|
||||
"red-lower": ["bots", t("Robots de combat", "Battlebots")],
|
||||
"white-lower": [
|
||||
"observation",
|
||||
t("Observation", "Visual confirmation"),
|
||||
|
|
@ -147,12 +160,12 @@ export function createTacticalView({
|
|||
level === "upper"
|
||||
? t("Pont supérieur", "Upper deck")
|
||||
: t("Pont inférieur", "Lower deck");
|
||||
return `<section class="station ${occupants.some((p) => p.id === selectedCrew) ? "selected-station" : ""}" data-station="${station}" style="--zone:var(--${zone})" aria-label="${esc(zoneName(zone))} · ${deckName}"><div class="station-title">${esc(zoneName(zone))}${symbol(level === "upper" ? "up" : "down", deckName)}${level === "upper" && s.damage.length ? `<span class="damage">${symbol("warning", `${t("Dégâts de la zone", "Zone damage")} : ${s.damage.length}/6`, `${s.damage.length}/6`)}</span>` : ""}</div>${stationControls({ station, zone, deck: level, ship, power, capacity, system, cIcon, c, canPlan })}<div class="occupants">${occupants.map((p) => `<span style="${playerColor(p.id) ? `--player-color:${playerColor(p.id)};--player-stroke:#c4d4e0` : ""}" class="crew-pawn ${p.id === selectedCrew ? "selected" : ""} ${p.knockedOut ? "out" : ""}" role="img" title="${esc(crewLabel(p.id))}${p.knockedOut ? " · " + t("Hors combat", "Knocked out") : ""}${p.bots !== null ? " · " + t("Robots", "Battlebots") : ""}" aria-label="${esc(crewLabel(p.id))}${p.knockedOut ? " · " + t("Hors combat", "Knocked out") : ""}${p.bots !== null ? " · " + t("Robots", "Battlebots") : ""}"><svg viewBox="0 0 24 30" aria-hidden="true"><path d="M4 28v-9a8 8 0 0 1 16 0v9Z"/><circle cx="12" cy="8" r="7"/><path class="visor" d="M7 6h10v5H7z"/></svg><b>${p.id + 1}</b>${p.bots !== null ? `<i>${pictogram("bots")}</i>` : ""}</span>`).join("")}</div></section>`;
|
||||
return `<section class="station ${occupants.some((p) => p.id === selectedCrew) ? "selected-station" : ""}" data-station="${station}" style="--zone:var(--${zone})" aria-label="${esc(zoneName(zone))} · ${deckName}"><div class="station-title">${symbol(level === "upper" ? "up" : "down", deckName)}${level === "upper" && s.damage.length ? `<span class="damage">${symbol("warning", `${t("Dégâts de la zone", "Zone damage")} : ${s.damage.length}/6`, `${s.damage.length}/6`)}</span>` : ""}</div>${stationControls({ station, zone, deck: level, ship, power, capacity, system, cIcon, c, canPlan })}<div class="occupants">${occupants.map((p) => `<span style="${playerColor(p.id) ? `--player-color:${playerColor(p.id)};--player-stroke:#c4d4e0` : ""}" class="crew-pawn ${p.id === selectedCrew ? "selected" : ""} ${p.knockedOut ? "out" : ""}" role="img" title="${esc(crewLabel(p.id))}${p.knockedOut ? " · " + t("Hors combat", "Knocked out") : ""}${p.bots !== null ? " · " + t("Robots de combat", "Battlebots") : ""}" aria-label="${esc(crewLabel(p.id))}${p.knockedOut ? " · " + t("Hors combat", "Knocked out") : ""}${p.bots !== null ? " · " + t("Robots de combat", "Battlebots") : ""}">${isAndroid(p.id) ? equipmentPicture("android") : pictogram("crew")}<b>${p.id + 1}</b>${p.bots !== null ? `<i>${pictogram("bots")}</i>` : ""}</span>`).join("")}</div></section>`;
|
||||
})
|
||||
.join(
|
||||
"",
|
||||
)}${[1, 2].map((i) => `<div class="ship-passage passage-${i}"><button data-inspect="door-${level}-${i}" data-inspect-title="${t("Portes · Même pont", "Doors · Same deck")}" aria-label="${t("Passage", "Passage")} ${esc(zoneName(zones[i - 1]))} ↔ ${esc(zoneName(zones[i]))} · ${level === "upper" ? t("Pont supérieur", "Upper deck") : t("Pont inférieur", "Lower deck")}" aria-haspopup="dialog">${pictogram("move")}</button>${movementHelp(false)}</div>`).join("")}</div>`;
|
||||
return `<div class="ship-bow" aria-hidden="true"><svg viewBox="0 0 600 46" preserveAspectRatio="none"><path class="hull-shell" d="M8 45 40 24 200 12 240 3h120l40 9 160 12 32 21Z"/><path class="bridge-window" d="m237 16 11-6h104l11 6-13 12H250Z"/><path d="M275 11v16m50-16v16M32 39h135m266 0h135"/></svg></div>${deck("upper")}<div class="between-decks"><svg class="energy-conduits" viewBox="0 0 600 44" preserveAspectRatio="none" aria-hidden="true"><path class="conduit-back" d="M300 44V28H120V44m180-16h180v16M100 44V0M300 28V0M500 44V0"/><path d="M300 44V28H120V44m180-16h180v16M100 44V0M300 28V0M500 44V0"/><path d="m96 6 4-4 4 4m192 0 4-4 4 4m192 0 4-4 4 4M116 38l4 4 4-4m352 0 4 4 4-4M193 24l-5 4 5 4m214-8 5 4-5 4"/></svg>${zones.map((z) => `<div class="lift-bay"><button class="lift-control ${ship.zones[z].damage.includes("lift") ? "damaged-lift" : ""}" data-inspect="lift-${z}" data-inspect-title="${t("Ascenseur", "Gravolift")} · ${esc(zoneName(z))}" aria-label="${t("Ascenseur", "Gravolift")} · ${esc(zoneName(z))}${ship.zones[z].damage.includes("lift") ? " · " + t("Endommagé", "Damaged") : ""}" aria-haspopup="dialog">${pictogram("lift")}</button>${movementHelp(true)}</div>`).join("")}</div>${deck("lower")}<div class="ship-stern" aria-hidden="true">${zones.map(() => `<span><i></i><i></i><i></i></span>`).join("")}</div><div class="ship-key"><span><b>A</b>${t("Tirer", "Fire")}</span><span><b>B</b>${t("Énergie", "Energy")}</span><span><b>C</b>${t("Systèmes", "Systems")}</span></div>`;
|
||||
return `<div class="ship-hull"><div class="ship-bow" aria-hidden="true"><svg viewBox="0 0 600 46" preserveAspectRatio="none"><path class="hull-shell" d="M2 46V32L40 20 200 10 240 3h120l40 7 160 10 38 12v14"/><path class="bridge-window" d="m237 16 11-6h104l11 6-13 12H250Z"/><path d="M275 11v16m50-16v16M32 39h135m266 0h135"/></svg></div>${deck("upper")}<div class="between-decks"><svg class="energy-conduits" viewBox="0 0 600 44" preserveAspectRatio="none" aria-hidden="true"><path class="conduit-back" d="M300 44V28H120V44m180-16h180v16M100 44V0M300 28V0M500 44V0"/><path d="M300 44V28H120V44m180-16h180v16M100 44V0M300 28V0M500 44V0"/><path d="m96 6 4-4 4 4m192 0 4-4 4 4m192 0 4-4 4 4M116 38l4 4 4-4m352 0 4 4 4-4M193 24l-5 4 5 4m214-8 5 4-5 4"/></svg>${zones.map((z) => `<div class="lift-bay"><button class="lift-control ${ship.zones[z].damage.includes("lift") ? "damaged-lift" : ""}" data-inspect="lift-${z}" data-inspect-title="${t("Ascenseur", "Gravolift")} · ${esc(zoneName(z))}" aria-label="${t("Ascenseur", "Gravolift")} · ${esc(zoneName(z))}${ship.zones[z].damage.includes("lift") ? " · " + t("Endommagé", "Damaged") : ""}" aria-haspopup="dialog">${pictogram("lift")}</button>${movementHelp(true)}</div>`).join("")}</div>${deck("lower")}</div><div class="ship-stern" aria-hidden="true">${zones.map(() => `<span><i></i><i></i><i></i></span>`).join("")}</div><div class="ship-key"><span>${pictogram("A")}${t("Tirer", "Fire")}</span><span>${pictogram("B")}${t("Énergie", "Energy")}</span><span>${pictogram("C")}${t("Systèmes", "Systems")}</span></div>`;
|
||||
}
|
||||
|
||||
function threatPortrait(th) {
|
||||
|
|
@ -180,7 +193,7 @@ export function createTacticalView({
|
|||
.join(", ")}`
|
||||
: `${t("Trajectoire", "Trajectory")} : ${zoneName(th.zone)}`;
|
||||
const target = `<span class="threat-target" style="--zone:var(--${["red", "white", "blue"].includes(th.zone) ? th.zone : "cyan"})" role="img" aria-label="${esc(targetName)}" title="${esc(targetName)}">${shipLocator(stations, internal ? null : th.zone)}</span>`;
|
||||
return `<span class="threat-portrait ${gone ? "resolved-threat" : ""}">${visual}<span class="threat-hud"><span class="hull-gauge"><span>${symbol("hull", `${t("Points de vie", "Hit points")} : ${hp}/${th.hp}`, `<b>${hp}<small>/${th.hp}</small></b>`)}</span><span class="hull-bar"><i style="width:${Math.max(0, Math.min(100, (hp / Math.max(1, th.hp)) * 100))}%"></i></span></span>${target}<span class="shield-badge">${symbol("shield", `${t("Bouclier", "Shield")} : ${th.shield}`, `<b>${th.shield}</b>`)}</span></span>${status ? `<span class="threat-outcome">${esc(status)}</span>` : ""}</span>`;
|
||||
return `<span class="threat-portrait ${gone ? "resolved-threat" : ""}">${target}${visual}<span class="threat-hud"><span class="hull-gauge"><span>${symbol("hull", `${t("Points de vie", "Hit points")} : ${hp}/${th.hp}`, `<b>${hp}<small>/${th.hp}</small></b>`)}</span><span class="hull-bar"><i style="width:${Math.max(0, Math.min(100, (hp / Math.max(1, th.hp)) * 100))}%"></i></span></span><span class="shield-badge">${symbol("shield", `${t("Bouclier", "Shield")} : ${th.shield}`, `<b>${th.shield}</b>`)}</span></span>${status ? `<span class="threat-outcome">${esc(status)}</span>` : ""}</span>`;
|
||||
}
|
||||
return { shipCutaway, threatPortrait };
|
||||
}
|
||||
|
|
|
|||
7
preview/tutorial-entry.js
Normal file
7
preview/tutorial-entry.js
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import { mountLesson } from "../bgs/tutorial.js";
|
||||
const query = new URL(location.href).searchParams;
|
||||
mountLesson(document.body, {
|
||||
chapter: query.get("chapter") ?? "basics",
|
||||
locale: query.get("locale") ?? "fr",
|
||||
standalone: true,
|
||||
}).catch(error => { document.body.textContent = error.message; });
|
||||
50
src/tutorial-controller.js
Normal file
50
src/tutorial-controller.js
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
import { createTutorial } from "@boardgamers/protocol/tutorial";
|
||||
import { LESSONS, createLesson } from "./tutorials.js";
|
||||
import { advanceClock, submit } from "./session.js";
|
||||
|
||||
export function completedTurns(state) {
|
||||
const r = state.game.resolution;
|
||||
return r?.step === "damage" ? r.turn : Math.max(0, (r?.turn ?? 0) - 1);
|
||||
}
|
||||
|
||||
// BGS owns checkpoints and saved action history. All moves still use our engine.
|
||||
export function createLessonTutorial(id, { locale = "en", storage, onProgress } = {}) {
|
||||
const lesson = LESSONS.find(l => l.id === id);
|
||||
if (!lesson) throw Error("Unknown lesson");
|
||||
const t = (fr, en) => locale === "fr" ? fr : en;
|
||||
return createTutorial({
|
||||
game: "space-alert", id, version: 2, storage, onProgress,
|
||||
initialState: () => createLesson(id, 1000),
|
||||
move(state, move) {
|
||||
if (move.type === "practice-phase") {
|
||||
if (state.stage !== "programming") throw Error("Planning has ended");
|
||||
return advanceClock(state, state.missionStartAt + state.mission.phaseEndsMs[state.phase - 1]);
|
||||
}
|
||||
if (move.type === "practice-clock") {
|
||||
if (state.stage !== "programming") throw Error("Planning has ended");
|
||||
state.tutorial.clockRunning = !!move.running;
|
||||
state.revision++;
|
||||
return state;
|
||||
}
|
||||
if (move.type === "practice-tick") {
|
||||
if (!state.tutorial.clockRunning || state.stage !== "programming") return state;
|
||||
if (!Number.isSafeInteger(move.ms) || move.ms < 0) throw Error("Invalid practice time");
|
||||
return advanceClock(state, state.observedAt + move.ms);
|
||||
}
|
||||
const result = submit(state, 0, { ...move, sequence: state.players[0].lastSequence + 1 }, state.observedAt);
|
||||
if (!result.accepted) throw Error(result.error);
|
||||
return result.state;
|
||||
},
|
||||
steps: [
|
||||
{ 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."),
|
||||
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 },
|
||||
],
|
||||
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.") },
|
||||
});
|
||||
}
|
||||
|
|
@ -9,6 +9,12 @@ const lesson = (id, title, instructions, options = {}) => ({
|
|||
...options,
|
||||
});
|
||||
export const LESSONS = [
|
||||
lesson(
|
||||
"basics",
|
||||
["Commencer ici : programmer les tours", "Start here: planning turns"],
|
||||
[],
|
||||
{ basics: true },
|
||||
),
|
||||
lesson(
|
||||
"first-shot",
|
||||
["Votre premier tir", "Your first shot"],
|
||||
|
|
@ -155,7 +161,7 @@ export function createLesson(id, now) {
|
|||
id: `lesson-${id}`,
|
||||
title: l.title[1],
|
||||
doubleActions: !!l.doubleActions,
|
||||
phaseEndsMs: [600000, 1200000],
|
||||
phaseEndsMs: [300000, 600000],
|
||||
events: l.threat
|
||||
? [
|
||||
{
|
||||
|
|
@ -186,7 +192,13 @@ export function createLesson(id, now) {
|
|||
);
|
||||
s = submit(s, 0, { type: "ready", sequence: 1 }, now).state;
|
||||
s = advanceClock(s, now + 3000);
|
||||
s.tutorial = { id, title: l.title, instructions: l.instructions };
|
||||
s.tutorial = {
|
||||
id,
|
||||
title: l.title,
|
||||
instructions: l.instructions,
|
||||
basics: !!l.basics,
|
||||
clockRunning: false,
|
||||
};
|
||||
s.game.tracks = Object.fromEntries(
|
||||
["red", "white", "blue", "internal"].map((z) => [
|
||||
z,
|
||||
|
|
|
|||
|
|
@ -227,3 +227,66 @@ test("career progress is bounded, contains no mission secrets, and rejects unkno
|
|||
assert.equal(next.players[0].ready, false);
|
||||
assert.equal(next.players[0].lastSequence, 0);
|
||||
});
|
||||
|
||||
test("table careers survive sitting out a game without gating the current crew", () => {
|
||||
const old = initial({ careers: true });
|
||||
old.bgs.explorers.alice.level = 2;
|
||||
old.bgs.explorers.alice.xp = 24;
|
||||
// Bob is still level zero and must not prevent Alice's solo campaign.
|
||||
const progress = e.tableProgress(e.dropPlayer(old));
|
||||
const solo = e.init(
|
||||
1,
|
||||
[],
|
||||
{ careers: true, campaign: 3 },
|
||||
"solo",
|
||||
0,
|
||||
ctx(2000, {
|
||||
gameId: "solo",
|
||||
playerIds: ["alice"],
|
||||
present: [0],
|
||||
table: { id: "table", round: 2, progress },
|
||||
}),
|
||||
);
|
||||
assert.equal(solo.bgs.explorers.bob.level, 0);
|
||||
assert.deepEqual(
|
||||
e.stripSecret(solo, 0, ctx(2000)).explorers.map((x) => x.id),
|
||||
["alice"],
|
||||
);
|
||||
const soloProgress = e.tableProgress(e.dropPlayer(solo));
|
||||
const disabled = e.init(
|
||||
1,
|
||||
[],
|
||||
{ careers: false },
|
||||
"disabled",
|
||||
0,
|
||||
ctx(3000, {
|
||||
gameId: "disabled",
|
||||
playerIds: ["bob"],
|
||||
present: [0],
|
||||
table: { id: "table", round: 3, progress: soloProgress },
|
||||
}),
|
||||
);
|
||||
assert.deepEqual(e.stripSecret(disabled, 0, ctx(3000)).explorers, []);
|
||||
const returned = e.init(
|
||||
2,
|
||||
[],
|
||||
{ careers: true },
|
||||
"return",
|
||||
0,
|
||||
ctx(4000, {
|
||||
gameId: "return",
|
||||
playerIds: ["bob", "alice"],
|
||||
table: {
|
||||
id: "table",
|
||||
round: 4,
|
||||
progress: e.tableProgress(e.dropPlayer(disabled)),
|
||||
},
|
||||
}),
|
||||
);
|
||||
assert.equal(returned.bgs.explorers.alice.xp, 24);
|
||||
assert.equal(returned.bgs.explorers.alice.level, 2);
|
||||
assert.equal(returned.bgs.explorers.alice.activeRun, null);
|
||||
assert.equal(returned.players[1].lastSequence, 0);
|
||||
assert.equal(returned.players[1].ready, false);
|
||||
assert.equal(progress.data.explorers.alice.xp, 24);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -205,3 +205,96 @@ test("untimed lessons advance only explicitly and remain paused after restart",
|
|||
await rm(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("practice clock starts, pauses, resumes without charging paused time, and rejects ordinary games", async () => {
|
||||
let now = 1000;
|
||||
const server = createPreviewServer({ clock: () => now });
|
||||
server.listen(0, "127.0.0.1");
|
||||
await once(server, "listening");
|
||||
const base = `http://127.0.0.1:${server.address().port}`;
|
||||
const post = (path, body) =>
|
||||
fetch(base + path + "?seat=0", {
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/json" },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
const state = () => fetch(base + "/api/state?seat=0").then((r) => r.json());
|
||||
try {
|
||||
assert.equal(
|
||||
(await post("/api/lesson-clock", { running: true })).status,
|
||||
400,
|
||||
);
|
||||
let s = await (await post("/api/lesson", { lesson: "basics" })).json();
|
||||
const start = s.serverNow;
|
||||
now += 1000000;
|
||||
assert.equal((await state()).serverNow, start);
|
||||
s = await (await post("/api/lesson-clock", { running: true })).json();
|
||||
assert.equal(s.tutorial.clockRunning, true);
|
||||
now += 12000;
|
||||
s = await (await post("/api/lesson-clock", { running: false })).json();
|
||||
assert.equal(s.serverNow, start + 12000);
|
||||
now += 1000000;
|
||||
assert.equal((await state()).serverNow, start + 12000);
|
||||
await post("/api/lesson-clock", { running: true });
|
||||
now += 5000;
|
||||
assert.equal((await state()).serverNow, start + 17000);
|
||||
now += 300000;
|
||||
s = await state();
|
||||
assert.equal(s.phase, 2);
|
||||
assert.equal(s.game.ship.crew[0].station, "white-upper");
|
||||
await post("/api/lesson-clock", { running: false });
|
||||
now += 1000000;
|
||||
assert.equal((await state()).phase, 2);
|
||||
} finally {
|
||||
server.closeAllConnections();
|
||||
await new Promise((resolve) => server.close(resolve));
|
||||
}
|
||||
});
|
||||
|
||||
test("basics can return from playback to an editable plan with cards preserved", async () => {
|
||||
const server = createPreviewServer({ clock: () => 1000 });
|
||||
server.listen(0, "127.0.0.1");
|
||||
await once(server, "listening");
|
||||
const base = `http://127.0.0.1:${server.address().port}`;
|
||||
const post = async (path, body = {}) => {
|
||||
const response = await fetch(base + path + "?seat=0", {
|
||||
method: "POST", headers: { "content-type": "application/json" },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
assert.equal(response.status, 200);
|
||||
return response.json();
|
||||
};
|
||||
try {
|
||||
let s = await post("/api/lesson", { lesson: "basics" });
|
||||
const card = s.game.hand.find(c => c.sides.some(side => side[0] === "blue"));
|
||||
s = (await post("/api/command", {
|
||||
type: "program", sequence: s.nextSequence, crew: 0, turn: 1,
|
||||
slotVersion: s.game.programs[0][0].revision,
|
||||
cards: [{ id: card.id, side: card.sides.findIndex(side => side[0] === "blue") }],
|
||||
})).view;
|
||||
const plan = structuredClone(s.game.programs[0]);
|
||||
await post("/api/lesson-next");
|
||||
s = await post("/api/lesson-next");
|
||||
for (let i = 0; i < 10; i++) {
|
||||
s = (await post("/api/command", { type: "resolve", sequence: s.nextSequence })).view;
|
||||
if (s.game.resolution.turn === 1 && s.game.resolution.step === "damage") break;
|
||||
}
|
||||
assert.equal(s.game.ship.crew[0].station, "blue-upper");
|
||||
const revision = s.revision;
|
||||
s = await post("/api/lesson-back");
|
||||
assert.equal(s.stage, "programming");
|
||||
assert.equal(s.phase, 1);
|
||||
assert.equal(s.tutorial.clockRunning, false);
|
||||
assert.ok(s.revision > revision);
|
||||
assert.equal(s.game.ship.crew[0].station, "white-upper");
|
||||
assert.deepEqual(s.game.programs[0], plan);
|
||||
const removed = await post("/api/command", {
|
||||
type: "remove", sequence: s.nextSequence, crew: 0, turn: 1,
|
||||
slotVersion: s.game.programs[0][0].revision,
|
||||
});
|
||||
assert.equal(removed.accepted, true);
|
||||
} finally {
|
||||
server.closeAllConnections();
|
||||
await new Promise(resolve => server.close(resolve));
|
||||
}
|
||||
});
|
||||
|
|
|
|||
55
test/tutorial-controller.test.js
Normal file
55
test/tutorial-controller.test.js
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { snapshot } from "../src/view.js";
|
||||
import { createLessonTutorial, completedTurns } from "../src/tutorial-controller.js";
|
||||
|
||||
async function place(tutorial, turn, direction) {
|
||||
const s = tutorial.snapshot.state;
|
||||
const id = s.game.hands[0].find(id => s.game.cards[id].sides.some(side => side.length === 1 && side[0] === direction));
|
||||
const side = s.game.cards[id].sides.findIndex(side => side.length === 1 && side[0] === direction);
|
||||
assert.equal(await tutorial.play({ type: "program", crew: 0, turn,
|
||||
slotVersion: s.game.slotVersions[0][turn - 1], cards: [{ id, side }] }), true, tutorial.snapshot.error);
|
||||
}
|
||||
|
||||
test("BGS tutorial validates moves, saves progress, and restores native checkpoints", async () => {
|
||||
const data = new Map();
|
||||
const storage = { getItem: key => data.get(key), setItem: (key, value) => data.set(key, value) };
|
||||
const t = await createLessonTutorial("basics", { storage });
|
||||
assert.equal(t.snapshot.step, 0);
|
||||
await t.continue();
|
||||
await place(t, 1, "blue");
|
||||
await place(t, 2, "red");
|
||||
assert.equal(snapshot(t.snapshot.state, 0).game.ship.crew[0].station, "white-upper");
|
||||
assert.equal(t.snapshot.step, 1);
|
||||
await t.play({ type: "practice-phase" });
|
||||
await t.play({ type: "practice-phase" });
|
||||
assert.equal(t.snapshot.step, 2);
|
||||
assert.equal(completedTurns(t.snapshot.state), 0);
|
||||
for (let i = 0; i < 10 && completedTurns(t.snapshot.state) < 1; i++)
|
||||
assert.equal(await t.play({ type: "resolve" }), true);
|
||||
assert.equal(t.snapshot.state.game.resolution.ship.crew[0].station, "blue-upper");
|
||||
const restored = await createLessonTutorial("basics", { storage });
|
||||
assert.deepEqual(restored.snapshot.state, t.snapshot.state);
|
||||
await restored.restartStep();
|
||||
assert.equal(restored.snapshot.step, 2);
|
||||
assert.equal(completedTurns(restored.snapshot.state), 0);
|
||||
assert.ok(restored.snapshot.state.game.programs[0][0].cards.length);
|
||||
await restored.previousStep();
|
||||
assert.equal(restored.snapshot.step, 1);
|
||||
assert.equal(restored.snapshot.state.stage, "programming");
|
||||
assert.equal(restored.snapshot.state.game.programs[0][0], null);
|
||||
await place(restored, 1, "red");
|
||||
restored.destroy(); t.destroy();
|
||||
});
|
||||
|
||||
test("practice clock advances planning only; resolution remains untimed", async () => {
|
||||
const t = await createLessonTutorial("basics");
|
||||
await t.continue();
|
||||
await t.play({ type: "practice-clock", running: true });
|
||||
await t.play({ type: "practice-tick", ms: 600000 });
|
||||
assert.equal(t.snapshot.step, 2);
|
||||
assert.equal(completedTurns(t.snapshot.state), 0);
|
||||
await t.play({ type: "practice-tick", ms: 600000 });
|
||||
assert.equal(completedTurns(t.snapshot.state), 0);
|
||||
t.destroy();
|
||||
});
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { LESSONS, createLesson } from "../src/tutorials.js";
|
||||
import { snapshot } from "../src/view.js";
|
||||
import { submit, advanceClock } from "../src/session.js";
|
||||
import {
|
||||
traitDescriptions,
|
||||
|
|
@ -119,3 +120,20 @@ test("every catalogue effect has explanatory FR and EN text, and replay names wo
|
|||
/Fighter/,
|
||||
);
|
||||
});
|
||||
|
||||
test("first lesson separates planning from movement and an empty turn waits", () => {
|
||||
let s = createLesson("basics", 0);
|
||||
s = program(s, 0, 1, ["blue"]);
|
||||
s = program(s, 0, 2, ["red"]);
|
||||
assert.equal(snapshot(s, 0).game.ship.crew[0].station, "white-upper");
|
||||
const r = resolve(s);
|
||||
for (const [turn, station] of [
|
||||
[1, "blue-upper"],
|
||||
[2, "white-upper"],
|
||||
[3, "white-upper"],
|
||||
]) {
|
||||
const frame = r.frames.find((f) => f.turn === turn && f.step === "damage");
|
||||
assert.equal(frame.ship.crew[0].station, station);
|
||||
}
|
||||
assert.equal(r.threats.length, 0);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue