@zylem/game-lib 0.5.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
- import { I as InputGamepad, b as UpdateFunction, f as InputPlayerNumber, g as Inputs, h as ButtonState, A as AnalogState, c as SetupContext, U as UpdateContext, d as DestroyContext, i as GameEntityLifeCycle, e as BaseNode, j as IGame, S as SetupFunction, D as DestroyFunction, L as LoadingEvent, k as LoadedContext, C as CleanupContext } from './entity-bQElAdpo.js';
2
- import { Z as ZylemCamera } from './camera-Dk-fOVZE.js';
3
- import { B as BaseEntityInterface, a as Stage } from './stage-CrmY7V0i.js';
4
- import { Color, Vector3 } from 'three';
1
+ import { I as InputGamepad, c as UpdateFunction, f as InputPlayerNumber, g as Inputs, h as ButtonState, A as AnalogState, S as SetupContext, U as UpdateContext, d as DestroyContext, i as GameEntityLifeCycle, e as BaseNode, j as IGame, b as SetupFunction, D as DestroyFunction, k as LoadedContext, C as CleanupContext } from './entity-COvRtFNG.js';
2
+ import { Z as ZylemCamera } from './camera-CpbDr4-V.js';
3
+ import { d as StageInterface, b as Stage } from './stage-types-CD21XoIU.js';
4
+ import { Vector3 } from 'three';
5
5
  import { Vector3 as Vector3$1 } from '@dimforge/rapier3d-compat';
6
6
 
7
7
  interface InputProvider {
@@ -141,30 +141,6 @@ declare class Timer {
141
141
  update(timestamp?: number): Timer;
142
142
  }
143
143
 
144
- /**
145
- * Stage state interface - minimal to prevent circular dependencies
146
- */
147
- interface StageStateInterface {
148
- backgroundColor: Color;
149
- backgroundImage: string | null;
150
- inputs: {
151
- p1: string[];
152
- p2: string[];
153
- };
154
- variables: Record<string, any>;
155
- gravity: Vector3;
156
- entities: Partial<BaseEntityInterface>[];
157
- stageRef?: any;
158
- }
159
- /**
160
- * Minimal stage interface to break circular dependencies
161
- */
162
- interface StageInterface {
163
- uuid: string;
164
- children: any[];
165
- state: StageStateInterface;
166
- }
167
-
168
144
  declare const AspectRatio: {
169
145
  readonly FourByThree: number;
170
146
  readonly SixteenByNine: number;
@@ -309,6 +285,19 @@ declare class GameCanvas {
309
285
  private ensureContainer;
310
286
  }
311
287
 
288
+ /**
289
+ * Game-level loading event that includes stage context.
290
+ */
291
+ interface GameLoadingEvent {
292
+ type: 'start' | 'progress' | 'complete';
293
+ stageName?: string;
294
+ stageIndex?: number;
295
+ message: string;
296
+ progress: number;
297
+ current?: number;
298
+ total?: number;
299
+ }
300
+
312
301
  type ZylemGameOptions<TGlobals extends BaseGlobals> = ZylemGameConfig<Stage, ZylemGame<TGlobals>, TGlobals> & Partial<GameConfig>;
313
302
  declare class ZylemGame<TGlobals extends BaseGlobals> {
314
303
  id: string;
@@ -324,12 +313,6 @@ declare class ZylemGame<TGlobals extends BaseGlobals> {
324
313
  timer: Timer;
325
314
  inputManager: InputManager;
326
315
  wrapperRef: Game<TGlobals>;
327
- statsRef: {
328
- begin: () => void;
329
- end: () => void;
330
- showPanel: (panel: number) => void;
331
- dom: HTMLElement;
332
- } | null;
333
316
  defaultCamera: ZylemCamera | null;
334
317
  container: HTMLElement | null;
335
318
  canvas: HTMLCanvasElement | null;
@@ -338,13 +321,17 @@ declare class ZylemGame<TGlobals extends BaseGlobals> {
338
321
  gameCanvas: GameCanvas | null;
339
322
  private animationFrameId;
340
323
  private isDisposed;
324
+ private debugDelegate;
325
+ private loadingDelegate;
326
+ private rendererObserver;
327
+ private eventBusUnsubscribes;
341
328
  static FRAME_LIMIT: number;
342
329
  static FRAME_DURATION: number;
343
330
  static MAX_DELTA_SECONDS: number;
344
331
  constructor(options: ZylemGameOptions<TGlobals>, wrapperRef: Game<TGlobals>);
345
332
  loadGameCanvas(config: GameConfig): void;
346
333
  loadDebugOptions(options: ZylemGameOptions<TGlobals>): void;
347
- loadStage(stage: Stage): Promise<void>;
334
+ loadStage(stage: Stage, stageIndex?: number): Promise<void>;
348
335
  unloadCurrentStage(): void;
349
336
  setGlobals(options: ZylemGameConfig<Stage, ZylemGame<TGlobals>, TGlobals>): void;
350
337
  params(): UpdateContext<ZylemGame<TGlobals>, TGlobals>;
@@ -354,6 +341,18 @@ declare class ZylemGame<TGlobals extends BaseGlobals> {
354
341
  outOfLoop(): void;
355
342
  getStage(id: string): Stage | undefined;
356
343
  currentStage(): Stage | undefined;
344
+ /**
345
+ * Subscribe to loading events from the game.
346
+ * Events include stage context (stageName, stageIndex).
347
+ * @param callback Invoked for each loading event
348
+ * @returns Unsubscribe function
349
+ */
350
+ onLoading(callback: (event: GameLoadingEvent) => void): () => void;
351
+ /**
352
+ * Subscribe to the game event bus for stage loading and state events.
353
+ * Emits window events for cross-application communication.
354
+ */
355
+ private subscribeToEventBus;
357
356
  }
358
357
 
359
358
  type GameOptions<TGlobals extends BaseGlobals> = Array<ZylemGameConfig<Stage, any, TGlobals> | GameConfigLike | Stage | GameEntityLifeCycle | BaseNode>;
@@ -361,24 +360,60 @@ type GameOptions<TGlobals extends BaseGlobals> = Array<ZylemGameConfig<Stage, an
361
360
  declare class Game<TGlobals extends BaseGlobals> implements IGame<TGlobals> {
362
361
  private wrappedGame;
363
362
  options: GameOptions<TGlobals>;
364
- update: UpdateFunction<ZylemGame<TGlobals>, TGlobals>;
365
- setup: SetupFunction<ZylemGame<TGlobals>, TGlobals>;
366
- destroy: DestroyFunction<ZylemGame<TGlobals>, TGlobals>;
363
+ private setupCallbacks;
364
+ private updateCallbacks;
365
+ private destroyCallbacks;
366
+ private pendingLoadingCallbacks;
367
+ private globalChangeCallbacks;
368
+ private globalChangesCallbacks;
369
+ private activeGlobalSubscriptions;
367
370
  refErrorMessage: string;
368
371
  constructor(options: GameOptions<TGlobals>);
372
+ onSetup(...callbacks: Array<SetupFunction<ZylemGame<TGlobals>, TGlobals>>): this;
373
+ onUpdate(...callbacks: Array<UpdateFunction<ZylemGame<TGlobals>, TGlobals>>): this;
374
+ onDestroy(...callbacks: Array<DestroyFunction<ZylemGame<TGlobals>, TGlobals>>): this;
369
375
  start(): Promise<this>;
370
376
  private load;
371
- setOverrides(): void;
377
+ private setOverrides;
378
+ /**
379
+ * Subscribe to changes on a global value. Subscriptions are registered
380
+ * when the game starts and cleaned up when disposed.
381
+ * The callback receives the value and the current stage.
382
+ * @example game.onGlobalChange('score', (val, stage) => console.log(val));
383
+ */
384
+ onGlobalChange<T = unknown>(path: string, callback: (value: T, stage: Stage | null) => void): this;
385
+ /**
386
+ * Subscribe to changes on multiple global paths. Subscriptions are registered
387
+ * when the game starts and cleaned up when disposed.
388
+ * The callback receives the values and the current stage.
389
+ * @example game.onGlobalChanges(['score', 'lives'], ([score, lives], stage) => console.log(score, lives));
390
+ */
391
+ onGlobalChanges<T extends unknown[] = unknown[]>(paths: string[], callback: (values: T, stage: Stage | null) => void): this;
392
+ /**
393
+ * Register all stored global change callbacks.
394
+ * Called internally during start().
395
+ */
396
+ private registerGlobalSubscriptions;
397
+ /**
398
+ * Get the current stage wrapper.
399
+ */
400
+ getCurrentStage(): Stage | null;
372
401
  pause(): Promise<void>;
373
402
  resume(): Promise<void>;
374
403
  reset(): Promise<void>;
375
- previousStage(): Promise<void>;
404
+ previousStage(): void;
376
405
  loadStageFromId(stageId: string): Promise<void>;
377
- nextStage(): Promise<void>;
406
+ nextStage(): void;
378
407
  goToStage(): Promise<void>;
379
408
  end(): Promise<void>;
380
409
  dispose(): void;
381
- onLoading(callback: (event: LoadingEvent) => void): void;
410
+ /**
411
+ * Subscribe to loading events from the game.
412
+ * Events include stage context (stageName, stageIndex).
413
+ * @param callback Invoked for each loading event
414
+ * @returns Unsubscribe function
415
+ */
416
+ onLoading(callback: (event: GameLoadingEvent) => void): () => void;
382
417
  }
383
418
  /**
384
419
  * create a new game
package/dist/core.d.ts CHANGED
@@ -1,9 +1,10 @@
1
- export { V as Vect3, Z as ZylemGameConfig, c as createGame, a as globalChange, b as globalChanges, d as variableChange, e as variableChanges, v as vessel } from './core-C2mjetAd.js';
2
- import './entity-bQElAdpo.js';
1
+ export { V as Vect3, Z as ZylemGameConfig, c as createGame, a as globalChange, b as globalChanges, d as variableChange, e as variableChanges, v as vessel } from './core-CZhozNRH.js';
2
+ import './entity-COvRtFNG.js';
3
3
  import 'three';
4
4
  import '@dimforge/rapier3d-compat';
5
5
  import 'bitecs';
6
- import './camera-Dk-fOVZE.js';
7
- import 'three/addons/controls/OrbitControls.js';
6
+ import './camera-CpbDr4-V.js';
8
7
  import 'three/examples/jsm/postprocessing/EffectComposer.js';
9
- import './stage-CrmY7V0i.js';
8
+ import './entity-Bq_eNEDI.js';
9
+ import './stage-types-CD21XoIU.js';
10
+ import './entities-BAxfJOkk.js';