From b201aceec4e4399f4087b3afb6d7b436ed526d8d Mon Sep 17 00:00:00 2001 From: coyotte508 Date: Sat, 31 Oct 2026 19:53:33 +0100 Subject: [PATCH] Teach mission planning, preview intended routes and lazy-load locales --- AGENTS.md | 12 +- README.md | 39 +- bgs/gameinfo.json | 103 +++- bgs/pictogram.svg | 12 + bgs/tutorial.js | 341 ++++++++++-- bgs/viewer.js | 233 ++++---- package-lock.json | 4 +- package.json | 3 +- preview/app.js | 733 +++++++++++++++---------- preview/basics.js | 96 ++-- preview/i18n.js | 103 ++++ preview/index.html | 111 ++-- preview/local.js | 4 + preview/locales/en.json | 595 ++++++++++++++++++++ preview/locales/fr.json | 595 ++++++++++++++++++++ preview/navigation.js | 21 +- preview/program-route.js | 36 ++ preview/server.js | 6 + preview/sound.js | 68 ++- preview/style.css | 39 ++ preview/tactical.js | 121 ++--- preview/text.js | 905 ++++++++++--------------------- preview/tutorial-entry.js | 6 +- scripts/build.mjs | 34 +- src/tutorial-controller.js | 256 ++++++++- src/tutorials.js | 131 ++--- test/bgs.test.js | 2 + test/locales.test.js | 131 +++++ test/program-route.test.js | 53 ++ test/tutorial-controller.test.js | 189 ++++++- test/tutorials.test.js | 2 + 31 files changed, 3537 insertions(+), 1447 deletions(-) create mode 100644 bgs/pictogram.svg create mode 100644 preview/i18n.js create mode 100644 preview/locales/en.json create mode 100644 preview/locales/fr.json create mode 100644 preview/program-route.js create mode 100644 test/locales.test.js create mode 100644 test/program-route.test.js diff --git a/AGENTS.md b/AGENTS.md index 4b2e445..179dbb1 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -9,7 +9,7 @@ ## BGS tables and clock -Read [integration notes](docs/realtime-host.md) before touching lifecycle code. Protocol **0.8** is published; native presence, wakeups and table progress already exist. Do not rebuild them with viewer heartbeat moves. +Read [integration notes](docs/realtime-host.md) before touching lifecycle code. Protocol **0.10.0** is published; native presence, wakeups and table progress already exist. Do not rebuild them with viewer heartbeat moves. - Preserve `tableMode: "live"`, `timeControl: "engine"`, `rating: "none"`. Readiness expires after two minutes; BGS uses a ten-second launch countdown. Expiry/disconnection before launch returns to waiting, not cancellation. Reconnection during flight does not pause or restart it. - A campaign stays within one game. **Play again** creates a new game at the same table; only versioned `tableProgress` crosses that boundary. Careers are keyed by account ID, not seat, and remain table-local. Reject unknown checkpoint schemas rather than erasing progress. @@ -19,8 +19,14 @@ Read [integration notes](docs/realtime-host.md) before touching lifecycle code. ## Publication and verification - GitHub remote: `boardgamers/space-alert`. BGS slug `space-alert`, version **1**, stays **private** until explicitly requested otherwise. Git pushes do not update BGS. -- `npm test`, `npm run build`, then `npm pack`; upload the tarball with entry `bgs/engine.js` and `dist/viewer.js` with global `SpaceAlert`. Follow [README](README.md#build-for-bgs); `bgs/gameinfo.json` is a metadata template, not a snapshot of the deployed package version. -- BGS admin API base: `https://admin.boardgamers.space/api/admin/gameinfo/space-alert`. Load the bearer token from `~/.bgs` without printing it. Read/back up `/1` and `/meta` first; POST the tarball to `/1/engine`, POST the viewer to `/1/viewer/file?filename=viewer.js&bundle=`, then PUT `/1` with the returned asset metadata while preserving unrelated settings. Verify the private flag, clock/table settings and downloaded viewer bytes afterward. Bump the package version for engine changes. +- `npm test`, `npm run build`, then `npm pack`; upload the tarball with entry `bgs/engine.js` and the complete viewer bundle (`dist/viewer.js` plus `dist/locales/*.json`, preserving paths) with global `SpaceAlert`. Follow [README](README.md#build-for-bgs); `bgs/gameinfo.json` is a metadata template, not a snapshot of the deployed package version. +- BGS admin API base: `https://admin.boardgamers.space/api/admin/gameinfo/space-alert`. Load the bearer token from `~/.bgs` without printing it. Read/back up `/1` and `/meta` first; POST the tarball to `/1/engine`, POST each viewer bundle file to `/1/viewer/file?filename=&bundle=`, then PUT `/1` with the returned asset metadata while preserving unrelated settings. Verify the private flag, clock/table settings and downloaded viewer bytes afterward. Bump the package version for engine changes. +- Follow the current [Adding a game guide](https://docs.boardgamers.space/guide/adding-a-game); the sibling monorepo has the same source at `apps/docs/docs/guide/adding-a-game.md`. The public-release checklist is not satisfied merely by this private playtest. +- Stage only `viewer.js` and the current hashed `locales/*.json` in a clean release directory; exclude `viewer-meta.json`. The sibling `scripts/publish-viewer.mjs --game space-alert --version 1 --dir --entry viewer.js --token ~/.bgs --record --apply --activate` uploads and verifies every file before switching the viewer URL. Do not update only the entry script. +- Publish `version.tutorial` from `bgs/gameinfo.json` with the viewer; IDs and progress versions must match the controller. Use English base titles and empty descriptions, not translated subtitles. In-game translations are authored EN/FR JSON chunks; other BGS locales currently fall back to English. +- `/meta` protects `translations` and `optionTranslations`; round-tripping those fields does not publish them. As in Puerto Rico, use BGS's dedicated `/meta/translate` or `/meta/translate-all` for platform catalog/setup/chapter metadata only, and verify hashes and chapter labels afterward. Do not use translation APIs for authored in-game/tutorial catalogs. +- Upload the original, tightly bounded transparent `bgs/pictogram.svg` with `PUT /assets/pictogram`, content type `image/svg+xml`. The server crops transparent borders and normalizes it. Save only the intended metadata fields (description, etc.), not a stale full metadata snapshot. +- Engine upload immediately changes the requested package; installation/activation is asynchronous. Verify tarball/download integrity and distinguish requested metadata from confirmed activation. Keep `public: false`, `timeControl: "engine"`, `tableMode: "live"`, and `rating: "none"`; never create production test tables or alter existing missions just to check a release. - Lifecycle changes need multi-client checks: expired readiness, background/disconnected tabs, late commands, reconnect, and Play again with seats reordered/careers retained. Rules tests alone do not validate deployed table behavior or phone audio. Broader expansion playtesting remains necessary before public release. ## BGS publication and Git delivery diff --git a/README.md b/README.md index cb7c045..59ca300 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ A playable local adaptation of **Space Alert** and **The New Frontier**, with a deterministic engine and a French/English browser viewer. Repository: [boardgamers/space-alert](https://github.com/boardgamers/space-alert). -**Status: local playtest, under rules review.** The game runs through programming, ship resolution and scoring. The BGS adapter is implemented and tested against an isolated platform instance. Public release still needs human playtesting. +**Status: private BGS playtest, under rules review.** The game runs through programming, ship resolution and scoring. The BGS adapter is implemented and tested against an isolated platform instance. Public release still needs human playtesting. ## Play locally @@ -13,7 +13,7 @@ npm test npm run dev ``` -Open . Start with **Flight school / École de vol**: eight exercises use the real engine. Start with **Planning turns**: one crew member, a highlighted destination, two movement actions, and an empty turn. Choose left, right or a deck change to reach the destination; try the start/pause practice clock, then watch each turn execute. A missed destination can be retried. The later exercises have editable programs and a teammate already maintaining the computer; they cover firing, energy, malfunctions, battlebots/interceptors, double actions, phasing and specializations. +Open . Start with **Flight school / École de vol**: nine exercises use the real engine. Start with **Planning turns**: one crew member, a highlighted destination, two movement actions, and an empty turn. Choose left, right or a deck change to reach the destination; start the planning clock, finish early, and watch all three turns execute. A second attempt runs out of time with empty turns. The next chapter reveals a threat, locks the first group at its deadline, then executes the complete seven-turn training mission. A missed destination can be retried. The later exercises have editable programs and a teammate already maintaining the computer; they cover firing, energy, malfunctions, battlebots/interceptors, double actions, phasing and specializations. For a full mission, expand **Local session / Session locale**. Select 1–5 humans, the crew, mission, threat pools and optional modules. In solo, you control four androids and have access to the full action deck. In multiplayer testing, open another tab with `?seat=1`, etc. Readiness lasts two minutes; everyone must be ready together. The local mission starts after a three-second countdown. If someone misses the window, the crew keeps waiting. Click a card half to fill the next empty editable turn. Click a filled turn to clear it; Backspace undoes your last placement for the selected crew member. Left/right arrow keys queue horizontal movement; up/down queue a deck change, using an available card. Typing in fields is unaffected. Shift-click or Combine retains multi-card selection; then choose 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. @@ -68,7 +68,7 @@ npm install --no-save --package-lock=false ../boardgamers-mono/packages/protocol 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. +Upload the generated engine tarball and the complete viewer bundle (`dist/viewer.js` plus `dist/locales/*.json`) through BGS admin, keeping their relative paths in the same immutable bundle. The entry point remains `viewer.js`; `viewer-meta.json` is only a local build report. 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 @@ -76,14 +76,39 @@ Upload the generated engine tarball and `dist/viewer.js` through BGS admin. Use 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. +registers the same `mountLesson` through `launchTutorial`. Publish its chapter +metadata together with the viewer; chapter versions must match saved progress. 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). +During planning, each visible action has a small intended-room marker. Hover or +focus a turn to show a translucent crew marker there; the solid crew stays in its +actual room. This preview assumes movement succeeds and stops when hidden cards +or crew-dependent movement make the route unknown. + +Short synthesized action cues are enabled by default and unlock on the first interaction; the speaker toggle preserves the user’s mute choice. [BGS playable tutorial API](https://codeberg.org/boardgamers/boardgamers/src/branch/main/apps/docs/docs/guide/tutorials.md) + +### Localization + +English source chapter titles live in `bgs/gameinfo.json`; translated titles use +BGS metadata `optionTranslations` (for example `tutorial.chapters.basics.title`). +A translated title is not a chapter description. Chapter IDs and progress versions +are independent of language. + +In-game copy lives in `preview/locales/.json`. The viewer and tutorials load +only the requested catalog, using BGS preferences / tutorial launch locale. English +and French are currently available; regional French tags resolve to French and +unsupported languages fall back to English. Language changes preserve the table, +selected android, and program. Failed catalog requests fall back to English and +can be retried; stale requests cannot replace a newer language choice. + +To add a language, create a catalog with the English keys and named placeholders, +and register its source filename in `preview/i18n.js` and `preview/server.js`. The +build validates key/placeholder parity, emits content-hashed JSON language files, +and embeds only their filenames. URLs resolve relative to the viewer script, so +BGS asset proxies and deployments under subdirectories work. Run `npm test` and +`npm run build` before uploading the **whole viewer bundle**. diff --git a/bgs/gameinfo.json b/bgs/gameinfo.json index 9ac1e38..01cfe99 100644 --- a/bgs/gameinfo.json +++ b/bgs/gameinfo.json @@ -12,7 +12,7 @@ "engine": { "package": { "name": "@boardgamers/space-alert", - "version": "0.1.2" + "version": "0.1.6" }, "entryPoint": "bgs/engine.js" }, @@ -241,51 +241,57 @@ "chapters": [ { "id": "basics", - "version": 3, - "title": "Commencer ici : programmer les tours", - "description": "Start here: planning turns" + "version": 4, + "title": "Start here: planning turns", + "description": "" + }, + { + "id": "planning-phases", + "version": 2, + "title": "The clock and planning phases", + "description": "" }, { "id": "first-shot", "version": 2, - "title": "Votre premier tir", - "description": "Your first shot" + "title": "Your first shot", + "description": "" }, { "id": "energy", "version": 2, - "title": "Énergie et coordination", - "description": "Energy and coordination" + "title": "Energy and coordination", + "description": "" }, { "id": "repairs", "version": 2, - "title": "Réparer une panne", - "description": "Repairing a malfunction" + "title": "Repairing a malfunction", + "description": "" }, { "id": "battlebots", "version": 2, - "title": "Robots et intercepteurs", - "description": "Battlebots and interceptors" + "title": "Battlebots and interceptors", + "description": "" }, { "id": "double-actions", "version": 2, - "title": "Deux actions, dans l’ordre", - "description": "Two actions, in order" + "title": "Two actions, in order", + "description": "" }, { "id": "phasing", "version": 2, - "title": "Menaces de l’extension", - "description": "Expansion threats" + "title": "Expansion threats", + "description": "" }, { "id": "specializations", "version": 2, - "title": "Spécialisations", - "description": "Specializations" + "title": "Specializations", + "description": "" } ] } @@ -304,6 +310,65 @@ "releaseYear": 2008, "tags": [ "cooperative" - ] + ], + "optionTranslations": { + "fr": { + "tutorial.chapters.basics.title": { + "label": "Commencer ici : programmer les tours", + "translatedFrom": { + "hash": "4a22aa1dcb1eebe9" + } + }, + "tutorial.chapters.first-shot.title": { + "label": "Votre premier tir", + "translatedFrom": { + "hash": "c3f20469e7380f25" + } + }, + "tutorial.chapters.energy.title": { + "label": "Énergie et coordination", + "translatedFrom": { + "hash": "bd4494096f44bf35" + } + }, + "tutorial.chapters.repairs.title": { + "label": "Réparer une panne", + "translatedFrom": { + "hash": "6ec76f37d1db03af" + } + }, + "tutorial.chapters.battlebots.title": { + "label": "Robots et intercepteurs", + "translatedFrom": { + "hash": "dac9cb08473d893b" + } + }, + "tutorial.chapters.double-actions.title": { + "label": "Deux actions, dans l’ordre", + "translatedFrom": { + "hash": "71a2a375cf06780d" + } + }, + "tutorial.chapters.phasing.title": { + "label": "Menaces de l’extension", + "translatedFrom": { + "hash": "4aed91fa1b00f780" + } + }, + "tutorial.chapters.specializations.title": { + "label": "Spécialisations", + "translatedFrom": { + "hash": "b2561b50e122a682" + } + }, + "tutorial.chapters.planning-phases.title": { + "label": "Le chrono et les phases", + "translatedFrom": { + "hash": "f138f99de90125e8" + } + } + } + }, + "description": "Keep your spaceship alive: spend 10 minutes planning together as threats are announced, then watch the entire mission execute, turn by turn." } } diff --git a/bgs/pictogram.svg b/bgs/pictogram.svg new file mode 100644 index 0000000..f63ab7d --- /dev/null +++ b/bgs/pictogram.svg @@ -0,0 +1,12 @@ + + Space Alert + + + + + + + + + + diff --git a/bgs/tutorial.js b/bgs/tutorial.js index 3ff8183..972cc59 100644 --- a/bgs/tutorial.js +++ b/bgs/tutorial.js @@ -1,4 +1,8 @@ -import { createLessonTutorial, completedTurns } from "../src/tutorial-controller.js"; +import { translate, loadLocale } from "../preview/i18n.js"; +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"; @@ -7,24 +11,60 @@ 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); +export async function mountLesson( + target, + { + chapter = "basics", + locale = "en", + onProgress, + nextChapter, + standalone = false, + } = {}, +) { + locale = await loadLocale(locale); + const t = (key, params) => translate(locale, key, params); + const index = LESSONS.findIndex((l) => l.id === chapter); if (index < 0) throw Error("Unknown tutorial chapter"); const sound = createSoundDesign(); - let soundOn = true, disposed = false, lastStep = -1, lastTurn = 0, lastTick = performance.now(); - let playing = false, previousStage, playbackBusy = false; - const shotExerciseEnded = s => chapter === "first-shot" && s.state.tutorial.stopAtTarget && - s.state.game.resolution?.turn >= 3 && ["threats", "computer", "appear"].includes(s.state.game.resolution.step); - const canPlay = s => !shotExerciseEnded(s) && s.state.stage === "resolution" && !s.completed && !s.state.game.resolution?.outcome && !(chapter === "basics" && completedTurns(s.state) >= 3); + let soundOn = true, + disposed = false, + lastStep = -1, + lastTurn = 0, + lastTick = performance.now(); + let playing = false, + previousStage, + previousPhase, + previousThreats, + playbackBusy = false; + const shotExerciseEnded = (s) => + chapter === "first-shot" && + s.state.tutorial.stopAtTarget && + s.state.game.resolution?.turn >= 3 && + ["threats", "computer", "appear"].includes(s.state.game.resolution.step); + const canPlay = (s) => + !shotExerciseEnded(s) && + s.state.stage === "resolution" && + !s.completed && + !s.state.game.resolution?.outcome && + !(chapter === "basics" && completedTurns(s.state) >= 3); let storage; - try { storage = window.localStorage; soundOn = storage.getItem("space-alert:tutorial-sound") !== "off"; } catch {} + try { + storage = window.localStorage; + soundOn = storage.getItem("space-alert:tutorial-sound") !== "off"; + } catch {} // Unlock audio on the first real interaction, respecting browser autoplay rules. const unlockSound = () => sound.enable(soundOn); target.ownerDocument.addEventListener("pointerdown", unlockSound, true); target.ownerDocument.addEventListener("keydown", unlockSound, true); - const tutorial = await createLessonTutorial(chapter, { locale, storage, onProgress }); - target.innerHTML = html.split("")[1].split('