@moku-labs/game 0.0.0

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.
@@ -0,0 +1,327 @@
1
+ import { A as Patch, B as PauseReason, C as State, D as Root, E as Json, F as StoreApi, G as State$4, H as types_d_exports$2, I as RngApi, J as Events, K as types_d_exports$4, O as State$3, P as SaveUnreadableError, R as Api$2, T as Config$3, U as Api$3, V as State$2, W as Config$4, _ as GuideOptions, a as Kit, b as Api, c as exit, d as type, f as FeatureDescription, g as Descriptor, i as GameTypes, k as types_d_exports$3, l as slot, n as Config$1, o as State$1, q as Config$5, r as FeaturePlugin, s as types_d_exports$1, t as Api$1, u as to, v as Hint, w as types_d_exports, x as Config, z as Config$2 } from "./types-BfsmUzLC.mjs";
2
+
3
+ //#region src/plugins/clock/index.d.ts
4
+ /**
5
+ * Clock plugin: `app.clock.now()`, `app.clock.scheduleAt(moment)`, `app.clock.onElapsed(fn)`.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * ctx.require(clockPlugin).scheduleAt(nextDue);
10
+ * ```
11
+ */
12
+ declare const clockPlugin: import("@moku-labs/core").PluginInstance<"clock", Config, State, Api, {}> & Record<never, never>;
13
+ //#endregion
14
+ //#region src/plugins/flow/index.d.ts
15
+ /**
16
+ * Flow plugin: `app.flow.run()`, `app.flow.gate.answer(...)`, `app.flow.fx.handle(...)`.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * createApp({ pluginConfigs: { flow: { mainFlow } }, onStart: startGraph });
21
+ * ```
22
+ */
23
+ declare const flowPlugin: import("@moku-labs/core").PluginInstance<"flow", Config$1, State$1, Api$1, {
24
+ "flow:edge": {
25
+ flow: string;
26
+ node: string;
27
+ outcome: string;
28
+ payload: Json;
29
+ next: string;
30
+ patches: {
31
+ doc: Patch[];
32
+ session: Patch[];
33
+ };
34
+ index: number;
35
+ now: number;
36
+ };
37
+ "flow:rest": {
38
+ path: string;
39
+ checkpoint: boolean;
40
+ };
41
+ "flow:error": {
42
+ path: string;
43
+ error: unknown;
44
+ rolledBackTo: string;
45
+ retry: boolean;
46
+ };
47
+ }> & Record<never, never>;
48
+ //#endregion
49
+ //#region src/plugins/lifecycle/index.d.ts
50
+ /**
51
+ * Lifecycle plugin: `app.lifecycle.push(reason)`, `app.lifecycle.pop(reason)`.
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * ctx.require(lifecyclePlugin).push("background");
56
+ * ```
57
+ */
58
+ declare const lifecyclePlugin: import("@moku-labs/core").PluginInstance<"lifecycle", Config$2, State$2, Api$2, {
59
+ "lifecycle:changed": {
60
+ reason: PauseReason;
61
+ action: "push" | "pop";
62
+ reasons: readonly PauseReason[];
63
+ paused: boolean;
64
+ resumed: boolean;
65
+ };
66
+ }> & Record<never, never>;
67
+ //#endregion
68
+ //#region src/plugins/model/index.d.ts
69
+ /**
70
+ * Model plugin: `app.model.store`, `app.model.rng`.
71
+ *
72
+ * @example
73
+ * ```ts
74
+ * const transaction = ctx.require(modelPlugin).store.begin();
75
+ * ```
76
+ */
77
+ declare const modelPlugin: import("@moku-labs/core").PluginInstance<"model", Config$3, State$3, {
78
+ store: StoreApi;
79
+ rng: RngApi;
80
+ }, {
81
+ "model:committed": {
82
+ roots: readonly Root[];
83
+ cause: "edge" | "rollback" | "restore" | "load";
84
+ };
85
+ }> & Record<never, never>;
86
+ //#endregion
87
+ //#region src/plugins/time/index.d.ts
88
+ /**
89
+ * Time plugin: `app.time.onFrame(phase, fn)`, `app.time.step(dt)`.
90
+ *
91
+ * @example
92
+ * ```ts
93
+ * ctx.require(timePlugin).onFrame("animate", advanceTweens);
94
+ * ```
95
+ */
96
+ declare const timePlugin: import("@moku-labs/core").PluginInstance<"time", Config$4, State$4, Api$3, {}> & Record<never, never>;
97
+ //#endregion
98
+ //#region src/plugins/flow/feature.d.ts
99
+ /**
100
+ * Turns a feature description into a plugin that registers it with `flow.features` in `onInit`.
101
+ * Throws for a name that is reserved or already a plugin. The plugin carries `logicOnly`: the
102
+ * same plugin built from the V1 keys of the description, for headless tests.
103
+ *
104
+ * @param name - Feature name. Shares the namespace with plugin names.
105
+ * @param description - What the feature brings: nodes, flows, slot contributions.
106
+ * @returns The feature plugin, with its `logicOnly` twin.
107
+ * @throws {Error} When the name is reserved or belongs to an engine plugin.
108
+ * @example
109
+ * ```ts
110
+ * export const boardFeature = defineFeature("board", {
111
+ * flows: [boardFlow],
112
+ * contribute: { afterWin: { flow: rewardFlow, order: 10 } }
113
+ * });
114
+ * ```
115
+ */
116
+ declare function defineFeature(name: string, description: FeatureDescription): FeaturePlugin;
117
+ //#endregion
118
+ //#region src/plugins/flow/fx/descriptors.d.ts
119
+ /**
120
+ * Creates a fire-and-forget cosmetic descriptor for `fx.emit`. It is dispatched only after the
121
+ * commit of its transaction and dropped in fast mode.
122
+ *
123
+ * @param kind - Effect kind a handler is registered for.
124
+ * @param payload - Plain JSON for the handler.
125
+ * @returns The hint as plain data.
126
+ * @example
127
+ * ```ts
128
+ * fx.emit(hint("sparkle", { cell: "c3" }));
129
+ * ```
130
+ */
131
+ declare function hint(kind: string, payload?: Json): Hint;
132
+ /**
133
+ * Creates the awaited effect that asks the clock for one `elapsed` at this moment. `undefined`
134
+ * means nothing is due and leaves the `moment` key out, so the descriptor stays plain JSON. Its
135
+ * handler runs in fast mode too.
136
+ *
137
+ * @param moment - Epoch milliseconds of the next due timer, or `undefined`.
138
+ * @returns The descriptor a node awaits.
139
+ * @example
140
+ * ```ts
141
+ * await fx(schedule(rules.nextDue(player, tables)));
142
+ * ```
143
+ */
144
+ declare function schedule(moment: number | undefined): Descriptor;
145
+ /**
146
+ * Creates the tutorial descriptor: it narrows the gate to one answer until the node exits. Its
147
+ * visual part (highlight, hand, text) is handled by `ui` later. The highlight list is copied, so
148
+ * a later change of the caller's array cannot reach the descriptor.
149
+ *
150
+ * @param options - The allowed answer and the visual hints.
151
+ * @returns The descriptor a node awaits.
152
+ * @example
153
+ * ```ts
154
+ * await fx(guide({ allow: { intent: "merge", payload: { from: "c2", to: "c3" } }, hand: "drag" }));
155
+ * ```
156
+ */
157
+ declare function guide(options: GuideOptions): Descriptor;
158
+ //#endregion
159
+ //#region src/teardown.d.ts
160
+ /**
161
+ * @file Teardown registry — the single allowlisted module-scope state of the package.
162
+ */
163
+ /**
164
+ * Function that frees one plugin's resources.
165
+ *
166
+ * @example
167
+ * ```ts
168
+ * const dispose: Disposer = () => cancelAnimationFrame(handle);
169
+ * ```
170
+ */
171
+ type Disposer = () => void | Promise<void>;
172
+ /**
173
+ * Registers a disposer for one plugin of one app. A second call with the same key replaces the first.
174
+ *
175
+ * @param global - The app's frozen global config object, used as identity.
176
+ * @param key - Plugin name.
177
+ * @param dispose - Function that frees the plugin's resources.
178
+ * @example
179
+ * ```ts
180
+ * teardown.register(ctx.global, "time", stopLoop);
181
+ * ```
182
+ */
183
+ declare function register(global: object, key: string, dispose: Disposer): void;
184
+ /**
185
+ * Runs and removes the disposer of one plugin. A missing key is a no-op.
186
+ * A throwing disposer is reported and never rethrown, so one plugin cannot block the stop of the others.
187
+ *
188
+ * @param global - The app's global config object.
189
+ * @param key - Plugin name.
190
+ * @returns Resolves when the disposer has finished.
191
+ * @example
192
+ * ```ts
193
+ * await teardown.run(global, "time");
194
+ * ```
195
+ */
196
+ declare function run(global: object, key: string): Promise<void>;
197
+ /**
198
+ * Teardown registry keyed by `ctx.global`.
199
+ *
200
+ * @example
201
+ * ```ts
202
+ * onStop: ({ global }) => teardown.run(global, "time")
203
+ * ```
204
+ */
205
+ declare const teardown: {
206
+ register: typeof register;
207
+ run: typeof run;
208
+ };
209
+ //#endregion
210
+ //#region src/index.d.ts
211
+ /**
212
+ * Creates a game application.
213
+ *
214
+ * @example
215
+ * ```ts
216
+ * const app = createApp({ plugins: [boardFeature] });
217
+ * ```
218
+ */
219
+ declare const createApp: <const ExtraPlugins extends readonly import("@moku-labs/core").AnyPluginInstance[] = readonly []>(options?: import("@moku-labs/core").CreateAppOptions<Config$5, Events, (import("@moku-labs/core").PluginInstance<"time", Config$4, State$4, Api$3, {}> & Record<never, never>) | (import("@moku-labs/core").PluginInstance<"lifecycle", Config$2, State$2, Api$2, {
220
+ "lifecycle:changed": {
221
+ reason: PauseReason;
222
+ action: "push" | "pop";
223
+ reasons: readonly PauseReason[];
224
+ paused: boolean;
225
+ resumed: boolean;
226
+ };
227
+ }> & Record<never, never>) | (import("@moku-labs/core").PluginInstance<"model", Config$3, State$3, {
228
+ store: StoreApi;
229
+ rng: RngApi;
230
+ }, {
231
+ "model:committed": {
232
+ roots: readonly Root[];
233
+ cause: "edge" | "rollback" | "restore" | "load";
234
+ };
235
+ }> & Record<never, never>) | (import("@moku-labs/core").PluginInstance<"clock", Config, State, Api, {}> & Record<never, never>) | (import("@moku-labs/core").PluginInstance<"flow", Config$1, State$1, Api$1, {
236
+ "flow:edge": {
237
+ flow: string;
238
+ node: string;
239
+ outcome: string;
240
+ payload: Json;
241
+ next: string;
242
+ patches: {
243
+ doc: Patch[];
244
+ session: Patch[];
245
+ };
246
+ index: number;
247
+ now: number;
248
+ };
249
+ "flow:rest": {
250
+ path: string;
251
+ checkpoint: boolean;
252
+ };
253
+ "flow:error": {
254
+ path: string;
255
+ error: unknown;
256
+ rolledBackTo: string;
257
+ retry: boolean;
258
+ };
259
+ }> & Record<never, never>) | ExtraPlugins[number], [...ExtraPlugins], import("@moku-labs/core").CoreApisFromTuple<[import("@moku-labs/core").CorePluginInstance<"log", import("@moku-labs/common/browser").LogConfig, import("@moku-labs/common/browser").LogState, import("@moku-labs/common/browser").LogApi>, import("@moku-labs/core").CorePluginInstance<"env", import("@moku-labs/common/browser").EnvConfig, import("@moku-labs/common/browser").EnvState, import("@moku-labs/common/browser").EnvApi>]>> | undefined) => import("@moku-labs/core").App<Config$5, Events, (import("@moku-labs/core").PluginInstance<"time", Config$4, State$4, Api$3, {}> & Record<never, never>) | (import("@moku-labs/core").PluginInstance<"lifecycle", Config$2, State$2, Api$2, {
260
+ "lifecycle:changed": {
261
+ reason: PauseReason;
262
+ action: "push" | "pop";
263
+ reasons: readonly PauseReason[];
264
+ paused: boolean;
265
+ resumed: boolean;
266
+ };
267
+ }> & Record<never, never>) | (import("@moku-labs/core").PluginInstance<"model", Config$3, State$3, {
268
+ store: StoreApi;
269
+ rng: RngApi;
270
+ }, {
271
+ "model:committed": {
272
+ roots: readonly Root[];
273
+ cause: "edge" | "rollback" | "restore" | "load";
274
+ };
275
+ }> & Record<never, never>) | (import("@moku-labs/core").PluginInstance<"clock", Config, State, Api, {}> & Record<never, never>) | (import("@moku-labs/core").PluginInstance<"flow", Config$1, State$1, Api$1, {
276
+ "flow:edge": {
277
+ flow: string;
278
+ node: string;
279
+ outcome: string;
280
+ payload: Json;
281
+ next: string;
282
+ patches: {
283
+ doc: Patch[];
284
+ session: Patch[];
285
+ };
286
+ index: number;
287
+ now: number;
288
+ };
289
+ "flow:rest": {
290
+ path: string;
291
+ checkpoint: boolean;
292
+ };
293
+ "flow:error": {
294
+ path: string;
295
+ error: unknown;
296
+ rolledBackTo: string;
297
+ retry: boolean;
298
+ };
299
+ }> & Record<never, never>) | ExtraPlugins[number], import("@moku-labs/core").CoreApisFromTuple<[import("@moku-labs/core").CorePluginInstance<"log", import("@moku-labs/common/browser").LogConfig, import("@moku-labs/common/browser").LogState, import("@moku-labs/common/browser").LogApi>, import("@moku-labs/core").CorePluginInstance<"env", import("@moku-labs/common/browser").EnvConfig, import("@moku-labs/common/browser").EnvState, import("@moku-labs/common/browser").EnvApi>]>>;
300
+ /**
301
+ * Creates a game plugin.
302
+ *
303
+ * @example
304
+ * ```ts
305
+ * export const scorePlugin = createPlugin("score", { api: createScoreApi });
306
+ * ```
307
+ */
308
+ declare const createPlugin: import("@moku-labs/core").BoundCreatePluginFunction<Config$5, Events, import("@moku-labs/core").CoreApisFromTuple<[import("@moku-labs/core").CorePluginInstance<"log", import("@moku-labs/common/browser").LogConfig, import("@moku-labs/common/browser").LogState, import("@moku-labs/common/browser").LogApi>, import("@moku-labs/core").CorePluginInstance<"env", import("@moku-labs/common/browser").EnvConfig, import("@moku-labs/common/browser").EnvState, import("@moku-labs/common/browser").EnvApi>]>>;
309
+ /**
310
+ * Binds the authoring helpers to the types of one game: "createApp for a game". The binding is
311
+ * type-only; at run time these are the same functions the plugins export. One line per helper,
312
+ * no logic: anything a single plugin can own lives in that plugin.
313
+ *
314
+ * @returns The helpers typed with the game's `player` and `session`.
315
+ * @example
316
+ * ```ts
317
+ * export const { defineNode, defineFlow, defineFeature } = defineGame<{
318
+ * player: Player;
319
+ * session: Session;
320
+ * assets: AssetKey;
321
+ * strings: StringTable;
322
+ * }>();
323
+ * ```
324
+ */
325
+ declare function defineGame<Types extends GameTypes>(): Kit<Types>;
326
+ //#endregion
327
+ export { types_d_exports as Clock, types_d_exports$1 as Flow, types_d_exports$2 as Lifecycle, types_d_exports$3 as Model, SaveUnreadableError, types_d_exports$4 as Time, clockPlugin, createApp, createPlugin, defineFeature, defineGame, exit, flowPlugin, guide, hint, lifecyclePlugin, modelPlugin, schedule, slot, teardown, timePlugin, to, type };