@skewedaspect/sage 0.3.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.
Files changed (86) hide show
  1. package/LICENSE +21 -0
  2. package/Readme.md +53 -0
  3. package/dist/classes/bindings/toggle.d.ts +122 -0
  4. package/dist/classes/bindings/trigger.d.ts +79 -0
  5. package/dist/classes/bindings/value.d.ts +104 -0
  6. package/dist/classes/entity.d.ts +83 -0
  7. package/dist/classes/eventBus.d.ts +94 -0
  8. package/dist/classes/gameEngine.d.ts +57 -0
  9. package/dist/classes/input/gamepad.d.ts +94 -0
  10. package/dist/classes/input/keyboard.d.ts +66 -0
  11. package/dist/classes/input/mouse.d.ts +80 -0
  12. package/dist/classes/input/readers/gamepad.d.ts +77 -0
  13. package/dist/classes/input/readers/keyboard.d.ts +60 -0
  14. package/dist/classes/input/readers/mouse.d.ts +45 -0
  15. package/dist/classes/loggers/consoleBackend.d.ts +29 -0
  16. package/dist/classes/loggers/nullBackend.d.ts +14 -0
  17. package/dist/engines/scene.d.ts +11 -0
  18. package/dist/interfaces/action.d.ts +20 -0
  19. package/dist/interfaces/binding.d.ts +144 -0
  20. package/dist/interfaces/entity.d.ts +9 -0
  21. package/dist/interfaces/game.d.ts +26 -0
  22. package/dist/interfaces/input.d.ts +181 -0
  23. package/dist/interfaces/logger.d.ts +88 -0
  24. package/dist/managers/binding.d.ts +185 -0
  25. package/dist/managers/entity.d.ts +70 -0
  26. package/dist/managers/game.d.ts +20 -0
  27. package/dist/managers/input.d.ts +56 -0
  28. package/dist/managers/level.d.ts +55 -0
  29. package/dist/sage.d.ts +20 -0
  30. package/dist/sage.es.js +2208 -0
  31. package/dist/sage.es.js.map +1 -0
  32. package/dist/sage.umd.js +2 -0
  33. package/dist/sage.umd.js.map +1 -0
  34. package/dist/utils/capabilities.d.ts +2 -0
  35. package/dist/utils/graphics.d.ts +10 -0
  36. package/dist/utils/logger.d.ts +66 -0
  37. package/dist/utils/physics.d.ts +2 -0
  38. package/dist/utils/version.d.ts +5 -0
  39. package/docs/architecture.md +129 -0
  40. package/docs/behaviors.md +706 -0
  41. package/docs/binding_system.md +820 -0
  42. package/docs/design/input.md +86 -0
  43. package/docs/entity_system.md +538 -0
  44. package/docs/eventbus.md +225 -0
  45. package/docs/getting_started.md +264 -0
  46. package/docs/images/sage_logo.png +0 -0
  47. package/docs/images/sage_logo_shape.png +0 -0
  48. package/docs/overview.md +38 -0
  49. package/docs/physics_system.md +686 -0
  50. package/docs/scene_system.md +513 -0
  51. package/package.json +69 -0
  52. package/src/classes/bindings/toggle.ts +261 -0
  53. package/src/classes/bindings/trigger.ts +211 -0
  54. package/src/classes/bindings/value.ts +227 -0
  55. package/src/classes/entity.ts +256 -0
  56. package/src/classes/eventBus.ts +259 -0
  57. package/src/classes/gameEngine.ts +125 -0
  58. package/src/classes/input/gamepad.ts +388 -0
  59. package/src/classes/input/keyboard.ts +189 -0
  60. package/src/classes/input/mouse.ts +276 -0
  61. package/src/classes/input/readers/gamepad.ts +179 -0
  62. package/src/classes/input/readers/keyboard.ts +123 -0
  63. package/src/classes/input/readers/mouse.ts +133 -0
  64. package/src/classes/loggers/consoleBackend.ts +135 -0
  65. package/src/classes/loggers/nullBackend.ts +51 -0
  66. package/src/engines/scene.ts +112 -0
  67. package/src/images/sage_logo.svg +172 -0
  68. package/src/images/sage_logo_shape.svg +146 -0
  69. package/src/interfaces/action.ts +30 -0
  70. package/src/interfaces/binding.ts +191 -0
  71. package/src/interfaces/entity.ts +21 -0
  72. package/src/interfaces/game.ts +44 -0
  73. package/src/interfaces/input.ts +221 -0
  74. package/src/interfaces/logger.ts +118 -0
  75. package/src/managers/binding.ts +729 -0
  76. package/src/managers/entity.ts +252 -0
  77. package/src/managers/game.ts +111 -0
  78. package/src/managers/input.ts +233 -0
  79. package/src/managers/level.ts +261 -0
  80. package/src/sage.ts +119 -0
  81. package/src/types/global.d.ts +11 -0
  82. package/src/utils/capabilities.ts +16 -0
  83. package/src/utils/graphics.ts +148 -0
  84. package/src/utils/logger.ts +225 -0
  85. package/src/utils/physics.ts +16 -0
  86. package/src/utils/version.ts +11 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Christopher Case
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/Readme.md ADDED
@@ -0,0 +1,53 @@
1
+
2
+ # SkewedAspect Game Engine (SAGE)
3
+
4
+ <div align="center">
5
+
6
+ ![SAGE Logo](https://gitlab.com/skewed-aspect/games/sa-game-engine/-/raw/main/docs/images/sage_logo.png)
7
+ </div>
8
+
9
+ The SkewedAspect Game Engine (SAGE) is a powerful and flexible game engine designed for creating 2D and 3D games. It leverages BabylonJS for rendering and Havok for physics simulation.
10
+
11
+ ## Installation
12
+
13
+ To install the SAGE library, use npm:
14
+
15
+ ```sh
16
+ npm install @skewedaspect/sage
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ### Creating a Game Engine Instance
22
+
23
+ To create an instance of the SkewedAspect Game Engine, you need to provide a game canvas and rendering options.
24
+
25
+ ```typescript
26
+ import { createGameEngine, GameCanvas, RenderEngineOptions } from '@skewedaspect/sage';
27
+
28
+ const canvas: GameCanvas = document.getElementById('gameCanvas') as HTMLCanvasElement;
29
+ const renderOptions: RenderEngineOptions = {
30
+ // ...your rendering options...
31
+ };
32
+
33
+ const gameEngine = await createGameEngine(canvas, renderOptions);
34
+
35
+ // Start the game engine
36
+ gameEngine.start();
37
+ ```
38
+
39
+ ### Stopping the Game Engine
40
+
41
+ To stop the game engine, simply call the `stop` method on the game engine instance.
42
+
43
+ ```typescript
44
+ gameEngine.stop();
45
+ ```
46
+
47
+ ## Contributing
48
+
49
+ Contributions are welcome! Please open an issue or submit a pull request on GitHub.
50
+
51
+ ## License
52
+
53
+ This project is licensed under the MIT License.
@@ -0,0 +1,122 @@
1
+ import type { GameEventBus } from '../eventBus.ts';
2
+ import type { Action } from '../../interfaces/action.ts';
3
+ import type { Binding, ToggleBindingDefinition } from '../../interfaces/binding.ts';
4
+ import type { DeviceValueReader, InputState } from '../../interfaces/input.ts';
5
+ /**
6
+ * Options for configuring a toggle binding
7
+ */
8
+ export interface ToggleBindingOptions {
9
+ /**
10
+ * If true, toggle on falling edge (true -> false) instead of rising edge (false -> true)
11
+ */
12
+ invert?: boolean;
13
+ /**
14
+ * Initial toggle state (defaults to false - off)
15
+ */
16
+ initialState?: boolean;
17
+ /**
18
+ * Threshold for analog inputs (0.0 to 1.0)
19
+ * When input value is >= threshold, it's considered "active" (true)
20
+ * When input value is < threshold, it's considered "inactive" (false)
21
+ * Defaults to 0.5 for analog inputs
22
+ */
23
+ threshold?: number;
24
+ /**
25
+ * Value to emit when the toggle is in the "on" state for digital actions
26
+ * If undefined, will emit boolean true
27
+ * Ignored for analog actions
28
+ */
29
+ onValue?: boolean | number;
30
+ /**
31
+ * Value to emit when the toggle is in the "off" state for digital actions
32
+ * If undefined, will emit boolean false
33
+ * Ignored for analog actions
34
+ */
35
+ offValue?: boolean | number;
36
+ /**
37
+ * Optional context name this binding belongs to
38
+ */
39
+ context?: string;
40
+ }
41
+ /**
42
+ * Implementation of a toggle binding, which maintains and toggles state between true/false
43
+ * when a button/key is pressed or released, remaining in that state until toggled again.
44
+ * Can handle both digital and analog inputs with configurable threshold.
45
+ * Can output either digital or analog values based on the action type.
46
+ */
47
+ export declare class ToggleBinding implements Binding {
48
+ readonly type: "toggle";
49
+ readonly action: Action;
50
+ readonly context?: string;
51
+ readonly deviceID: string;
52
+ readonly reader: DeviceValueReader;
53
+ private readonly _invert;
54
+ private readonly _threshold;
55
+ private readonly _initialState;
56
+ private readonly _onValue;
57
+ private readonly _offValue;
58
+ private _lastDigitalState;
59
+ private _toggleState;
60
+ /**
61
+ * Get the current toggle state
62
+ *
63
+ * @returns Current toggle state (true = on, false = off)
64
+ */
65
+ get state(): boolean;
66
+ /**
67
+ * Set the toggle state directly (useful for programmatic control)
68
+ *
69
+ * @param value - New toggle state
70
+ */
71
+ set state(value: boolean);
72
+ /**
73
+ * Get the value emitted when toggle is in the "on" state
74
+ *
75
+ * @returns The value for the "on" state
76
+ */
77
+ get onValue(): boolean | number;
78
+ /**
79
+ * Get the value emitted when toggle is in the "off" state
80
+ *
81
+ * @returns The value for the "off" state
82
+ */
83
+ get offValue(): boolean | number;
84
+ /**
85
+ * Get the current value based on toggle state
86
+ *
87
+ * @returns The current value (boolean or number)
88
+ */
89
+ get value(): boolean | number;
90
+ /**
91
+ * Get the current options for this toggle binding.
92
+ *
93
+ * @returns The current options for this toggle binding
94
+ */
95
+ get options(): ToggleBindingOptions;
96
+ /**
97
+ * Create a new toggle binding
98
+ *
99
+ * @param action - Action to toggle
100
+ * @param deviceID - Device ID this binding is for
101
+ * @param reader - Input reader to read values from
102
+ * @param options - Binding configuration options
103
+ */
104
+ constructor(action: Action, deviceID: string, reader: DeviceValueReader, options?: ToggleBindingOptions);
105
+ /**
106
+ * Process input state and emit a digital action if toggled
107
+ *
108
+ * @param state - Current input state
109
+ * @param eventBus - Event bus to emit action events to
110
+ */
111
+ process(state: InputState, eventBus: GameEventBus): void;
112
+ /**
113
+ * Reset toggle to its initial state
114
+ */
115
+ reset(): void;
116
+ /**
117
+ * Returns a JSON-serializable representation of this toggle binding
118
+ *
119
+ * @returns A simple object representation that can be converted to JSON
120
+ */
121
+ toJSON(): ToggleBindingDefinition;
122
+ }
@@ -0,0 +1,79 @@
1
+ import type { GameEventBus } from '../eventBus.ts';
2
+ import type { Action } from '../../interfaces/action.ts';
3
+ import type { Binding, TriggerBindingDefinition } from '../../interfaces/binding.ts';
4
+ import type { DeviceValueReader, InputState } from '../../interfaces/input.ts';
5
+ /**
6
+ * All supported edge modes for validation
7
+ */
8
+ export declare const edgeModes: readonly ["rising", "falling", "both"];
9
+ /**
10
+ * Defines when a trigger binding will fire based on input state changes
11
+ */
12
+ export type EdgeMode = typeof edgeModes[number];
13
+ /**
14
+ * Options for configuring a trigger binding
15
+ */
16
+ export interface TriggerBindingOptions {
17
+ /**
18
+ * Which edge(s) should cause the trigger to fire
19
+ * - 'rising': Only trigger on false -> true transitions
20
+ * - 'falling': Only trigger on true -> false transitions
21
+ * - 'both': Trigger on any state change
22
+ */
23
+ edgeMode?: EdgeMode;
24
+ /**
25
+ * Threshold for analog inputs (0.0 to 1.0)
26
+ * When input value is >= threshold, it's considered "active" (true)
27
+ * When input value is < threshold, it's considered "inactive" (false)
28
+ * Defaults to 0.5 for analog inputs
29
+ */
30
+ threshold?: number;
31
+ /**
32
+ * Optional context name this binding belongs to
33
+ */
34
+ context?: string;
35
+ }
36
+ /**
37
+ * Implementation of a trigger binding, which emits an action when a button/key is pressed or released.
38
+ * Can handle both digital and analog inputs with configurable threshold.
39
+ * Can output either digital or analog values based on the action type.
40
+ */
41
+ export declare class TriggerBinding implements Binding {
42
+ readonly type: "trigger";
43
+ readonly action: Action;
44
+ readonly context?: string;
45
+ readonly deviceID: string;
46
+ readonly reader: DeviceValueReader;
47
+ private readonly _edgeMode;
48
+ private readonly _threshold;
49
+ private _lastDigitalState;
50
+ /**
51
+ * Get the current options for this trigger binding.
52
+ *
53
+ * @returns The current options for this trigger binding
54
+ */
55
+ get options(): TriggerBindingOptions;
56
+ /**
57
+ * Create a new trigger binding
58
+ *
59
+ * @param action - Action to trigger
60
+ * @param deviceID - Device ID this binding is for
61
+ * @param reader - Input reader to read values from
62
+ * @param options - Binding configuration options
63
+ */
64
+ constructor(action: Action, deviceID: string, reader: DeviceValueReader, options?: TriggerBindingOptions);
65
+ /**
66
+ * Process input state and emit an action if triggered
67
+ *
68
+ * @param state - Current input state
69
+ * @param eventBus - Event bus to emit action events to
70
+ * @returns True if an action was triggered, false otherwise
71
+ */
72
+ process(state: InputState, eventBus: GameEventBus): void;
73
+ /**
74
+ * Returns a JSON-serializable representation of this trigger binding
75
+ *
76
+ * @returns A simple object representation that can be converted to JSON
77
+ */
78
+ toJSON(): TriggerBindingDefinition;
79
+ }
@@ -0,0 +1,104 @@
1
+ import type { GameEventBus } from '../eventBus.ts';
2
+ import type { Action } from '../../interfaces/action.ts';
3
+ import type { Binding, ValueBindingDefinition } from '../../interfaces/binding.ts';
4
+ import type { DeviceValueReader, InputState } from '../../interfaces/input.ts';
5
+ /**
6
+ * Options for configuring a value binding
7
+ */
8
+ export interface ValueBindingOptions {
9
+ /**
10
+ * Factor to scale the input value by (1.0 = no scaling)
11
+ */
12
+ scale?: number;
13
+ /**
14
+ * Value to add to the input value after scaling
15
+ */
16
+ offset?: number;
17
+ /**
18
+ * Whether to invert the input value (multiply by -1)
19
+ */
20
+ invert?: boolean;
21
+ /**
22
+ * Optional context name this binding belongs to
23
+ */
24
+ context?: string;
25
+ /**
26
+ * If true, only emit values when they change
27
+ * If false, always emit values on each process call
28
+ */
29
+ emitOnChange?: boolean;
30
+ /**
31
+ * Deadzone threshold (0.0 to 1.0)
32
+ * Input values below this threshold will be treated as 0
33
+ */
34
+ deadzone?: number;
35
+ /**
36
+ * Value to emit when the input is digital and true
37
+ * Only used when action is digital
38
+ */
39
+ onValue?: boolean | number;
40
+ /**
41
+ * Value to emit when the input is digital and false
42
+ * Only used when action is digital
43
+ */
44
+ offValue?: boolean | number;
45
+ /**
46
+ * Minimum value to clamp output to
47
+ */
48
+ min?: number;
49
+ /**
50
+ * Maximum value to clamp output to
51
+ */
52
+ max?: number;
53
+ }
54
+ /**
55
+ * Implementation of a value binding, which directly converts an analog input
56
+ * to an analog output with optional scaling, offset, and clamping.
57
+ * Can handle both digital and analog inputs/outputs based on action type.
58
+ */
59
+ export declare class ValueBinding implements Binding {
60
+ readonly type: "value";
61
+ readonly action: Action;
62
+ readonly context?: string;
63
+ readonly deviceID: string;
64
+ readonly reader: DeviceValueReader;
65
+ private readonly _scale;
66
+ private readonly _offset;
67
+ private readonly _invert;
68
+ private readonly _emitOnChange;
69
+ private readonly _deadzone;
70
+ private readonly _onValue;
71
+ private readonly _offValue;
72
+ private readonly _min;
73
+ private readonly _max;
74
+ private _lastValue;
75
+ /**
76
+ * Get the current options for this value binding.
77
+ *
78
+ * @returns The current options for this value binding
79
+ */
80
+ get options(): ValueBindingOptions;
81
+ /**
82
+ * Create a new value binding
83
+ *
84
+ * @param action - Action to emit values for
85
+ * @param deviceID - Device ID this binding is for
86
+ * @param reader - Input reader to read values from
87
+ * @param options - Binding configuration options
88
+ */
89
+ constructor(action: Action, deviceID: string, reader: DeviceValueReader, options?: ValueBindingOptions);
90
+ /**
91
+ * Process input state and emit an action value
92
+ *
93
+ * @param state - Current input state
94
+ * @param eventBus - Event bus to emit action events to
95
+ * @returns True if a value was emitted, false otherwise
96
+ */
97
+ process(state: InputState, eventBus: GameEventBus): void;
98
+ /**
99
+ * Returns a JSON-serializable representation of this value binding
100
+ *
101
+ * @returns A simple object representation that can be converted to JSON
102
+ */
103
+ toJSON(): ValueBindingDefinition;
104
+ }
@@ -0,0 +1,83 @@
1
+ import type { GameEntityBehaviorConstructor } from '../interfaces/entity.ts';
2
+ import { type GameEvent, GameEventBus } from './eventBus.ts';
3
+ /**
4
+ * Interface representing the context of a game entity.
5
+ * @template EntityState - The type of the state object.
6
+ */
7
+ interface SimpleGameEntity<EntityState extends object = object> {
8
+ id: string;
9
+ type: string;
10
+ state: EntityState;
11
+ eventBus: GameEventBus;
12
+ }
13
+ /**
14
+ * Base class for game entity behaviors.
15
+ */
16
+ export declare abstract class GameEntityBehavior<RequiredState extends object = object> {
17
+ abstract name: string;
18
+ abstract eventSubscriptions: string[];
19
+ protected entity: SimpleGameEntity | null;
20
+ $emit(event: GameEvent): void;
21
+ /**
22
+ * Sets the entity for this behavior.
23
+ * @param entity - The entity to set.
24
+ */
25
+ $setEntity(entity: SimpleGameEntity | null): void;
26
+ abstract processEvent(event: GameEvent, state: RequiredState): Promise<boolean> | boolean;
27
+ update?(dt: number, state: RequiredState): void;
28
+ destroy?(): Promise<void>;
29
+ }
30
+ /**
31
+ * Base class for game entities.
32
+ * @template EntityState - The type of the state object.
33
+ */
34
+ export declare class GameEntity<EntityState extends object = object> implements SimpleGameEntity<EntityState> {
35
+ /** The unique identifier of the entity. */
36
+ readonly id: string;
37
+ /** The type of the entity. */
38
+ readonly type: string;
39
+ /** The state of the entity. */
40
+ state: EntityState;
41
+ /** A map of behaviors attached to the entity. */
42
+ behaviors: Map<string, GameEntityBehavior>;
43
+ /** The event bus for the entity. */
44
+ eventBus: GameEventBus;
45
+ /** The event subscriptions for the entity. */
46
+ private subscriptions;
47
+ /**
48
+ * Creates an instance of GameEntityBase.
49
+ * @param type - The type of the entity.
50
+ * @param initialState - The initial state of the entity.
51
+ * @param behaviors - An array of behaviors to attach to the entity.
52
+ * @param eventBus
53
+ */
54
+ constructor(type: string, eventBus: GameEventBus, initialState: EntityState, behaviors: GameEntityBehaviorConstructor[]);
55
+ /**
56
+ * Processes a game event by passing it to the entity's behaviors.
57
+ * @param event - The game event to process.
58
+ * @returns A promise that resolves when the event has been processed.
59
+ */
60
+ $processEvent(event: GameEvent): Promise<void>;
61
+ /**
62
+ * Updates the entity by calling the update method of its behaviors.
63
+ * @param dt - The delta time since the last update.
64
+ */
65
+ $update(dt: number): void;
66
+ /**
67
+ * Destroys the entity by calling the destroy method of its behaviors.
68
+ * @returns A promise that resolves when the entity has been destroyed.
69
+ */
70
+ $destroy(): Promise<void>;
71
+ /**
72
+ * Attaches a behavior to the entity.
73
+ * @param behavior - The behavior to attach.
74
+ * @throws Will throw an error if the behavior is already attached.
75
+ */
76
+ attachBehavior(behavior: GameEntityBehavior): void;
77
+ /**
78
+ * Detaches a behavior from the entity.
79
+ * @param behaviorName - The behavior to detach.
80
+ */
81
+ detachBehavior(behaviorName: string): void;
82
+ }
83
+ export {};
@@ -0,0 +1,94 @@
1
+ import { LoggingUtility } from '../utils/logger.ts';
2
+ /**
3
+ * A generic game event type.
4
+ *
5
+ * @template P - The shape of the payload. Default is a generic object if omitted.
6
+ */
7
+ export interface GameEvent<P extends Record<string, any> = Record<string, any>> {
8
+ /** The string identifier/category of the event (e.g. "input:keydown"). */
9
+ type: string;
10
+ /** The optional ID of whoever sent this event. */
11
+ senderID?: string;
12
+ /** The optional ID of who should receive this event. */
13
+ targetID?: string;
14
+ /** The payload, with user-defined shape. */
15
+ payload?: P;
16
+ }
17
+ /**
18
+ * A callback function that receives a {@link GameEvent} with a given payload type.
19
+ *
20
+ * @template P - The shape of the payload in the event.
21
+ */
22
+ export type GameEventCallback<P extends Record<string, any> = Record<string, any>> = (event: GameEvent<P>) => void | Promise<void>;
23
+ /**
24
+ * An unsubscribe function, returned by any subscribe method.
25
+ */
26
+ export type Unsubscribe = () => void;
27
+ /**
28
+ * A high-performance event bus that supports exact or pattern-based subscriptions,
29
+ * and allows subscribers to specify a more specific `payload` type for convenience.
30
+ *
31
+ * **Note**: This does NOT enforce that a given `type` always has a certain payload shape.
32
+ * It's a best-effort approach that lets you avoid `as` casts in callbacks.
33
+ */
34
+ export declare class GameEventBus {
35
+ /**
36
+ * For exact event-type matches:
37
+ * - Key = event type string (e.g. "input:keydown")
38
+ * - Value = set of subscriptions for that exact type
39
+ */
40
+ private directMap;
41
+ /**
42
+ * For pattern-based (wildcard or RegExp) subscriptions.
43
+ */
44
+ private patternSubs;
45
+ /**
46
+ * Logger instance
47
+ */
48
+ private _log;
49
+ /**
50
+ * Creates a new GameEventBus instance
51
+ *
52
+ * @param logger - The logging utility to use
53
+ */
54
+ constructor(logger?: LoggingUtility);
55
+ /**
56
+ * Subscribe with automatic detection:
57
+ * - If `eventTypeOrPattern` is a `RegExp` or a string containing `*`, treat it as a pattern subscription.
58
+ * - Otherwise, treat it as an exact subscription.
59
+ *
60
+ * @template P - The payload shape you want to expect in the callback.
61
+ * @param {string | RegExp} eventTypeOrPattern - The exact event type or a wildcard/RegExp pattern.
62
+ * @param {GameEventCallback<P>} callback - A callback expecting a `GameEvent<P>`.
63
+ * @returns {Unsubscribe} function that, when called, removes this subscription.
64
+ */
65
+ subscribe<P extends Record<string, any> = Record<string, any>>(eventTypeOrPattern: string | RegExp, callback: GameEventCallback<P>): Unsubscribe;
66
+ /**
67
+ * Subscribes to an exact event type (e.g. "input:keydown").
68
+ *
69
+ * @template P - The payload shape you want to expect in the callback.
70
+ * @param {string} eventType - The exact string to match.
71
+ * @param {GameEventCallback<P>} callback - A callback expecting a `GameEvent<P>`.
72
+ * @returns {Unsubscribe} function that unsubscribes this exact subscription.
73
+ */
74
+ subscribeExact<P extends Record<string, any> = Record<string, any>>(eventType: string, callback: GameEventCallback<P>): Unsubscribe;
75
+ /**
76
+ * Subscribes with either:
77
+ * - a wildcard string (contains `*`) that gets converted to a RegExp
78
+ * - a RegExp directly
79
+ *
80
+ * @template P - The payload shape you want to expect in the callback.
81
+ * @param {string | RegExp} patternOrRegExp - The pattern to match (`"input:*"` or `/^input:/`).
82
+ * @param {GameEventCallback<P>} callback - A callback expecting a `GameEvent<P>`.
83
+ * @returns {Unsubscribe} function that unsubscribes this pattern-based subscription.
84
+ */
85
+ subscribePattern<P extends Record<string, any> = Record<string, any>>(patternOrRegExp: string | RegExp, callback: GameEventCallback<P>): Unsubscribe;
86
+ /**
87
+ * Publishes an event, invoking all matching callbacks.
88
+ *
89
+ * Callbacks are called asynchronously (microtask) via `Promise.resolve()`.
90
+ *
91
+ * @param {GameEvent<any>} event - The event object to publish.
92
+ */
93
+ publish(event: GameEvent<any>): void;
94
+ }
@@ -0,0 +1,57 @@
1
+ import { AbstractEngine, HavokPlugin } from '@babylonjs/core';
2
+ import { GameCanvas } from '../interfaces/game.ts';
3
+ import { SceneEngine } from '../engines/scene.ts';
4
+ import { BindingManager } from '../managers/binding.ts';
5
+ import { GameManager } from '../managers/game.ts';
6
+ import { GameEntityManager } from '../managers/entity.ts';
7
+ import { UserInputManager } from '../managers/input.ts';
8
+ import { GameEventBus } from './eventBus.ts';
9
+ import { LoggingUtility } from '../utils/logger.ts';
10
+ /**
11
+ * Interface representing the engines used in the game.
12
+ */
13
+ interface Engines {
14
+ sceneEngine: SceneEngine;
15
+ }
16
+ /**
17
+ * Interface representing the managers used in the game.
18
+ */
19
+ interface Managers {
20
+ bindingManager: BindingManager;
21
+ gameManager: GameManager;
22
+ entityManager: GameEntityManager;
23
+ inputManager: UserInputManager;
24
+ }
25
+ /**
26
+ * Class representing the SkewedAspect Game Engine.
27
+ */
28
+ export declare class SkewedAspectGameEngine {
29
+ canvas: GameCanvas;
30
+ renderEngine: AbstractEngine;
31
+ physics: HavokPlugin;
32
+ managers: Managers;
33
+ engines: Engines;
34
+ eventBus: GameEventBus;
35
+ logger: LoggingUtility;
36
+ private _log;
37
+ /**
38
+ * Creates an instance of SkewedAspectGameEngine.
39
+ * @param canvas - The game canvas.
40
+ * @param renderEngine - The rendering engine.
41
+ * @param physics - The physics engine.
42
+ * @param eventBus - The event bus.
43
+ * @param logger - The logging utility.
44
+ * @param engines - The engines used in the game.
45
+ * @param managers - The managers used in the game.
46
+ */
47
+ constructor(canvas: GameCanvas, renderEngine: AbstractEngine, physics: HavokPlugin, eventBus: GameEventBus, logger: LoggingUtility, engines: Engines, managers: Managers);
48
+ /**
49
+ * Starts the game engine.
50
+ */
51
+ start(): Promise<void>;
52
+ /**
53
+ * Stops the game engine.
54
+ */
55
+ stop(): Promise<void>;
56
+ }
57
+ export {};