@zylem/game-lib 0.8.9 → 0.9.1

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 (69) hide show
  1. package/README.md +7 -1
  2. package/dist/api/game-lib.api.json +37952 -19547
  3. package/dist/api/game-lib.api.md +1302 -7
  4. package/dist/api/game-lib.d.ts +1696 -3
  5. package/dist/api/game-lib.typedoc.json +174596 -76562
  6. package/dist/audio.d.ts +193 -1
  7. package/dist/audio.js +1 -1
  8. package/dist/bridge.d.ts +17 -2
  9. package/dist/bridge.js +1 -1
  10. package/dist/catalog.js +1 -1
  11. package/dist/chunk-2PFNNGTV.js +1 -0
  12. package/dist/chunk-2XMG3NJS.js +1 -0
  13. package/dist/chunk-4CZZZCFB.js +9 -0
  14. package/dist/chunk-7CBJKE42.js +1 -0
  15. package/dist/{chunk-CBUQBP2U.js → chunk-BQRMYLYD.js} +1 -1
  16. package/dist/chunk-FZNEWOC5.js +1 -0
  17. package/dist/chunk-GPCSX3M6.js +1 -0
  18. package/dist/chunk-K3NNXZIJ.js +1 -0
  19. package/dist/{chunk-JNFFTNMH.js → chunk-KSEP7AUF.js} +1 -1
  20. package/dist/{chunk-7JSZEEAE.js → chunk-LI43BZQN.js} +1 -1
  21. package/dist/chunk-NVVLLWIM.js +1 -0
  22. package/dist/chunk-QGIYILYI.js +1 -0
  23. package/dist/chunk-SHDHPDOV.js +24 -0
  24. package/dist/chunk-STVEILJJ.js +1 -0
  25. package/dist/chunk-SWDNK4GG.js +1 -0
  26. package/dist/chunk-UUOPT2N4.js +1 -0
  27. package/dist/chunk-VMXSE3EC.js +0 -0
  28. package/dist/{chunk-EYDC2PMO.js → chunk-VSFULLND.js} +1 -1
  29. package/dist/chunk-YNX3Q3CL.js +1 -0
  30. package/dist/chunk-ZZO4CKRU.js +1 -0
  31. package/dist/cinematics.d.ts +279 -0
  32. package/dist/cinematics.js +1 -0
  33. package/dist/core.d.ts +124 -10
  34. package/dist/core.js +1 -1
  35. package/dist/cutscene-definition-C479fkei.d.ts +509 -0
  36. package/dist/debug.d.ts +1 -0
  37. package/dist/debug.js +1 -1
  38. package/dist/{entity-type-map-D6BeAdvg.d.ts → entity-type-map-CrsrKT8c.d.ts} +12 -3
  39. package/dist/entity.d.ts +2 -1
  40. package/dist/entity.js +1 -1
  41. package/dist/game-D8KTP3fD.d.ts +652 -0
  42. package/dist/game-default-JV3Q6JAL.js +1 -0
  43. package/dist/graphics.d.ts +1 -1
  44. package/dist/graphics.js +1 -1
  45. package/dist/public.d.ts +12 -6
  46. package/dist/public.js +1 -1
  47. package/dist/schema/cutscene.schema.json +782 -0
  48. package/dist/schema/song.schema.json +430 -0
  49. package/dist/schema.d.ts +2 -0
  50. package/dist/schema.js +1 -1
  51. package/dist/selection-bounds-BKmSo9aG.d.ts +50 -0
  52. package/dist/song-definition-rEKksP0B.d.ts +263 -0
  53. package/dist/song-player-7QPLFLAS.js +1 -0
  54. package/dist/{game-DyKbOeck.d.ts → stage-CAPlk_cN.d.ts} +146 -647
  55. package/dist/web-components.d.ts +5 -3
  56. package/dist/web-components.js +1 -1
  57. package/dist/{zylem-camera-DZTpPOiD.d.ts → zylem-camera-CYDtrVgi.d.ts} +134 -102
  58. package/package.json +11 -4
  59. package/dist/chunk-34MYRTRP.js +0 -9
  60. package/dist/chunk-AXJTUVGC.js +0 -24
  61. package/dist/chunk-BWOZF5YK.js +0 -1
  62. package/dist/chunk-EVMLNMGU.js +0 -1
  63. package/dist/chunk-G3TBBZUI.js +0 -1
  64. package/dist/chunk-J6KD2G6F.js +0 -1
  65. package/dist/chunk-X7T7QRYP.js +0 -1
  66. package/dist/chunk-YVWDCZNT.js +0 -1
  67. package/dist/chunk-ZRT3ZQVH.js +0 -1
  68. package/dist/game-default-6YXFFZ2Q.js +0 -1
  69. /package/dist/{chunk-MSCVL5OK.js → chunk-ELQN62PQ.js} +0 -0
@@ -0,0 +1,652 @@
1
+ import { e as InputPlayerNumber, f as InputProvider, I as Inputs, a as SetupContext, U as UpdateContext, D as DestroyContext, m as IGame, h as SetupFunction, g as UpdateFunction, j as DestroyFunction, S as StageNavigationOptions } from './base-node-life-cycle-BK9xebT9.js';
2
+ import { G as GameInputConfig, B as BaseGlobals, Z as ZylemGameConfig } from './game-interfaces-vF5sRi1n.js';
3
+ import { B as BaseNode } from './base-node-idopiSw5.js';
4
+ import { B as BaseEntityInterface, q as Stage } from './stage-CAPlk_cN.js';
5
+ import { y as GameEntityLifeCycle } from './entity-XqvuWgPm.js';
6
+ import { Color, Vector3 } from 'three';
7
+ import { d as Vec3Components } from './vector-D3eDzvcA.js';
8
+ import { D as DefaultTouchControlsOptions } from './default-controls-CAKJ5zlo.js';
9
+ import { GameEvents } from './events.js';
10
+ import { Simulation } from '@zylem/behaviors/core';
11
+ import { l as ZylemCamera, R as RendererManager } from './zylem-camera-CYDtrVgi.js';
12
+ import { S as StageTransitionConfig } from './stage-transition-CmGpV4tc.js';
13
+
14
+ declare class InputManager {
15
+ private inputMap;
16
+ private currentInputs;
17
+ private previousInputs;
18
+ private readonly targetElement?;
19
+ private readonly mouseTargetElement?;
20
+ constructor(config?: GameInputConfig, options?: {
21
+ targetElement?: HTMLElement;
22
+ mouseTargetElement?: HTMLElement;
23
+ });
24
+ /**
25
+ * Reconfigure keyboard and mouse providers at runtime without affecting gamepad providers.
26
+ * Disposes existing keyboard/mouse providers and creates new ones from the given config.
27
+ */
28
+ configure(config: GameInputConfig): void;
29
+ addInputProvider(playerNumber: InputPlayerNumber, provider: InputProvider): void;
30
+ dispose(): void;
31
+ getInputs(delta: number): Inputs;
32
+ private buildPlayerEntries;
33
+ private addConfigurableProviders;
34
+ private createConfigurableProviders;
35
+ private mergeInputs;
36
+ }
37
+
38
+ /**
39
+ * This class is an alternative to {@link Clock} with a different API design and behavior.
40
+ * The goal is to avoid the conceptual flaws that became apparent in `Clock` over time.
41
+ *
42
+ * - `Timer` has an `update()` method that updates its internal state. That makes it possible to
43
+ * call `getDelta()` and `getElapsed()` multiple times per simulation step without getting different values.
44
+ * - The class can make use of the Page Visibility API to avoid large time delta values when the app
45
+ * is inactive (e.g. tab switched or browser hidden).
46
+ *
47
+ * ```js
48
+ * const timer = new Timer();
49
+ * timer.connect( document ); // use Page Visibility API
50
+ * ```
51
+ *
52
+ * @three_import import { Timer } from 'three/addons/misc/Timer.js';
53
+ */
54
+ declare class Timer {
55
+ protected _previousTime: number;
56
+ protected _currentTime: number;
57
+ protected _startTime: number;
58
+ protected _delta: number;
59
+ protected _elapsed: number;
60
+ protected _timescale: number;
61
+ protected _document: Document | null;
62
+ protected _pageVisibilityHandler: (() => void) | null;
63
+ /**
64
+ * Constructs a new timer.
65
+ */
66
+ constructor();
67
+ /**
68
+ * Connect the timer to the given document.Calling this method is not mandatory to
69
+ * use the timer but enables the usage of the Page Visibility API to avoid large time
70
+ * delta values.
71
+ *
72
+ * @param {Document} document - The document.
73
+ */
74
+ connect(document: Document): void;
75
+ /**
76
+ * Disconnects the timer from the DOM and also disables the usage of the Page Visibility API.
77
+ */
78
+ disconnect(): void;
79
+ /**
80
+ * Returns the time delta in seconds.
81
+ *
82
+ * @return {number} The time delta in second.
83
+ */
84
+ getDelta(): number;
85
+ /**
86
+ * Returns the elapsed time in seconds.
87
+ *
88
+ * @return {number} The elapsed time in second.
89
+ */
90
+ getElapsed(): number;
91
+ /**
92
+ * Returns the timescale.
93
+ *
94
+ * @return {number} The timescale.
95
+ */
96
+ getTimescale(): number;
97
+ /**
98
+ * Sets the given timescale which scale the time delta computation
99
+ * in `update()`.
100
+ *
101
+ * @param {number} timescale - The timescale to set.
102
+ * @return {Timer} A reference to this timer.
103
+ */
104
+ setTimescale(timescale: number): Timer;
105
+ /**
106
+ * Resets the time computation for the current simulation step.
107
+ *
108
+ * @return {Timer} A reference to this timer.
109
+ */
110
+ reset(): Timer;
111
+ /**
112
+ * Can be used to free all internal resources. Usually called when
113
+ * the timer instance isn't required anymore.
114
+ */
115
+ dispose(): void;
116
+ /**
117
+ * Updates the internal state of the timer. This method should be called
118
+ * once per simulation step and before you perform queries against the timer
119
+ * (e.g. via `getDelta()`).
120
+ *
121
+ * @param {number} timestamp - The current time in milliseconds. Can be obtained
122
+ * from the `requestAnimationFrame` callback argument. If not provided, the current
123
+ * time will be determined with `performance.now`.
124
+ * @return {Timer} A reference to this timer.
125
+ */
126
+ update(timestamp?: number): Timer;
127
+ }
128
+
129
+ /**
130
+ * Stage state interface - minimal to prevent circular dependencies
131
+ */
132
+ interface StageStateInterface {
133
+ backgroundColor: Color;
134
+ backgroundImage: string | null;
135
+ inputs: {
136
+ p1: string[];
137
+ p2: string[];
138
+ };
139
+ variables: Record<string, any>;
140
+ gravity: Vector3 | Vec3Components;
141
+ entities: Partial<BaseEntityInterface>[];
142
+ stageRef?: any;
143
+ }
144
+ /**
145
+ * Minimal stage interface to break circular dependencies
146
+ */
147
+ interface StageInterface {
148
+ uuid: string;
149
+ children: any[];
150
+ state: StageStateInterface;
151
+ }
152
+
153
+ declare const AspectRatio: {
154
+ readonly FourByThree: number;
155
+ readonly SixteenByNine: number;
156
+ readonly NineBySixteen: number;
157
+ readonly TwentyOneByNine: number;
158
+ readonly OneByOne: number;
159
+ };
160
+ type AspectRatioValue = (typeof AspectRatio)[keyof typeof AspectRatio] | number;
161
+ /**
162
+ * AspectRatioDelegate manages sizing a canvas to fit within a container
163
+ * while preserving a target aspect ratio. It notifies a consumer via
164
+ * onResize when the final width/height are applied so renderers/cameras
165
+ * can update their viewports.
166
+ */
167
+ declare class AspectRatioDelegate {
168
+ container: HTMLElement;
169
+ canvas: HTMLCanvasElement;
170
+ aspectRatio: number;
171
+ onResize?: (width: number, height: number) => void;
172
+ private handleResizeBound;
173
+ private resizeObserver;
174
+ constructor(params: {
175
+ container: HTMLElement;
176
+ canvas: HTMLCanvasElement;
177
+ aspectRatio: AspectRatioValue;
178
+ onResize?: (width: number, height: number) => void;
179
+ });
180
+ /** Attach window resize listener and apply once. */
181
+ attach(): void;
182
+ /** Detach window resize listener. */
183
+ detach(): void;
184
+ /** Compute the largest size that fits container while preserving aspect. */
185
+ measure(): {
186
+ width: number;
187
+ height: number;
188
+ };
189
+ /** Apply measured size to canvas and notify. */
190
+ apply(): void;
191
+ }
192
+
193
+ interface ViewportSize {
194
+ width: number;
195
+ height: number;
196
+ }
197
+
198
+ type RetroResolution = {
199
+ key: string;
200
+ width: number;
201
+ height: number;
202
+ notes?: string;
203
+ };
204
+ type RetroPreset = {
205
+ displayAspect: number;
206
+ resolutions: RetroResolution[];
207
+ };
208
+ /**
209
+ * Retro, console, and device display presets.
210
+ * displayAspect represents the intended display aspect (letterboxing target),
211
+ * not necessarily the raw pixel aspect of internal buffers.
212
+ */
213
+ declare const RetroPresets: Record<string, RetroPreset>;
214
+ type RetroPresetKey = keyof typeof RetroPresets;
215
+ declare function getDisplayAspect(preset: RetroPresetKey): number;
216
+ declare function getPresetResolution(preset: RetroPresetKey, key?: string): RetroResolution | undefined;
217
+ declare function parseResolution(text: string): {
218
+ width: number;
219
+ height: number;
220
+ } | null;
221
+
222
+ /**
223
+ * Resolution descriptor for the game's internal render buffer.
224
+ * - `string` : a "WxH" literal or a known retro preset (e.g. `'NES'`).
225
+ * - `{ width, height }` : explicit pixel dimensions.
226
+ * - `'native'` : skip internal-resolution scaling — render at the
227
+ * canvas' CSS size × DPR (i.e. 1:1 with the device viewport).
228
+ */
229
+ type ResolutionInput = string | {
230
+ width: number;
231
+ height: number;
232
+ } | 'native';
233
+ type DeviceProfile = 'auto' | 'desktop' | 'mobile';
234
+ interface ResolveGameConfigRuntime {
235
+ deviceProfile?: DeviceProfile;
236
+ viewportSize?: ViewportSize;
237
+ }
238
+ type GameDeviceConfig = Partial<{
239
+ /** numeric value or key in AspectRatio */
240
+ aspectRatio: AspectRatioValue | keyof typeof AspectRatio;
241
+ /** console/display preset to derive aspect ratio */
242
+ preset: RetroPresetKey;
243
+ /** lock internal render buffer for this device profile */
244
+ resolution: ResolutionInput;
245
+ /**
246
+ * Auto-merge built-in virtual touch controls into the resolved input
247
+ * config. The provider auto-enables on mobile devices via
248
+ * `enabled: 'auto'`, so on desktop runtimes the UI stays dormant.
249
+ * - `true` : default joystick + A/B layout, default theme.
250
+ * - options object : forwarded to `defaultTouchControls('p1', ...)`.
251
+ * - `false` / unset: no auto-injection (caller wires controls manually).
252
+ */
253
+ controls: boolean | DefaultTouchControlsOptions;
254
+ }>;
255
+ type GameConfigLike = Partial<{
256
+ id: string;
257
+ globals: Record<string, any>;
258
+ stages: StageInterface[];
259
+ debug: boolean;
260
+ time: number;
261
+ input: GameInputConfig;
262
+ /** numeric value or key in AspectRatio */
263
+ aspectRatio: AspectRatioValue | keyof typeof AspectRatio;
264
+ /** console/display preset to derive aspect ratio */
265
+ preset: RetroPresetKey;
266
+ /** lock internal render buffer to this desktop/default resolution */
267
+ resolution: ResolutionInput;
268
+ /** mobile-specific aspect/preset/resolution overrides */
269
+ mobile: GameDeviceConfig;
270
+ fullscreen: boolean;
271
+ /** CSS background value for document body */
272
+ bodyBackground: string;
273
+ /** existing container by reference */
274
+ container: HTMLElement;
275
+ /** create/find container by id */
276
+ containerId: string;
277
+ /** optional canvas if caller wants to manage it */
278
+ canvas: HTMLCanvasElement;
279
+ }>;
280
+ declare class GameConfig {
281
+ id: string;
282
+ globals: Record<string, any>;
283
+ stages: StageInterface[];
284
+ debug: boolean;
285
+ time: number;
286
+ input: GameInputConfig | undefined;
287
+ aspectRatio: number;
288
+ internalResolution: {
289
+ width: number;
290
+ height: number;
291
+ } | undefined;
292
+ fullscreen: boolean;
293
+ bodyBackground: string | undefined;
294
+ container: HTMLElement;
295
+ containerId?: string | undefined;
296
+ canvas?: HTMLCanvasElement | undefined;
297
+ constructor(id: string, globals: Record<string, any>, stages: StageInterface[], debug: boolean, time: number, input: GameInputConfig | undefined, aspectRatio: number, internalResolution: {
298
+ width: number;
299
+ height: number;
300
+ } | undefined, fullscreen: boolean, bodyBackground: string | undefined, container: HTMLElement, containerId?: string | undefined, canvas?: HTMLCanvasElement | undefined);
301
+ }
302
+ /**
303
+ * Factory for authoring configuration objects in user code.
304
+ * Returns a plain object that can be passed to `game(...)`.
305
+ */
306
+ declare function gameConfig(config: GameConfigLike): GameConfigLike;
307
+
308
+ interface GameCanvasOptions {
309
+ id: string;
310
+ container?: HTMLElement;
311
+ containerId?: string;
312
+ canvas?: HTMLCanvasElement;
313
+ bodyBackground?: string;
314
+ fullscreen?: boolean;
315
+ aspectRatio: AspectRatioValue | number;
316
+ }
317
+ /**
318
+ * GameCanvas is a DOM delegate that owns:
319
+ * - container lookup/creation and styling (including fullscreen centering)
320
+ * - body background application
321
+ * - canvas mounting into container
322
+ * - aspect ratio sizing via AspectRatioDelegate
323
+ */
324
+ declare class GameCanvas {
325
+ id: string;
326
+ container: HTMLElement;
327
+ canvas: HTMLCanvasElement;
328
+ bodyBackground?: string;
329
+ fullscreen: boolean;
330
+ aspectRatio: number;
331
+ private ratioDelegate;
332
+ private overlayContainer;
333
+ constructor(options: GameCanvasOptions);
334
+ applyBodyBackground(): void;
335
+ mountCanvas(): void;
336
+ mountRenderer(rendererDom: HTMLCanvasElement, onResize: (width: number, height: number) => void): void;
337
+ getOverlayContainer(): HTMLElement;
338
+ centerIfFullscreen(): void;
339
+ attachAspectRatio(onResize: (width: number, height: number) => void): void;
340
+ setAspectRatio(aspectRatio: number): void;
341
+ reapplyLayout(): void;
342
+ destroy(): void;
343
+ private mountChildren;
344
+ private ensureOverlayContainer;
345
+ private ensureContainer;
346
+ }
347
+
348
+ /**
349
+ * Game-level loading event that includes stage context.
350
+ */
351
+ interface GameLoadingEvent {
352
+ type: 'start' | 'progress' | 'complete';
353
+ stageName?: string;
354
+ stageIndex?: number;
355
+ message: string;
356
+ progress: number;
357
+ current?: number;
358
+ total?: number;
359
+ }
360
+
361
+ type ZylemGameOptions<TGlobals extends BaseGlobals> = ZylemGameConfig<Stage, ZylemGame<TGlobals>, TGlobals> & Partial<GameConfig>;
362
+ declare class ZylemGame<TGlobals extends BaseGlobals> {
363
+ id: string;
364
+ initialGlobals: TGlobals;
365
+ customSetup: ((params: SetupContext<ZylemGame<TGlobals>, TGlobals>) => void) | null;
366
+ customUpdate: ((params: UpdateContext<ZylemGame<TGlobals>, TGlobals>) => void) | null;
367
+ customDestroy: ((params: DestroyContext<ZylemGame<TGlobals>, TGlobals>) => void) | null;
368
+ stages: Stage[];
369
+ stageMap: Map<string, Stage>;
370
+ currentStageId: string;
371
+ previousTimeStamp: number;
372
+ totalTime: number;
373
+ timer: Timer;
374
+ inputManager: InputManager;
375
+ wrapperRef: Game<TGlobals>;
376
+ globalInputConfig: GameInputConfig | undefined;
377
+ defaultCamera: ZylemCamera | null;
378
+ /** Shared renderer manager for all stages */
379
+ rendererManager: RendererManager | null;
380
+ container: HTMLElement | null;
381
+ canvas: HTMLCanvasElement | null;
382
+ aspectRatioDelegate: AspectRatioDelegate | null;
383
+ resolvedConfig: GameConfig | null;
384
+ gameCanvas: GameCanvas | null;
385
+ private animationFrameId;
386
+ private isDisposed;
387
+ /**
388
+ * True while a `loadStage` is in progress. Used to reject re-entrant stage
389
+ * navigation (e.g. a button press during a transition), which would race
390
+ * two loads on `stageMap`/the render loop and, because `currentStageId` is
391
+ * transiently `''`, misresolve the target stage.
392
+ */
393
+ private loadInFlight;
394
+ /**
395
+ * True once `start()` has been invoked for this game's initial stage.
396
+ * Used by `loadStage` to decide whether to drive the stage's `_setup`
397
+ * lifecycle directly (for subsequent stages loaded via `nextStage`
398
+ * / `loadStage`) or defer to `start()` (for the very first stage).
399
+ */
400
+ private hasStarted;
401
+ private debugDelegate;
402
+ private loadingDelegate;
403
+ private rendererObserver;
404
+ private eventBusUnsubscribes;
405
+ private thumbnailUnsubscribes;
406
+ /** Serialized last-published game config, for dirty-checking resize churn. */
407
+ private lastPublishedGameConfig;
408
+ /** Editor ↔ game bridge adapter (RAF-coalesced publishes, command intake). */
409
+ private gameBridge;
410
+ /** Director mode's in-game cutscene preview, driven over the bridge. */
411
+ private cutscenePreview;
412
+ /** Stops republishing the entity catalog on registry changes. */
413
+ private catalogUnsubscribe;
414
+ private readonly gameUpdateParams;
415
+ private readonly stageSetupParams;
416
+ private readonly stageUpdateParams;
417
+ private readonly frameCallback;
418
+ private readonly sourceOptions;
419
+ private displayRuntime;
420
+ static FRAME_LIMIT: number;
421
+ static FRAME_DURATION: number;
422
+ static MAX_DELTA_SECONDS: number;
423
+ constructor(options: ZylemGameOptions<TGlobals>, wrapperRef: Game<TGlobals>, displayRuntime?: ResolveGameConfigRuntime);
424
+ /**
425
+ * Raycast at normalized device coordinates (editor `entity:pick`) and
426
+ * describe the hit the same way the entity list does, so a consumer can
427
+ * show name, type, and pose for whatever is under the pointer.
428
+ */
429
+ private pickEntityAtNdc;
430
+ /** Publish the placeable entity types the editor's Add palette lists. */
431
+ private publishEntityCatalog;
432
+ /** Spawn a catalog type programmatically (editor `entity:create`). */
433
+ private createCatalogEntity;
434
+ setDisplayRuntime(runtime: ResolveGameConfigRuntime): void;
435
+ loadGameCanvas(config: GameConfig): void;
436
+ loadDebugOptions(options: ZylemGameOptions<TGlobals>): void;
437
+ /** Whether a stage load is currently in progress. */
438
+ isLoading(): boolean;
439
+ loadStage(stage: Stage, stageIndex?: number, transition?: StageTransitionConfig): Promise<void>;
440
+ private performLoadStage;
441
+ /**
442
+ * Merges game-level global input config with the stage's per-stage overrides
443
+ * and reconfigures the InputManager.
444
+ */
445
+ applyInputConfig(stage: Stage): void;
446
+ /**
447
+ * Update the game-level global input config and re-apply to the current stage.
448
+ */
449
+ setGlobalInputConfig(config: GameInputConfig): void;
450
+ unloadCurrentStage(): void;
451
+ setGlobals(options: ZylemGameConfig<Stage, ZylemGame<TGlobals>, TGlobals>): void;
452
+ params(): UpdateContext<ZylemGame<TGlobals>, TGlobals>;
453
+ start(): void;
454
+ /**
455
+ * Execute a single frame update.
456
+ * This method can be called directly for testing or from the game loop.
457
+ * @param deltaTime Optional delta time in seconds. If not provided, uses timer delta.
458
+ */
459
+ step(deltaTime?: number): void;
460
+ loop(timestamp: number): void;
461
+ dispose(): void;
462
+ outOfLoop(): void;
463
+ getStage(id: string): Stage | undefined;
464
+ currentStage(): Stage | undefined;
465
+ /**
466
+ * Subscribe to loading events from the game.
467
+ * Events include stage context (stageName, stageIndex).
468
+ * @param callback Invoked for each loading event
469
+ * @returns Unsubscribe function
470
+ */
471
+ onLoading(callback: (event: GameLoadingEvent) => void): () => void;
472
+ /**
473
+ * Build the stage config payload for the current stage.
474
+ */
475
+ private buildStageConfigPayload;
476
+ /**
477
+ * Build a bridge entity summary for one entity, or null for entities on
478
+ * the managed render path (instanced packs/bundles), which can number in
479
+ * the thousands and are not useful in the editor panel.
480
+ */
481
+ private buildEntitySummary;
482
+ /**
483
+ * Build the full entities payload for the current stage.
484
+ */
485
+ private buildEntitiesPayload;
486
+ /**
487
+ * Generate entity thumbnails as entities become available, streaming
488
+ * upserts/thumbnails/removals to the editor through the bridge
489
+ * (RAF-coalesced, merged by uuid).
490
+ *
491
+ * All of this work exists only to feed the editor, and thumbnails in
492
+ * particular cost an offscreen render plus a pixel readback on the shared
493
+ * renderer. Each publisher therefore checks the bridge for a live listener
494
+ * first, and a late-connecting editor is backfilled from
495
+ * {@link wireEditorBackfill}.
496
+ */
497
+ private wireEntityThumbnails;
498
+ /**
499
+ * Republish the current stage when an editor subscribes after the game
500
+ * started. Without this, entities added while nothing was listening would
501
+ * never appear, since the per-entity publishers were skipped.
502
+ */
503
+ private wireEditorBackfill;
504
+ private clearEntityThumbnailWiring;
505
+ private buildGameConfigPayload;
506
+ /** Publish the resolved display config over the bridge. */
507
+ /**
508
+ * Publish the display config, skipping unchanged payloads. The
509
+ * `ResizeObserver` on `<zylem-game>` funnels into `setDisplayRuntime`, which
510
+ * fires on every layout tick even when nothing about the config moved.
511
+ */
512
+ private publishGameConfig;
513
+ /** Publish a full stage snapshot (config + entity list) over the bridge. */
514
+ private publishStageSnapshot;
515
+ /**
516
+ * Subscribe to the game event bus for stage loading and state events,
517
+ * mirroring global-variable updates to the editor over the bridge.
518
+ */
519
+ private subscribeToEventBus;
520
+ }
521
+
522
+ type GameOptions<TGlobals extends BaseGlobals> = Array<ZylemGameConfig<Stage, any, TGlobals> | GameConfigLike | Stage | GameEntityLifeCycle | BaseNode>;
523
+
524
+ declare class Game<TGlobals extends BaseGlobals> implements IGame<TGlobals> {
525
+ private wrappedGame;
526
+ options: GameOptions<TGlobals>;
527
+ private setupCallbacks;
528
+ private updateCallbacks;
529
+ private destroyCallbacks;
530
+ private pendingLoadingCallbacks;
531
+ private globalChangeCallbacks;
532
+ private globalChangesCallbacks;
533
+ private activeGlobalSubscriptions;
534
+ private eventDelegate;
535
+ /** Pending global input config set before the game starts. */
536
+ private pendingInputConfig;
537
+ private displayRuntime;
538
+ refErrorMessage: string;
539
+ constructor(options: GameOptions<TGlobals>);
540
+ onSetup(...callbacks: Array<SetupFunction<ZylemGame<TGlobals>, TGlobals>>): this;
541
+ onUpdate(...callbacks: Array<UpdateFunction<ZylemGame<TGlobals>, TGlobals>>): this;
542
+ onDestroy(...callbacks: Array<DestroyFunction<ZylemGame<TGlobals>, TGlobals>>): this;
543
+ /**
544
+ * Set composable input configuration as global defaults for the entire game.
545
+ * Multiple configs are deep-merged (later configs win on key conflicts).
546
+ * Per-stage overrides (via stage.setInputConfiguration) are merged on top.
547
+ * Can be called before or after start().
548
+ * @example game.setInputConfiguration(useArrowsForAxes('p1'), useWASDForDirections('p2'));
549
+ */
550
+ setInputConfiguration(...configs: GameInputConfig[]): this;
551
+ start(): Promise<this>;
552
+ setDisplayRuntime(runtime: Partial<ResolveGameConfigRuntime>): this;
553
+ setDeviceProfile(profile: DeviceProfile): this;
554
+ setViewportSize(width: number, height: number): this;
555
+ private load;
556
+ private setOverrides;
557
+ /**
558
+ * Subscribe to changes on a global value. Subscriptions are registered
559
+ * when the game starts and cleaned up when disposed.
560
+ * The callback receives the value and the current stage.
561
+ * @example game.onGlobalChange('score', (val, stage) => console.log(val));
562
+ */
563
+ onGlobalChange<T = unknown>(path: string, callback: (value: T, stage: Stage | null) => void): this;
564
+ /**
565
+ * Subscribe to changes on multiple global paths. Subscriptions are registered
566
+ * when the game starts and cleaned up when disposed.
567
+ * The callback receives the values and the current stage.
568
+ * @example game.onGlobalChanges(['score', 'lives'], ([score, lives], stage) => console.log(score, lives));
569
+ */
570
+ onGlobalChanges<T extends unknown[] = unknown[]>(paths: string[], callback: (values: T, stage: Stage | null) => void): this;
571
+ /**
572
+ * Register all stored global change callbacks.
573
+ * Called internally during start().
574
+ */
575
+ private registerGlobalSubscriptions;
576
+ /**
577
+ * Get the current stage wrapper.
578
+ */
579
+ getCurrentStage(): Stage | null;
580
+ /**
581
+ * Experimental escape hatches. APIs here are unstable and may change or be
582
+ * removed without a major version bump.
583
+ */
584
+ readonly experimental: {
585
+ /**
586
+ * The `@zylem/behaviors` {@link Simulation} backing the current stage's
587
+ * physics world, or `null` before a stage is loaded. Intended for debug
588
+ * tooling and the editor; games should not need it.
589
+ */
590
+ getRuntime: () => Simulation | null;
591
+ };
592
+ pause(): Promise<void>;
593
+ resume(): Promise<void>;
594
+ /**
595
+ * Execute a single frame update.
596
+ * Useful for testing or manual frame stepping.
597
+ * @param deltaTime Optional delta time in seconds (defaults to 1/60)
598
+ */
599
+ step(deltaTime?: number): void;
600
+ /**
601
+ * Reload the first stage. Pass `{ transition }` to blend from the current
602
+ * stage instead of cutting.
603
+ * @example game.reset({ transition: { duration: 1 } });
604
+ */
605
+ reset(options?: StageNavigationOptions): Promise<void>;
606
+ /**
607
+ * Go to the previous stage in the stage array. Pass `{ transition }` to
608
+ * blend from the current stage instead of cutting.
609
+ */
610
+ previousStage(options?: StageNavigationOptions): void;
611
+ loadStageFromId(stageId: string): Promise<void>;
612
+ /**
613
+ * Go to the next stage. Pass `{ transition }` to blend from the current
614
+ * stage instead of cutting.
615
+ * @example
616
+ * game.nextStage({
617
+ * transition: { duration: 1.2, shader: createStageTransition({ pattern: 'noise' }) },
618
+ * });
619
+ */
620
+ nextStage(options?: StageNavigationOptions): void;
621
+ goToStage(): Promise<void>;
622
+ end(): Promise<void>;
623
+ dispose(): void;
624
+ /**
625
+ * Dispatch an event from the game.
626
+ * Events are emitted both locally and to the global event bus.
627
+ */
628
+ dispatch<K extends keyof GameEvents>(event: K, payload: GameEvents[K]): void;
629
+ /**
630
+ * Listen for events on this game instance.
631
+ * @returns Unsubscribe function
632
+ */
633
+ listen<K extends keyof GameEvents>(event: K, handler: (payload: GameEvents[K]) => void): () => void;
634
+ /**
635
+ * Subscribe to loading events from the game.
636
+ * Events include stage context (stageName, stageIndex).
637
+ * @param callback Invoked for each loading event
638
+ * @returns Unsubscribe function
639
+ */
640
+ onLoading(callback: (event: GameLoadingEvent) => void): () => void;
641
+ }
642
+ /**
643
+ * create a new game
644
+ * @param options GameOptions - Array of IGameOptions, Stage, GameEntity, or BaseNode objects
645
+ * @param options.id Game name string (when using IGameOptions)
646
+ * @param options.globals Game globals object (when using IGameOptions)
647
+ * @param options.stages Array of stage objects (when using IGameOptions)
648
+ * @returns Game
649
+ */
650
+ declare function createGame<TGlobals extends BaseGlobals>(...options: GameOptions<TGlobals>): Game<TGlobals>;
651
+
652
+ export { AspectRatio as A, type DeviceProfile as D, Game as G, type ResolutionInput as R, type StageStateInterface as S, type GameLoadingEvent as a, type GameConfigLike as b, createGame as c, type GameDeviceConfig as d, type ResolveGameConfigRuntime as e, type AspectRatioValue as f, gameConfig as g, getDisplayAspect as h, getPresetResolution as i, type RetroPreset as j, type RetroPresetKey as k, type RetroResolution as l, parseResolution as p };
@@ -0,0 +1 @@
1
+ import{y as e}from"./chunk-SWDNK4GG.js";import"./chunk-BCFFS3FP.js";import"./chunk-2HSR5XDQ.js";import"./chunk-7CBJKE42.js";import"./chunk-BQRMYLYD.js";import"./chunk-GPCSX3M6.js";import"./chunk-WBQ5TNRZ.js";import"./chunk-YQS7CGXE.js";import"./chunk-KP6DLLJO.js";import"./chunk-6FGXC4T6.js";import"./chunk-AIQ6IVT5.js";import"./chunk-QXVH6POE.js";import"./chunk-UUOPT2N4.js";import"./chunk-EVYHPR3J.js";import"./chunk-D2PATZCC.js";import"./chunk-4QLJUQSJ.js";import"./chunk-7WRQ2UAN.js";import"./chunk-BH53MBAZ.js";import"./chunk-XRP4JJXL.js";import"./chunk-UG22Z42P.js";import"./chunk-WOT6VMZA.js";import{proxy as t}from"valtio/vanilla";var s=()=>({id:"zylem",globals:{},stages:[e()],debug:!1,time:0,input:void 0}),a=t({...s()});function o(){return{id:a.id??"zylem",globals:a.globals??{},stages:a.stages??[e()],debug:a.debug,time:a.time,input:a.input}}export{o as getGameDefaultConfig};
@@ -1,6 +1,6 @@
1
1
  import { b as ZylemTSLShader } from './material-CxxAyJYp.js';
2
2
  export { d as ZylemShader, Z as ZylemShaderObject, c as createNodeMaterialFromTSL, a as isGLSLShader, i as isTSLShader } from './material-CxxAyJYp.js';
3
- export { Z as ZylemPostEffect } from './zylem-camera-DZTpPOiD.js';
3
+ export { Z as ZylemPostEffect } from './zylem-camera-CYDtrVgi.js';
4
4
  export { S as StageTransitionConfig, a as StageTransitionEasing, Z as ZylemTransitionShader, c as crossfadeTransitionShader } from './stage-transition-CmGpV4tc.js';
5
5
  export { Fn, abs, asin, atan, clamp, cos, dot, exp, float, floor, fract, length, max, min, mix, mod, normalize, positionWorld, positionWorldDirection, pow, sin, smoothstep, step, time, uniform, uv, vec2, vec3, vec4 } from 'three/tsl';
6
6
  import 'three';
package/dist/graphics.js CHANGED
@@ -1 +1 @@
1
- import{a as n,b as o,c as p,d as q,e as r,f as s,g as t,h as u,i as v,j as w,k as x,l as y,m as z,n as A,o as B,p as C,q as D,r as E,s as F,t as G,u as H,v as I,w as J}from"./chunk-QB3NL7VQ.js";import{a as m}from"./chunk-7GYFZKK7.js";import{c as a,d as b,h as c,i as d,k as e,l as f,m as g,n as h,o as i,p as j,q as k,r as l}from"./chunk-6FGXC4T6.js";import"./chunk-QXVH6POE.js";import"./chunk-7WRQ2UAN.js";import"./chunk-WOT6VMZA.js";export{l as Fn,y as abs,x as asin,w as atan,t as clamp,v as cos,n as createBackgroundShader,e as createNodeMaterialFromTSL,m as crossfadeTransitionShader,G as dot,z as exp,k as float,E as floor,F as fract,d as isGLSLShader,c as isTSLShader,H as length,C as max,D as min,r as mix,J as mod,q as normalize,a as objectVertexShader,p as positionWorld,o as positionWorldDirection,A as pow,u as sin,s as smoothstep,b as standardShader,B as step,h as time,f as uniform,g as uv,I as vec2,i as vec3,j as vec4};
1
+ import{a as n,b as o,c as p,d as q,e as r,f as s,g as t,h as u,i as v,j as w,k as x,l as y,m as z,n as A,o as B,p as C,q as D,r as E,s as F,t as G,u as H,v as I,w as J}from"./chunk-QB3NL7VQ.js";import{c as a,d as b,h as c,i as d,k as e,l as f,m as g,n as h,o as i,p as j,q as k,r as l}from"./chunk-6FGXC4T6.js";import"./chunk-QXVH6POE.js";import{a as m}from"./chunk-7GYFZKK7.js";import"./chunk-7WRQ2UAN.js";import"./chunk-WOT6VMZA.js";export{l as Fn,y as abs,x as asin,w as atan,t as clamp,v as cos,n as createBackgroundShader,e as createNodeMaterialFromTSL,m as crossfadeTransitionShader,G as dot,z as exp,k as float,E as floor,F as fract,d as isGLSLShader,c as isTSLShader,H as length,C as max,D as min,r as mix,J as mod,q as normalize,a as objectVertexShader,p as positionWorld,o as positionWorldDirection,A as pow,u as sin,s as smoothstep,b as standardShader,B as step,h as time,f as uniform,g as uv,I as vec2,i as vec3,j as vec4};