@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
@@ -1,134 +1,17 @@
1
- import { e as InputPlayerNumber, f as InputProvider, I as Inputs, h as SetupFunction, g as UpdateFunction, j as DestroyFunction, a as SetupContext, U as UpdateContext, D as DestroyContext, L as LoadingEvent, m as IGame, 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
1
  import { B as BaseNode } from './base-node-idopiSw5.js';
2
+ import { h as SetupFunction, g as UpdateFunction, j as DestroyFunction, a as SetupContext, U as UpdateContext, D as DestroyContext, L as LoadingEvent } from './base-node-life-cycle-BK9xebT9.js';
4
3
  import { Scene, Color, Object3D, Vector3, BufferGeometry, Material, Group, Texture } from 'three';
5
- import { al as ZylemWorld, aj as EntityTypeMap } from './entity-type-map-D6BeAdvg.js';
4
+ import { al as ZylemWorld, aj as EntityTypeMap } from './entity-type-map-CrsrKT8c.js';
6
5
  import { E as Entity, L as LifecycleFunction, S as StageEntity } from './entity-BIf_a4dl.js';
7
- import { G as GameEntity, a as GameEntityOptions, y as GameEntityLifeCycle } from './entity-XqvuWgPm.js';
8
- import { k as ZylemCamera, R as RendererManager, e as CameraPerspective, d as CameraContext, C as CameraPose, P as PerspectiveType, f as CameraBehavior, g as CameraAction, h as CameraPipelineState, V as Viewport, Z as ZylemPostEffect } from './zylem-camera-DZTpPOiD.js';
6
+ import { G as GameEntity, a as GameEntityOptions } from './entity-XqvuWgPm.js';
7
+ import { l as ZylemCamera, R as RendererManager, e as CameraPerspective, d as CameraContext, C as CameraPose, P as PerspectiveType, f as CameraBehavior, g as CameraAction, h as CameraPipelineState, V as Viewport, Z as ZylemPostEffect } from './zylem-camera-CYDtrVgi.js';
9
8
  import { d as ZylemShader } from './material-CxxAyJYp.js';
10
9
  import { a as SimulationBody } from './simulation-body-zQw-emOr.js';
11
10
  import { e as Vec3Input, b as Vec2Input, d as Vec3Components } from './vector-D3eDzvcA.js';
11
+ import { StageEvents } from './events.js';
12
+ import { G as GameInputConfig } from './game-interfaces-vF5sRi1n.js';
12
13
  import { SwatchApplyResult, SceneOperationEntry, EntityApplySwatchPayload, SceneOperationPayload } from '@zylem/bridge';
13
- import { BehaviorSystem, BehaviorEntityLink, BehaviorRuntime, BehaviorSystemFactory, BehaviorRef, Simulation } from '@zylem/behaviors/core';
14
- import { StageEvents, GameEvents } from './events.js';
15
- import { D as DefaultTouchControlsOptions } from './default-controls-CAKJ5zlo.js';
16
- import { S as StageTransitionConfig } from './stage-transition-CmGpV4tc.js';
17
-
18
- declare class InputManager {
19
- private inputMap;
20
- private currentInputs;
21
- private previousInputs;
22
- private readonly targetElement?;
23
- private readonly mouseTargetElement?;
24
- constructor(config?: GameInputConfig, options?: {
25
- targetElement?: HTMLElement;
26
- mouseTargetElement?: HTMLElement;
27
- });
28
- /**
29
- * Reconfigure keyboard and mouse providers at runtime without affecting gamepad providers.
30
- * Disposes existing keyboard/mouse providers and creates new ones from the given config.
31
- */
32
- configure(config: GameInputConfig): void;
33
- addInputProvider(playerNumber: InputPlayerNumber, provider: InputProvider): void;
34
- dispose(): void;
35
- getInputs(delta: number): Inputs;
36
- private buildPlayerEntries;
37
- private addConfigurableProviders;
38
- private createConfigurableProviders;
39
- private mergeInputs;
40
- }
41
-
42
- /**
43
- * This class is an alternative to {@link Clock} with a different API design and behavior.
44
- * The goal is to avoid the conceptual flaws that became apparent in `Clock` over time.
45
- *
46
- * - `Timer` has an `update()` method that updates its internal state. That makes it possible to
47
- * call `getDelta()` and `getElapsed()` multiple times per simulation step without getting different values.
48
- * - The class can make use of the Page Visibility API to avoid large time delta values when the app
49
- * is inactive (e.g. tab switched or browser hidden).
50
- *
51
- * ```js
52
- * const timer = new Timer();
53
- * timer.connect( document ); // use Page Visibility API
54
- * ```
55
- *
56
- * @three_import import { Timer } from 'three/addons/misc/Timer.js';
57
- */
58
- declare class Timer {
59
- protected _previousTime: number;
60
- protected _currentTime: number;
61
- protected _startTime: number;
62
- protected _delta: number;
63
- protected _elapsed: number;
64
- protected _timescale: number;
65
- protected _document: Document | null;
66
- protected _pageVisibilityHandler: (() => void) | null;
67
- /**
68
- * Constructs a new timer.
69
- */
70
- constructor();
71
- /**
72
- * Connect the timer to the given document.Calling this method is not mandatory to
73
- * use the timer but enables the usage of the Page Visibility API to avoid large time
74
- * delta values.
75
- *
76
- * @param {Document} document - The document.
77
- */
78
- connect(document: Document): void;
79
- /**
80
- * Disconnects the timer from the DOM and also disables the usage of the Page Visibility API.
81
- */
82
- disconnect(): void;
83
- /**
84
- * Returns the time delta in seconds.
85
- *
86
- * @return {number} The time delta in second.
87
- */
88
- getDelta(): number;
89
- /**
90
- * Returns the elapsed time in seconds.
91
- *
92
- * @return {number} The elapsed time in second.
93
- */
94
- getElapsed(): number;
95
- /**
96
- * Returns the timescale.
97
- *
98
- * @return {number} The timescale.
99
- */
100
- getTimescale(): number;
101
- /**
102
- * Sets the given timescale which scale the time delta computation
103
- * in `update()`.
104
- *
105
- * @param {number} timescale - The timescale to set.
106
- * @return {Timer} A reference to this timer.
107
- */
108
- setTimescale(timescale: number): Timer;
109
- /**
110
- * Resets the time computation for the current simulation step.
111
- *
112
- * @return {Timer} A reference to this timer.
113
- */
114
- reset(): Timer;
115
- /**
116
- * Can be used to free all internal resources. Usually called when
117
- * the timer instance isn't required anymore.
118
- */
119
- dispose(): void;
120
- /**
121
- * Updates the internal state of the timer. This method should be called
122
- * once per simulation step and before you perform queries against the timer
123
- * (e.g. via `getDelta()`).
124
- *
125
- * @param {number} timestamp - The current time in milliseconds. Can be obtained
126
- * from the `requestAnimationFrame` callback argument. If not provided, the current
127
- * time will be determined with `performance.now`.
128
- * @return {Timer} A reference to this timer.
129
- */
130
- update(timestamp?: number): Timer;
131
- }
14
+ import { BehaviorSystem, BehaviorEntityLink, BehaviorRuntime, BehaviorSystemFactory, BehaviorRef } from '@zylem/behaviors/core';
132
15
 
133
16
  /**
134
17
  * CameraManager orchestrates multiple cameras per stage.
@@ -524,6 +407,7 @@ interface ThirdPersonOptions {
524
407
  */
525
408
  declare class ThirdPersonPerspective implements CameraPerspective {
526
409
  readonly id = "third-person";
410
+ readonly projection: "perspective";
527
411
  /**
528
412
  * Slightly looser than the previous 0.15 to compose better with the
529
413
  * trailing-delay follow: the trail absorbs short, fast moves and the
@@ -589,6 +473,7 @@ interface Fixed2DOptions {
589
473
  */
590
474
  declare class Fixed2DPerspective implements CameraPerspective {
591
475
  readonly id = "fixed-2d";
476
+ readonly projection: "orthographic";
592
477
  readonly defaults: {
593
478
  damping: number;
594
479
  };
@@ -636,6 +521,7 @@ interface FirstPersonOptions {
636
521
  */
637
522
  declare class FirstPersonPerspective implements CameraPerspective {
638
523
  readonly id = "first-person";
524
+ readonly projection: "perspective";
639
525
  readonly defaults: {
640
526
  damping: number;
641
527
  };
@@ -690,11 +576,128 @@ declare class FirstPersonPerspective implements CameraPerspective {
690
576
  private deriveYawPitchFromQuaternion;
691
577
  }
692
578
 
579
+ /**
580
+ * Configuration for the isometric perspective.
581
+ * The offset is world-locked along (1, 1, 1): yaw 45°, elevation atan(√2).
582
+ */
583
+ interface IsometricOptions {
584
+ /** Distance from the target along the isometric axis. Default 10. */
585
+ distance?: number;
586
+ /** Orthographic frustum size. Default 10. */
587
+ zoom?: number;
588
+ /** Key in CameraContext.targets to frame. Default 'primary'. */
589
+ targetKey?: string;
590
+ /** Fallback camera position when no target exists. */
591
+ initialPosition?: Vec3Input;
592
+ /** Fallback lookAt point when no target exists. */
593
+ initialLookAt?: Vec3Input;
594
+ }
595
+ /**
596
+ * Orthographic isometric perspective.
597
+ *
598
+ * The view direction stays locked in world space, so the target can move
599
+ * without the camera orbiting around it. Player look input is not accepted.
600
+ */
601
+ declare class IsometricPerspective implements CameraPerspective {
602
+ readonly id = "isometric";
603
+ readonly projection: "orthographic";
604
+ readonly defaults: {
605
+ damping: number;
606
+ };
607
+ private opts;
608
+ private initialPosition?;
609
+ private initialLookAt?;
610
+ constructor(options?: IsometricOptions);
611
+ getBasePose(ctx: CameraContext): CameraPose;
612
+ private staticPose;
613
+ private pose;
614
+ }
615
+
616
+ /**
617
+ * Configuration for the top-down perspective.
618
+ * The camera sits above the target and looks straight down at the XZ plane.
619
+ */
620
+ interface TopDownOptions {
621
+ /** Height above the target, in world units. Default 10. */
622
+ height?: number;
623
+ /** Orthographic frustum size. Default 10. */
624
+ zoom?: number;
625
+ /** Key in CameraContext.targets to frame. Default 'primary'. */
626
+ targetKey?: string;
627
+ /** Fallback camera position when no target exists. */
628
+ initialPosition?: Vec3Input;
629
+ /** Fallback lookAt point when no target exists. */
630
+ initialLookAt?: Vec3Input;
631
+ }
632
+ /**
633
+ * Orthographic top-down perspective.
634
+ *
635
+ * Rotation is locked to world -Y. The camera follows the target's XZ and
636
+ * stays `height` above it. Player look input is not accepted.
637
+ */
638
+ declare class TopDownPerspective implements CameraPerspective {
639
+ readonly id = "top-down";
640
+ readonly projection: "orthographic";
641
+ readonly defaults: {
642
+ damping: number;
643
+ };
644
+ private opts;
645
+ private initialPosition?;
646
+ private initialLookAt?;
647
+ constructor(options?: TopDownOptions);
648
+ getBasePose(ctx: CameraContext): CameraPose;
649
+ private staticPose;
650
+ private pose;
651
+ }
652
+
653
+ /**
654
+ * Configuration for the second-person perspective.
655
+ *
656
+ * The camera sits on another entity (`anchorKey`) and looks at the subject.
657
+ * Nothing here reads player look input.
658
+ */
659
+ interface SecondPersonOptions {
660
+ /** Key of the entity whose eyes the camera uses. Default 'anchor'. */
661
+ anchorKey?: string;
662
+ /** Key of the entity to look at. Default 'primary'. */
663
+ subjectKey?: string;
664
+ /** Height above the anchor's position. Default 1.7. */
665
+ eyeHeight?: number;
666
+ /** Perspective field of view. Default 75. */
667
+ fov?: number;
668
+ /** Fallback camera position when the anchor is missing. */
669
+ initialPosition?: Vec3Input;
670
+ /** Fallback lookAt point when the anchor is missing. */
671
+ initialLookAt?: Vec3Input;
672
+ }
673
+ /**
674
+ * Second-person perspective.
675
+ *
676
+ * Position comes from an anchor entity. The subject, when present, is the
677
+ * look-at; otherwise the camera looks along the anchor's forward (−Z).
678
+ * The player's facing does not move this camera.
679
+ */
680
+ declare class SecondPersonPerspective implements CameraPerspective {
681
+ readonly id = "second-person";
682
+ readonly projection: "perspective";
683
+ readonly defaults: {
684
+ damping: number;
685
+ };
686
+ private opts;
687
+ private initialPosition?;
688
+ private initialLookAt?;
689
+ constructor(options?: SecondPersonOptions);
690
+ getBasePose(ctx: CameraContext): CameraPose;
691
+ private staticPose;
692
+ /** Anchor forward in world space. Three.js objects look down −Z. */
693
+ private anchorForward;
694
+ }
695
+
693
696
  /**
694
697
  * Perspective-specific options union.
695
698
  * Extend as new perspective types are added.
696
699
  */
697
- type PerspectiveOptions = ThirdPersonOptions | Fixed2DOptions | FirstPersonOptions;
700
+ type PerspectiveOptions = ThirdPersonOptions | Fixed2DOptions | FirstPersonOptions | IsometricOptions | TopDownOptions | SecondPersonOptions;
698
701
  /**
699
702
  * Factory: create a CameraPerspective from a PerspectiveType string.
700
703
  * Unrecognized types default to ThirdPersonPerspective.
@@ -916,6 +919,10 @@ declare class StageDebugDelegate {
916
919
  private warnedMissingAddFactory;
917
920
  private transformTool;
918
921
  private swatchApplier;
922
+ private marquee;
923
+ private selectionHighlight;
924
+ private selectionBoundsPool;
925
+ private hoverBounds;
919
926
  private grid;
920
927
  private lastTool;
921
928
  /** Element the current gizmo drag captured, so pointerup is never missed. */
@@ -929,6 +936,13 @@ declare class StageDebugDelegate {
929
936
  /** Camera used for debug orbit / raycasts (active primary, usually `__debug__`). */
930
937
  private getDebugViewCamera;
931
938
  private resolveEntity;
939
+ /**
940
+ * Every entity a marquee may catch. `childrenMap` is the live stage;
941
+ * `debugMap` is consulted too so anything only registered there (the same
942
+ * set the single pick resolves through) is not skipped. Whether an entity
943
+ * has a selectable volume is the marquee's call, via its selection bounds.
944
+ */
945
+ private forEachSelectableEntity;
932
946
  /** Copy all stage children into debugMap so raycast/select tools work after enabling debug mid-session. */
933
947
  private populateDebugMap;
934
948
  private ensureCameraDebugDelegate;
@@ -961,6 +975,12 @@ declare class StageDebugDelegate {
961
975
  * available when a tool is armed with debug off.
962
976
  */
963
977
  private ensureToolVisuals;
978
+ /**
979
+ * Outline every selected entity. Re-fitted each frame so the boxes follow
980
+ * entities that move, and so a uuid whose entity has gone (deleted, or
981
+ * undone) simply drops out instead of leaving a stale box behind.
982
+ */
983
+ private updateSelectionHighlight;
964
984
  /**
965
985
  * Hide the overlays whose tool has just gone away.
966
986
  *
@@ -1664,525 +1684,4 @@ declare class Stage {
1664
1684
  */
1665
1685
  declare function createStage(...options: StageOptions): Stage;
1666
1686
 
1667
- /**
1668
- * Stage state interface - minimal to prevent circular dependencies
1669
- */
1670
- interface StageStateInterface {
1671
- backgroundColor: Color;
1672
- backgroundImage: string | null;
1673
- inputs: {
1674
- p1: string[];
1675
- p2: string[];
1676
- };
1677
- variables: Record<string, any>;
1678
- gravity: Vector3 | Vec3Components;
1679
- entities: Partial<BaseEntityInterface>[];
1680
- stageRef?: any;
1681
- }
1682
- /**
1683
- * Minimal stage interface to break circular dependencies
1684
- */
1685
- interface StageInterface {
1686
- uuid: string;
1687
- children: any[];
1688
- state: StageStateInterface;
1689
- }
1690
-
1691
- declare const AspectRatio: {
1692
- readonly FourByThree: number;
1693
- readonly SixteenByNine: number;
1694
- readonly NineBySixteen: number;
1695
- readonly TwentyOneByNine: number;
1696
- readonly OneByOne: number;
1697
- };
1698
- type AspectRatioValue = (typeof AspectRatio)[keyof typeof AspectRatio] | number;
1699
- /**
1700
- * AspectRatioDelegate manages sizing a canvas to fit within a container
1701
- * while preserving a target aspect ratio. It notifies a consumer via
1702
- * onResize when the final width/height are applied so renderers/cameras
1703
- * can update their viewports.
1704
- */
1705
- declare class AspectRatioDelegate {
1706
- container: HTMLElement;
1707
- canvas: HTMLCanvasElement;
1708
- aspectRatio: number;
1709
- onResize?: (width: number, height: number) => void;
1710
- private handleResizeBound;
1711
- private resizeObserver;
1712
- constructor(params: {
1713
- container: HTMLElement;
1714
- canvas: HTMLCanvasElement;
1715
- aspectRatio: AspectRatioValue;
1716
- onResize?: (width: number, height: number) => void;
1717
- });
1718
- /** Attach window resize listener and apply once. */
1719
- attach(): void;
1720
- /** Detach window resize listener. */
1721
- detach(): void;
1722
- /** Compute the largest size that fits container while preserving aspect. */
1723
- measure(): {
1724
- width: number;
1725
- height: number;
1726
- };
1727
- /** Apply measured size to canvas and notify. */
1728
- apply(): void;
1729
- }
1730
-
1731
- interface ViewportSize {
1732
- width: number;
1733
- height: number;
1734
- }
1735
-
1736
- type RetroResolution = {
1737
- key: string;
1738
- width: number;
1739
- height: number;
1740
- notes?: string;
1741
- };
1742
- type RetroPreset = {
1743
- displayAspect: number;
1744
- resolutions: RetroResolution[];
1745
- };
1746
- /**
1747
- * Retro, console, and device display presets.
1748
- * displayAspect represents the intended display aspect (letterboxing target),
1749
- * not necessarily the raw pixel aspect of internal buffers.
1750
- */
1751
- declare const RetroPresets: Record<string, RetroPreset>;
1752
- type RetroPresetKey = keyof typeof RetroPresets;
1753
- declare function getDisplayAspect(preset: RetroPresetKey): number;
1754
- declare function getPresetResolution(preset: RetroPresetKey, key?: string): RetroResolution | undefined;
1755
- declare function parseResolution(text: string): {
1756
- width: number;
1757
- height: number;
1758
- } | null;
1759
-
1760
- /**
1761
- * Resolution descriptor for the game's internal render buffer.
1762
- * - `string` : a "WxH" literal or a known retro preset (e.g. `'NES'`).
1763
- * - `{ width, height }` : explicit pixel dimensions.
1764
- * - `'native'` : skip internal-resolution scaling — render at the
1765
- * canvas' CSS size × DPR (i.e. 1:1 with the device viewport).
1766
- */
1767
- type ResolutionInput = string | {
1768
- width: number;
1769
- height: number;
1770
- } | 'native';
1771
- type DeviceProfile = 'auto' | 'desktop' | 'mobile';
1772
- interface ResolveGameConfigRuntime {
1773
- deviceProfile?: DeviceProfile;
1774
- viewportSize?: ViewportSize;
1775
- }
1776
- type GameDeviceConfig = Partial<{
1777
- /** numeric value or key in AspectRatio */
1778
- aspectRatio: AspectRatioValue | keyof typeof AspectRatio;
1779
- /** console/display preset to derive aspect ratio */
1780
- preset: RetroPresetKey;
1781
- /** lock internal render buffer for this device profile */
1782
- resolution: ResolutionInput;
1783
- /**
1784
- * Auto-merge built-in virtual touch controls into the resolved input
1785
- * config. The provider auto-enables on mobile devices via
1786
- * `enabled: 'auto'`, so on desktop runtimes the UI stays dormant.
1787
- * - `true` : default joystick + A/B layout, default theme.
1788
- * - options object : forwarded to `defaultTouchControls('p1', ...)`.
1789
- * - `false` / unset: no auto-injection (caller wires controls manually).
1790
- */
1791
- controls: boolean | DefaultTouchControlsOptions;
1792
- }>;
1793
- type GameConfigLike = Partial<{
1794
- id: string;
1795
- globals: Record<string, any>;
1796
- stages: StageInterface[];
1797
- debug: boolean;
1798
- time: number;
1799
- input: GameInputConfig;
1800
- /** numeric value or key in AspectRatio */
1801
- aspectRatio: AspectRatioValue | keyof typeof AspectRatio;
1802
- /** console/display preset to derive aspect ratio */
1803
- preset: RetroPresetKey;
1804
- /** lock internal render buffer to this desktop/default resolution */
1805
- resolution: ResolutionInput;
1806
- /** mobile-specific aspect/preset/resolution overrides */
1807
- mobile: GameDeviceConfig;
1808
- fullscreen: boolean;
1809
- /** CSS background value for document body */
1810
- bodyBackground: string;
1811
- /** existing container by reference */
1812
- container: HTMLElement;
1813
- /** create/find container by id */
1814
- containerId: string;
1815
- /** optional canvas if caller wants to manage it */
1816
- canvas: HTMLCanvasElement;
1817
- }>;
1818
- declare class GameConfig {
1819
- id: string;
1820
- globals: Record<string, any>;
1821
- stages: StageInterface[];
1822
- debug: boolean;
1823
- time: number;
1824
- input: GameInputConfig | undefined;
1825
- aspectRatio: number;
1826
- internalResolution: {
1827
- width: number;
1828
- height: number;
1829
- } | undefined;
1830
- fullscreen: boolean;
1831
- bodyBackground: string | undefined;
1832
- container: HTMLElement;
1833
- containerId?: string | undefined;
1834
- canvas?: HTMLCanvasElement | undefined;
1835
- constructor(id: string, globals: Record<string, any>, stages: StageInterface[], debug: boolean, time: number, input: GameInputConfig | undefined, aspectRatio: number, internalResolution: {
1836
- width: number;
1837
- height: number;
1838
- } | undefined, fullscreen: boolean, bodyBackground: string | undefined, container: HTMLElement, containerId?: string | undefined, canvas?: HTMLCanvasElement | undefined);
1839
- }
1840
- /**
1841
- * Factory for authoring configuration objects in user code.
1842
- * Returns a plain object that can be passed to `game(...)`.
1843
- */
1844
- declare function gameConfig(config: GameConfigLike): GameConfigLike;
1845
-
1846
- interface GameCanvasOptions {
1847
- id: string;
1848
- container?: HTMLElement;
1849
- containerId?: string;
1850
- canvas?: HTMLCanvasElement;
1851
- bodyBackground?: string;
1852
- fullscreen?: boolean;
1853
- aspectRatio: AspectRatioValue | number;
1854
- }
1855
- /**
1856
- * GameCanvas is a DOM delegate that owns:
1857
- * - container lookup/creation and styling (including fullscreen centering)
1858
- * - body background application
1859
- * - canvas mounting into container
1860
- * - aspect ratio sizing via AspectRatioDelegate
1861
- */
1862
- declare class GameCanvas {
1863
- id: string;
1864
- container: HTMLElement;
1865
- canvas: HTMLCanvasElement;
1866
- bodyBackground?: string;
1867
- fullscreen: boolean;
1868
- aspectRatio: number;
1869
- private ratioDelegate;
1870
- private overlayContainer;
1871
- constructor(options: GameCanvasOptions);
1872
- applyBodyBackground(): void;
1873
- mountCanvas(): void;
1874
- mountRenderer(rendererDom: HTMLCanvasElement, onResize: (width: number, height: number) => void): void;
1875
- getOverlayContainer(): HTMLElement;
1876
- centerIfFullscreen(): void;
1877
- attachAspectRatio(onResize: (width: number, height: number) => void): void;
1878
- setAspectRatio(aspectRatio: number): void;
1879
- reapplyLayout(): void;
1880
- destroy(): void;
1881
- private mountChildren;
1882
- private ensureOverlayContainer;
1883
- private ensureContainer;
1884
- }
1885
-
1886
- /**
1887
- * Game-level loading event that includes stage context.
1888
- */
1889
- interface GameLoadingEvent {
1890
- type: 'start' | 'progress' | 'complete';
1891
- stageName?: string;
1892
- stageIndex?: number;
1893
- message: string;
1894
- progress: number;
1895
- current?: number;
1896
- total?: number;
1897
- }
1898
-
1899
- type ZylemGameOptions<TGlobals extends BaseGlobals> = ZylemGameConfig<Stage, ZylemGame<TGlobals>, TGlobals> & Partial<GameConfig>;
1900
- declare class ZylemGame<TGlobals extends BaseGlobals> {
1901
- id: string;
1902
- initialGlobals: TGlobals;
1903
- customSetup: ((params: SetupContext<ZylemGame<TGlobals>, TGlobals>) => void) | null;
1904
- customUpdate: ((params: UpdateContext<ZylemGame<TGlobals>, TGlobals>) => void) | null;
1905
- customDestroy: ((params: DestroyContext<ZylemGame<TGlobals>, TGlobals>) => void) | null;
1906
- stages: Stage[];
1907
- stageMap: Map<string, Stage>;
1908
- currentStageId: string;
1909
- previousTimeStamp: number;
1910
- totalTime: number;
1911
- timer: Timer;
1912
- inputManager: InputManager;
1913
- wrapperRef: Game<TGlobals>;
1914
- globalInputConfig: GameInputConfig | undefined;
1915
- defaultCamera: ZylemCamera | null;
1916
- /** Shared renderer manager for all stages */
1917
- rendererManager: RendererManager | null;
1918
- container: HTMLElement | null;
1919
- canvas: HTMLCanvasElement | null;
1920
- aspectRatioDelegate: AspectRatioDelegate | null;
1921
- resolvedConfig: GameConfig | null;
1922
- gameCanvas: GameCanvas | null;
1923
- private animationFrameId;
1924
- private isDisposed;
1925
- /**
1926
- * True while a `loadStage` is in progress. Used to reject re-entrant stage
1927
- * navigation (e.g. a button press during a transition), which would race
1928
- * two loads on `stageMap`/the render loop and, because `currentStageId` is
1929
- * transiently `''`, misresolve the target stage.
1930
- */
1931
- private loadInFlight;
1932
- /**
1933
- * True once `start()` has been invoked for this game's initial stage.
1934
- * Used by `loadStage` to decide whether to drive the stage's `_setup`
1935
- * lifecycle directly (for subsequent stages loaded via `nextStage`
1936
- * / `loadStage`) or defer to `start()` (for the very first stage).
1937
- */
1938
- private hasStarted;
1939
- private debugDelegate;
1940
- private loadingDelegate;
1941
- private rendererObserver;
1942
- private eventBusUnsubscribes;
1943
- private thumbnailUnsubscribes;
1944
- /** Serialized last-published game config, for dirty-checking resize churn. */
1945
- private lastPublishedGameConfig;
1946
- /** Editor ↔ game bridge adapter (RAF-coalesced publishes, command intake). */
1947
- private gameBridge;
1948
- /** Stops republishing the entity catalog on registry changes. */
1949
- private catalogUnsubscribe;
1950
- private readonly gameUpdateParams;
1951
- private readonly stageSetupParams;
1952
- private readonly stageUpdateParams;
1953
- private readonly frameCallback;
1954
- private readonly sourceOptions;
1955
- private displayRuntime;
1956
- static FRAME_LIMIT: number;
1957
- static FRAME_DURATION: number;
1958
- static MAX_DELTA_SECONDS: number;
1959
- constructor(options: ZylemGameOptions<TGlobals>, wrapperRef: Game<TGlobals>, displayRuntime?: ResolveGameConfigRuntime);
1960
- /**
1961
- * Raycast at normalized device coordinates (editor `entity:pick`) and
1962
- * describe the hit the same way the entity list does, so a consumer can
1963
- * show name, type, and pose for whatever is under the pointer.
1964
- */
1965
- private pickEntityAtNdc;
1966
- /** Publish the placeable entity types the editor's Add palette lists. */
1967
- private publishEntityCatalog;
1968
- /** Spawn a catalog type programmatically (editor `entity:create`). */
1969
- private createCatalogEntity;
1970
- setDisplayRuntime(runtime: ResolveGameConfigRuntime): void;
1971
- loadGameCanvas(config: GameConfig): void;
1972
- loadDebugOptions(options: ZylemGameOptions<TGlobals>): void;
1973
- /** Whether a stage load is currently in progress. */
1974
- isLoading(): boolean;
1975
- loadStage(stage: Stage, stageIndex?: number, transition?: StageTransitionConfig): Promise<void>;
1976
- private performLoadStage;
1977
- /**
1978
- * Merges game-level global input config with the stage's per-stage overrides
1979
- * and reconfigures the InputManager.
1980
- */
1981
- applyInputConfig(stage: Stage): void;
1982
- /**
1983
- * Update the game-level global input config and re-apply to the current stage.
1984
- */
1985
- setGlobalInputConfig(config: GameInputConfig): void;
1986
- unloadCurrentStage(): void;
1987
- setGlobals(options: ZylemGameConfig<Stage, ZylemGame<TGlobals>, TGlobals>): void;
1988
- params(): UpdateContext<ZylemGame<TGlobals>, TGlobals>;
1989
- start(): void;
1990
- /**
1991
- * Execute a single frame update.
1992
- * This method can be called directly for testing or from the game loop.
1993
- * @param deltaTime Optional delta time in seconds. If not provided, uses timer delta.
1994
- */
1995
- step(deltaTime?: number): void;
1996
- loop(timestamp: number): void;
1997
- dispose(): void;
1998
- outOfLoop(): void;
1999
- getStage(id: string): Stage | undefined;
2000
- currentStage(): Stage | undefined;
2001
- /**
2002
- * Subscribe to loading events from the game.
2003
- * Events include stage context (stageName, stageIndex).
2004
- * @param callback Invoked for each loading event
2005
- * @returns Unsubscribe function
2006
- */
2007
- onLoading(callback: (event: GameLoadingEvent) => void): () => void;
2008
- /**
2009
- * Build the stage config payload for the current stage.
2010
- */
2011
- private buildStageConfigPayload;
2012
- /**
2013
- * Build a bridge entity summary for one entity, or null for entities on
2014
- * the managed render path (instanced packs/bundles), which can number in
2015
- * the thousands and are not useful in the editor panel.
2016
- */
2017
- private buildEntitySummary;
2018
- /**
2019
- * Build the full entities payload for the current stage.
2020
- */
2021
- private buildEntitiesPayload;
2022
- /**
2023
- * Generate entity thumbnails as entities become available, streaming
2024
- * upserts/thumbnails/removals to the editor through the bridge
2025
- * (RAF-coalesced, merged by uuid).
2026
- *
2027
- * All of this work exists only to feed the editor, and thumbnails in
2028
- * particular cost an offscreen render plus a pixel readback on the shared
2029
- * renderer. Each publisher therefore checks the bridge for a live listener
2030
- * first, and a late-connecting editor is backfilled from
2031
- * {@link wireEditorBackfill}.
2032
- */
2033
- private wireEntityThumbnails;
2034
- /**
2035
- * Republish the current stage when an editor subscribes after the game
2036
- * started. Without this, entities added while nothing was listening would
2037
- * never appear, since the per-entity publishers were skipped.
2038
- */
2039
- private wireEditorBackfill;
2040
- private clearEntityThumbnailWiring;
2041
- private buildGameConfigPayload;
2042
- /** Publish the resolved display config over the bridge. */
2043
- /**
2044
- * Publish the display config, skipping unchanged payloads. The
2045
- * `ResizeObserver` on `<zylem-game>` funnels into `setDisplayRuntime`, which
2046
- * fires on every layout tick even when nothing about the config moved.
2047
- */
2048
- private publishGameConfig;
2049
- /** Publish a full stage snapshot (config + entity list) over the bridge. */
2050
- private publishStageSnapshot;
2051
- /**
2052
- * Subscribe to the game event bus for stage loading and state events,
2053
- * mirroring global-variable updates to the editor over the bridge.
2054
- */
2055
- private subscribeToEventBus;
2056
- }
2057
-
2058
- type GameOptions<TGlobals extends BaseGlobals> = Array<ZylemGameConfig<Stage, any, TGlobals> | GameConfigLike | Stage | GameEntityLifeCycle | BaseNode>;
2059
-
2060
- declare class Game<TGlobals extends BaseGlobals> implements IGame<TGlobals> {
2061
- private wrappedGame;
2062
- options: GameOptions<TGlobals>;
2063
- private setupCallbacks;
2064
- private updateCallbacks;
2065
- private destroyCallbacks;
2066
- private pendingLoadingCallbacks;
2067
- private globalChangeCallbacks;
2068
- private globalChangesCallbacks;
2069
- private activeGlobalSubscriptions;
2070
- private eventDelegate;
2071
- /** Pending global input config set before the game starts. */
2072
- private pendingInputConfig;
2073
- private displayRuntime;
2074
- refErrorMessage: string;
2075
- constructor(options: GameOptions<TGlobals>);
2076
- onSetup(...callbacks: Array<SetupFunction<ZylemGame<TGlobals>, TGlobals>>): this;
2077
- onUpdate(...callbacks: Array<UpdateFunction<ZylemGame<TGlobals>, TGlobals>>): this;
2078
- onDestroy(...callbacks: Array<DestroyFunction<ZylemGame<TGlobals>, TGlobals>>): this;
2079
- /**
2080
- * Set composable input configuration as global defaults for the entire game.
2081
- * Multiple configs are deep-merged (later configs win on key conflicts).
2082
- * Per-stage overrides (via stage.setInputConfiguration) are merged on top.
2083
- * Can be called before or after start().
2084
- * @example game.setInputConfiguration(useArrowsForAxes('p1'), useWASDForDirections('p2'));
2085
- */
2086
- setInputConfiguration(...configs: GameInputConfig[]): this;
2087
- start(): Promise<this>;
2088
- setDisplayRuntime(runtime: Partial<ResolveGameConfigRuntime>): this;
2089
- setDeviceProfile(profile: DeviceProfile): this;
2090
- setViewportSize(width: number, height: number): this;
2091
- private load;
2092
- private setOverrides;
2093
- /**
2094
- * Subscribe to changes on a global value. Subscriptions are registered
2095
- * when the game starts and cleaned up when disposed.
2096
- * The callback receives the value and the current stage.
2097
- * @example game.onGlobalChange('score', (val, stage) => console.log(val));
2098
- */
2099
- onGlobalChange<T = unknown>(path: string, callback: (value: T, stage: Stage | null) => void): this;
2100
- /**
2101
- * Subscribe to changes on multiple global paths. Subscriptions are registered
2102
- * when the game starts and cleaned up when disposed.
2103
- * The callback receives the values and the current stage.
2104
- * @example game.onGlobalChanges(['score', 'lives'], ([score, lives], stage) => console.log(score, lives));
2105
- */
2106
- onGlobalChanges<T extends unknown[] = unknown[]>(paths: string[], callback: (values: T, stage: Stage | null) => void): this;
2107
- /**
2108
- * Register all stored global change callbacks.
2109
- * Called internally during start().
2110
- */
2111
- private registerGlobalSubscriptions;
2112
- /**
2113
- * Get the current stage wrapper.
2114
- */
2115
- getCurrentStage(): Stage | null;
2116
- /**
2117
- * Experimental escape hatches. APIs here are unstable and may change or be
2118
- * removed without a major version bump.
2119
- */
2120
- readonly experimental: {
2121
- /**
2122
- * The `@zylem/behaviors` {@link Simulation} backing the current stage's
2123
- * physics world, or `null` before a stage is loaded. Intended for debug
2124
- * tooling and the editor; games should not need it.
2125
- */
2126
- getRuntime: () => Simulation | null;
2127
- };
2128
- pause(): Promise<void>;
2129
- resume(): Promise<void>;
2130
- /**
2131
- * Execute a single frame update.
2132
- * Useful for testing or manual frame stepping.
2133
- * @param deltaTime Optional delta time in seconds (defaults to 1/60)
2134
- */
2135
- step(deltaTime?: number): void;
2136
- /**
2137
- * Reload the first stage. Pass `{ transition }` to blend from the current
2138
- * stage instead of cutting.
2139
- * @example game.reset({ transition: { duration: 1 } });
2140
- */
2141
- reset(options?: StageNavigationOptions): Promise<void>;
2142
- /**
2143
- * Go to the previous stage in the stage array. Pass `{ transition }` to
2144
- * blend from the current stage instead of cutting.
2145
- */
2146
- previousStage(options?: StageNavigationOptions): void;
2147
- loadStageFromId(stageId: string): Promise<void>;
2148
- /**
2149
- * Go to the next stage. Pass `{ transition }` to blend from the current
2150
- * stage instead of cutting.
2151
- * @example
2152
- * game.nextStage({
2153
- * transition: { duration: 1.2, shader: createStageTransition({ pattern: 'noise' }) },
2154
- * });
2155
- */
2156
- nextStage(options?: StageNavigationOptions): void;
2157
- goToStage(): Promise<void>;
2158
- end(): Promise<void>;
2159
- dispose(): void;
2160
- /**
2161
- * Dispatch an event from the game.
2162
- * Events are emitted both locally and to the global event bus.
2163
- */
2164
- dispatch<K extends keyof GameEvents>(event: K, payload: GameEvents[K]): void;
2165
- /**
2166
- * Listen for events on this game instance.
2167
- * @returns Unsubscribe function
2168
- */
2169
- listen<K extends keyof GameEvents>(event: K, handler: (payload: GameEvents[K]) => void): () => void;
2170
- /**
2171
- * Subscribe to loading events from the game.
2172
- * Events include stage context (stageName, stageIndex).
2173
- * @param callback Invoked for each loading event
2174
- * @returns Unsubscribe function
2175
- */
2176
- onLoading(callback: (event: GameLoadingEvent) => void): () => void;
2177
- }
2178
- /**
2179
- * create a new game
2180
- * @param options GameOptions - Array of IGameOptions, Stage, GameEntity, or BaseNode objects
2181
- * @param options.id Game name string (when using IGameOptions)
2182
- * @param options.globals Game globals object (when using IGameOptions)
2183
- * @param options.stages Array of stage objects (when using IGameOptions)
2184
- * @returns Game
2185
- */
2186
- declare function createGame<TGlobals extends BaseGlobals>(...options: GameOptions<TGlobals>): Game<TGlobals>;
2187
-
2188
- export { AspectRatio as A, Stage as B, CameraWrapper as C, type DeviceProfile as D, type StageStateInterface as E, Fixed2DPerspective as F, Game as G, type PerspectiveOptions as P, type ResolutionInput as R, type StageConfigLike as S, ThirdPersonPerspective as T, type GameLoadingEvent as a, type GameConfigLike as b, createGame as c, type GameDeviceConfig as d, type ResolveGameConfigRuntime as e, createStage as f, gameConfig as g, type StageOptions as h, createCamera as i, type CameraOptions as j, CameraManager as k, FirstPersonPerspective as l, createPerspective as m, type ThirdPersonOptions as n, type Fixed2DOptions as o, type FirstPersonOptions as p, type AspectRatioValue as q, getDisplayAspect as r, stageConfig as s, getPresetResolution as t, parseResolution as u, type RetroPreset as v, type RetroPresetKey as w, type RetroResolution as x, RenderBundleManager as y, RenderStrategyManager as z };
1687
+ export { type BaseEntityInterface as B, CameraWrapper as C, Fixed2DPerspective as F, IsometricPerspective as I, type PerspectiveOptions as P, RenderBundleManager as R, type StageConfigLike as S, ThirdPersonPerspective as T, ZylemStage as Z, type StageOptions as a, createCamera as b, createStage as c, type CameraOptions as d, CameraManager as e, FirstPersonPerspective as f, SecondPersonPerspective as g, TopDownPerspective as h, createPerspective as i, type ThirdPersonOptions as j, type Fixed2DOptions as k, type FirstPersonOptions as l, type SecondPersonOptions as m, type IsometricOptions as n, type TopDownOptions as o, RenderStrategyManager as p, Stage as q, stageConfig as s };