@skewedaspect/sage 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.
@@ -7,6 +7,10 @@ import { GameEntityManager } from "../managers/entity.d.ts";
7
7
  import { UserInputManager } from "../managers/input.d.ts";
8
8
  import { GameEventBus } from "./eventBus.d.ts";
9
9
  import { LoggingUtility } from "../utils/logger.d.ts";
10
+ /**
11
+ * Type definition for game lifecycle hook functions
12
+ */
13
+ export type GameHook = (gameEngine: SkewedAspectGameEngine) => Promise<void>;
10
14
  /**
11
15
  * Interface representing the engines used in the game.
12
16
  */
@@ -34,6 +38,9 @@ export declare class SkewedAspectGameEngine {
34
38
  eventBus: GameEventBus;
35
39
  logger: LoggingUtility;
36
40
  private _log;
41
+ private _beforeStartHook;
42
+ private _onStartHook;
43
+ private _onTeardownHook;
37
44
  /**
38
45
  * Creates an instance of SkewedAspectGameEngine.
39
46
  * @param canvas - The game canvas.
@@ -45,6 +52,24 @@ export declare class SkewedAspectGameEngine {
45
52
  * @param managers - The managers used in the game.
46
53
  */
47
54
  constructor(canvas: GameCanvas, renderEngine: AbstractEngine, physics: HavokPlugin, eventBus: GameEventBus, logger: LoggingUtility, engines: Engines, managers: Managers);
55
+ /**
56
+ * Register a function to be called before the game engine starts
57
+ * @param hook - Async function to be called before start
58
+ * @throws Error if a hook is already registered
59
+ */
60
+ onBeforeStart(hook: GameHook): void;
61
+ /**
62
+ * Register a function to be called after the game engine starts
63
+ * @param hook - Async function to be called after start
64
+ * @throws Error if a hook is already registered
65
+ */
66
+ onStart(hook: GameHook): void;
67
+ /**
68
+ * Register a function to be called when the game engine stops
69
+ * @param hook - Async function to be called during teardown
70
+ * @throws Error if a hook is already registered
71
+ */
72
+ onTeardown(hook: GameHook): void;
48
73
  /**
49
74
  * Starts the game engine.
50
75
  */
@@ -64,9 +64,9 @@ export declare class GamepadInputPlugin {
64
64
  */
65
65
  pollGamepads(): void;
66
66
  /**
67
- * Destroy the gamepad resource access and clean up event listeners
67
+ * Tears down the gamepad resource access and cleans up event listeners
68
68
  */
69
- destroy(): void;
69
+ $teardown(): Promise<void>;
70
70
  /**
71
71
  * Set up gamepad event listeners
72
72
  */
@@ -40,9 +40,9 @@ export declare class KeyboardInputPlugin {
40
40
  */
41
41
  getDevice(): KeyboardDevice;
42
42
  /**
43
- * Destroy the keyboard resource access and clean up event listeners
43
+ * Tears down the keyboard resource access and cleans up event listeners
44
44
  */
45
- destroy(): void;
45
+ $teardown(): Promise<void>;
46
46
  /**
47
47
  * Set up keyboard event listeners
48
48
  */
@@ -46,9 +46,9 @@ export declare class MouseInputPlugin {
46
46
  */
47
47
  getDevice(): MouseDevice;
48
48
  /**
49
- * Destroy the mouse resource access and clean up event listeners
49
+ * Tears down the mouse resource access and cleans up event listeners
50
50
  */
51
- destroy(): void;
51
+ $teardown(): Promise<void>;
52
52
  /**
53
53
  * Set up mouse event listeners
54
54
  */
@@ -8,4 +8,8 @@ export declare class SceneEngine {
8
8
  constructor(engine: AbstractEngine, physics: HavokPlugin, logger?: LoggingUtility);
9
9
  private _buildDemoScene;
10
10
  loadScene(canvas: GameCanvas): Promise<Scene>;
11
+ /**
12
+ * Tears down the scene engine and cleans up any resources
13
+ */
14
+ $teardown(): Promise<void>;
11
15
  }
@@ -6,4 +6,8 @@ export interface GameEntityDefinition<State extends object = object> {
6
6
  actions?: Action[];
7
7
  defaultState: State;
8
8
  behaviors: GameEntityBehaviorConstructor[];
9
+ onBeforeCreate?: (state: State) => Promise<State | undefined> | State | undefined;
10
+ onCreate?: (state: State) => Promise<State | undefined> | State | undefined;
11
+ onBeforeDestroy?: (state: State) => Promise<State | undefined> | State | undefined;
12
+ onDestroy?: (state: State) => Promise<void> | void;
9
13
  }
@@ -182,4 +182,8 @@ export declare class BindingManager {
182
182
  * @param config - The configuration to import
183
183
  */
184
184
  importConfiguration(config: BindingConfiguration): void;
185
+ /**
186
+ * Tears down the binding manager and cleans up any resources
187
+ */
188
+ $teardown(): Promise<void>;
185
189
  }
@@ -45,12 +45,12 @@ export declare class GameEntityManager {
45
45
  * @param initialState - The initial state of the entity.
46
46
  * @returns The created entity.
47
47
  */
48
- createEntity<State extends object = object>(type: string, initialState?: Partial<State>): GameEntity<State>;
48
+ createEntity<State extends object = object>(type: string, initialState?: Partial<State>): Promise<GameEntity<State>>;
49
49
  /**
50
50
  * Destroys the entity with the given ID.
51
51
  * @param entityID - The ID of the entity to destroy.
52
52
  */
53
- destroyEntity(entityID: string): void;
53
+ destroyEntity(entityID: string): Promise<void>;
54
54
  /**
55
55
  * Gets the entity with the given ID.
56
56
  * @param entityID - The ID of the entity to get.
@@ -67,4 +67,9 @@ export declare class GameEntityManager {
67
67
  * @param entityID - The ID of the entity to remove.
68
68
  */
69
69
  removeEntity(entityID: string): void;
70
+ /**
71
+ * Tears down all entities and releases resources
72
+ * @returns A promise that resolves when all entities have been destroyed
73
+ */
74
+ $teardown(): Promise<void>;
70
75
  }
@@ -11,10 +11,16 @@ export declare class GameManager {
11
11
  private _sceneEngine;
12
12
  private _currentScene;
13
13
  private _log;
14
+ private _boundResizeHandler;
14
15
  started: boolean;
15
16
  constructor(engine: AbstractEngine, sceneEngine: SceneEngine, entityManager: GameEntityManager, inputManager: UserInputManager, logger?: LoggingUtility);
16
17
  private _renderLoop;
17
18
  private _resizeHandler;
18
19
  start(canvas: GameCanvas): Promise<void>;
19
20
  stop(): Promise<void>;
21
+ /**
22
+ * Tears down any resources held by the GameManager
23
+ * This handles unregistering event listeners and any other cleanup
24
+ */
25
+ $teardown(): Promise<void>;
20
26
  }
@@ -32,9 +32,9 @@ export declare class UserInputManager {
32
32
  */
33
33
  private _publishInputChanged;
34
34
  /**
35
- * Destroy the input manager and clean up event listeners
35
+ * Tears down the input manager and clean up event listeners
36
36
  */
37
- $destroy(): void;
37
+ $teardown(): Promise<void>;
38
38
  /**
39
39
  * Get all input devices
40
40
  *
@@ -33,6 +33,10 @@ export declare class LevelManager {
33
33
  * Disposes the current scene and container (if any), freeing up memory.
34
34
  */
35
35
  disposeCurrentScene(): void;
36
+ /**
37
+ * Tears down the level manager and cleans up any resources
38
+ */
39
+ $teardown(): Promise<void>;
36
40
  /**
37
41
  * Returns the current active scene, if one is loaded.
38
42
  */