@moku-labs/game 0.0.1 → 0.0.2
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 +424 -37
- package/dist/assets.d.mts +161 -0
- package/dist/assets.mjs +4729 -0
- package/dist/component-DGg5DqKK.mjs +44 -0
- package/dist/control.d.mts +162 -0
- package/dist/control.mjs +758 -0
- package/dist/define-sFoO3y6X.d.mts +263 -0
- package/dist/headless-CvamCUcR.mjs +186 -0
- package/dist/headless-KaSWcd0s.d.mts +181 -0
- package/dist/index.d.mts +1204 -50
- package/dist/index.mjs +20978 -2010
- package/dist/inspect.d.mts +109 -0
- package/dist/inspect.mjs +519 -0
- package/dist/jsx-dev-runtime.d.mts +2 -0
- package/dist/jsx-dev-runtime.mjs +2 -0
- package/dist/jsx-runtime.d.mts +2 -0
- package/dist/jsx-runtime.mjs +2 -0
- package/dist/memory-CvgdnsQO.mjs +259 -0
- package/dist/registry-DlpRCibU.mjs +384 -0
- package/dist/runtime-DRlwxkIv.mjs +182 -0
- package/dist/runtime-DiOTkDZz.d.mts +77 -0
- package/dist/session-DmAxY6Ll.mjs +145 -0
- package/dist/testing.d.mts +23 -111
- package/dist/testing.mjs +12 -289
- package/dist/types-BxkNNYul.d.mts +2840 -0
- package/dist/types-CTPS9GBu.d.mts +742 -0
- package/dist/types-DD-QrG_z.d.mts +588 -0
- package/dist/types-DWILGrPn.d.mts +622 -0
- package/dist/types-DYLnSgMI.d.mts +570 -0
- package/dist/types-JNc_UQBo.d.mts +2896 -0
- package/dist/types-yg_ywtT-.d.mts +1859 -0
- package/dist/visual-BDUHSRvf.mjs +734 -0
- package/package.json +26 -4
- package/dist/registry-DWV5C0Mf.mjs +0 -666
- package/dist/types-BfsmUzLC.d.mts +0 -1908
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
//#region src/plugins/ui/jsx/component.ts
|
|
2
|
+
/** The local state a component that declares none starts every instance with. */
|
|
3
|
+
const noLocal = {};
|
|
4
|
+
/**
|
|
5
|
+
* Tells a component definition from a plain function component, which JSX calls at build time.
|
|
6
|
+
*
|
|
7
|
+
* @param type - What stood in the tag position.
|
|
8
|
+
* @returns True when `defineComponent` built it.
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* isComponentDefinition(() => ({ type: "row", props: {}, children: [] })); // false
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
function isComponentDefinition(type) {
|
|
15
|
+
return typeof type === "function" && type.isUiComponent === true;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The one implementation behind the two overloads.
|
|
19
|
+
*
|
|
20
|
+
* @param name - Component name.
|
|
21
|
+
* @param spec - What the game declared.
|
|
22
|
+
* @returns The callable definition.
|
|
23
|
+
*/
|
|
24
|
+
function defineComponent(name, spec) {
|
|
25
|
+
const local = spec.local ?? noLocal;
|
|
26
|
+
const call = (props) => ({
|
|
27
|
+
type: name,
|
|
28
|
+
props,
|
|
29
|
+
children: []
|
|
30
|
+
});
|
|
31
|
+
const definition = Object.assign(call, {
|
|
32
|
+
outcomes: spec.outcomes,
|
|
33
|
+
local,
|
|
34
|
+
view: spec.view,
|
|
35
|
+
isUiComponent: true
|
|
36
|
+
});
|
|
37
|
+
Object.defineProperty(definition, "name", {
|
|
38
|
+
value: name,
|
|
39
|
+
configurable: true
|
|
40
|
+
});
|
|
41
|
+
return definition;
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
export { isComponentDefinition as n, defineComponent as t };
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { M as Time, X as Api, g as Bookmark, y as FlowState } from "./types-JNc_UQBo.mjs";
|
|
2
|
+
import { s as DebugSwitches, t as Api$1 } from "./types-BxkNNYul.mjs";
|
|
3
|
+
import { t as HeadlessApp } from "./headless-KaSWcd0s.mjs";
|
|
4
|
+
import { a as ControlApp, c as InputSchema, i as Command, l as Ran, o as InputArguments, t as defineCommand } from "./define-sFoO3y6X.mjs";
|
|
5
|
+
import { H as InputApi } from "./types-yg_ywtT-.mjs";
|
|
6
|
+
import { r as UiApi } from "./types-DD-QrG_z.mjs";
|
|
7
|
+
import { t as AnimApi } from "./types-CTPS9GBu.mjs";
|
|
8
|
+
|
|
9
|
+
//#region src/plugins/flow/doors/commands.d.ts
|
|
10
|
+
/**
|
|
11
|
+
* Every command of the engine, keyed by its short name: what an editor lists as buttons and MCP
|
|
12
|
+
* tools. Frozen. Each runs in dev builds only.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* // An e2e script taps Play, and the editor registers every command.
|
|
17
|
+
* (await run(app, commands.tap, { key: "play" })).state.path; // "board/awaitIntent"
|
|
18
|
+
* for (const command of Object.values(commands)) registry.add(command);
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
declare const commands: Readonly<{
|
|
22
|
+
answer: Command<{
|
|
23
|
+
intent: "string";
|
|
24
|
+
payload: "json?";
|
|
25
|
+
}, boolean, ControlApp>;
|
|
26
|
+
tap: Command<{
|
|
27
|
+
key: "string?";
|
|
28
|
+
target: "json?";
|
|
29
|
+
}, boolean, HeadlessApp & {
|
|
30
|
+
readonly log: import("@moku-labs/common/browser").LogApi;
|
|
31
|
+
} & {
|
|
32
|
+
readonly input: Pick<InputApi, "tap">;
|
|
33
|
+
readonly ui: Pick<UiApi, "find">;
|
|
34
|
+
}>;
|
|
35
|
+
drag: Command<{
|
|
36
|
+
from: "json";
|
|
37
|
+
to: "json";
|
|
38
|
+
}, boolean, HeadlessApp & {
|
|
39
|
+
readonly log: import("@moku-labs/common/browser").LogApi;
|
|
40
|
+
} & {
|
|
41
|
+
readonly input: InputApi;
|
|
42
|
+
}>;
|
|
43
|
+
key: Command<{
|
|
44
|
+
key: "string";
|
|
45
|
+
shift: "boolean?";
|
|
46
|
+
}, boolean, HeadlessApp & {
|
|
47
|
+
readonly log: import("@moku-labs/common/browser").LogApi;
|
|
48
|
+
} & {
|
|
49
|
+
readonly input: InputApi;
|
|
50
|
+
}>;
|
|
51
|
+
walk: Command<{
|
|
52
|
+
route: "json";
|
|
53
|
+
}, FlowState, ControlApp>;
|
|
54
|
+
bookmark: Command<{}, Bookmark, ControlApp>;
|
|
55
|
+
restore: Command<{
|
|
56
|
+
bookmark: "json?";
|
|
57
|
+
repro: "json?";
|
|
58
|
+
}, FlowState, ControlApp>;
|
|
59
|
+
step: Command<{
|
|
60
|
+
frames: "number";
|
|
61
|
+
deltaMs: "number?";
|
|
62
|
+
}, Readonly<Time>, ControlApp>;
|
|
63
|
+
pause: Command<{}, boolean, HeadlessApp & {
|
|
64
|
+
readonly log: import("@moku-labs/common/browser").LogApi;
|
|
65
|
+
} & {
|
|
66
|
+
readonly lifecycle: Api;
|
|
67
|
+
}>;
|
|
68
|
+
resume: Command<{}, boolean, HeadlessApp & {
|
|
69
|
+
readonly log: import("@moku-labs/common/browser").LogApi;
|
|
70
|
+
} & {
|
|
71
|
+
readonly lifecycle: Api;
|
|
72
|
+
}>;
|
|
73
|
+
capture: Command<{}, string | undefined, HeadlessApp & {
|
|
74
|
+
readonly log: import("@moku-labs/common/browser").LogApi;
|
|
75
|
+
} & {
|
|
76
|
+
readonly renderer: Api$1;
|
|
77
|
+
}>;
|
|
78
|
+
debug: Command<{
|
|
79
|
+
nineSlice: "boolean";
|
|
80
|
+
}, DebugSwitches, HeadlessApp & {
|
|
81
|
+
readonly log: import("@moku-labs/common/browser").LogApi;
|
|
82
|
+
} & {
|
|
83
|
+
readonly renderer: Api$1;
|
|
84
|
+
}>;
|
|
85
|
+
reducedMotion: Command<{
|
|
86
|
+
on: "boolean";
|
|
87
|
+
}, boolean, HeadlessApp & {
|
|
88
|
+
readonly log: import("@moku-labs/common/browser").LogApi;
|
|
89
|
+
} & {
|
|
90
|
+
readonly anim: AnimApi;
|
|
91
|
+
}>;
|
|
92
|
+
}>;
|
|
93
|
+
//#endregion
|
|
94
|
+
//#region src/plugins/flow/doors/dev.d.ts
|
|
95
|
+
/**
|
|
96
|
+
* @file flow/doors — the dev flag. `__MOKU_GAME_DEV__` is a global the engine never replaces: a
|
|
97
|
+
* game's dev build defines it `true` (bundler `define`) or sets `globalThis.__MOKU_GAME_DEV__`
|
|
98
|
+
* before the engine runs; undefined means a production build.
|
|
99
|
+
*
|
|
100
|
+
* Bun does not inline `isDev()` across modules (checked on Bun 1.3.14), so a branch that must
|
|
101
|
+
* vanish from a production bundle writes the guard inline:
|
|
102
|
+
* `if (typeof __MOKU_GAME_DEV__ === "undefined" || !__MOKU_GAME_DEV__) throw controlRefused();`.
|
|
103
|
+
* A `define` of `false` folds that condition, and the minifier drops the code behind it.
|
|
104
|
+
*/
|
|
105
|
+
declare global {
|
|
106
|
+
/**
|
|
107
|
+
* The dev flag of a game. A game never re-declares it: it defines it in the bundler, or sets
|
|
108
|
+
* `globalThis.__MOKU_GAME_DEV__ = true` in its dev entry.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* // web/dev.ts, imported first by the dev page: /control commands run from here on.
|
|
113
|
+
* globalThis.__MOKU_GAME_DEV__ = true;
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
var __MOKU_GAME_DEV__: boolean | undefined;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Reads the dev flag at call time. Undefined means off: production is the default.
|
|
120
|
+
*
|
|
121
|
+
* @returns True only when `__MOKU_GAME_DEV__` is exactly `true`.
|
|
122
|
+
* @example
|
|
123
|
+
* ```ts
|
|
124
|
+
* // The dev page set the flag in web/dev.ts before the engine started.
|
|
125
|
+
* globalThis.__MOKU_GAME_DEV__ = true;
|
|
126
|
+
* isDev(); // true
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
/**
|
|
130
|
+
* Builds the error a control command throws outside a dev build.
|
|
131
|
+
*
|
|
132
|
+
* @returns The error, ready to throw.
|
|
133
|
+
* @example
|
|
134
|
+
* ```ts
|
|
135
|
+
* // A production build called a /control command.
|
|
136
|
+
* controlRefused().message; // "[game] Control commands run in dev builds only.\n Define __MOKU_GAME_DEV__ as true in the dev build."
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
declare function controlRefused(): Error;
|
|
140
|
+
//#endregion
|
|
141
|
+
//#region src/plugins/flow/doors/run.d.ts
|
|
142
|
+
/**
|
|
143
|
+
* Runs a command in a dev build. A `cheat` or `raw` command taints the session and is journaled
|
|
144
|
+
* before it runs, so a failing one still counts.
|
|
145
|
+
*
|
|
146
|
+
* @param app - The app the command acts on.
|
|
147
|
+
* @param command - The command.
|
|
148
|
+
* @param input - Its input; left out when every field of its schema is optional.
|
|
149
|
+
* @returns The command's value and the envelope read after it.
|
|
150
|
+
* @throws {Error} Outside a dev build, and whatever the command throws.
|
|
151
|
+
* @example
|
|
152
|
+
* ```ts
|
|
153
|
+
* // An e2e script: load the bug report, then tap Play.
|
|
154
|
+
* await run(app, commands.restore, { repro }); // state: { path: "home", frame: 12, tainted: true }
|
|
155
|
+
* const ran = await run(app, commands.answer, { intent: "play" });
|
|
156
|
+
* ran.value; // true
|
|
157
|
+
* ran.state; // { path: "board/awaitIntent", frame: 14, tainted: true }
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
declare function run<S extends InputSchema, O, App extends HeadlessApp>(app: App, command: Command<S, O, App>, ...input: InputArguments<S>): Promise<Ran<O>>;
|
|
161
|
+
//#endregion
|
|
162
|
+
export { type Command, type Ran, commands, controlRefused, defineCommand, run };
|