@zylem/game-lib 0.9.1 → 0.9.3

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.
@@ -169,6 +169,8 @@ import { JumpInput3D } from '@zylem/behaviors';
169
169
  import { JumpState2D } from '@zylem/behaviors';
170
170
  import { JumpState3D } from '@zylem/behaviors';
171
171
  import { length as length_2 } from 'three/tsl';
172
+ import { LevelBuffer } from '@zylem/bridge';
173
+ import { LevelEntry } from '@zylem/bridge';
172
174
  import { Light } from 'three';
173
175
  import { Line2 } from 'three/addons/lines/webgpu/Line2.js';
174
176
  import { Material } from 'three';
@@ -679,22 +681,24 @@ export const CameraKeyframeSchema: _sinclair_typebox.TObject<{
679
681
  easing: _sinclair_typebox.TUnion<[_sinclair_typebox.TLiteral<"linear">, _sinclair_typebox.TLiteral<"easeIn">, _sinclair_typebox.TLiteral<"easeOut">, _sinclair_typebox.TLiteral<"easeInOut">]>;
680
682
  }>;
681
683
 
684
+ // Warning: (ae-forgotten-export) The symbol "EditorCameraHost" needs to be exported by the entry point public.d.ts
685
+ //
682
686
  // @public
683
- export class CameraManager {
684
- constructor();
685
- activateDebugCamera(): boolean;
687
+ export class CameraManager implements EditorCameraHost {
688
+ activateCameraById(id: string): boolean;
686
689
  // Warning: (ae-forgotten-export) The symbol "ZylemCamera" needs to be exported by the entry point public.d.ts
687
690
  get activeCameras(): ReadonlyArray<ZylemCamera>;
688
691
  addActiveCamera(nameOrRef: string | ZylemCamera): boolean;
689
692
  addCamera(camera: ZylemCamera, name?: string): string;
690
693
  get allCameras(): ReadonlyArray<ZylemCamera>;
691
694
  deactivateCamera(nameOrRef: string | ZylemCamera): boolean;
692
- deactivateDebugCamera(): boolean;
693
- get debugCamera(): ZylemCamera | null;
695
+ destroyEditorCameras(): void;
694
696
  dispose(): void;
695
697
  ensureDefaultCamera(): ZylemCamera;
698
+ ensureEditorCameras(): Promise<void>;
696
699
  getCamera(name: string): ZylemCamera | null;
697
- get preDebugPrimary(): ZylemCamera | null;
700
+ hasEditorCameras(): boolean;
701
+ isEditorViewActive(): boolean;
698
702
  get primaryCamera(): ZylemCamera | null;
699
703
  removeCamera(nameOrRef: string | ZylemCamera): boolean;
700
704
  render(scene: Scene): void;
@@ -2152,6 +2156,7 @@ export class GameBridge {
2152
2156
  // (undocumented)
2153
2157
  disconnect(): void;
2154
2158
  onEditorAttached(callback: () => void): () => void;
2159
+ onEditorDetached(callback: () => void): () => void;
2155
2160
  publishCatalog(entities: EntityTypeDescriptor[]): void;
2156
2161
  // (undocumented)
2157
2162
  publishConfig(config: GameConfigPayload): void;
@@ -3173,6 +3178,14 @@ export function lerpPose(a: EvaluatedPose, b: EvaluatedPose, t: number): Evaluat
3173
3178
  // @public (undocumented)
3174
3179
  export function lerpVec3(a: Vec3Def, b: Vec3Def, t: number): Vec3Def;
3175
3180
 
3181
+ export { LevelBuffer }
3182
+
3183
+ // @public
3184
+ export interface LevelStage {
3185
+ // (undocumented)
3186
+ spawnEntity(node: BaseNode): Promise<void> | void;
3187
+ }
3188
+
3176
3189
  // @public (undocumented)
3177
3190
  export const LIGHT_TYPE: unique symbol;
3178
3191
 
@@ -4942,6 +4955,23 @@ export interface StrategyPointer {
4942
4955
  y: number;
4943
4956
  }
4944
4957
 
4958
+ // @public
4959
+ export function streamLevel(buffer: LevelBuffer, spawn: (entry: LevelEntry) => void | Promise<void>, options?: StreamLevelOptions): Promise<StreamLevelResult>;
4960
+
4961
+ // @public
4962
+ export function streamLevelOnStage(stage: LevelStage, buffer: LevelBuffer, options?: StreamLevelOptions): Promise<StreamLevelResult>;
4963
+
4964
+ // @public
4965
+ export interface StreamLevelOptions {
4966
+ // (undocumented)
4967
+ batchSize?: number;
4968
+ }
4969
+
4970
+ // @public (undocumented)
4971
+ export interface StreamLevelResult {
4972
+ spawned: number;
4973
+ }
4974
+
4945
4975
  export { SwatchApplyFailureReason }
4946
4976
 
4947
4977
  // @public
@@ -6178,8 +6208,8 @@ export class ZylemZone extends GameEntity<ZylemZoneOptions> implements Collision
6178
6208
  // dist/entity-XqvuWgPm.d.ts:343:9 - (ae-forgotten-export) The symbol "EntityMeshBuilder" needs to be exported by the entry point public.d.ts
6179
6209
  // dist/entity-XqvuWgPm.d.ts:344:9 - (ae-forgotten-export) The symbol "EntityCollisionBuilder" needs to be exported by the entry point public.d.ts
6180
6210
  // dist/entity-XqvuWgPm.d.ts:345:9 - (ae-forgotten-export) The symbol "MaterialBuilder" needs to be exported by the entry point public.d.ts
6181
- // dist/game-D8KTP3fD.d.ts:258:5 - (ae-forgotten-export) The symbol "StageInterface" needs to be exported by the entry point public.d.ts
6182
- // dist/stage-CAPlk_cN.d.ts:1117:5 - (ae-forgotten-export) The symbol "StageAssetLoaderConfig" needs to be exported by the entry point public.d.ts
6211
+ // dist/game-DBNxY6mb.d.ts:258:5 - (ae-forgotten-export) The symbol "StageInterface" needs to be exported by the entry point public.d.ts
6212
+ // dist/stage-bVLyYnOQ.d.ts:1148:5 - (ae-forgotten-export) The symbol "StageAssetLoaderConfig" needs to be exported by the entry point public.d.ts
6183
6213
 
6184
6214
  // (No @packageDocumentation comment for this package)
6185
6215
 
@@ -163,6 +163,8 @@ import { JumpInput3D } from '@zylem/behaviors';
163
163
  import { JumpState2D } from '@zylem/behaviors';
164
164
  import { JumpState3D } from '@zylem/behaviors';
165
165
  import { length as length_2 } from 'three/tsl';
166
+ import { LevelBuffer } from '@zylem/bridge';
167
+ import { LevelEntry } from '@zylem/bridge';
166
168
  import { Light } from 'three';
167
169
  import { Line2 } from 'three/addons/lines/webgpu/Line2.js';
168
170
  import { Material } from 'three';
@@ -456,8 +458,9 @@ declare type ActorOptions = BaseNode | ZylemActorOptions;
456
458
  * hover/select/delete/spawn, the `DebugEntityCursor` highlight and the
457
459
  * `PlacementGhost` — is live whenever a tool is armed, so the toolbar's buttons
458
460
  * work on their own. The debug layer — the wasm simulation's collider
459
- * wireframes and the orbit camera — is the part `debugState.enabled` gates, and
460
- * is torn down when it goes off while the delegate stays alive to re-activate.
461
+ * wireframes — is the part `debugState.enabled` gates, and is torn down when
462
+ * it goes off while the delegate stays alive to re-activate. Debug mode does
463
+ * not switch cameras; picking and gizmos use whichever camera is rendering.
461
464
  *
462
465
  * Centralizes all of this so `ZylemStage` doesn't have to know about
463
466
  * raycasting, DOM input, or debug rendering.
@@ -956,28 +959,38 @@ export declare const CameraKeyframeSchema: _sinclair_typebox.TObject<{
956
959
  * Responsibilities:
957
960
  * - Named camera registry (add/remove/get by name or reference)
958
961
  * - Active camera list management (determines which cameras render)
959
- * - Always-available debug camera with orbit controls
962
+ * - Editor view cameras (side, top, isometric, free), created only while an editor is attached
960
963
  * - Per-frame update of all active cameras' perspective controllers
961
964
  * - Coordinating rendering via RendererManager for all active viewports
962
965
  */
963
- export declare class CameraManager {
966
+ export declare class CameraManager implements EditorCameraHost {
964
967
  /** Named camera registry */
965
968
  private cameras;
966
969
  /** Currently active cameras, ordered by render layer (first = bottom) */
967
970
  private _activeCameras;
968
- /** Auto-created debug camera with orbit controls */
969
- private _debugCamera;
970
- /** Gameplay primary camera saved while the debug camera is active. */
971
- private _preDebugPrimary;
972
- /** Scene anchor at world origin for debug orbit when nothing is selected. */
973
- private _debugOrbitTargetAnchor;
971
+ /** Editor view cameras, keyed by `editor:*` id. */
972
+ private _editorCameras;
973
+ /** Which editor views freeze rotation. */
974
+ private _lockedEditorIds;
975
+ /** Game camera to restore when the editor releases the main view. */
976
+ private _rememberedGameCamera;
977
+ /**
978
+ * True while an editor view is the main camera. Game calls to
979
+ * {@link setActiveCamera} update {@link _rememberedGameCamera} and leave
980
+ * the view on screen.
981
+ */
982
+ private _editorViewLocked;
983
+ /** Game cameras whose orbit input was suspended for an editor view. */
984
+ private _suspendedOrbits;
985
+ /** In-flight creation, so a second attach does not build a second set. */
986
+ private _editorCamerasPromise;
974
987
  /** Reference to the shared renderer manager */
975
988
  private _rendererManager;
976
989
  /** Scene reference */
977
990
  private _sceneRef;
978
991
  /** Counter for auto-generated camera names */
979
992
  private _autoNameCounter;
980
- constructor();
993
+ private _unregisterEditorHost;
981
994
  /**
982
995
  * Get the list of currently active cameras.
983
996
  */
@@ -986,14 +999,10 @@ export declare class CameraManager {
986
999
  * Get the primary active camera (first in the active list).
987
1000
  */
988
1001
  get primaryCamera(): ZylemCamera | null;
989
- /**
990
- * Get the debug camera.
991
- */
992
- get debugCamera(): ZylemCamera | null;
993
- /**
994
- * Gameplay primary camera that was active before debug mode was enabled.
995
- */
996
- get preDebugPrimary(): ZylemCamera | null;
1002
+ /** True while side, top, isometric, or free is the main view. */
1003
+ isEditorViewActive(): boolean;
1004
+ /** True after the four editor views have been created. */
1005
+ hasEditorCameras(): boolean;
997
1006
  /**
998
1007
  * Get all registered cameras.
999
1008
  */
@@ -1010,13 +1019,15 @@ export declare class CameraManager {
1010
1019
  addCamera(camera: ZylemCamera, name?: string): string;
1011
1020
  /**
1012
1021
  * Remove a camera by name or reference.
1013
- * Cannot remove the debug camera via this method.
1014
1022
  */
1015
1023
  removeCamera(nameOrRef: string | ZylemCamera): boolean;
1016
1024
  /**
1017
1025
  * Set a camera as the primary active camera (replaces all active cameras
1018
1026
  * except additional viewport cameras).
1019
1027
  *
1028
+ * While an editor view owns the main view, a game camera is remembered
1029
+ * and the rendered camera does not change.
1030
+ *
1020
1031
  * @param nameOrRef Camera name or reference to activate
1021
1032
  */
1022
1033
  setActiveCamera(nameOrRef: string | ZylemCamera): boolean;
@@ -1034,19 +1045,27 @@ export declare class CameraManager {
1034
1045
  getCamera(name: string): ZylemCamera | null;
1035
1046
  /**
1036
1047
  * Setup all cameras with the given scene and renderer manager.
1037
- * Also creates the debug camera.
1048
+ * Editor view cameras are created here only when an editor is already attached.
1038
1049
  */
1039
1050
  setup(scene: Scene, rendererManager: RendererManager): Promise<void>;
1040
1051
  /**
1041
- * Switch the primary viewport to the debug orbit camera, remembering the
1042
- * previous primary so gameplay cameras (e.g. first-person) can be restored.
1052
+ * Create side, top, isometric, and free cameras seeded from the current
1053
+ * game camera. Does not change which camera is rendering.
1054
+ */
1055
+ ensureEditorCameras(): Promise<void>;
1056
+ /**
1057
+ * Restore the game camera when an editor view is showing, then destroy
1058
+ * the four editor cameras.
1043
1059
  */
1044
- activateDebugCamera(): boolean;
1060
+ destroyEditorCameras(): void;
1045
1061
  /**
1046
- * Restore the gameplay primary camera that was active before
1047
- * {@link activateDebugCamera}.
1062
+ * Switch the main view.
1063
+ *
1064
+ * `game` releases to the remembered game camera. Editor view ids show
1065
+ * that view. Any other id activates a game-registered camera and clears
1066
+ * the editor override.
1048
1067
  */
1049
- deactivateDebugCamera(): boolean;
1068
+ activateCameraById(id: string): boolean;
1050
1069
  /**
1051
1070
  * Update all active cameras' controllers.
1052
1071
  */
@@ -1066,16 +1085,19 @@ export declare class CameraManager {
1066
1085
  * Dispose all cameras and cleanup.
1067
1086
  */
1068
1087
  dispose(): void;
1069
- /**
1070
- * Create the always-available debug camera with orbit controls.
1071
- * Registered for lookup/activation, but not added to the active list.
1072
- */
1073
- private createDebugCamera;
1074
- /**
1075
- * Seed the debug camera orbit pose on first activation, framing the origin
1076
- * or offsetting from the saved gameplay primary.
1077
- */
1078
- private seedDebugCameraPose;
1088
+ private createEditorCameras;
1089
+ private showEditorCamera;
1090
+ private showGameCamera;
1091
+ /** Enable orbit on the active editor view only. Inactive views keep their pose. */
1092
+ private syncEditorOrbit;
1093
+ /** Stop game-camera orbit controls from sharing the canvas with an editor view. */
1094
+ private suspendOtherOrbits;
1095
+ private restoreOrbitFor;
1096
+ private gameCameraToRestore;
1097
+ private cameraIsRegistered;
1098
+ private isEditorCamera;
1099
+ /** Replace the primary camera and keep picture-in-picture viewports. */
1100
+ private commitActive;
1079
1101
  /**
1080
1102
  * Resolve a camera from a name or reference.
1081
1103
  */
@@ -2692,6 +2714,19 @@ export { dot }
2692
2714
  */
2693
2715
  export declare function easeValue(easing: CutsceneEasing, t: number): number;
2694
2716
 
2717
+ /**
2718
+ * Editor-view cameras exist only while an editor is attached.
2719
+ *
2720
+ * `GameBridge.connect()` runs for every game, so it is not the signal. The
2721
+ * bridge marks the session attached when an editor subscribes, and every live
2722
+ * camera manager creates or destroys its four view cameras from that flag.
2723
+ */
2724
+ declare interface EditorCameraHost {
2725
+ ensureEditorCameras(): Promise<void>;
2726
+ destroyEditorCameras(): void;
2727
+ activateCameraById(id: string): boolean;
2728
+ }
2729
+
2695
2730
  export { EditorToGameMessages }
2696
2731
 
2697
2732
  export declare type EffectType = Static<typeof EffectTypeSchema>;
@@ -3320,8 +3355,9 @@ export { floor }
3320
3355
  export { Fn }
3321
3356
 
3322
3357
  /**
3323
- * Select an entity by UUID and frame the debug camera to fit it.
3324
- * Enables debug mode so orbit controls are active.
3358
+ * Select an entity by UUID and frame the active editor camera to fit it.
3359
+ * When the game camera is showing, the stage switches to the free editor
3360
+ * camera first. Enables debug mode so the selection is visible.
3325
3361
  *
3326
3362
  * @returns true if the entity was found and framed
3327
3363
  */
@@ -3488,6 +3524,8 @@ export declare class GameBridge {
3488
3524
  * not themselves recorded as new operations.
3489
3525
  */
3490
3526
  private applyingSceneOperation;
3527
+ /** Frame watch used when the channel cannot report subscriber removal. */
3528
+ private editorCameraFrame;
3491
3529
  constructor();
3492
3530
  /**
3493
3531
  * Subscribe to editor commands and announce the game side as ready.
@@ -3540,6 +3578,29 @@ export declare class GameBridge {
3540
3578
  * @returns An unsubscribe function.
3541
3579
  */
3542
3580
  onEditorAttached(callback: () => void): () => void;
3581
+ /**
3582
+ * Run a callback when the editor drops both entity subscriptions.
3583
+ *
3584
+ * Mirrors {@link onEditorAttached}: the first of the pair to unsubscribe
3585
+ * is the same editor finishing teardown, so the callback waits until the
3586
+ * other type is already at zero.
3587
+ *
3588
+ * @returns An unsubscribe function.
3589
+ */
3590
+ onEditorDetached(callback: () => void): () => void;
3591
+ /** True when an editor is listening for entity data. */
3592
+ private editorIsAttached;
3593
+ /** Create the view cameras and, if needed, watch for the editor leaving. */
3594
+ private attachEditorCameras;
3595
+ /** Destroy the view cameras and stop watching for editor removal. */
3596
+ private detachEditorCameras;
3597
+ /**
3598
+ * Published bridge builds do not report the last subscriber leaving.
3599
+ * While the editor is attached, look again each frame and tear the view
3600
+ * cameras down once both entity subscriptions are gone.
3601
+ */
3602
+ private watchEditorDetached;
3603
+ private stopWatchingEditorDetached;
3543
3604
  publishConfig(config: GameConfigPayload): void;
3544
3605
  publishLoading(payload: BridgeLoadingPayload): void;
3545
3606
  publishStatus(status: {
@@ -3555,6 +3616,13 @@ export declare class GameBridge {
3555
3616
  * variable's update would never reach the editor.
3556
3617
  */
3557
3618
  publishVariable(payload: GameVariablePayload): void;
3619
+ /**
3620
+ * Stream a level buffer through the host's catalog spawn.
3621
+ *
3622
+ * Each entry is handed to `createEntity`, which no-ops for an unknown
3623
+ * type. The notice counts entries handed off, not bodies that appeared.
3624
+ */
3625
+ private loadLevel;
3558
3626
  /** Surface a diagnostic message in the editor console. */
3559
3627
  publishNotice(level: GameNoticePayload['level'], message: string): void;
3560
3628
  publishStageSnapshot(snapshot: StageSnapshotPayload): void;
@@ -4986,6 +5054,21 @@ export declare function lerpPose(a: EvaluatedPose, b: EvaluatedPose, t: number):
4986
5054
 
4987
5055
  export declare function lerpVec3(a: Vec3Def, b: Vec3Def, t: number): Vec3Def;
4988
5056
 
5057
+ export { LevelBuffer }
5058
+
5059
+ /**
5060
+ * Stream a level buffer into a stage through the catalog.
5061
+ *
5062
+ * `streamLevel` only walks entries. This is the call gameplay code makes:
5063
+ * each entry is created from its catalog id, spawned, then posed. Unknown
5064
+ * catalog ids are skipped. Batching stays in `streamLevel`.
5065
+ */
5066
+
5067
+ /** The slice of a stage `streamLevelOnStage` needs. */
5068
+ export declare interface LevelStage {
5069
+ spawnEntity(node: BaseNode): Promise<void> | void;
5070
+ }
5071
+
4989
5072
  /**
4990
5073
  * Provides BaseNode-like lifecycle without ECS/children. Consumers implement
4991
5074
  * the protected hooks and may assign public setup/update/destroy callbacks.
@@ -7596,7 +7679,6 @@ declare class StageDebugDelegate {
7596
7679
  private debugCursor;
7597
7680
  private placementGhost;
7598
7681
  private debugLines;
7599
- private cameraDebugDelegate;
7600
7682
  private debugStateUnsubscribe;
7601
7683
  private focusContextUnregister;
7602
7684
  private entityResolverUnregister;
@@ -7618,7 +7700,7 @@ declare class StageDebugDelegate {
7618
7700
  * point. Without one the tool warns instead of silently doing nothing.
7619
7701
  */
7620
7702
  setAddEntityFactory(factory: AddEntityFactory | null): void;
7621
- /** Camera used for debug orbit / raycasts (active primary, usually `__debug__`). */
7703
+ /** Camera used for raycasts and gizmos: whichever one is rendering. */
7622
7704
  private getDebugViewCamera;
7623
7705
  private resolveEntity;
7624
7706
  /**
@@ -7630,7 +7712,6 @@ declare class StageDebugDelegate {
7630
7712
  private forEachSelectableEntity;
7631
7713
  /** Copy all stage children into debugMap so raycast/select tools work after enabling debug mid-session. */
7632
7714
  private populateDebugMap;
7633
- private ensureCameraDebugDelegate;
7634
7715
  /**
7635
7716
  * Activate/deactivate only when `debugState.enabled` actually flips.
7636
7717
  * Hover and selection write to `debugState` every frame, and `activate()`
@@ -7641,9 +7722,9 @@ declare class StageDebugDelegate {
7641
7722
  /** Hand the transform tool its mode whenever the active tool changes. */
7642
7723
  private syncToolMode;
7643
7724
  private syncGrid;
7644
- /** Initialize DOM listeners and switch rendering to the debug orbit camera. */
7725
+ /** Initialize DOM listeners. The rendering camera stays whatever the editor selected. */
7645
7726
  private activate;
7646
- /** Tear down visuals and restore the gameplay primary camera. */
7727
+ /** Tear down visuals without changing which camera is rendering. */
7647
7728
  private deactivate;
7648
7729
  private rebindPostProcessing;
7649
7730
  /**
@@ -8345,6 +8426,43 @@ export declare interface StrategyPointer {
8345
8426
  centered?: boolean;
8346
8427
  }
8347
8428
 
8429
+ /**
8430
+ * Hand each buffer entry to `spawn`, in order, yielding between batches.
8431
+ *
8432
+ * @returns How many entries were handed off. A spawn that no-ops for an
8433
+ * unknown catalog type still counts: the entry was delivered.
8434
+ */
8435
+ export declare function streamLevel(buffer: LevelBuffer, spawn: (entry: LevelEntry) => void | Promise<void>, options?: StreamLevelOptions): Promise<StreamLevelResult>;
8436
+
8437
+ /**
8438
+ * Spawn every catalog entry in `buffer` onto `stage`.
8439
+ *
8440
+ * Position is handed to the type's factory. Rotation and scale are applied
8441
+ * after spawn, and a scale change rebuilds colliders. An entry whose catalog
8442
+ * id is not registered is skipped.
8443
+ */
8444
+ export declare function streamLevelOnStage(stage: LevelStage, buffer: LevelBuffer, options?: StreamLevelOptions): Promise<StreamLevelResult>;
8445
+
8446
+ /**
8447
+ * Stream a level buffer into a stage.
8448
+ *
8449
+ * The streamer does not know the catalog. `spawn` is the host's existing
8450
+ * create path, which resolves a catalog id and no-ops when the type is
8451
+ * unknown. Entries are handed off in batches, yielding to the event loop
8452
+ * between them so a large level does not stall the frame the way a single
8453
+ * synchronous spawn loop would.
8454
+ */
8455
+
8456
+ export declare interface StreamLevelOptions {
8457
+ /** @default 5 */
8458
+ batchSize?: number;
8459
+ }
8460
+
8461
+ export declare interface StreamLevelResult {
8462
+ /** Entries handed to `spawn`, in buffer order. */
8463
+ spawned: number;
8464
+ }
8465
+
8348
8466
  export { SwatchApplyFailureReason }
8349
8467
 
8350
8468
  /** What a host reports back from a swatch batch. */
@@ -9701,6 +9819,17 @@ declare class ZylemCamera {
9701
9819
  * Disable user-configured orbital controls.
9702
9820
  */
9703
9821
  disableOrbitalControls(): void;
9822
+ /**
9823
+ * Turn on orbit for an editor view camera.
9824
+ *
9825
+ * Locked views keep pan and zoom and freeze the seeded angle. The free
9826
+ * view can rotate. Controls stay allocated after this so a later visit
9827
+ * keeps the panned pose; use {@link setOrbitInteractionEnabled} to ignore
9828
+ * pointer input while another camera is showing.
9829
+ */
9830
+ armEditorOrbit(lockRotation: boolean): void;
9831
+ /** Ignore pointer input without disposing orbit controls or their pose. */
9832
+ disarmEditorOrbit(): void;
9704
9833
  /**
9705
9834
  * Whether user orbital controls are enabled.
9706
9835
  */