@moku-labs/game 0.15.57 → 0.15.58
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/app/page.d.mts +3 -2
- package/dist/app/page.mjs +56 -2
- package/dist/app/system.d.mts +1 -1
- package/dist/app.d.mts +1 -1
- package/dist/cli.mjs +104 -26
- package/dist/{config-B87aFTW-.mjs → config-HpC-p8Ow.mjs} +35 -6
- package/dist/testing.d.mts +1 -1
- package/dist/{types-DuqbyY_j.d.mts → types-CuFoPhWD.d.mts} +40 -3
- package/llms.txt +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -118,6 +118,8 @@ import type { GameConfig } from "@moku-labs/game/app";
|
|
|
118
118
|
export default { page: { title: "Dice" } } satisfies GameConfig;
|
|
119
119
|
```
|
|
120
120
|
|
|
121
|
+
`page.boot: { image: "assets/boot.png" }` shows a picture from the first paint until the first scene drew, then fades it out. Every key of `config.ts`: [docs/shell.md](./docs/shell.md).
|
|
122
|
+
|
|
121
123
|
Tests make the app with `game.headless()` or `game.screen()`, not started, on a fake clock and an in-memory save:
|
|
122
124
|
|
|
123
125
|
```ts
|
package/dist/app/page.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { m as StartedPage, r as GameConfig, t as AnyGameApp, u as PageOptions } from "../types-
|
|
1
|
+
import { m as StartedPage, r as GameConfig, t as AnyGameApp, u as PageOptions } from "../types-CuFoPhWD.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/app/page.d.ts
|
|
4
4
|
/**
|
|
@@ -6,7 +6,8 @@ import { m as StartedPage, r as GameConfig, t as AnyGameApp, u as PageOptions }
|
|
|
6
6
|
* fresh memory save, never on the stored one), builds the system shell when the page has one,
|
|
7
7
|
* picks the save, makes the screen app on `#game` over the device clock and the manifest next to
|
|
8
8
|
* the page, sets `globalThis.game`, `system` and `doors`, follows reduced motion, starts the shell,
|
|
9
|
-
* then the app,
|
|
9
|
+
* then the app, follows the boot picture of `page.boot` (it fades once the first scene drew, and
|
|
10
|
+
* is removed), and runs the graph. A graph that stops is logged, never thrown. In dev and in a
|
|
10
11
|
* debug build it then logs `page:build` (the build id, the engine id, the control profile),
|
|
11
12
|
* starts the agents and shows the overlay as `config.ts` `debug.overlay` asks. Every problem goes
|
|
12
13
|
* to the app's log. On `pagehide` it flushes the save, and stops the app when the page is really
|
package/dist/app/page.mjs
CHANGED
|
@@ -3,7 +3,44 @@ import { t as applyTo } from "../drafts-BawpSaVp.mjs";
|
|
|
3
3
|
import { i as isControl } from "../dev-BNndV-hU.mjs";
|
|
4
4
|
import { n as fakeClock, t as VISUAL_CLOCK } from "../fake-hnJcJeYf.mjs";
|
|
5
5
|
import { n as read, r as watch, t as sources } from "../sources-Bp9xmX3f.mjs";
|
|
6
|
-
import { t as resolveConfig } from "../config-
|
|
6
|
+
import { t as resolveConfig } from "../config-HpC-p8Ow.mjs";
|
|
7
|
+
//#region src/app/boot.ts
|
|
8
|
+
/** How long after the fade the timer removes a picture whose transition never ended, ms. */
|
|
9
|
+
const FALLBACK_MS = 100;
|
|
10
|
+
/**
|
|
11
|
+
* Fades the boot picture out after the first scene drew. It adds one render callback: in the
|
|
12
|
+
* first render frame with a mounted scene it sets the opacity to 0, so the page's CSS transition
|
|
13
|
+
* fades it over `fadeMs`, and unsubscribes. The picture is removed on `transitionend`, or by a
|
|
14
|
+
* timer `fadeMs + 100` ms later for a page in the background, where no transition ends: whichever
|
|
15
|
+
* comes first removes it and clears the other, and a second removal does nothing. `fadeMs` 0
|
|
16
|
+
* removes it in that frame. Before the first scene the callback is one `current()` read a frame.
|
|
17
|
+
*
|
|
18
|
+
* @param time - `app.time`: the render phase runs after the frame's draw.
|
|
19
|
+
* @param scenes - `app.scenes`: `current()` is set before the frame that first draws the scene.
|
|
20
|
+
* @param element - The `<img id="moku-boot">` of the page.
|
|
21
|
+
* @param fadeMs - The fade of `page.boot`, ms.
|
|
22
|
+
*/
|
|
23
|
+
function fadeBoot(time, scenes, element, fadeMs) {
|
|
24
|
+
const off = time.onFrame("render", () => {
|
|
25
|
+
if (scenes.current() === void 0) return;
|
|
26
|
+
off();
|
|
27
|
+
if (fadeMs === 0) {
|
|
28
|
+
element.remove();
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
let removed = false;
|
|
32
|
+
const remove = () => {
|
|
33
|
+
if (removed) return;
|
|
34
|
+
removed = true;
|
|
35
|
+
clearTimeout(timer);
|
|
36
|
+
element.remove();
|
|
37
|
+
};
|
|
38
|
+
const timer = setTimeout(remove, fadeMs + FALLBACK_MS);
|
|
39
|
+
element.addEventListener("transitionend", remove, { once: true });
|
|
40
|
+
element.style.opacity = "0";
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
7
44
|
//#region src/app/save.ts
|
|
8
45
|
/**
|
|
9
46
|
* @file The saves of the page: `localSave` keeps the player in `localStorage`, `pageSave` picks
|
|
@@ -319,6 +356,21 @@ function followPageHide(app) {
|
|
|
319
356
|
addEventListener("pagehide", listener);
|
|
320
357
|
}
|
|
321
358
|
/**
|
|
359
|
+
* Fades the boot picture once the first scene drew, when the page has one: a page with a
|
|
360
|
+
* document and an `<img id="moku-boot">`. Without a document (a test) or the element, nothing is
|
|
361
|
+
* added. A picture the config no longer names, on a page written before, goes without a fade in the
|
|
362
|
+
* first scene frame.
|
|
363
|
+
*
|
|
364
|
+
* @param app - The started screen app: its renderer registered its render callback first.
|
|
365
|
+
* @param boot - `page.boot` of the resolved config, or `undefined`.
|
|
366
|
+
*/
|
|
367
|
+
function followBoot(app, boot) {
|
|
368
|
+
if (typeof document === "undefined") return;
|
|
369
|
+
const element = document.querySelector("#moku-boot");
|
|
370
|
+
if (element === null) return;
|
|
371
|
+
fadeBoot(app.time, app.scenes, element, boot?.fadeMs ?? 0);
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
322
374
|
* Starts the agents, in order, after the app, in dev and in a debug build: each gets the app, the
|
|
323
375
|
* page title and the game's `.dev` modules. A throwing agent is logged and the page keeps running.
|
|
324
376
|
*
|
|
@@ -354,7 +406,8 @@ function openStartOverlay(app, overlay) {
|
|
|
354
406
|
* fresh memory save, never on the stored one), builds the system shell when the page has one,
|
|
355
407
|
* picks the save, makes the screen app on `#game` over the device clock and the manifest next to
|
|
356
408
|
* the page, sets `globalThis.game`, `system` and `doors`, follows reduced motion, starts the shell,
|
|
357
|
-
* then the app,
|
|
409
|
+
* then the app, follows the boot picture of `page.boot` (it fades once the first scene drew, and
|
|
410
|
+
* is removed), and runs the graph. A graph that stops is logged, never thrown. In dev and in a
|
|
358
411
|
* debug build it then logs `page:build` (the build id, the engine id, the control profile),
|
|
359
412
|
* starts the agents and shows the overlay as `config.ts` `debug.overlay` asks. Every problem goes
|
|
360
413
|
* to the app's log. On `pagehide` it flushes the save, and stops the app when the page is really
|
|
@@ -418,6 +471,7 @@ async function startPage(game, config, options = {}) {
|
|
|
418
471
|
followReducedMotion(app);
|
|
419
472
|
await shell?.start();
|
|
420
473
|
await app.start();
|
|
474
|
+
followBoot(app, settings.page.boot);
|
|
421
475
|
app.flow.run().catch((error) => {
|
|
422
476
|
app.log.error("[game] The graph stopped.", void 0, toError(error));
|
|
423
477
|
});
|
package/dist/app/system.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Fr as PlayerStateProvider } from "../types-C6PML3Il.mjs";
|
|
2
2
|
import { ht as PlatformProvider } from "../index-m2g9-8_E.mjs";
|
|
3
|
-
import { _ as SystemShellFactory, g as SystemName, h as SystemModules } from "../types-
|
|
3
|
+
import { _ as SystemShellFactory, g as SystemName, h as SystemModules } from "../types-CuFoPhWD.mjs";
|
|
4
4
|
import { Back, Haptics, KeepAwake, Lifecycle, Store } from "@moku-labs/system";
|
|
5
5
|
|
|
6
6
|
//#region src/app/system.d.ts
|
package/dist/app.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Ar as Json } from "./types-C6PML3Il.mjs";
|
|
2
2
|
import { U as StringTable } from "./types-FtzEwwWY.mjs";
|
|
3
|
-
import { a as GameHandle, c as MemoryProvider, d as SaveKind, f as Scenario, g as SystemName, i as GameDefinition, l as PageAgent, n as GameApp, o as GamePluginConfigs, p as ScreenSeams, r as GameConfig, s as HeadlessSeams, v as WithGameState } from "./types-
|
|
3
|
+
import { a as GameHandle, c as MemoryProvider, d as SaveKind, f as Scenario, g as SystemName, i as GameDefinition, l as PageAgent, n as GameApp, o as GamePluginConfigs, p as ScreenSeams, r as GameConfig, s as HeadlessSeams, v as WithGameState } from "./types-CuFoPhWD.mjs";
|
|
4
4
|
import { AnyPluginInstance } from "@moku-labs/core";
|
|
5
5
|
|
|
6
6
|
//#region src/app/define.d.ts
|
package/dist/cli.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as resolveConfig } from "./config-
|
|
1
|
+
import { t as resolveConfig } from "./config-HpC-p8Ow.mjs";
|
|
2
2
|
import { t as findFeatureOwners } from "./features-DowEilZm.mjs";
|
|
3
3
|
import { r as watchTree, t as createBatcher, x as isSkippedFolder$1 } from "./watch-BSgptowj.mjs";
|
|
4
4
|
import { a as runCli$1, i as compileStrings, n as importStrings, t as exportStrings } from "./assets-BRTUagOC.mjs";
|
|
@@ -239,7 +239,7 @@ const DEBUG_AGENT = "@moku-labs/editor/agent/page";
|
|
|
239
239
|
* of `moku-game visual` import the same one.
|
|
240
240
|
*/
|
|
241
241
|
const ASSETS_STAMP = "assets-stamp.ts";
|
|
242
|
-
/** A colour or a
|
|
242
|
+
/** A colour, a language tag or a CSS length: it lands in a `<style>` and in attributes, so nothing else passes. */
|
|
243
243
|
const SAFE_VALUE = /^[#\w(),.%\s-]+$/;
|
|
244
244
|
/** The files of `tests/scenarios/` that are not scenarios. */
|
|
245
245
|
const NOT_SCENARIO = /\.(?:test|spec|d)\.ts$|^index\.ts$/;
|
|
@@ -270,10 +270,10 @@ function escapeHtml(text) {
|
|
|
270
270
|
/**
|
|
271
271
|
* Checks a value of the page that lands in the style and in attributes.
|
|
272
272
|
*
|
|
273
|
-
* @param value - The background or the
|
|
273
|
+
* @param value - The background, the lang or the width of the boot picture.
|
|
274
274
|
* @param problem - The error when the value has another character.
|
|
275
275
|
* @returns The value.
|
|
276
|
-
* @throws {Error} The problem, when the value is not a plain colour or
|
|
276
|
+
* @throws {Error} The problem, when the value is not a plain colour, tag or length.
|
|
277
277
|
* @example
|
|
278
278
|
* ```ts
|
|
279
279
|
* safeValue("#10161d", "not a colour"); // "#10161d"
|
|
@@ -284,20 +284,21 @@ function safeValue(value, problem) {
|
|
|
284
284
|
return value;
|
|
285
285
|
}
|
|
286
286
|
/**
|
|
287
|
-
* The link of one icon: a path inside the game folder,
|
|
287
|
+
* The link of one file of the page, an icon or the boot picture: a path inside the game folder,
|
|
288
|
+
* never above it.
|
|
288
289
|
*
|
|
289
|
-
* @param
|
|
290
|
+
* @param field - The config field, such as `page.icons.favicon` or `page.boot.image`.
|
|
290
291
|
* @param file - The path the config gives, relative to the game folder.
|
|
291
292
|
* @returns The path with `/` separators.
|
|
292
293
|
* @throws {Error} When the path is absolute or climbs out of the game folder.
|
|
293
294
|
* @example
|
|
294
295
|
* ```ts
|
|
295
|
-
*
|
|
296
|
+
* gamePath("page.boot.image", "assets\\boot.png"); // "assets/boot.png"
|
|
296
297
|
* ```
|
|
297
298
|
*/
|
|
298
|
-
function
|
|
299
|
+
function gamePath(field, file) {
|
|
299
300
|
const slashed = file.replaceAll("\\", "/");
|
|
300
|
-
if (slashed.startsWith("/") || /^[a-z]:/i.test(slashed) || slashed.split("/").includes("..") || slashed === "") throw new Error(`[game] moku-game:
|
|
301
|
+
if (slashed.startsWith("/") || /^[a-z]:/i.test(slashed) || slashed.split("/").includes("..") || slashed === "") throw new Error(`[game] moku-game: ${field} "${file}" is not a file in the game.`);
|
|
301
302
|
return slashed;
|
|
302
303
|
}
|
|
303
304
|
/**
|
|
@@ -315,19 +316,71 @@ function iconLinks(icons, toRoot) {
|
|
|
315
316
|
return [["favicon", "icon"], ["appleTouch", "apple-touch-icon"]].flatMap(([name, relation]) => {
|
|
316
317
|
const file = icons[name];
|
|
317
318
|
if (file === void 0) return [];
|
|
318
|
-
return [` <link rel="${relation}" href="${escapeHtml(toRoot +
|
|
319
|
+
return [` <link rel="${relation}" href="${escapeHtml(toRoot + gamePath(`page.icons.${name}`, file))}" />`];
|
|
319
320
|
});
|
|
320
321
|
}
|
|
321
322
|
/**
|
|
323
|
+
* The files of the game the page links, each with its config field, in a fixed order: the favicon,
|
|
324
|
+
* the apple touch icon, the boot picture. The build copies the ones Bun left as links; the dev
|
|
325
|
+
* server checks that each is a file.
|
|
326
|
+
*
|
|
327
|
+
* @param page - The page of the resolved `config.ts`.
|
|
328
|
+
* @returns The field and the path, as the config gives it, of each file the page names.
|
|
329
|
+
* @example
|
|
330
|
+
* ```ts
|
|
331
|
+
* linkedFiles(resolveConfig({ page: { title: "T", icons: { favicon: "icon.png" }, boot: { image: "boot.png" } } }).page); // [["page.icons.favicon", "icon.png"], ["page.boot.image", "boot.png"]]
|
|
332
|
+
* ```
|
|
333
|
+
*/
|
|
334
|
+
function linkedFiles(page) {
|
|
335
|
+
const { favicon, appleTouch } = page.icons;
|
|
336
|
+
return [
|
|
337
|
+
...favicon === void 0 ? [] : [["page.icons.favicon", favicon]],
|
|
338
|
+
...appleTouch === void 0 ? [] : [["page.icons.appleTouch", appleTouch]],
|
|
339
|
+
...page.boot === void 0 ? [] : [["page.boot.image", page.boot.image]]
|
|
340
|
+
];
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* The style rule of the boot picture: centred, above the canvas, deaf to the pointer, fading
|
|
344
|
+
* over `fadeMs` once the page sets its opacity to 0.
|
|
345
|
+
*
|
|
346
|
+
* @param boot - The boot picture of the page.
|
|
347
|
+
* @returns The rule, with a space before it.
|
|
348
|
+
* @throws {Error} When the width is not a CSS length.
|
|
349
|
+
* @example
|
|
350
|
+
* ```ts
|
|
351
|
+
* bootRule({ image: "boot.png", width: "52vmin", fadeMs: 0 }).includes("width: 52vmin;"); // true
|
|
352
|
+
* ```
|
|
353
|
+
*/
|
|
354
|
+
function bootRule(boot) {
|
|
355
|
+
return ` #moku-boot { position: fixed; left: 50%; top: 50%; width: ${safeValue(boot.width, `[game] moku-game: page.boot.width "${boot.width}" is not a CSS length.`)}; height: auto; transform: translate(-50%, -50%); z-index: 1; pointer-events: none; transition: opacity ${String(boot.fadeMs)}ms linear; }`;
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* The `<img>` of the boot picture, the first element of the body.
|
|
359
|
+
*
|
|
360
|
+
* @param boot - The boot picture of the page.
|
|
361
|
+
* @param toRoot - The path from the page to the game folder.
|
|
362
|
+
* @returns The line.
|
|
363
|
+
* @throws {Error} When the picture is not a file in the game.
|
|
364
|
+
* @example
|
|
365
|
+
* ```ts
|
|
366
|
+
* bootImage({ image: "assets/boot.png", width: "40vmin", fadeMs: 300 }, "../"); // ' <img id="moku-boot" src="../assets/boot.png" alt="" />'
|
|
367
|
+
* ```
|
|
368
|
+
*/
|
|
369
|
+
function bootImage(boot, toRoot) {
|
|
370
|
+
return ` <img id="moku-boot" src="${escapeHtml(toRoot + gamePath("page.boot.image", boot.image))}" alt="" />`;
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
322
373
|
* The page a game runs in: the title, the language, the background (also the theme colour), the
|
|
323
374
|
* icons as links (never `url()` in the style: `Bun.build` does not rewrite it), the `head` tags
|
|
324
|
-
* verbatim after the style,
|
|
375
|
+
* verbatim after the style, then the body: the boot picture first when the page has one (an
|
|
376
|
+
* `<img id="moku-boot">`, its rule in the style), `<div id="game">` and the module script. A page
|
|
377
|
+
* without a boot is the same HTML as before `page.boot`.
|
|
325
378
|
*
|
|
326
379
|
* @param page - The page of the resolved `config.ts`.
|
|
327
380
|
* @param links - The path to the game folder and the script.
|
|
328
381
|
* @returns The HTML.
|
|
329
|
-
* @throws {Error} When the background is not a CSS colour, the lang not a language tag,
|
|
330
|
-
*
|
|
382
|
+
* @throws {Error} When the background is not a CSS colour, the lang not a language tag, an icon
|
|
383
|
+
* path or the boot picture leaves the game folder, or the boot width is not a CSS length.
|
|
331
384
|
* @example
|
|
332
385
|
* ```ts
|
|
333
386
|
* pageHtml(resolveConfig({ page: { title: "mini-game" } }).page, { toRoot: "../", script: "./main.ts" }).includes("<title>mini-game</title>"); // true
|
|
@@ -336,7 +389,7 @@ function iconLinks(icons, toRoot) {
|
|
|
336
389
|
function pageHtml(page, links) {
|
|
337
390
|
const background = safeValue(page.background, `[game] moku-game: page.background "${page.background}" is not a CSS color.`);
|
|
338
391
|
const lang = safeValue(page.lang, `[game] moku-game: page.lang "${page.lang}" is not a language tag.`);
|
|
339
|
-
const style = `html, body { margin: 0; height: 100%; background: ${background}; } #game { width: 100%; height: 100%; touch-action: none; }
|
|
392
|
+
const style = `html, body { margin: 0; height: 100%; background: ${background}; } #game { width: 100%; height: 100%; touch-action: none; }` + (page.boot === void 0 ? "" : bootRule(page.boot));
|
|
340
393
|
return [
|
|
341
394
|
"<!doctype html>",
|
|
342
395
|
`<html lang="${lang}">`,
|
|
@@ -350,6 +403,7 @@ function pageHtml(page, links) {
|
|
|
350
403
|
...page.head.map((tag) => ` ${tag}`),
|
|
351
404
|
" </head>",
|
|
352
405
|
" <body>",
|
|
406
|
+
...page.boot === void 0 ? [] : [bootImage(page.boot, links.toRoot)],
|
|
353
407
|
" <div id=\"game\"></div>",
|
|
354
408
|
` <script type="module" src="${escapeHtml(links.script)}"><\/script>`,
|
|
355
409
|
" </body>",
|
|
@@ -974,29 +1028,30 @@ async function loadSettings(root) {
|
|
|
974
1028
|
return resolveConfig(loaded.default);
|
|
975
1029
|
}
|
|
976
1030
|
/**
|
|
977
|
-
* Checks that every
|
|
1031
|
+
* Checks that every file the page links, the icons and the boot picture, is a file of the game.
|
|
978
1032
|
*
|
|
979
1033
|
* @param root - The game folder.
|
|
980
1034
|
* @param page - The resolved page.
|
|
981
|
-
* @throws {Error} When an icon is not a file in the game.
|
|
1035
|
+
* @throws {Error} When an icon or the boot picture is not a file in the game.
|
|
982
1036
|
*/
|
|
983
|
-
function
|
|
984
|
-
for (const [
|
|
1037
|
+
function checkPageFiles(root, page) {
|
|
1038
|
+
for (const [field, file] of linkedFiles(page)) if (!isFile(path.join(root, file))) throw new Error(`[game] moku-game: ${field} "${file}" is not a file in the game.`);
|
|
985
1039
|
}
|
|
986
1040
|
/**
|
|
987
1041
|
* Reads and checks a game folder for a page: `config.ts` and `index.ts` exist, the config
|
|
988
|
-
* resolves
|
|
1042
|
+
* resolves (a bad `page.boot.fadeMs` is refused here, before any page is made) and the files the
|
|
1043
|
+
* page links, its icons and its boot picture, are files of the game.
|
|
989
1044
|
*
|
|
990
1045
|
* @param root - The game folder, absolute.
|
|
991
1046
|
* @returns The resolved config.
|
|
992
1047
|
* @throws {Error} When `config.ts` or `index.ts` is missing, a config value is refused, or an icon
|
|
993
|
-
* is not a file in the game.
|
|
1048
|
+
* or the boot picture is not a file in the game.
|
|
994
1049
|
*/
|
|
995
1050
|
async function loadGame(root) {
|
|
996
1051
|
configFileOf(root);
|
|
997
1052
|
if (!isFile(path.join(root, "index.ts"))) throw new Error(`[game] moku-game: no index.ts in "${root}".\n It default-exports defineGameApp({ ... }).`);
|
|
998
1053
|
const settings = await loadSettings(root);
|
|
999
|
-
|
|
1054
|
+
checkPageFiles(root, settings.page);
|
|
1000
1055
|
return settings;
|
|
1001
1056
|
}
|
|
1002
1057
|
/**
|
|
@@ -1760,19 +1815,42 @@ async function bundlePage(run, settings, page) {
|
|
|
1760
1815
|
if (!result.success) throw new Error(["[game] build: the page did not bundle.", ...result.logs.map(String)].join("\n"));
|
|
1761
1816
|
}
|
|
1762
1817
|
/**
|
|
1763
|
-
*
|
|
1764
|
-
*
|
|
1818
|
+
* Refuses the boot picture when its copy would share one name beside the page with another file left in the game. One
|
|
1819
|
+
* file linked twice (the favicon also the boot picture) is one copy, not a clash. Two icons of one name build as
|
|
1820
|
+
* before: the boot picture is the only new file the copy can lose.
|
|
1821
|
+
*
|
|
1822
|
+
* @param left - The field and the `/` path of each file Bun left as a link, in page order.
|
|
1823
|
+
* @throws {Error} When the boot picture and another file have one base name.
|
|
1824
|
+
*/
|
|
1825
|
+
function refuseNameClash(left) {
|
|
1826
|
+
const byName = /* @__PURE__ */ new Map();
|
|
1827
|
+
for (const entry of left) {
|
|
1828
|
+
const [field, linked] = entry;
|
|
1829
|
+
const name = path.basename(linked);
|
|
1830
|
+
const earlier = byName.get(name);
|
|
1831
|
+
const involvesBoot = field === "page.boot.image" || earlier?.[0] === "page.boot.image";
|
|
1832
|
+
if (earlier !== void 0 && earlier[1] !== linked && involvesBoot) throw new Error(`[game] build: ${field} and ${earlier[0]} share the name "${name}" beside the page.`);
|
|
1833
|
+
byName.set(name, entry);
|
|
1834
|
+
}
|
|
1835
|
+
}
|
|
1836
|
+
/**
|
|
1837
|
+
* The fallback for page files Bun left as links into the game, the icons and the boot picture:
|
|
1838
|
+
* copies each beside the page and links it as `./<name>`. Two such files with one name are
|
|
1839
|
+
* refused before anything is copied when one is the boot picture; a file Bun already linked is never copied, so it cannot
|
|
1840
|
+
* clash.
|
|
1765
1841
|
*
|
|
1766
1842
|
* @param run - The flags of the run.
|
|
1767
1843
|
* @param settings - The resolved config.
|
|
1844
|
+
* @throws {Error} When two files left in the game share a name beside the page.
|
|
1768
1845
|
*/
|
|
1769
1846
|
function relinkIcons(run, settings) {
|
|
1770
1847
|
const file = path.join(run.out, "index.html");
|
|
1771
1848
|
let html = readFileSync(file, "utf8");
|
|
1772
1849
|
if (!html.includes(`"${TO_ROOT}`)) return;
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1850
|
+
const left = linkedFiles(settings.page).map(([field, linkedFile]) => [field, linkedFile.replaceAll("\\", "/")]).filter(([, linked]) => html.includes(`"${TO_ROOT}${linked}"`));
|
|
1851
|
+
refuseNameClash(left);
|
|
1852
|
+
for (const [, linked] of left) {
|
|
1853
|
+
if (!html.includes(`"${TO_ROOT}${linked}"`)) continue;
|
|
1776
1854
|
const name = path.basename(linked);
|
|
1777
1855
|
copyFileSync(path.join(run.root, linked), path.join(run.out, name));
|
|
1778
1856
|
html = html.replaceAll(`"${TO_ROOT}${linked}"`, `"./${name}"`);
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
//#region src/app/config.ts
|
|
2
|
+
/** The CSS width of a boot picture whose config names none. */
|
|
3
|
+
const BOOT_WIDTH = "40vmin";
|
|
4
|
+
/** The fade of a boot picture whose config names none, ms. */
|
|
5
|
+
const BOOT_FADE_MS = 300;
|
|
2
6
|
/**
|
|
3
7
|
* The save kinds a config may name.
|
|
4
8
|
*
|
|
@@ -54,8 +58,9 @@ function overlayStarts() {
|
|
|
54
58
|
* Throws for the first value of a config that TypeScript would have refused.
|
|
55
59
|
*
|
|
56
60
|
* @param config - The default export of `config.ts`.
|
|
57
|
-
* @throws {Error} When `save` is not a save kind, a `system` name is not wired, the title is empty,
|
|
58
|
-
* `debug.overlay` is not a start mode.
|
|
61
|
+
* @throws {Error} When `save` is not a save kind, a `system` name is not wired, the title is empty,
|
|
62
|
+
* `debug.overlay` is not a start mode, `page.boot` has no image, or `page.boot.fadeMs` is not a finite number of 0
|
|
63
|
+
* or more.
|
|
59
64
|
*/
|
|
60
65
|
function checkConfig(config) {
|
|
61
66
|
if (config.save !== void 0 && !saveKinds().has(config.save)) throw new Error(`[game] config.save is "${config.save}".\n Use "memory", "local" or "store".`);
|
|
@@ -65,16 +70,39 @@ function checkConfig(config) {
|
|
|
65
70
|
if (config.page.title.trim() === "") throw new Error("[game] config.page.title is empty.\n Give the page a title in config.ts.");
|
|
66
71
|
const overlay = config.debug?.overlay;
|
|
67
72
|
if (overlay !== void 0 && !overlayStarts().has(overlay)) throw new Error(`[game] config.ts: debug.overlay must be "closed", "pill" or "open", got "${String(overlay)}".`);
|
|
73
|
+
const image = config.page.boot?.image;
|
|
74
|
+
if (config.page.boot !== void 0 && (typeof image !== "string" || image === "")) throw new Error("[game] config.page.boot has no image.\n Name a picture file of the game in page.boot.image.");
|
|
75
|
+
const fadeMs = config.page.boot?.fadeMs;
|
|
76
|
+
if (fadeMs !== void 0 && !(Number.isFinite(fadeMs) && fadeMs >= 0)) throw new Error(`[game] config.page.boot.fadeMs is ${String(fadeMs)}.\n Use a number of milliseconds, 0 or more.`);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Fills the defaults of `page.boot`: the width `"40vmin"`, the fade 300 ms.
|
|
80
|
+
*
|
|
81
|
+
* @param boot - `page.boot` of the config.
|
|
82
|
+
* @returns The boot with every field set.
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* resolveBoot({ image: "assets/boot.png", fadeMs: 0 }); // { image: "assets/boot.png", width: "40vmin", fadeMs: 0 }
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
function resolveBoot(boot) {
|
|
89
|
+
return {
|
|
90
|
+
image: boot.image,
|
|
91
|
+
width: boot.width ?? BOOT_WIDTH,
|
|
92
|
+
fadeMs: boot.fadeMs ?? BOOT_FADE_MS
|
|
93
|
+
};
|
|
68
94
|
}
|
|
69
95
|
/**
|
|
70
96
|
* Fills every default of a game's `config.ts`: `lang` `"en"`, `background` `"#000000"`,
|
|
71
97
|
* `orientation` `"portrait"`, no icons, no head tags, no system plugin, the memory save, no asset
|
|
72
|
-
* layers, the overlay of a debug page closed at its start.
|
|
98
|
+
* layers, the overlay of a debug page closed at its start. A `page.boot` gets the width
|
|
99
|
+
* `"40vmin"` and the fade 300 ms; without one the page has no `boot` key.
|
|
73
100
|
*
|
|
74
101
|
* @param config - The default export of `config.ts`.
|
|
75
102
|
* @returns The config with every field set.
|
|
76
|
-
* @throws {Error} When `save` is not a save kind, a `system` name is not wired, the title is empty,
|
|
77
|
-
* `debug.overlay` is not a start mode.
|
|
103
|
+
* @throws {Error} When `save` is not a save kind, a `system` name is not wired, the title is empty,
|
|
104
|
+
* `debug.overlay` is not a start mode, `page.boot` has no image, or `page.boot.fadeMs` is not a finite number of 0
|
|
105
|
+
* or more.
|
|
78
106
|
* @example
|
|
79
107
|
* ```ts
|
|
80
108
|
* resolveConfig({ page: { title: "T" } }).save; // "memory"
|
|
@@ -89,7 +117,8 @@ function resolveConfig(config) {
|
|
|
89
117
|
background: config.page.background ?? "#000000",
|
|
90
118
|
orientation: config.page.orientation ?? "portrait",
|
|
91
119
|
icons: config.page.icons ?? {},
|
|
92
|
-
head: config.page.head ?? []
|
|
120
|
+
head: config.page.head ?? [],
|
|
121
|
+
...config.page.boot === void 0 ? {} : { boot: resolveBoot(config.page.boot) }
|
|
93
122
|
},
|
|
94
123
|
native: config.native,
|
|
95
124
|
system: config.system ?? [],
|
package/dist/testing.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Ar as Json, Dn as NodeTable, Fn as Hint, In as NodeFx, Sr as ClockSource, jn as Descriptor, wr as FakeClock, xn as AnyFlow, yn as FeaturePlugin } from "./types-C6PML3Il.mjs";
|
|
2
2
|
import { t as createApp } from "./index-m2g9-8_E.mjs";
|
|
3
|
-
import { b as saveOf, v as WithGameState, y as memory } from "./types-
|
|
3
|
+
import { b as saveOf, v as WithGameState, y as memory } from "./types-CuFoPhWD.mjs";
|
|
4
4
|
import { a as createHeadless, i as ReproResult, n as HeadlessGame, o as runRepro, r as Repro, s as stepFrames, t as HeadlessApp } from "./headless-7IBMNGda.mjs";
|
|
5
5
|
import { AnyPluginInstance } from "@moku-labs/core";
|
|
6
6
|
|
|
@@ -81,7 +81,7 @@ type SaveKind = "memory" | "local" | "store";
|
|
|
81
81
|
* // config.ts of a game
|
|
82
82
|
* import type { GameConfig } from "@moku-labs/game/app";
|
|
83
83
|
* export default {
|
|
84
|
-
* page: { title: "Лесной городок", lang: "ru", background: "#10161d", orientation: "portrait", icons: { favicon: "assets/icon.png" } },
|
|
84
|
+
* page: { title: "Лесной городок", lang: "ru", background: "#10161d", orientation: "portrait", icons: { favicon: "assets/icon.png" }, boot: { image: "assets/boot.png" } },
|
|
85
85
|
* native: { name: "Лесной городок", identifier: "com.mokulabs.timber", icon: "assets/icon.png" },
|
|
86
86
|
* system: ["lifecycle", "back", "haptics", "keepAwake"],
|
|
87
87
|
* save: "memory",
|
|
@@ -100,6 +100,26 @@ type GameConfig = {
|
|
|
100
100
|
appleTouch?: string;
|
|
101
101
|
}; /** Raw tags written into `<head>`, verbatim, in order. None by default. */
|
|
102
102
|
head?: readonly string[];
|
|
103
|
+
/**
|
|
104
|
+
* The boot picture: an `<img>` centred over the canvas from the first paint, faded out after
|
|
105
|
+
* the first scene drew, then removed. Absent by default: the page shows only `background`
|
|
106
|
+
* until the first scene. `image` is a file relative to the game folder, never absolute, never
|
|
107
|
+
* `..`; `width` is its CSS width, default `"40vmin"`; `fadeMs` the fade, default `300`, `0`
|
|
108
|
+
* removes the picture in that frame.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* // config.ts of A Memory Missing: the logo from the icon tap to the splash scene's first frame.
|
|
113
|
+
* export default {
|
|
114
|
+
* page: { title: "A Memory Missing", background: "#F4E6CA", boot: { image: "assets/boot.png", width: "52vmin" } }
|
|
115
|
+
* } satisfies GameConfig; // the logo fades over 300 ms, the default
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
boot?: {
|
|
119
|
+
image: string;
|
|
120
|
+
width?: string;
|
|
121
|
+
fadeMs?: number;
|
|
122
|
+
};
|
|
103
123
|
}; /** The native app. Left out, the game has no native build. */
|
|
104
124
|
native?: {
|
|
105
125
|
/** The app name under the icon. */name: string; /** The bundle identifier, reverse DNS. */
|
|
@@ -120,6 +140,19 @@ type GameConfig = {
|
|
|
120
140
|
overlay?: OverlayStart;
|
|
121
141
|
};
|
|
122
142
|
};
|
|
143
|
+
/**
|
|
144
|
+
* `page.boot` of `config.ts` with every default filled, as `resolveConfig` returns it.
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```ts
|
|
148
|
+
* resolveConfig({ page: { title: "T", boot: { image: "assets/boot.png" } } }).page.boot; // { image: "assets/boot.png", width: "40vmin", fadeMs: 300 }
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
type ResolvedPageBoot = {
|
|
152
|
+
/** The picture file, relative to the game folder. */image: string; /** The CSS width of the picture. */
|
|
153
|
+
width: string; /** The fade-out after the first scene drew, ms. */
|
|
154
|
+
fadeMs: number;
|
|
155
|
+
};
|
|
123
156
|
/**
|
|
124
157
|
* How the editor's overlay shows when a debug page starts, `config.ts` `debug.overlay`.
|
|
125
158
|
*
|
|
@@ -132,7 +165,8 @@ type GameConfig = {
|
|
|
132
165
|
type OverlayStart = "closed" | "pill" | "open";
|
|
133
166
|
/**
|
|
134
167
|
* `GameConfig` with every default filled, as `resolveConfig` returns it. The page, the CLI and the
|
|
135
|
-
* shell read this one, never the raw config.
|
|
168
|
+
* shell read this one, never the raw config. `page.boot` is the one key left out when the game
|
|
169
|
+
* names no boot picture.
|
|
136
170
|
*
|
|
137
171
|
* @example
|
|
138
172
|
* ```ts
|
|
@@ -140,10 +174,13 @@ type OverlayStart = "closed" | "pill" | "open";
|
|
|
140
174
|
* page: { title: "mini-game", lang: "en", background: "#000000", orientation: "portrait", icons: {}, head: [] },
|
|
141
175
|
* native: undefined, system: [], save: "memory", assets: { layers: {} }, debug: { overlay: "closed" }
|
|
142
176
|
* };
|
|
177
|
+
* settings.page.boot; // undefined: no boot picture, the page as before
|
|
143
178
|
* ```
|
|
144
179
|
*/
|
|
145
180
|
type ResolvedGameConfig = {
|
|
146
|
-
/** The page, every field set. */page: Required<GameConfig["page"]
|
|
181
|
+
/** The page, every field set; `boot` only when the game names a boot picture. */page: Required<Omit<GameConfig["page"], "boot">> & {
|
|
182
|
+
boot?: ResolvedPageBoot;
|
|
183
|
+
}; /** The native app, or `undefined` for a game with no native build. */
|
|
147
184
|
native: GameConfig["native"]; /** The system plugins the shell wires. */
|
|
148
185
|
system: readonly SystemName[]; /** Where the save lives. */
|
|
149
186
|
save: SaveKind; /** The asset build. */
|
package/llms.txt
CHANGED
|
@@ -302,7 +302,7 @@ app.model.store.snapshot().session; // { rolls: 2 }
|
|
|
302
302
|
await run.stop();
|
|
303
303
|
```
|
|
304
304
|
|
|
305
|
-
`config.ts` keys and defaults: `page.title` (required, never empty), `page.lang` (`"en"`), `page.background` (`"#000000"`: the page behind the canvas, the `theme-color` meta and the native window; the canvas clear colour stays `pluginConfigs.renderer.background`), `page.orientation` (`"portrait"`, or `"landscape"`, `"any"`: the native build locks it), `page.icons: { favicon?, appleTouch? }` (files relative to the game, `<link>` tags), `page.head` (raw tags, verbatim), `native: { name, identifier, icon?, targets? }` (absent: no native build), `system` (`[]`; names `lifecycle`, `back`, `haptics`, `keepAwake`, `store`), `save` (`"memory"`, or `"local"`, `"store"`), `assets.layers` (`{}`; `{ shared: "ui" }` becomes `--layer shared=ui`), `debug.overlay` (`"closed"`, or `"pill"`, `"open"`: how the editor's overlay shows when a debug page starts; the page calls `app.debug.overlay.open({ mode })` right after the agents started; only a page with the agent reads it). A refused value throws, for example `[game] config.save is "disk".` or `[game] config.system names "tray", which the game shell does not wire.`
|
|
305
|
+
`config.ts` keys and defaults: `page.title` (required, never empty), `page.lang` (`"en"`), `page.background` (`"#000000"`: the page behind the canvas, the `theme-color` meta and the native window; the canvas clear colour stays `pluginConfigs.renderer.background`), `page.orientation` (`"portrait"`, or `"landscape"`, `"any"`: the native build locks it), `page.icons: { favicon?, appleTouch? }` (files relative to the game, `<link>` tags), `page.head` (raw tags, verbatim), `page.boot: { image, width?, fadeMs? }` (absent by default; an `<img id="moku-boot">` centred over the canvas from the first paint until the first scene drew, then faded over `fadeMs`, `300`, and removed; `image` a file relative to the game, `width` `"40vmin"`), `native: { name, identifier, icon?, targets? }` (absent: no native build), `system` (`[]`; names `lifecycle`, `back`, `haptics`, `keepAwake`, `store`), `save` (`"memory"`, or `"local"`, `"store"`), `assets.layers` (`{}`; `{ shared: "ui" }` becomes `--layer shared=ui`), `debug.overlay` (`"closed"`, or `"pill"`, `"open"`: how the editor's overlay shows when a debug page starts; the page calls `app.debug.overlay.open({ mode })` right after the agents started; only a page with the agent reads it). A refused value throws, for example `[game] config.save is "disk".` or `[game] config.system names "tray", which the game shell does not wire.`
|
|
306
306
|
|
|
307
307
|
```ts
|
|
308
308
|
// config.ts of a game in a native shell
|