Server-run play, part 1: game prerequisites and shared contracts
Groundwork for running multiplayer games on the session server; nothing
of it is switched on yet, and the plain build is unchanged.
- A new network in two halves (beginState/beginShow), the coach split into
tutAdvance/coachDom, toastPop split out of toast, bootNotes() for the
once-per-load toasts, the five text actions take their text as an
argument, and srvOn() with its two checks in the loop.
- Live state is what a reload makes of it (migrate() is a no-op on it):
new POPs, ports, PNIs, customers, attacks, dark fiber and the intern's
notes are written in their saved shape; a 365-day test proves it.
- pniAll and bstdApply check the quote the sheet showed (bstdApply by its
plan, within 1% for the daily hardware drift; utilityKit too).
- assemble({mp}) leaves src/game/98-server-play/ and its CSS out of every
page but a multiplayer build's, which also gets a SIM_ID build id.
- Contracts for the server, protocol and browser parts: the action tables
and envelope check (scripts/lib/mp-sim-acts.js), event fixtures, a shape
checker, a fake engine, and load({mp:true}) in the test harness.
- route-fuzz judges both pages with one migrate(), so reload repairs of
the base no longer count as divergences.
This commit is contained in:
parent
e25f843526
commit
d1e127da67
60 changed files with 2200 additions and 105 deletions
|
|
@ -7,11 +7,12 @@
|
|||
// npm run build VERSION, BUILD_DATE and OUT can be set in the environment
|
||||
// REQUIRE_NOTES=1 npm run build fail when CHANGELOG.md has no bullets for this version
|
||||
// MP_API=/api/mp npm run build a self-hosted copy with multiplayer (docs/MULTIPLAYER.md): the
|
||||
// page talks to scripts/mp-server.js at that path, same origin
|
||||
// page talks to scripts/mp-server.js at that path, same origin, and
|
||||
// has the server-run play (src/game/98-server-play/) and its SIM_ID
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const { execFileSync } = require('node:child_process');
|
||||
const { shipped, ROOT } = require('./lib/page');
|
||||
const { shipped, simId, assemble, ROOT } = require('./lib/page');
|
||||
|
||||
const VERSION = process.env.VERSION || require(path.join(ROOT, 'package.json')).version;
|
||||
const BUILD_DATE = process.env.BUILD_DATE || new Date().toISOString().slice(0, 10);
|
||||
|
|
@ -31,7 +32,9 @@ fs.cpSync(path.join(ROOT, 'site'), OUT, { recursive: true });
|
|||
if (fs.existsSync(path.join(OUT, 'index.html'))) die('site/index.html must not exist: the page is assembled from src/');
|
||||
// The page and the translations ship with labels shrunk to short ids (docs/adr/0003-translations-by-label.md).
|
||||
const D = require('./lib/dict');
|
||||
const { html: page0, dicts } = shipped(Object.fromEntries(D.langs().map((l) => [l, D.read(l).dict])));
|
||||
const { html: page0, dicts } = shipped(Object.fromEntries(D.langs().map((l) => [l, D.read(l).dict])), { mp: !!MP_API });
|
||||
// Server-run play's build id: only a multiplayer build has one (scripts/lib/page.js simId()).
|
||||
const SIM_ID = MP_API ? simId(assemble({ mp: true }).html) : '';
|
||||
fs.writeFileSync(path.join(OUT, 'index.html'), page0);
|
||||
for (const [lang, dict] of Object.entries(dicts)) fs.writeFileSync(path.join(OUT, 'i18n', `${lang}.js`), D.format(lang, '', dict));
|
||||
|
||||
|
|
@ -50,10 +53,13 @@ if (!html.includes(PH)) die('release-notes placeholder missing from the page');
|
|||
// A release can also open with a story (prose before its first bullet), shown in full in "What's new".
|
||||
const story = execFileSync(process.execPath, [path.join(__dirname, 'release-notes.js'), VERSION, '--story'], { encoding: 'utf8' }), PS = '/*__RELEASE_STORY__*/[]';
|
||||
if (!html.includes(PS)) die('release-story placeholder missing from the page');
|
||||
const PM = "/*__MP_API__*/''";
|
||||
const PM = "/*__MP_API__*/''", PI = "/*__SIM_ID__*/''";
|
||||
if (!html.includes(PM)) die('multiplayer placeholder missing from the page');
|
||||
fs.writeFileSync(page, html.replace(PH, () => notes.replace(/</g, '\\u003c')).replace(PS, () => story.replace(/</g, '\\u003c')).replace(PM, () => `'${MP_API}'`));
|
||||
fs.writeFileSync(path.join(OUT, 'version.json'), JSON.stringify({ version: VERSION, date: BUILD_DATE, notes: JSON.parse(notes), story: JSON.parse(story) }, null, 2) + '\n');
|
||||
if (!html.includes(PI)) die('server-play build id placeholder missing from the page');
|
||||
let out = html.replace(PH, () => notes.replace(/</g, '\\u003c')).replace(PS, () => story.replace(/</g, '\\u003c')).replace(PM, () => `'${MP_API}'`);
|
||||
if (SIM_ID) out = out.replace(PI, () => `'${SIM_ID}'`);
|
||||
fs.writeFileSync(page, out);
|
||||
fs.writeFileSync(path.join(OUT, 'version.json'), JSON.stringify({ version: VERSION, date: BUILD_DATE, notes: JSON.parse(notes), story: JSON.parse(story), ...(SIM_ID ? { simId: SIM_ID } : {}) }, null, 2) + '\n');
|
||||
|
||||
// Nothing may ship half-stamped.
|
||||
const left = [];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue