@moku-labs/game 0.15.86 → 0.15.88

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.
Files changed (39) hide show
  1. package/README.md +4 -3
  2. package/dist/app/page.d.mts +1 -1
  3. package/dist/app/page.mjs +2 -2
  4. package/dist/app/system.d.mts +3 -3
  5. package/dist/app.d.mts +3 -3
  6. package/dist/app.mjs +1 -1
  7. package/dist/assets.d.mts +1 -1
  8. package/dist/cli.mjs +351 -83
  9. package/dist/{commands-CeBF2nRY.d.mts → commands-C6RMqrY8.d.mts} +5 -5
  10. package/dist/{config-Cn1VZ-tx.mjs → config-BYx_7HL1.mjs} +24 -5
  11. package/dist/control.d.mts +12 -8
  12. package/dist/control.mjs +2 -2
  13. package/dist/{define-N-2nQNK_.d.mts → define-DE1XcBwC.d.mts} +27 -5
  14. package/dist/{headless-DtDdn5gg.d.mts → headless-CtRq6Uij.d.mts} +1 -1
  15. package/dist/{index-Bn0pFiae.d.mts → index-nK7iVsWx.d.mts} +30 -7
  16. package/dist/index.d.mts +5 -5
  17. package/dist/index.mjs +3 -3
  18. package/dist/inspect.d.mts +6 -6
  19. package/dist/inspect.mjs +2 -2
  20. package/dist/jsx-dev-runtime.d.mts +1 -1
  21. package/dist/jsx-runtime.d.mts +1 -1
  22. package/dist/{run-3QhrffgM.mjs → run-B5if0jxE.mjs} +1 -1
  23. package/dist/{runtime-DOvgFNLH.d.mts → runtime-CmRqaHmz.d.mts} +1 -1
  24. package/dist/{session-DuZfGZWk.mjs → session-D0AYRm5T.mjs} +39 -3
  25. package/dist/{sources-Djd8MjP9.mjs → sources-kL64Svgl.mjs} +2 -2
  26. package/dist/{src-BFa-zMmW.mjs → src-BTPWdbHH.mjs} +268 -158
  27. package/dist/testing.d.mts +4 -4
  28. package/dist/testing.mjs +1 -1
  29. package/dist/{types-OBpR0u05.d.mts → types-BbLjYfGR.d.mts} +113 -16
  30. package/dist/{types-CyPbo757.d.mts → types-BlXL-VC3.d.mts} +15 -5
  31. package/dist/{types-C5gLBKbm.d.mts → types-CJYudpme.d.mts} +2 -2
  32. package/dist/{types-DNWWlVky.d.mts → types-ehmvA6yu.d.mts} +41 -11
  33. package/dist/{types-CbVXXqPs.d.mts → types-w5_A5TPL.d.mts} +35 -4
  34. package/dist/{visual-B7TxMv1J.mjs → visual-CULAJg6b.mjs} +161 -10
  35. package/dist/{visual-Di8ecxYD.d.mts → visual-DvhjRhgP.d.mts} +6 -6
  36. package/dist/visual.d.mts +1 -1
  37. package/dist/visual.mjs +2 -2
  38. package/llms.txt +10 -9
  39. package/package.json +3 -3
@@ -642,8 +642,9 @@ const countdownDefaults = {
642
642
  /**
643
643
  * Shows a numeric component field of the label's own entity: read every frame, written to
644
644
  * `Text.resolved` only when the shown string changes. The field must hold a number; the format
645
- * is `"int"` (rounded) unless named. Reads the component's own name, so a renamed component
646
- * cannot drift from its label.
645
+ * is `"int"` (rounded) unless named. This root `bind` takes the four built-in formats; the `bind`
646
+ * of `defineGame` is this function and takes the names of the game's `defineTextFormats` too. Reads
647
+ * the component's own name, so a renamed component cannot drift from its label.
647
648
  *
648
649
  * @param component - The component whose field the label shows.
649
650
  * @param field - A numeric field of that component.
@@ -813,6 +814,29 @@ function defineTextStyles(map) {
813
814
  };
814
815
  }
815
816
  /**
817
+ * Declares the number formats of a feature. The result goes under the `textFormats` key of the
818
+ * feature description, and `text` reads it in `onStart`; a label names a format in its `bind`. A
819
+ * format takes the whole value and answers what the label shows and its style.
820
+ *
821
+ * @param map - Format name to its function. The four built-in names are refused at start.
822
+ * @returns The registration a feature carries.
823
+ * @example
824
+ * ```ts
825
+ * const formats = defineTextFormats({
826
+ * "pill.number": value => ({ content: String(value), style: "digits.17" })
827
+ * });
828
+ *
829
+ * formats.kind; // "textFormats"
830
+ * formats.map["pill.number"]?.(950); // { content: "950", style: "digits.17" }
831
+ * ```
832
+ */
833
+ function defineTextFormats(map) {
834
+ return {
835
+ kind: "textFormats",
836
+ map
837
+ };
838
+ }
839
+ /**
816
840
  * Tells whether a value is a plain record, so its fields can be read one by one.
817
841
  *
818
842
  * @param value - What a feature put in its description.
@@ -933,10 +957,10 @@ function builtInStyles(fonts) {
933
957
  };
934
958
  }
935
959
  /**
936
- * Binds `label` and `defineTextStyles` to one game's style names and font keys. Type-only: the
937
- * same two functions.
960
+ * Binds `label`, `bind`, `defineTextStyles` and `defineTextFormats` to one game's style names, font
961
+ * keys and format names. Type-only: the same four functions.
938
962
  *
939
- * @returns The two helpers, with the style and font arguments narrowed.
963
+ * @returns The four helpers, with the style, font and format arguments narrowed.
940
964
  * @example
941
965
  * ```ts
942
966
  * const { label } = textFor<"body", "ui.font-body">();
@@ -946,10 +970,112 @@ function builtInStyles(fonts) {
946
970
  function textFor() {
947
971
  return {
948
972
  label,
949
- defineTextStyles
973
+ bind,
974
+ defineTextStyles,
975
+ defineTextFormats
950
976
  };
951
977
  }
952
978
  //#endregion
979
+ //#region src/plugins/text/format.ts
980
+ /** Milliseconds in one second. */
981
+ const SECOND_MS = 1e3;
982
+ /** Seconds in one minute. */
983
+ const SECONDS_PER_MINUTE = 60;
984
+ /** Seconds in one hour. */
985
+ const SECONDS_PER_HOUR = 3600;
986
+ /**
987
+ * Tells whether a string is one of the four built-in formats. Any other string a bind carries is a
988
+ * name a feature registered, or a bind that slipped past the type.
989
+ *
990
+ * @param format - What a bind carries.
991
+ * @returns True for `"int"`, `"mm:ss"`, `"h:mm:ss"` and `"duration"`.
992
+ * @example
993
+ * ```ts
994
+ * isTextFormat("ss"); // false
995
+ * ```
996
+ */
997
+ function isTextFormat(format) {
998
+ return format === "int" || format === "mm:ss" || format === "h:mm:ss" || format === "duration";
999
+ }
1000
+ /**
1001
+ * Pads a number to two digits. A longer number stays as it is.
1002
+ *
1003
+ * @param value - A whole number, 0 or more.
1004
+ * @returns The number with a leading zero below 10.
1005
+ * @example
1006
+ * ```ts
1007
+ * pad2(5); // "05"
1008
+ * ```
1009
+ */
1010
+ function pad2(value) {
1011
+ return String(value).padStart(2, "0");
1012
+ }
1013
+ /**
1014
+ * Whole seconds of a time in milliseconds, rounded up, never below zero. A value that is not
1015
+ * finite counts as zero.
1016
+ *
1017
+ * @param ms - The time in milliseconds.
1018
+ * @returns The whole seconds a timer shows.
1019
+ * @example
1020
+ * ```ts
1021
+ * wholeSeconds(94_001); // 95
1022
+ * ```
1023
+ */
1024
+ function wholeSeconds(ms) {
1025
+ return Number.isFinite(ms) ? Math.max(0, Math.ceil(ms / SECOND_MS)) : 0;
1026
+ }
1027
+ /**
1028
+ * What the shown string of a bound value is built from: the rounded value for `"int"`, whole
1029
+ * seconds for a time format. Two values with the same unit show the same string.
1030
+ *
1031
+ * @param value - The bound number.
1032
+ * @param format - How it is shown.
1033
+ * @returns The unit of the shown string.
1034
+ * @example
1035
+ * ```ts
1036
+ * unitOf(94_500, "mm:ss"); // 95
1037
+ * ```
1038
+ */
1039
+ function unitOf(value, format) {
1040
+ if (format !== "int") return wholeSeconds(value);
1041
+ return Number.isFinite(value) ? Math.round(value) : 0;
1042
+ }
1043
+ /**
1044
+ * The whole number a format a game registered takes: rounded as `"int"` rounds, 0 for a value that
1045
+ * is not finite, and never `-0`, which a format could tell from 0.
1046
+ *
1047
+ * @param value - The bound number.
1048
+ * @returns The whole value.
1049
+ * @example
1050
+ * ```ts
1051
+ * wholeValue(999.6); // 1000
1052
+ * ```
1053
+ */
1054
+ function wholeValue(value) {
1055
+ return Number.isFinite(value) ? Math.round(value) || 0 : 0;
1056
+ }
1057
+ /**
1058
+ * Shows a bound number in one of the four formats. A value that is not finite shows as zero.
1059
+ *
1060
+ * @param value - The number; milliseconds for the time formats.
1061
+ * @param format - How it is shown.
1062
+ * @param duration - Formats milliseconds as words in the current locale.
1063
+ * @returns The string a label shows.
1064
+ * @example
1065
+ * ```ts
1066
+ * formatBound(95_000, "mm:ss", () => ""); // "01:35"
1067
+ * ```
1068
+ */
1069
+ function formatBound(value, format, duration) {
1070
+ const unit = unitOf(value, format);
1071
+ switch (format) {
1072
+ case "int": return String(unit);
1073
+ case "mm:ss": return `${pad2(Math.floor(unit / SECONDS_PER_MINUTE))}:${pad2(unit % SECONDS_PER_MINUTE)}`;
1074
+ case "h:mm:ss": return `${Math.floor(unit / SECONDS_PER_HOUR)}:${pad2(Math.floor(unit / SECONDS_PER_MINUTE) % SECONDS_PER_MINUTE)}:${pad2(unit % SECONDS_PER_MINUTE)}`;
1075
+ case "duration": return duration(unit * SECOND_MS);
1076
+ }
1077
+ }
1078
+ //#endregion
953
1079
  //#region src/plugins/ui/styles/define.ts
954
1080
  /**
955
1081
  * Declares one style. The work is the type: a field outside the vocabulary, or a value outside
@@ -1224,6 +1350,28 @@ function contentOf(props) {
1224
1350
  return props.content ?? "";
1225
1351
  }
1226
1352
  /**
1353
+ * The bind of a text, when the markup gave it one.
1354
+ *
1355
+ * @param element - The element to ask about.
1356
+ * @returns What `bind()` built, or `undefined` for any other element.
1357
+ */
1358
+ function bindOf(element) {
1359
+ const { bind } = element.node.props;
1360
+ return element.type === "text" && typeof bind === "object" && bind !== null ? bind : void 0;
1361
+ }
1362
+ /**
1363
+ * Tells whether an element is a text whose bind names a format of the game, not one of the four
1364
+ * built-in ones: such a format answers the style of the label too, so `Text.style` is what the
1365
+ * label shows and its `style` prop is only where it starts.
1366
+ *
1367
+ * @param element - The element to ask about.
1368
+ * @returns True for a text whose bind names a format.
1369
+ */
1370
+ function namesFormat(element) {
1371
+ const bind = bindOf(element);
1372
+ return bind !== void 0 && !isTextFormat(bind.format);
1373
+ }
1374
+ /**
1227
1375
  * Whether a nine-slice draws its rim alone: `true` while its style says so, `false` once it did and
1228
1376
  * no longer does, and no field on a panel that was never hollow, so a game's describe and saved
1229
1377
  * values stay as they were without it.
@@ -1367,9 +1515,11 @@ function leftSizes(width, height) {
1367
1515
  }
1368
1516
  /**
1369
1517
  * The fields of a value ui does not write onto a live element, or record as its rest: those its component type gives
1370
- * to a plugin and, for the `Sprite` of an image or an icon, the size on an axis its style does not state and the layout
1371
- * left at 0. A game's own system sizes such a sprite; written again by ui (a new viewport, a covered root, a restore)
1372
- * it went back to 0 by 0, drawn at its texture's size (F111). On a first add the size is 0 anyway, the texture's.
1518
+ * to a plugin; for the `Sprite` of an image or an icon, the size on an axis its style does not state and the layout
1519
+ * left at 0; and for the `Text` of a label whose bind names a format, the style its format answered (F135). A game's own
1520
+ * system sizes such a sprite; written again by ui (a new viewport, a covered root, a restore) it went back to 0 by 0,
1521
+ * drawn at its texture's size (F111). On a first add the size is 0 anyway, the texture's. `element.node` is the node of
1522
+ * this render, so a bind that went back to a built-in format or left has its prop written as usual.
1373
1523
  *
1374
1524
  * @param element - The element.
1375
1525
  * @param type - The component type of the value.
@@ -1377,6 +1527,7 @@ function leftSizes(width, height) {
1377
1527
  * @returns The fields left alone.
1378
1528
  */
1379
1529
  function fieldsLeftAlone(element, type, owned) {
1530
+ if (type === Text) return namesFormat(element) ? [...owned, "style"] : owned;
1380
1531
  const { style, rect } = element;
1381
1532
  if (!(element.type === "image" || element.type === "icon") || type !== Sprite) return owned;
1382
1533
  const sizes = leftSizes(rect.w <= 0 && !statesWidth(style), rect.h <= 0 && !statesHeight(style));
@@ -1575,4 +1726,4 @@ function drawnRect(pose, local) {
1575
1726
  };
1576
1727
  }
1577
1728
  //#endregion
1578
- export { Layer as $, readStyle as A, Display as B, defineStyle as C, builtInStyles as D, bind as E, parentOf as F, Parent as G, NineSlice as H, poseUnder as I, Transform as J, Shape as K, rootPointOf as L, applyPose as M, isLeaving as N, defineTextStyles as O, localPoseOf as P, Exiting as Q, rootPoseInto as R, defineTokens as S, Text as T, Overlay as U, HudPart as V, OverlayLevel as W, componentsFor as X, arcDefaults as Y, sprite as Z, ScrollState as _, fitScaleOf as a, resource as at, popup as b, samePose as c, tag as ct, Box as d, Now as et, Covered as f, Scroll as g, LocalWrite as h, fieldsLeftAlone as i, mut as it, textFor as j, label as k, visualOf as l, Escapable as m, CONTENT as n, Tree as nt, livePatch as o, system as ot, DebugTrigger as p, Sprite as q, drawnRect as r, component as rt, restValueOf as s, systemsFor as st, ANCHOR as t, Order as tt, visualRectOf as u, UI_OWNER as v, Countdown as w, uiFor as x, UiCounters as y, rootPoseOf as z };
1729
+ export { Shape as $, Countdown as A, isLeaving as B, uiFor as C, isTextFormat as D, formatBound as E, defineTextStyles as F, rootPoseInto as G, parentOf as H, label as I, HudPart as J, rootPoseOf as K, readStyle as L, bind as M, builtInStyles as N, unitOf as O, defineTextFormats as P, Parent as Q, textFor as R, popup as S, defineStyle as T, poseUnder as U, localPoseOf as V, rootPointOf as W, Overlay as X, NineSlice as Y, OverlayLevel as Z, LocalWrite as _, fieldsLeftAlone as a, Exiting as at, UI_OWNER as b, namesFormat as c, Order as ct, visualOf as d, mut as dt, Sprite as et, visualRectOf as f, resource as ft, Escapable as g, DebugTrigger as h, tag as ht, drawnRect as i, sprite as it, Text as j, wholeValue as k, restValueOf as l, Tree as lt, Covered as m, systemsFor as mt, CONTENT as n, arcDefaults as nt, fitScaleOf as o, Layer as ot, Box as p, system as pt, Display as q, bindOf as r, componentsFor as rt, livePatch as s, Now as st, ANCHOR as t, Transform as tt, samePose as u, component as ut, Scroll as v, defineTokens as w, UiCounters as x, ScrollState as y, applyPose as z };
@@ -1,9 +1,9 @@
1
- import { Fr as Api$2, Qr as Api$3, Z as Api, kr as Api$4, wr as Api$1 } from "./types-CbVXXqPs.mjs";
2
- import { P as AnimApi, r as UiApi } from "./types-C5gLBKbm.mjs";
3
- import { N as InputApi } from "./types-OBpR0u05.mjs";
4
- import { r as Repro } from "./headless-DtDdn5gg.mjs";
5
- import { a as InputOf, r as ControlApp } from "./types-DNWWlVky.mjs";
6
- import { t as commands } from "./commands-CeBF2nRY.mjs";
1
+ import { $r as Api$3, Ar as Api$4, Ir as Api$2, Tr as Api$1, Z as Api } from "./types-w5_A5TPL.mjs";
2
+ import { P as AnimApi, r as UiApi } from "./types-CJYudpme.mjs";
3
+ import { L as InputApi } from "./types-BbLjYfGR.mjs";
4
+ import { r as Repro } from "./headless-CtRq6Uij.mjs";
5
+ import { i as ControlApp, o as InputOf } from "./types-ehmvA6yu.mjs";
6
+ import { t as commands } from "./commands-C6RMqrY8.mjs";
7
7
 
8
8
  //#region src/visual/types.d.ts
9
9
  /** The base commands of the `/control` door, keyed by their short names. */
package/dist/visual.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as VisualApp, c as VisualRenderer, d as VisualStart, f as VisualStep, h as VisualTolerance, i as CheckpointResult, l as VisualReport, m as VisualTestResult, n as runVisualTests, o as VisualOptions, p as VisualTest, r as defineVisualTest, s as VisualPage, t as parseVisualArgv, u as VisualSetup } from "./visual-Di8ecxYD.mjs";
1
+ import { a as VisualApp, c as VisualRenderer, d as VisualStart, f as VisualStep, h as VisualTolerance, i as CheckpointResult, l as VisualReport, m as VisualTestResult, n as runVisualTests, o as VisualOptions, p as VisualTest, r as defineVisualTest, s as VisualPage, t as parseVisualArgv, u as VisualSetup } from "./visual-DvhjRhgP.mjs";
2
2
  export { type CheckpointResult, type VisualApp, type VisualOptions, type VisualPage, type VisualRenderer, type VisualReport, type VisualSetup, type VisualStart, type VisualStep, type VisualTest, type VisualTestResult, type VisualTolerance, defineVisualTest, parseVisualArgv, runVisualTests };
package/dist/visual.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { t as VISUAL_CLOCK } from "./fake-hnJcJeYf.mjs";
2
- import { n as read, t as sources } from "./sources-Djd8MjP9.mjs";
3
- import { n as commands, t as run } from "./run-3QhrffgM.mjs";
2
+ import { n as read, t as sources } from "./sources-kL64Svgl.mjs";
3
+ import { n as commands, t as run } from "./run-B5if0jxE.mjs";
4
4
  import path from "node:path";
5
5
  import { createBrandConsole } from "@moku-labs/common/cli";
6
6
  import { mkdir, readFile, writeFile } from "node:fs/promises";
package/llms.txt CHANGED
@@ -27,10 +27,10 @@ Root exports:
27
27
  - Class: `SaveUnreadableError`.
28
28
  - Plugin instances: `timePlugin`, `lifecyclePlugin`, `modelPlugin`, `clockPlugin`, `flowPlugin`, `worldPlugin`, `rendererPlugin`, `inputPlugin`, `assetsPlugin`, `scenesPlugin`, `animPlugin`, `i18nPlugin`, `textPlugin`, `uiPlugin`, `audioPlugin`, `effectsPlugin`, `platformPlugin`; the list `screen` = `world`, `renderer`, `input`, `assets`, `scenes`, `anim`, `i18n`, `text`, `ui`. `effects`, `audio` and `platform` are opt-in: `plugins: [...screen, effectsPlugin, audioPlugin, platformPlugin]`, `platform` last.
29
29
  - Screen helpers from the root: `component`, `tag`, `resource`, `mut`, `system`, `projection`, `Layer`, `Order`, `Exiting`, `Tree`, `Now`, `Transform`, `Sprite`, `NineSlice`, `Shape`, `Parent`, `Display`, `Overlay`, `HudPart`, `sprite`, `Tappable`, `Pressable`, `Draggable`, `DropTarget`, `Swipeable`, `Traceable`, `Touchable`, `Held`, `Hovered`, `PointerOver`, `Pressed`, `Pointer`, `Traced`, `defineBundles`, `load`, `defineScene`.
30
- - Interface helpers from the root (V3): `defineAnimation`, `sequence`, `parallel`, `stagger`, `tween`, `set`, `wait`, `mark`, `frames`, `sfx`, `haptic`, `use`, `spawn`, `spawned`, `play`, `external`, `defineMotion`, `Animation`, `Frames`, the resource `AnimPlayer`; `tr`, `messageArgument`, `messageDuration`; `Text`, `label`, `defineTextStyles`, `bind`, `Countdown` and the types `BindOptions`, `CountdownValue`, `TextFormat`; `defineComponent`, `popup`, `defineStyle`, `defineTokens`, `resolve`, `Box`, `LocalWrite`, `DebugTrigger`, `ScrollState`; `music`. Also `stopSfx(id, { fadeMs? })` (ends a named sound, see audio) and `cubicBezier(x1, y1, x2, y2)` (a CSS-style easing curve for `tween`'s `ease`).
30
+ - Interface helpers from the root (V3): `defineAnimation`, `sequence`, `parallel`, `stagger`, `tween`, `set`, `wait`, `mark`, `frames`, `sfx`, `haptic`, `use`, `spawn`, `spawned`, `play`, `external`, `defineMotion`, `Animation`, `Frames`, the resource `AnimPlayer`; `tr`, `messageArgument`, `messageDuration`; `Text`, `label`, `defineTextStyles`, `defineTextFormats`, `bind`, `Countdown` and the types `BindOptions`, `CountdownValue`, `TextFormat`, `TextFormats`, `TextFormatAnswer`, `TextFormatFunction`, `FormattedNumber`; `defineComponent`, `popup`, `defineStyle`, `defineTokens`, `resolve`, `Box`, `LocalWrite`, `DebugTrigger`, `ScrollState`; `music`. Also `stopSfx(id, { fadeMs? })` (ends a named sound, see audio) and `cubicBezier(x1, y1, x2, y2)` (a CSS-style easing curve for `tween`'s `ease`).
31
31
  - Effects helpers from the root (V5): `defineEmitter`, `Emitter`, `defineFilter`, `Glow`, `Outline`, `Blur`, `ColorMatrix`, `Noise`, `Displacement`, `Alpha`.
32
32
  - Platform from the root (V6): the types `PlatformProvider`, `BackResult`, `HapticKind` and the frozen list `HAPTIC_KINDS`.
33
- - `defineGame<Types>()` returns, typed by the game's `player`, `session`, `assets`, `bundles`, `scenes`, `strings` and `textStyles`: `defineNode`, `defineFlow`, `defineFeature`, `projection`, `sprite`, `Sprite`, `NineSlice`, `defineBundles`, `load`, `defineScene`, `defineAnimation`, `frames`, `sfx`, `play`, `tr`, `label`, `defineTextStyles`, `defineComponent`, `defineStyle`, `defineTokens`, `popup`, `music`, `Frames`, `defineEmitter`, `Emitter`, `Displacement`, and `system` (its `ctx.snapshot` typed by `player` and `session`), `volumes` (the `audio` config's reader of the typed player), `key` (string keys from data, below). `Types` is `{ player; session; assets: string; bundles?: string; scenes?: string; strings: Record<string, unknown>; textStyles?: string; emitters?: string }`.
33
+ - `defineGame<Types>()` returns, typed by the game's `player`, `session`, `assets`, `bundles`, `scenes`, `strings`, `textStyles` and `textFormats`: `defineNode`, `defineFlow`, `defineFeature`, `projection`, `sprite`, `Sprite`, `NineSlice`, `defineBundles`, `load`, `defineScene`, `defineAnimation`, `frames`, `sfx`, `play`, `tr`, `label`, `bind`, `defineTextStyles`, `defineTextFormats`, `defineComponent`, `defineStyle`, `defineTokens`, `popup`, `music`, `Frames`, `defineEmitter`, `Emitter`, `Displacement`, and `system` (its `ctx.snapshot` typed by `player` and `session`), `volumes` (the `audio` config's reader of the typed player), `key` (string keys from data, below). `Types` is `{ player; session; assets: string; bundles?: string; scenes?: string; strings: Record<string, unknown>; textStyles?: string; textFormats?: string; emitters?: string }`.
34
34
  - `@moku-labs/game/assets`: `scanAssets(options)`, `emitKeys`, `emitManifest`, `compileStrings(root, out, options?)`, `checkStrings`, `packAssets(options)`, `exportStrings`, `importStrings`, `runCli(argv, strings)` with `strings: StringsTools` = `{ compile: compileStrings, exportStrings, importStrings }`. Audio files are `.mp3` or `.m4a`. Asset key = feature (or layer name) + "." + path inside `assets/`; a sub-feature's own name, `features/episodes/ep01/assets/ward/room.png` → `ep01.ward.room`. `runCli` (a game's `bun run assets:keys`) scans the assets and compiles the `strings/<locale>.json` of every feature and sub-feature, and the `strings/` of every layer, into `generated/strings.ts` (the `Strings` type for `defineGame`), one `generated/strings.<locale>.ts` per locale for the top-level features and the layers, and `generated/strings.<feature>.<locale>.ts` per sub-feature with string files, its keys only, each starting with `<feature>.` (it imports `messageArgument` and `messageDuration` from `@moku-labs/game` when a message needs them, no helper is copied in); `--check` fails when any output is out of date; `--pack <dir>` writes the production build. `--layer <folder>[=<name>]`, repeatable and good with every mode, scans `<root>/<folder>/` like one more feature under `<name>` (`<folder>` alone maps to itself): its `assets.ts`, `assets/` and `strings/<locale>.json`. A game on the layered layout passes `--layer shared=ui`, so `shared/assets/*` keeps the `ui.*` keys. A missing layer folder is a warning. `scanAssets`, `compileStrings`, `exportStrings` and `importStrings` take the same map as `layers: { shared: "ui" }`. `--pseudo` also writes the pseudo-locale `en-XA`. `--export <dir>` and `--import <dir>` exchange strings with translators; `--source <locale>` names the locale they read from, `"en"` by default. The package bin `moku-game-assets` is this CLI: a script is `"assets:keys": "moku-game-assets --root src --manifest public/assets/manifest.json --keys src/generated/assets.ts"`. A game with `config.ts` runs `moku-game keys` and `moku-game pack` instead: they pass its paths and its layers.
35
35
  - Type namespaces: `Time`, `Lifecycle`, `Model`, `Clock`, `Flow`, `World`, `Renderer`, `Input`, `Assets`, `Scenes`, `Anim`, `I18n`, `TextTypes`, `Ui`, `Audio`, `Effects`, `Platform`. Use `import type { Flow } from "@moku-labs/game"` and then `Flow.RouteStep`, `Flow.NodeContext`, `Model.Json`, `Model.PlayerStateProvider`, `Clock.ClockSource`, `Time.Phase`, `Lifecycle.PauseReason`, `Anim.Target`, `I18n.Message`. `Text` is the component, so the text types are `TextTypes`.
36
36
  - `defineNode` and `defineFlow` are NOT root exports. They come from `defineGame<Types>()`.
@@ -116,6 +116,7 @@ function defineFeature(name: string, description: FeatureDescription): FeaturePl
116
116
  // ui?: readonly ComponentDefinition[]; // V3, read by ui (defineComponent results)
117
117
  // strings?: Record<locale, CompiledMessages | (() => Promise<unknown>)>; // V3, read by i18n
118
118
  // textStyles?: ReturnType<typeof defineTextStyles>; // V3, read by text
119
+ // textFormats?: ReturnType<typeof defineTextFormats>; // read by text
119
120
  // emitters?: readonly ReturnType<typeof defineEmitter>[]; // V5, read by effects
120
121
  // filters?: readonly ReturnType<typeof defineFilter>[]; // V5, read by effects
121
122
  // }
@@ -302,7 +303,7 @@ app.model.store.snapshot().session; // { rolls: 2 }
302
303
  await run.stop();
303
304
  ```
304
305
 
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?, signing?, ios? }` (absent: no native build; `signing.android: { keystorePath, keystorePasswordEnv, keyPasswordEnv?, keyAlias }`, the path absolute, `~/...` or relative to the game, the passwords by env var name only; `signing.apple: { teamId }`; `ios: { minimumVersion?, infoPlist?, privacyManifest? }`, the minimum `"26.0"` by default, `infoPlist` of `PlistValue`: strings, booleans, arrays, dictionaries, a number or `null` refused; the manifest relative to the game), `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
+ `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?, signing?, ios?, dev? }` (absent: no native build; `signing.android: { keystorePath, keystorePasswordEnv, keyPasswordEnv?, keyAlias }`, the path absolute, `~/...` or relative to the game, the passwords by env var name only; `signing.apple: { teamId }`; `ios: { minimumVersion?, infoPlist?, privacyManifest? }`, the minimum `"26.0"` by default, `infoPlist` of `PlistValue`: strings, booleans, arrays, dictionaries, a number or `null` refused; the manifest relative to the game; `dev: { identifier, name?, icon? }`, the test app of `--store --dev`, the identifier ending in `.dev` and not `native.identifier`, `name` `"<name> DEV"` and `icon` `native.icon` by default), `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
307
 
307
308
  ```ts
308
309
  // config.ts of a game in a native shell
@@ -341,9 +342,9 @@ await startPage(game, config, {
341
342
  Commands of the bin `moku-game` (bun). Every command takes `--root <dir>` (default `.`), `--preload <path>` and `--serve-plugin <path>` (both repeat), before or after the command word. Exit 0 on success, else 1 with a `[game] …` line.
342
343
  - `moku-game dev [--port 3000] [--packed]`: writes `.moku/index.html`, `script.ts` (the `moku:script` startup mark), `dev.ts` (sets `__MOKU_GAME_BUILD__` `"dev"`, the engine id `__MOKU_GAME_ENGINE__`, `__MOKU_GAME_CONTROL__`, `__MOKU_GAME_AGENT__` and last `__MOKU_GAME_DEV__`), `main.ts`, `assets-stamp.ts`, `bunfig.toml` (the hot plugin first, `__MOKU_GAME_DEV__`, `__MOKU_GAME_AGENT__` and `__MOKU_GAME_CONTROL__` defined `true`), runs Bun again under that bunfig in the game folder and serves `/`. It prints `› engine <id>` (and the patch file when there is one), then `› <folder>: dev server, raw assets. Ctrl+C stops it.` and then the bound URL alone on its own line, `http://localhost:3000/`. `--port 0` takes a free port. `--packed` serves `dist/assets`. A new or removed file in `tests/scenarios/` rewrites `main.ts`. On the raw files it keeps `generated/` fresh: it runs the scan of `keys` once before the page is written, and a save of an asset file (`.png`, `.webp`, `.fnt`, `.mp3`, `.m4a`) or of a `strings/<locale>.json` runs it again 100 ms after the last file event and prints `› keys: <path>` or `› keys: <path> and <n> more`; a folder that becomes or stops being a sub-feature (it gains or loses its door, `assets/`, `assets.ts` or `strings/`) scans too, `› keys: features/episodes/ep03/`; a changed or new string hot swaps through `generated/strings.<locale>.ts`, an asset file saved with new bytes swaps in the running page and a new or removed one reloads it, both through `.moku/assets-stamp.ts`, which `main.ts` imports (see "Hot swap"), and files answer `Cache-Control: no-store`. A failed scan is one warning `[game] keys: <message>` and the server runs on. A changed layer in `config.ts` needs a restart; `--packed` watches nothing. A taken port: `[game] dev: port 3000 is in use.` with `Pass --port 0 for a free port.` It watches the installed engine: 300 ms after a new version or dist it warns `[game] dev: the engine changed (<old id> -> <new id>), restarting the dev server.`, stops the child with SIGTERM, writes the page again with the new id and starts a new child (a fixed port keeps its URL, `--port 0` prints a new one); a patch file that changed while the engine did not is one warning that asks for `bun install`.
343
344
  - `moku-game build [--out dist/web]`: packs the assets, bundles the page minified with `__MOKU_GAME_DEV__`, `__MOKU_GAME_AGENT__` and `__MOKU_GAME_CONTROL__` defined `false` (no scenario, no agent, no `.dev` module, no `/control`, no engine id), every link `./`, and copies the pack beside it with `manifest.json` next to `index.html`. Every page marks `moku:script` first and `moku:main` first after its imports. A release page whose `.js` carries `"/__editor/hello"` or `"[moku-editor]"` (the editor's agent) fails with `[game] build: the release page carries the editor agent (…)` and its output folder is removed. Runs from any http sub-path and from Tauri, not from `file://`.
344
- - `moku-game build --debug[=read] [--editor host:port]`: a debug page, never shipped: the release page plus `@moku-labs/editor/agent/page` (resolved from the game, else `[game] build --debug needs @moku-labs/editor in the game.`) and the game's `.dev` modules, started after the app; DEV `false`, AGENT `true`, CONTROL `true` (`--debug`: every command, cheats too; `--debug=full` is an alias that prints one line) or `false` (`--debug=read`, the rare read-only page: read and cosmetic commands); `__MOKU_GAME_BUILD__` `debug-<UTC stamp>` for both, `__MOKU_GAME_ENGINE__` the engine id (`<version>+<dist hash>[.patch.<hash>]`, `+src` from sources), `__MOKU_GAME_EDITOR__` the `--editor` address (default `127.0.0.1:47600`); the title reads `<title> Debug`; no hot swap, no frame recorder, no audio journal, no scenario. It prints one warning naming the profile, the build id, the engine and the editor. `MOKU_NATIVE_PROFILE=store` with `--debug` is refused.
345
- - `moku-game native build <target> [--simulator] [--debug[=full] [--editor host:port]]`, `native dev <target>`, `native doctor [<target>]`, `native clean [<target>]`: one verb of `@moku-labs/native` (a dev dependency, `^0.3.12`) over `config.ts`. App name, identifier and icon from `native`, orientation and background colour from `page`; the web build is `moku-game build`, the dev server `moku-game dev --port 5173`; system rows for `back`, `haptics`, `store`; the Tauri project in `.moku/tauri`, the apps in `dist-native`; an Android app composes native's `shell` system first. `native build android --debug` builds a debug app (`debug: true` to native, which installs it beside the store app; the web build is `moku-game build --debug` with the same profile and `--editor`); other verbs and targets refuse `--debug`. `[game] config.ts has no native section.` without `native`.
346
- - `moku-game native build <ios|android> --store --build-number <n>`: a store build, an `.aab` on Android (`aab: true` to native), an `.ipa` with `exportMethod: "app-store-connect"` on iOS. `app.version` from `package.json`, `app.buildNumber` from the flag, an integer from 1 to 2100000000, one number for both stores. Refused before `config.ts` is read: outside `native build`, with `--debug`, `--editor` or `--simulator`, on another target, without a valid number; `--build-number` without `--store`. Then every problem at once, before anything compiles, in one `[game] native --store: …` error, a line per problem: no signing block for the target, on Android a keystore that is not a file or an unset password variable (its name only, never a value), a `package.json` version that is not `x.y.z`, an identifier that ends in `.soak`, `.debug`, `.dev`, `.test` or `.staging`. On iOS it warns, and goes on, without `ios.privacyManifest` or `ITSAppUsesNonExemptEncryption` in `ios.infoPlist`. A build without `--store` runs no store check: `native build ios` is a device build. Every build takes a valid `package.json` version (else native's `0.1.0`), `app.keepScreenOn` from `keepAwake` in `system`, and on iOS the minimum `26.0`; a debug app leaves `signing.android` out and keeps the SDK key.
345
+ - `moku-game build --debug[=read] [--editor host:port]`: a debug page, never shipped: the release page plus `@moku-labs/editor/agent/page` (resolved from the game, else `[game] build --debug needs @moku-labs/editor in the game.`) and the game's `.dev` modules, started after the app; DEV `false`, AGENT `true`, CONTROL `true` (`--debug`: every command, cheats too; `--debug=full` is an alias that prints one line) or `false` (`--debug=read`, the rare read-only page: read and cosmetic commands); `__MOKU_GAME_BUILD__` `debug-<UTC stamp>` for both, `__MOKU_GAME_ENGINE__` the engine id (`<version>+<dist hash>[.patch.<hash>]`, `+src` from sources), `__MOKU_GAME_EDITOR__` the `--editor` address (default `127.0.0.1:47600`); the title reads `<title> Debug`; no hot swap, no frame recorder, no audio journal, no scenario. It prints one warning naming the profile, the build id, the engine and the editor. `MOKU_NATIVE_PROFILE=store` with `--debug` is refused. `MOKU_NATIVE_PROFILE=dev`, a test app's web build: a run without `--debug` is refused (`[game] build: MOKU_NATIVE_PROFILE is dev: a dev page carries the overlay.`); `--debug` builds `__MOKU_GAME_EDITOR__` exactly `"off"`, so the agent opens no socket, with CONTROL `true` and `__MOKU_GAME_APP__` `native.dev.identifier`; `--editor`, `--debug=read` and an `@moku-labs/editor` below 0.10.19, or of a version that cannot be read, are refused.
346
+ - `moku-game native build <target> [--simulator] [--debug[=full] [--editor host:port]]`, `native dev <target>`, `native doctor [<target>]`, `native clean [<target>]`: one verb of `@moku-labs/native` (a dev dependency, `^0.3.13`) over `config.ts`. App name, identifier and icon from `native`, orientation and background colour from `page`; the web build is `moku-game build`, the dev server `moku-game dev --port 5173`; system rows for `back`, `haptics`, `store`; the Tauri project in `.moku/tauri`, the apps in `dist-native`; an Android app composes native's `shell` system first. `native build android --debug` builds a debug app (`debug: true` to native, which installs it beside the store app; the web build is `moku-game build --debug` with the same profile and `--editor`). `native build ios --debug [--simulator]` is the same app on iOS: the engine names it `<name> (debug)` and `<identifier>.debug`, in `.moku/tauri-debug`, native delivers to `dist-native/ios-debug`. Other verbs and targets refuse `--debug`. `native clean` also cleans `.moku/tauri-dev` and `.moku/tauri-debug` when they exist, one native clean per folder; `doctor` stays on `.moku/tauri`. `[game] config.ts has no native section.` without `native`.
347
+ - `moku-game native build <ios|android> --store --build-number <n>`: a store build, an `.aab` on Android (`aab: true` to native), an `.ipa` with `exportMethod: "app-store-connect"` on iOS. `app.version` from `package.json`, `app.buildNumber` from the flag, an integer from 1 to 2100000000, one number for both stores. Refused before `config.ts` is read: outside `native build`, with `--debug`, `--editor` or `--simulator`, on another target, without a valid number; `--build-number` without `--store`. Then every problem at once, before anything compiles, in one `[game] native --store: …` error, a line per problem: no signing block for the target, on Android a keystore that is not a file or an unset password variable (its name only, never a value), a `package.json` version that is not `x.y.z`, an identifier that ends in `.soak`, `.debug`, `.dev`, `.test` or `.staging`. On iOS it warns, and goes on, without `ios.privacyManifest` or `ITSAppUsesNonExemptEncryption` in `ios.infoPlist`. A build without `--store` runs no store check: `native build ios` is a device build. `--store --dev` builds the test app of `native.dev`: every store check, the identifier row reading `native.dev.identifier`; `dev: true` to native (`aab` on Android as before), the same signing, the web build `moku-game build --debug`, the project `.moku/tauri-dev`, a full Rust build of its own, the apps in `dist-native-dev`; the save stays under `native.identifier`. `--dev` without `--store` is refused before `config.ts` is read, with no `native.dev` right after, and `--store --debug` stays refused. Every build takes a valid `package.json` version (else native's `0.1.0`), `app.keepScreenOn` from `keepAwake` in `system`, and on iOS the minimum `26.0`; a debug app leaves `signing.android` out and keeps the SDK key.
347
348
  - `moku-game keys [--check]`: `generated/assets.ts`, the compiled strings (`strings.ts`, `strings.<locale>.ts` for the top-level features and the layers, and `strings.<feature>.<locale>.ts` for every sub-feature with string files) and the dev manifest `generated/manifest.json` (a sub-feature's bundle carries its `dir` and `parent`); `dev` runs the same scan at start and on save and serves the manifest on `/manifest.json`, `visual` stops without it. `moku-game pack [--no-cache]`: `dist/assets`. Both pass the layers of `config.ts`.
348
349
  - `moku-game visual [--update] [--only <name>] [--no-pixels | --pixels] [--webgl] [--dir <path>] [--tests <file>] [--url <url>]`: runs `runVisualTests` with the default export of `tests/visual/index.ts`, `{ app, tests }` (`app` is a `VisualSetup` `{ app, page? }`: `export default { app: { app: fixtureApp }, tests }`), against `tests/visual/baselines/`. The flags go through `parseVisualArgv`. The pixel leg runs on a Mac only unless `--pixels`/`--no-pixels`; without `--url` the command writes its own page into `.moku/visual/` (the page of `dev` and of the editor in `.moku/` stays), runs Bun again under `.moku/visual/bunfig.toml` as `dev` does (hot plugin, `--serve-plugin`, `--preload`), and the child serves the page on a free port, then stops it. No `manifest.json`: `[game] visual: no manifest.json in "<game>".` Exit 0 when the report is ok, else 1. `[game] visual: <file> must export default { app, tests }.` for a missing module or another shape, a bare app factory too.
349
350
  - `preparePage(root, { agents?, preload?, servePlugins? })` of `@moku-labs/game/cli` writes the dev page of `moku-game dev` and resolves `{ html, bunfig, engine }` (both paths absolute; `engine` the `EngineFingerprint` whose `id` the page shows in `globalThis.__MOKU_GAME_ENGINE__`), for a server the caller starts: `bun --config=<bunfig>`. With agents the page also imports the game's `**/*.dev.ts` and hands them to the agents. It also writes the first, empty `.moku/assets-stamp.ts` when the game has none. The editor calls it: `await preparePage("games/timber", { agents: ["@moku-labs/editor/agent/page"] })`.
@@ -596,7 +597,7 @@ A screen is a projection whose `view` returns JSX. The game's `tsconfig.json` se
596
597
  - `defineComponent(name, { local?, outcomes?, view(props, local) })`. A component with `outcomes` is a popup: `await fx(popup(Component, props))` opens the gate for its outcomes and resolves with `{ intent, payload }` of the pressed button. A button with `local` writes into the nearest component instance; it never reaches the graph.
597
598
  - `tr(key, params?)` returns a frozen `Message` `{ key, params }`; no locale is read at the call site. Strings live in `strings/<locale>.json` of any feature or sub-feature, as ICU MessageFormat 1 (`{n, plural, one {# order} other {# orders}}`, `select`, `selectordinal`, `number`, `date`, `time`; no skeletons, no `currency`). `bun run assets:keys` compiles them. The keys of the top-level features and the layers go into `generated/strings.<locale>.ts`, which one feature registers; a sub-feature's keys start with `<name>.` (`ep01.title`) and go into `generated/strings.<name>.<locale>.ts`, which the sub-feature registers lazily, `strings: { en: () => import("@generated/strings.ep01.en"), ru: () => import("@generated/strings.ep01.ru") }`. With `assets` composed those modules load and unload with the bundle named like the sub-feature: every way the bundle comes (a node entry, a scene's `bundles`, `load`, a restore, the `safeNode`) brings its strings, a locale switch brings them in the new locale, and while the bundle is not loaded a key of it gives `⟦key⟧` and `has(key)` is false. A compiled module calls the root helpers `messageArgument(value, intl)` (an element stays an element part, a list goes through `Intl.ListFormat`, a number through `Intl.NumberFormat`, else text) and `messageDuration(ms)` (`95_000` gives `{ minutes: 1, seconds: 35 }`). `app.i18n`: `locale()`, `setLocale(locale)` (async, emits `i18n:locale-changed`), `format(message, locale?)` returns `Part[]`, `plain(message)` returns a string, `has(key)`, `isKey(value)`, `locales()`, `replace(locale, messages)` (dev hot swap of a generated strings file). Config: `locale: "en"`, `fallback: "en"`, `locales: {}`.
598
599
  - Keys that come from data: `I18n.TextKey<Strings>` is the keys of the generated `Strings` without parameters (nothing new is generated). A data table types its keys `TextKey` or builds them with the kit's `key("board.hint.red")`; the kit's `tr` never takes a plain `string`. A key read back from a save is checked where the app is (an effect handler, app or page code, loading a save) with one `isKey(value)`: `defineGameApp({ ..., strings: type<Strings>() })` types the game's `app.i18n`, so a true `app.i18n.isKey(value)` narrows the value to `TextKey`; `ctx.require(i18nPlugin).isKey(value)` in a plugin narrows to `string`. `app.i18n.isKey(value)` answers true for a key of the loaded tables of the current locale or the fallback, and for the `<feature>.` prefix of a sub-feature whose strings are not loaded yet; a key that takes parameters answers true too.
599
- - Text: `Text` component, `label({ text, style, at, anchor? })` for board text in a projection view, `defineTextStyles({ "hud.digits": { font, size, fill, bold?, italic?, stroke?, strokeWidth?, letterSpacing?, align?, wrap? (a width, "none" or "box": wrap at the laid-out width of its ui element), digits?, lineHeight? (the line as a multiple of size above 0, such as 1.28; glyphs sit in the middle of the line; absent: the font's own line) } })` under the feature's `textStyles` key. Tags inside a string: `<b>`, `<i>`, `<color=#rrggbb>`, `<icon=key>`, `\<`, `\n`. Built-in styles `body` and `digits` from config `fonts: { body: "ui.font-body", digits: "ui.font-digits" }`. `app.text.measure(content, style, width?)` gives the same numbers in a browser and in Bun. `app.text.replaceStyles(styles)` is the dev hot swap of a saved `defineTextStyles` value.
600
+ - Text: `Text` component, `label({ text, style, at, anchor? })` for board text in a projection view, `defineTextStyles({ "hud.digits": { font, size, fill, bold?, italic?, stroke?, strokeWidth?, letterSpacing?, align?, wrap? (a width, "none" or "box": wrap at the laid-out width of its ui element), digits?, lineHeight? (the line as a multiple of size above 0, such as 1.28; glyphs sit in the middle of the line; absent: the font's own line) } })` under the feature's `textStyles` key. Tags inside a string: `<b>`, `<i>`, `<color=#rrggbb>`, `<icon=key>`, `\<`, `\n`. Built-in styles `body` and `digits` from config `fonts: { body: "ui.font-body", digits: "ui.font-digits" }`. `app.text.measure(content, style, width?)` gives the same numbers in a browser and in Bun. `app.text.replaceStyles(styles)` is the dev hot swap of a saved `defineTextStyles` value. A game's own number format: `defineTextFormats({ "pill.number": value => ({ content, style }) })` under the feature's `textFormats` key, named by the `bind` of `defineGame` (`GameTypes.textFormats`): `bind(Counter, "value", { format: "pill.number" })`. It takes the whole value, is pure over value and language, is not called while the whole value and the locale stand, and owns `Text.style`; a `Countdown` calls it every frame. `app.text.formatted(name, value)` answers `{ text, style }`, `undefined` for an unknown or built-in name and for a format that threw. A saved module exporting formats reloads the page.
600
601
  - Animation is data: `defineAnimation(id, { slots: { name: type<Anim.Target>() }, build: (slots, { at }) => Step })`. Steps: `sequence(...)`, `parallel(...)`, `stagger(items, ms, item => Step)`, `tween(target, Component, to, { ms, ease?, delayMs?, additive?, space?, reduced? })`, `set(target, Component, patch)`, `wait(ms)`, `mark(name)`, `frames(target, { keys, fps, loop? })`, `sfx(key, { bus? })`, `haptic(kind)`, `use(animation, slots, tools?)`, `spawn` (a temporary entity, flying coins, that the timeline despawns when it ends; see the anim README). `Frames({ keys, fps, loop, playing })` is a component that walks a sprite through its textures for the entity's whole life. A target is `{ projection, key }` or an entity. A timeline resolves each `{ projection, key }` target once, when it starts: every step writes the view that held the key then, also after a commit removed it and while its exit plays, until it despawns; a view spawned again under the same key is not followed, and a key nothing held at the start is looked up at its step. `reduced: "keep"` (on a `tween` step, `transition` and `loop` of `defineMotion`, `TweenOptions`, `RestOptions`) plays a track as written under reduced motion, a fade for one; the default `"cut"` lands it at once or holds a loop on its first key. A node plays it with `await fx(play(animation, slots))`; in fast mode it finishes at once. `defineMotion({ states, transition?, on: { enter?, exit?, change? }, when? })` builds the enter, exit and change hooks for a projection or the `motion` prop of a tag; `when: "change"` plays enter and exit only for a commit, so an element that comes or goes with its screen stands at rest and leaves without a motion (default `"always"`). Events `anim:mark` `{ animation, mark }` and `anim:finished` `{ animation }`. `app.anim.replace(definition)` is the dev hot swap: the next `play` builds the new tree. A system cannot `require` a plugin, so it plays through the resource `AnimPlayer`: `res(AnimPlayer).play(animation, slots)` returns the same handle as `app.anim.play`, and the registered animation of `animation.id` wins, so a hot swap reaches the system. Play on a change, never every frame; from phase `input` the tree moves in `animate` of the same frame. Before `anim` starts it throws `[game] AnimPlayer is not ready: anim has not started.` Config `maxTracks: 2000`.
601
602
  - A `tween` step takes `segments` and `repeat` as `ViewHandle.tween` does: `tween(chest, Transform, { y: 0, scale: 0 }, { ms: 2400, additive: true, repeat: "forever", segments: [{ at: 0.08, ease: "out", to: { y: -14, scale: 0.06 } }, { at: 1, to: { y: 0, scale: 0 } }] })`. Segments walk over `ms` on one clock, `to` is where the last one ends, an additive walk names offsets; a number counts the extra runs. A definition error throws for empty segments, an `at` outside 0..1 or out of order, a last segment before 1, a bad repeat, and a `sequence` step after one that never ends. A forever step ends only by cancel or finish (a finish and a fast world land it on its start pose), does not play under reduced motion `"cut"`, writes nothing while its view is unseen, and lets the clock idle; a system plays it once through `AnimPlayer` and keeps the handle.
602
603
  - Audio is opt-in: `plugins: [...screen, audioPlugin]`. `fx(sfx("orders.complete"))` resolves when the sound started. `await fx(music("board.theme"))` cross-fades; `music(null)` fades out; a scene's `music` key switches the track on `scenes:changed`. Buses `master`, `music`, `sfx`. Volumes come from the committed player: config `volumes: player => (player as Player).settings.audio`, applied on every `model:committed`. `app.audio`: `setVolume(bus, value)`, `volume(bus)`, `mute(bus, on)`, `muted(bus)`, `unlocked()`, `journal()` (the last started sounds, empty unless config `journal` is above 0). Config: `buses: { master: 1, music: 0.6, sfx: 1 }`, `musicFadeMs: 600`, `volumes`, `context`, `journal: 0`, `music: "decode" | "stream"` default `"decode"` (gapless buffer; `"stream"` is an `<audio>` element, less memory, a gap at every loop), `session: "ambient" | "playback" | "auto"` default `"ambient"` (iOS only: ambient mixes with other apps and obeys the silent switch). The context is asked to run at start: where the shell lets audio play (a native webview with the gesture requirement off) `unlocked()` is true with no touch; a browser that wants a gesture unlocks on the first `pointerdown` or `touchend`. Without `audio` every `sfx` and `music` effect resolves `undefined` at once, so the same node runs in a game with no sound. Named sounds: `sfx(key, { bus?, id?, fadeMs? })` with an `id` plays through its own gain, and the next sound with the same `id` fades the old one out over `fadeMs`, else config `sfxFadeMs` (default `120`, real milliseconds); `fx.start(stopSfx(id, { fadeMs? }))` and `app.audio.stop(id, { fadeMs? })` fade it out and end it (`fadeMs: 0` cuts it); an `id` nothing plays under changes nothing, and a sound of that `id` still decoding never starts. Without `id` an `sfx` plays to its end as before.
@@ -699,10 +700,10 @@ A plugin that owns a resource stores it in its state and frees it in `onStop: ({
699
700
  Two subpaths, neither on the root (V4). An editor, MCP tools and e2e scripts reach a running game through them; `docs/doors.md` in the engine repository has the full catalogue.
700
701
 
701
702
  - `@moku-labs/game/inspect`: `read(app, source, input?)` reads once; `watch(app, source, input, fn)` reads on the `signals` phase when the source changes and returns the stop function; `defineSource`; the frozen catalogue `sources`; the types `Source`, `InputSchema`, `InputOf`. Every source only reads, so the door is safe in a production build. Keys of `sources`: `graph`, `position`, `history`, `tainted`, `cheats`, `model`, `entities`, `projections`, `ui`, `locate`, `render`, `sounds`, `audioMuted`, `effects`, `filters`, `assets`, `log`, `explain`, `diff`, `schema`, `at`; their ids are `game.<key>`. `filters` answers `{ kinds, off }` of `effects.diagnostics`. `locate` takes `{ key }` (a ui element) or `{ target }` (a view by projection key) and answers its box in CSS px, the numbers Playwright clicks. `at` takes `{ x, y }` in CSS px and lists the views under that point, topmost first. `explain` takes `{ entity }` and answers that entity in full, `undefined` for a stale id. `diff` takes `{ from, to }` frames and answers what changed per entity; it throws in a production build and for a frame outside the last 120. `schema` lists every component and tag type the world met, with the JSON kind of each field. `audioMuted` answers whether the master bus is muted. `sounds` throws `[game] The source game.sounds needs audioPlugin.`, `audioMuted` throws `[game] The source game.audioMuted needs audioPlugin.` and `effects` and `filters` throw `[game] The source game.effects needs effectsPlugin.` (`game.filters` for `filters`) when that plugin is not installed; the editor lists such a source as not installed.
702
- - `@moku-labs/game/control`: `run(app, command, input?)` resolves `{ value, state }`, `state` being `{ path, frame, tainted }`; `defineCommand`; `controlRefused`; `controlReadOnly`; the frozen catalogue `commands`; the types `Command`, `Ran`, `ControlReadOnlyError`. Keys of `commands`: `answer`, `tap`, `drag`, `key`, `fill`, `scroll`, `walk`, `bookmark`, `restore`, `saveExport`, `saveImport`, `step`, `pause`, `resume`, `capture`, `debug`, `reducedMotion`, `timeScale`, `frameRate`, `mute`, `trace`, `filter`. `capture` resolves `{ png }`, and `{ png, legend }` with `legend: true`; `undefined` while the renderer is inert. `timeScale` takes `{ scale }`; 0 freezes game time while the frames keep running. `frameRate` takes `{ fps? }`, calls `time.setRate(fps ?? "auto")` and answers `time.rate()`. `mute` takes `{ muted }`, mutes the master bus and answers the flag. Without `audioPlugin` it throws `[game] The command game.mute needs audioPlugin.` `trace` takes `{ path }`, a list of views by projection key, and answers whether the gate took the answer. `scroll` takes `{ key, to }`, calls `ui.scroll(key, to)` and answers what it answers; a visual test writes it as the step `{ scroll: { key, to } }`. `filter` takes `{ kind, on }`, switches the filter kind through `effects.diagnostics` (cosmetic) and answers the off kinds; an unknown kind throws `[game] No filter kind "fx.nope".` naming the known ones; without `effectsPlugin` it throws `[game] The command game.filter needs effectsPlugin.`
703
+ - `@moku-labs/game/control`: `run(app, command, input?)` resolves `{ value, state }`, `state` being `{ path, frame, tainted }`; `defineCommand`; `controlRefused`; `controlReadOnly`; the frozen catalogue `commands`; the types `Command`, `ChoiceInput`, `Ran`, `ControlReadOnlyError`. Keys of `commands`: `answer`, `tap`, `drag`, `key`, `fill`, `scroll`, `walk`, `bookmark`, `restore`, `saveExport`, `saveImport`, `step`, `pause`, `resume`, `capture`, `debug`, `reducedMotion`, `timeScale`, `frameRate`, `mute`, `trace`, `filter`. `capture` resolves `{ png }`, and `{ png, legend }` with `legend: true`; `undefined` while the renderer is inert. `timeScale` takes `{ scale }`; 0 freezes game time while the frames keep running. `frameRate` takes `{ fps? }`, calls `time.setRate(fps ?? "auto")` and answers `time.rate()`. `mute` takes `{ muted }`, mutes the master bus and answers the flag. Without `audioPlugin` it throws `[game] The command game.mute needs audioPlugin.` `trace` takes `{ path }`, a list of views by projection key, and answers whether the gate took the answer. `scroll` takes `{ key, to }`, calls `ui.scroll(key, to)` and answers what it answers; a visual test writes it as the step `{ scroll: { key, to } }`. `filter` takes `{ kind, on }`, switches the filter kind through `effects.diagnostics` (cosmetic) and answers the off kinds; an unknown kind throws `[game] No filter kind "fx.nope".` naming the known ones; without `effectsPlugin` it throws `[game] The command game.filter needs effectsPlugin.`
703
704
  - Commands run in dev builds and debug builds. `__MOKU_GAME_DEV__ === true` (the dev page, a test's `vi.stubGlobal("__MOKU_GAME_DEV__", true)`) or `__MOKU_GAME_CONTROL__ === true` (`--debug`) runs every command; `__MOKU_GAME_AGENT__ === true` alone (`--debug=read`) runs the `read` and `cosmetic` ones and `run` refuses the others with `controlReadOnly(id)`, an error with `reason: "read-only"`: `[game] The command game.tap changes the game: this debug build runs read and cosmetic commands only.`; no flag: `run` throws `[game] Control commands run in dev builds only.` `moku-game build` defines the three flags `false`; a game without the shell uses a bundler `define` and should add `__MOKU_GAME_AGENT__: "false"` and `__MOKU_GAME_CONTROL__: "false"`. `saveExport` answers the committed `{ player, session, rng }` (read); `saveImport` takes `{ save }` of `saveExport`, restores it at the main flow's start and flushes the store (raw: not on a `--debug=read` page).
704
705
  - A command's effect is `read`, `route`, `cosmetic`, `cheat` or `raw`. A `cheat` or `raw` command taints the session and is journaled; read it with `sources.tainted` and `sources.cheats`. Of the base commands `restore` and `saveImport` are `raw`; `capture` with `diff` writes the state too, so a `--debug=read` page refuses it. `bookmark` answers `flow.bookmark()` plus `scene`, the mounted scene; `restore` calls `scenes.expect(scene)` before `flow.restore`, so a bookmark at a popup restores the scene under it, also on a page that shows another scene. A bookmark taken while an effect that takes answers waits names the waiting transit node (`info/show` in the mini game) and carries `rest`; `restore` of it answers once that node's gate is open, with `pending.gate` in its value, and the popup shows on the next frame.
705
- - A game's own: `defineSource({ id, title, input, changes, read })` with `changes` `"frame"`, `"commit"` or `"edge"`, and `defineCommand({ id, title, input, effect, run, overlay?, value? })`: `overlay: "toggle"` (input exactly `{ on: "boolean" }` and `value: app => boolean`, the switch's state) or `overlay: "button"` (no required input, no value) lists the command in the editor's overlay, which shows only such commands; any other combination is a type error. The id is camelCase words joined by dots, at least two: `dice.rolls`. An input schema maps field names to `"string"`, `"number"`, `"boolean"` or `"json"`; a trailing `?` makes one optional. A command body starts with `if (typeof __MOKU_GAME_DEV__ === "undefined" || !__MOKU_GAME_DEV__) throw controlRefused();`: it runs in dev and is refused on a debug page. A `.dev` command meant for a debug page writes the agent form for a read or cosmetic effect, `if ((typeof __MOKU_GAME_DEV__ === "undefined" || !__MOKU_GAME_DEV__) && (typeof __MOKU_GAME_AGENT__ === "undefined" || !__MOKU_GAME_AGENT__)) throw controlRefused();`, and the control form (`__MOKU_GAME_CONTROL__` in place of `__MOKU_GAME_AGENT__`) for the others. Keep them in `.dev` modules that only the dev page, a debug page and the tests import: the editor's dev page (`preparePage` with agents) and `moku-game build --debug` import every `**/*.dev.ts`, `moku-game build` none.
706
+ - A game's own: `defineSource({ id, title, input, changes, read })` with `changes` `"frame"`, `"commit"` or `"edge"`, and `defineCommand({ id, title, input, effect, run, overlay?, value?, choices?, choice? })`: `overlay: "toggle"` (input exactly `{ on: "boolean" }` and `value: app => boolean`, the switch's state; with `choices: readonly [string, ...string[]]`, each word once or `defineCommand` throws, the input is exactly `{ on: "boolean", choice: "string" | "string?" }` and `choice: app => string` answers the marked one, run with `{ on, choice }`) or `overlay: "button"` (no required input, no value) lists the command in the editor's overlay, which shows only such commands; any other combination is a type error. The id is camelCase words joined by dots, at least two: `dice.rolls`. An input schema maps field names to `"string"`, `"number"`, `"boolean"` or `"json"`; a trailing `?` makes one optional. A command body starts with `if (typeof __MOKU_GAME_DEV__ === "undefined" || !__MOKU_GAME_DEV__) throw controlRefused();`: it runs in dev and is refused on a debug page. A `.dev` command meant for a debug page writes the agent form for a read or cosmetic effect, `if ((typeof __MOKU_GAME_DEV__ === "undefined" || !__MOKU_GAME_DEV__) && (typeof __MOKU_GAME_AGENT__ === "undefined" || !__MOKU_GAME_AGENT__)) throw controlRefused();`, and the control form (`__MOKU_GAME_CONTROL__` in place of `__MOKU_GAME_AGENT__`) for the others. Keep them in `.dev` modules that only the dev page, a debug page and the tests import: the editor's dev page (`preparePage` with agents) and `moku-game build --debug` import every `**/*.dev.ts`, `moku-game build` none.
706
707
 
707
708
  ## Project index
708
709
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moku-labs/game",
3
- "version": "0.15.86",
3
+ "version": "0.15.88",
4
4
  "description": "2D puzzle game engine on TypeScript and PixiJS, built on @moku-labs/core.",
5
5
  "type": "module",
6
6
  "sideEffects": [
@@ -127,7 +127,7 @@
127
127
  "peerDependencies": {
128
128
  "@moku-labs/common": "^0.3.4",
129
129
  "@moku-labs/core": "^1.7.1",
130
- "@moku-labs/native": "^0.3.12",
130
+ "@moku-labs/native": "^0.3.13",
131
131
  "@moku-labs/system": "^0.3.1",
132
132
  "pixi.js": "^8.22.0",
133
133
  "playwright-core": ">=1.50.0",
@@ -162,7 +162,7 @@
162
162
  "@moku-labs/ci": "1.5.7",
163
163
  "@moku-labs/common": "0.3.10",
164
164
  "@moku-labs/core": "1.7.6",
165
- "@moku-labs/native": "0.3.12",
165
+ "@moku-labs/native": "0.3.13",
166
166
  "@moku-labs/system": "0.3.7",
167
167
  "@types/bun": "1.4.2",
168
168
  "@vitest/coverage-istanbul": "4.0.18",