@moku-labs/game 0.15.51 → 0.15.53

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.
@@ -1,4 +1,4 @@
1
- import { An as MotionHandle, Cn as TagType, Dn as Ease, K as TransformValue, Ln as ViewHandle, Mn as ProjectionMotion, On as Motion, Pn as ReducedMotion, Rn as Api$1, Tn as ChangeHook, Y as Api$3, Yr as Api, _r as Hint, ai as Require, br as Api$5, cn as AnyComponentType, dt as ViewportSize, fn as ComponentType, jn as NumericFields, kn as MotionCause, kr as Json, ln as AnyComponentValue, mn as Entity, nn as Api$2, pr as Descriptor, s as Events$1, sn as AnyComponent, t as Api$4, wn as AnchorTarget, yr as Answer } from "./types-BS0JBrBZ.mjs";
1
+ import { $n as AnyComponentType, Fn as Hint, Gn as NumericFields, Hn as Motion, Jn as ReducedMotion, K as TransformValue, Kn as ProjectionMotion, Ln as Answer, Qn as AnyComponent, Rn as AnchorTarget, Un as MotionCause, Vn as Ease, Wn as MotionHandle, Y as Api$3, Yr as Api, Zn as ViewHandle, ai as Require, ar as Entity, br as Api$5, dt as ViewportSize, er as AnyComponentValue, hr as Api$2, jn as Descriptor, kr as Json, mr as TagType, nn as Api$1, rr as ComponentType, s as Events$1, t as Api$4, zn as ChangeHook } from "./types-D9YSrw2Z.mjs";
2
2
  import { Log } from "@moku-labs/common/browser";
3
3
  import { PluginCtx } from "@moku-labs/core";
4
4
  import { Node, Yoga } from "yoga-layout/load";
@@ -849,7 +849,7 @@ type I18nKit<Table extends StringTable> = {
849
849
  key: <const Key extends TextKey<Table>>(key: Key) => Key;
850
850
  };
851
851
  declare namespace types_d_exports$1 {
852
- export { Carried, Config$1 as Config, Deps$1 as Deps, Direction, GesturePhase, InputApi, InputCtx, KernelSlice$1 as KernelSlice, KeyInput, KeyListener, Point$1 as Point, PointerListener, RawSample, State$1 as State, TapListener, Target };
852
+ export { Carried, Config$1 as Config, Deps$1 as Deps, Direction, GesturePhase, InputApi, InputCtx, KernelSlice$1 as KernelSlice, KeyInput, KeyListener, LockWindow, Point$1 as Point, PointerListener, RawSample, State$1 as State, TapListener, Target };
853
853
  }
854
854
  /**
855
855
  * A point in reference units, as `renderer.viewport.toReference` answers it.
@@ -863,6 +863,21 @@ type Point$1 = {
863
863
  x: number;
864
864
  y: number;
865
865
  };
866
+ /**
867
+ * The window of the input lock a `guide` sets: a rect in reference units, edges included. While a
868
+ * lock stands, a press, a drop and a trace sample outside it reach no view.
869
+ *
870
+ * @example
871
+ * ```ts
872
+ * const window: LockWindow = { x: 36, y: 1496, w: 124, h: 128 }; // the padded seat of the strip
873
+ * ```
874
+ */
875
+ type LockWindow = Readonly<{
876
+ x: number;
877
+ y: number;
878
+ w: number;
879
+ h: number;
880
+ }>;
866
881
  /**
867
882
  * The dominant axis of a swipe.
868
883
  *
@@ -1082,6 +1097,12 @@ type State$1 = {
1082
1097
  resolvedEarly: boolean; /** The cursor last written on the attached canvas; `undefined` while nothing was written. */
1083
1098
  cursor: string | undefined; /** Component types other plugins registered through `controls.add`, once per registration. */
1084
1099
  controls: AnyComponentType[];
1100
+ /**
1101
+ * The lock of a running `guide`, set through `lock.window`: `undefined` locks nothing, `null`
1102
+ * locks everything, a window locks everything outside it. Kept by reference: `ui` writes the same
1103
+ * object in place every frame.
1104
+ */
1105
+ lock: LockWindow | null | undefined;
1085
1106
  };
1086
1107
  /**
1087
1108
  * input plugin API, `app.input`: the same door for the finger, for a test and for an agent. Each
@@ -1288,6 +1309,34 @@ type InputApi = {
1288
1309
  * ```
1289
1310
  */
1290
1311
  listeners(): number;
1312
+ /**
1313
+ * The input lock of a tutorial guide: while it stands, the finger reaches only the views inside
1314
+ * its window.
1315
+ */
1316
+ lock: {
1317
+ /**
1318
+ * Sets the window of the lock. A press whose point lies outside it reaches no view, so no
1319
+ * `Tappable`, no `LocalWrite`, no scroll and no drag starts there: it answers the gate's
1320
+ * `blocked` (`flow.gate.state().blocked`, the `blocked` of the running guide) when there is one
1321
+ * and is dropped otherwise. A drop and a trace sample outside the window find no view either,
1322
+ * and the hover leaves the views outside it. Inside the window nothing changes. `undefined`
1323
+ * lifts the lock, `null` locks everything: a guide with no target shown. The rect is kept by
1324
+ * reference, so a caller writes the same object in place every frame; the frame step of
1325
+ * `input` runs before `layout`, so a press reads the window of the frame before. The doors
1326
+ * `tap`, `press`, `drag`, `swipe` and `trace` do no hit test: the lock never applies to them.
1327
+ *
1328
+ * @param rect - The window in reference units, `null` for none, `undefined` to lift the lock.
1329
+ * @example
1330
+ * ```ts
1331
+ * // ui's guide over the first seat of the strip, padded by 4: written in place every frame.
1332
+ * const window = { x: 36, y: 1496, w: 124, h: 128 };
1333
+ * ctx.require(inputPlugin).lock.window(window);
1334
+ * // a tap at (300, 900) reaches no view and answers { intent: "tutorialBlocked" }, the guide's blocked
1335
+ * ctx.require(inputPlugin).lock.window(undefined); // the guide ended: every view takes presses again
1336
+ * ```
1337
+ */
1338
+ window(rect: LockWindow | null | undefined): void;
1339
+ };
1291
1340
  /**
1292
1341
  * The components that make a view a control besides input's own: the cursor shows
1293
1342
  * `config.cursor.control` over a view that carries one of them.
@@ -2436,6 +2485,20 @@ declare function popup<Properties extends object, Local extends object, Outcomes
2436
2485
  }): Descriptor<Answer<keyof Outcomes & string>>;
2437
2486
  //#endregion
2438
2487
  //#region src/plugins/ui/layout/types.d.ts
2488
+ /**
2489
+ * A rectangle in root coordinates, in reference units.
2490
+ *
2491
+ * @example
2492
+ * ```ts
2493
+ * const rect: Rect = { x: 0, y: 0, w: 1080, h: 1920 };
2494
+ * ```
2495
+ */
2496
+ type Rect = {
2497
+ x: number;
2498
+ y: number;
2499
+ w: number;
2500
+ h: number;
2501
+ };
2439
2502
  /**
2440
2503
  * The patches the scroll step writes with, one object each, filled in place: a frame builds none.
2441
2504
  * Every number in them is a whole reference unit.
@@ -2460,6 +2523,33 @@ type ScrollPatches = {
2460
2523
  y: number;
2461
2524
  };
2462
2525
  };
2526
+ /**
2527
+ * The guide `ui` shows: its targets and padding, the veil it spawned, and the rects it writes in
2528
+ * place every frame. `window` is the object `input` keeps as the lock while a target is shown.
2529
+ */
2530
+ type Guide = {
2531
+ /** The targets the window is cut over; empty for a guide with no target: a full veil. */targets: readonly AnchorTarget[]; /** How far the window grows outward on every side, in screen reference units. */
2532
+ pad: number; /** The rectangles of the veil, in the order of `rects`; none for `veil: false`. */
2533
+ veils: Entity[]; /** One rect per rectangle of the veil: one for a guide with no target, four around a window. */
2534
+ rects: readonly Rect[]; /** The union of the shown targets, padded: the window of the veil and of the lock. */
2535
+ window: Rect; /** The viewport, read every frame. */
2536
+ screen: Rect; /** What the resolver writes on its way: one target's rect and its pose. */
2537
+ scratch: {
2538
+ part: Rect;
2539
+ pose: TransformValue;
2540
+ }; /** What `input` locks now: the window, every press, or nothing yet. */
2541
+ locked: "window" | "all" | "none"; /** Whether a target was shown at the last placement. */
2542
+ found: boolean;
2543
+ /**
2544
+ * Frames of the pass the window taken over from the guide this one replaced is kept while no
2545
+ * target is shown; 0 when nothing was taken over, or once a target showed.
2546
+ */
2547
+ grace: number; /** Frames in a row a key of the guide named no entity; counted in a dev build. */
2548
+ missing: number; /** True once a dev build named a key that named no entity. */
2549
+ warned: boolean; /** True once the guide ended: its veil left. */
2550
+ ended: boolean; /** The frame the guide ended in; -1 while it stands. */
2551
+ endedAt: number;
2552
+ };
2463
2553
  /**
2464
2554
  * layout module state. `nodes` is attach minus detach: Yoga 3.2.1 has no instance counter.
2465
2555
  * `scrolling` is the scroll the finger holds; `scrollClock` the ms the scroll step has run, the
@@ -2482,7 +2572,9 @@ type LayoutState = {
2482
2572
  scrollPatches: ScrollPatches; /** One line of the `body` style as the icons were last measured with it; none before that. */
2483
2573
  iconLine: number | undefined;
2484
2574
  order: number;
2485
- cleanups: Array<() => void>;
2575
+ cleanups: Array<() => void>; /** The guide on screen, placed every frame by the system `ui.guide`; none while no guide stands. */
2576
+ guide: Guide | undefined; /** The last guide that ended: one that follows in its frame with the same targets takes its window. */
2577
+ lastGuide: Guide | undefined;
2486
2578
  };
2487
2579
  /**
2488
2580
  * The longest finite track a motion hook started through its view handle: where it ends (delay included), its length,
@@ -1,7 +1,7 @@
1
- import { $ as PixiModule, Bn as Config$1, Cr as FakeClock, Dr as Config, Fr as ProviderCall, Ir as SaveDoc, Pr as PlayerStateProvider, X as Config$2, a as Config$3, d as Manifest, fr as TypeTag, kr as Json, lt as Orientation, n as AssetsIo, rr as AnyFlow, tr as FeaturePlugin, xr as ClockSource, zr as SnapshotOf } from "./types-BS0JBrBZ.mjs";
2
- import { o as AudioContextLike, s as Config$4 } from "./types-CEWtlmPp.mjs";
3
- import { R as I18nApi, U as StringTable, W as TextKey } from "./types-OvmeuFbz.mjs";
4
- import { St as effectsPlugin, Tt as audioPlugin, ht as PlatformProvider, i as screen, pt as platformPlugin, t as createApp } from "./index-BMnrhJy2.mjs";
1
+ import { $ as PixiModule, An as TypeTag, Cr as FakeClock, Dr as Config, Fr as ProviderCall, Ir as SaveDoc, Pr as PlayerStateProvider, X as Config$2, a as Config$3, d as Manifest, in as Config$1, kr as Json, lt as Orientation, n as AssetsIo, xn as AnyFlow, xr as ClockSource, yn as FeaturePlugin, zr as SnapshotOf } from "./types-D9YSrw2Z.mjs";
2
+ import { o as AudioContextLike, s as Config$4 } from "./types-CS-taLiS.mjs";
3
+ import { R as I18nApi, U as StringTable, W as TextKey } from "./types-DKSQ5lXh.mjs";
4
+ import { St as effectsPlugin, Tt as audioPlugin, ht as PlatformProvider, i as screen, pt as platformPlugin, t as createApp } from "./index-Bu1D4fG7.mjs";
5
5
  import { AnyPluginInstance } from "@moku-labs/core";
6
6
 
7
7
  //#region src/plugins/model/store/providers/memory.d.ts
@@ -1,9 +1,9 @@
1
- import { Er as Api$2, Ur as Api$3, Y as Api, br as Api$4, nn as Api$1 } from "./types-BS0JBrBZ.mjs";
2
- import { P as AnimApi, r as UiApi } from "./types-CEWtlmPp.mjs";
3
- import { N as InputApi } from "./types-OvmeuFbz.mjs";
4
- import { r as Repro } from "./headless-oFoYPHp1.mjs";
5
- import { a as InputOf, r as ControlApp } from "./types-DPliH9lD.mjs";
6
- import { t as commands } from "./commands-B4bQrMk7.mjs";
1
+ import { Er as Api$2, Ur as Api$3, Y as Api, br as Api$4, hr as Api$1 } from "./types-D9YSrw2Z.mjs";
2
+ import { P as AnimApi, r as UiApi } from "./types-CS-taLiS.mjs";
3
+ import { N as InputApi } from "./types-DKSQ5lXh.mjs";
4
+ import { r as Repro } from "./headless-C4YDmZv1.mjs";
5
+ import { a as InputOf, r as ControlApp } from "./types-BdwZpZce.mjs";
6
+ import { t as commands } from "./commands-4FGZndLY.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-BJ8-LEjY.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-CnGMkSF-.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/llms.txt CHANGED
@@ -77,6 +77,7 @@ defineNode(spec: {
77
77
  barrier?: boolean;
78
78
  inbox?: readonly (keyof Tags & string)[];
79
79
  run?: (ctx: NodeContext) => Result | Promise<Result>;
80
+ guide?: (state: { player; session }) => GuideOptions | undefined; // the tutorial step derived from committed state, see "Tutorial guide"
80
81
  }): NodeDefinition;
81
82
 
82
83
  defineFlow(id: string, spec: {
@@ -122,7 +123,9 @@ function defineFeature(name: string, description: FeatureDescription): FeaturePl
122
123
  function schedule(moment: number | undefined): Descriptor; // awaited, asks the clock for one `elapsed`
123
124
  function guide(options: GuideOptions): Descriptor; // awaited, narrows the gate to one answer
124
125
  function hint(kind: string, payload?: Json): Hint; // for fx.emit, cosmetic
125
- // GuideOptions = { allow: { intent: string; payload?: Json }; highlight?: readonly string[]; hand?: "tap" | "drag"; text?: string }
126
+ // GuideOptions = { allow: { intent: string; payload?: Json }; target?: AnchorTarget | readonly AnchorTarget[];
127
+ // pad?: number; veil?: { color?: number; alpha?: number } | false; blocked?: { intent: string; payload?: Json };
128
+ // highlight?, hand?, text? (deprecated: not drawn by the engine, draw them in an <anchor>) }
126
129
  // Descriptor = { kind: string; payload?: Json; answers?: readonly string[]; cosmetic?: boolean }
127
130
  ```
128
131
 
@@ -443,7 +446,31 @@ export const thanksFeature = defineFeature("thanks", {
443
446
  });
444
447
  ```
445
448
 
446
- A tutorial step is `await fx(guide({ allow: { intent: "roll" }, hand: "tap", text: "Tap the dice" }))`. Only that answer passes the gate until the node exits.
449
+ ### Tutorial guide
450
+
451
+ A tutorial step is data: the rest node derives it from the committed state with `guide`, so no save field and no `run` hold it.
452
+
453
+ ```ts
454
+ export const awaitIntent = defineNode({
455
+ rest: true,
456
+ outcomes: { merge: type<{ from: string; to: string }>(), tutorialBlocked: type() },
457
+ guide: ({ session }) =>
458
+ session.tutorial === 2
459
+ ? {
460
+ allow: { intent: "merge", payload: { from: "c2", to: "c3" } },
461
+ target: [{ projection: "board.items", key: "c2" }, { projection: "board.items", key: "c3" }],
462
+ pad: 8,
463
+ veil: false, // the game draws its own look in an <anchor>
464
+ blocked: { intent: "tutorialBlocked" } // a press outside the window answers this
465
+ }
466
+ : undefined
467
+ });
468
+ ```
469
+
470
+ - `guide` runs when the node is entered (after its `onEnter` stages) and again after a commit while it waits at its gate (never for the commit of an edge); an equal result (deep JSON) changes nothing, a new one replaces the guide, `undefined` lifts it. It goes when the node is left; a restore enters the node again, so it is derived again. Fast mode: only the narrow. A `guide` that throws fails the node: `[game] The guide of node "path" threw: <message>` (rollback, retry, safe node). A dev build fails it when `blocked.intent` is no outcome of the node.
471
+ - The gate takes only `allow` and `blocked` while a guide stands; `app.flow.gate.state()` reports `blocked`.
472
+ - `ui` draws a veil (black 0.6, or `veil: { color, alpha }`; `alpha: 0` invisible, `false` none) around a window over the target or the union of the shown targets, grown by `pad`, placed every frame (it follows a moving or scrolling target), and locks `input` outside the window: a press there reaches no view (no `Tappable`, `LocalWrite`, scroll, drag, trace) and answers `blocked`, or nothing. No target, or none shown: the veil covers the screen and every press is locked, so a target key that never shows soft-locks the step (only `blocked` and the keyboard answer); a dev build warns `ui:guide-target-missing` `{ targets }` once after a key named no entity two frames in a row. A guide derived again with the same targets keeps the previous window for two frames while its targets are not laid out yet. A text field outside the window opens no keyboard. The doors `app.input.tap/press/drag` do no hit test and are not locked; a press reads the window of the frame before (input runs before layout). 0 B a frame.
473
+ - `await fx(guide({ allow: { intent: "roll" } }))` in a body still works, with the same options. The rounded window, the rim, the glide, the hand and the text are the game's: an `<anchor>` on the same targets with `veil: false`.
447
474
 
448
475
  ## Graph rules checked at `run()`
449
476
 
@@ -510,7 +537,7 @@ The editor's overlay from the game, in every app. The plugin name `debug` is res
510
537
 
511
538
  The graph. Modules `runner`, `gate`, `inbox`, `fx`, `features`. Runner methods sit on the plugin root.
512
539
  - Runner: `run(): Promise<void>`, `onEnter(stage: "begin" | "load" | "scene", callback): () => void` (stages run in that order, each awaited; a `"begin"` callback must not wait: `scenes` shows the veil there before `assets` downloads at `"load"`), `walk(route, options?: { from?: Bookmark }): Promise<FlowState>`, `bookmark(): Bookmark`, `restore(bookmark): Promise<void>`, `describe(): FlowGraph`, `state(): FlowState`, `history(): readonly JournalEntry[]`, `setMode("live" | "fast")`.
513
- - `gate.answer({ intent, payload? }): boolean` is the one entry of player answers. `gate.pointer(active)`. `gate.state(): { open, allowed, narrowed }`.
540
+ - `gate.answer({ intent, payload? }): boolean` is the one entry of player answers. `gate.pointer(active)`. `gate.state(): { open, allowed, narrowed, blocked? }` (`blocked` while a guide names the answer of a press outside its window).
514
541
  - `inbox.post({ type, payload? })` queues a world event. One entry per type. It is delivered only to a rest node whose `inbox` lists the type.
515
542
  - `fx.handle(kind, handler, options?: { runInFast?: boolean }): () => void` registers the single handler of one effect kind. `fx.dispatch(descriptor)` is fire-and-forget. An awaited effect without a handler resolves `undefined` at once.
516
543
  - `features.register(name, description)`, `features.all()`, `features.contributions(slotName)`.
@@ -543,6 +570,7 @@ The graph. Modules `runner`, `gate`, `inbox`, `fx`, `features`. Runner methods s
543
570
  - Motion hooks are told why they play: `enter(view, item, hint, cause)` and `exit(view, item, hint, cause)` get `World.MotionCause`, `"mount"` (the view comes or goes with its screen: a mount, an unmount, a load, a restore, a paused or fast world) or `"change"` (a commit). A world projection plays them only for `"change"`; `ui` plays them for both. `app.world.projection.causeOf(entity)` answers how a view came or how it is leaving, also in a removal hook of its despawn, until the next frame.
544
571
  - `app.world.projection.replace(spec)` swaps the spec of a registered projection; a mounted one runs its new `view` on the next frame. An unknown name throws. The caller is the dev hot swap.
545
572
  - `projection({ …, initialOnly: [[Shape, ["sweep"]]] })`: `view` gives those fields once, at the birth of a view; after that they belong to another writer (a system drawing a timer arc from `Now`), and no changed item, motion, end-of-motion check (`world:view-corrected`), rollback, `settle`, restore or load writes or compares them, as with `mute()` for every view's whole life. Field names are checked per component; a pair with no field throws at register. Absent, every field is the projection's.
573
+ - `app.input.lock.window(rect | null | undefined)`: the input lock `ui` sets for a guide (`Input.LockWindow` = `{ x, y, w, h }` in reference units, kept by reference and written in place); a press outside reaches no view and answers `flow.gate.state().blocked` or nothing, a drop or trace sample outside finds nothing; `null` locks everything, `undefined` lifts it. The doors `tap`, `press`, `drag`, `swipe`, `trace` are never locked.
546
574
  - `input`: one followed pointer. A finger that has not started a gesture (pressed, inside the tap slop, no long press, no trace) gives way to the next finger that goes down, wherever it rests, and its press is cancelled; a finger that started a gesture keeps it. `Pointer.id` is the followed `pointerId` (`-1` at rest): a system that measures the finger's travel starts over when it changes.
547
575
  - `Draggable({ payload, carry?, aim? })`: `aim: { x, y }`, a point of the view in its own units, moves the hover and the drop lookup from the finger to that point of the view in the hand; `null` (default) is the finger.
548
576
  - `pluginConfigs.renderer.onDemand: true` draws a frame only when something visible changed (a written view, a filter value, a resize, a wake, a capture); `app.renderer.stats().drawn` is the frames drawn per second (`fps` without it); a game that writes into its own `Display` object calls `app.renderer.invalidate(entity)` before the write; `renderer.sync.debug.verifyFrames(true)` (dev/debug) checks skipped frames by pixels and logs `renderer:missed-frame`; a dev build warns `renderer:missed-mark` for a write without the call.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moku-labs/game",
3
- "version": "0.15.51",
3
+ "version": "0.15.53",
4
4
  "description": "2D puzzle game engine on TypeScript and PixiJS, built on @moku-labs/core.",
5
5
  "type": "module",
6
6
  "sideEffects": [