@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
@@ -0,0 +1,181 @@
1
+ /**
2
+ * Valid input device types
3
+ */
4
+ export declare const validDeviceTypes: readonly ["keyboard", "mouse", "gamepad"];
5
+ export type DeviceType = typeof validDeviceTypes[number];
6
+ /**
7
+ * Base input device interface
8
+ */
9
+ export interface InputDevice {
10
+ id: string;
11
+ name: string;
12
+ type: DeviceType;
13
+ connected: boolean;
14
+ }
15
+ /**
16
+ * Keyboard device information
17
+ */
18
+ export interface KeyboardDevice extends InputDevice {
19
+ type: 'keyboard';
20
+ }
21
+ /**
22
+ * Mouse device information
23
+ */
24
+ export interface MouseDevice extends InputDevice {
25
+ type: 'mouse';
26
+ }
27
+ /**
28
+ * Gamepad device information
29
+ */
30
+ export interface GamepadDevice extends InputDevice {
31
+ type: 'gamepad';
32
+ index: number;
33
+ mapping: string;
34
+ axes: number[];
35
+ buttons: GamepadButton[];
36
+ }
37
+ /**
38
+ * Base interface for all input device states
39
+ */
40
+ export interface BaseInputState {
41
+ event?: Event;
42
+ }
43
+ /**
44
+ * Button state interface (for both mouse and gamepad)
45
+ */
46
+ export interface ButtonState {
47
+ pressed: boolean;
48
+ touched?: boolean;
49
+ value?: number;
50
+ }
51
+ /**
52
+ * Mouse position interface
53
+ */
54
+ export interface Position {
55
+ absolute: {
56
+ x: number;
57
+ y: number;
58
+ };
59
+ relative: {
60
+ x: number;
61
+ y: number;
62
+ };
63
+ }
64
+ /**
65
+ * Unified keyboard input state with object literals instead of Maps
66
+ */
67
+ export interface KeyboardInputState extends BaseInputState {
68
+ type: 'keyboard';
69
+ keys: Record<string, boolean>;
70
+ delta: Record<string, boolean>;
71
+ event?: KeyboardEvent;
72
+ }
73
+ /**
74
+ * Unified mouse input state with object literals instead of Maps
75
+ */
76
+ export interface MouseInputState extends BaseInputState {
77
+ type: 'mouse';
78
+ buttons: Record<string, ButtonState>;
79
+ axes: Record<string, number>;
80
+ position: Position;
81
+ wheel?: {
82
+ deltaX: number;
83
+ deltaY: number;
84
+ deltaZ: number;
85
+ deltaMode: number;
86
+ };
87
+ event?: MouseEvent | WheelEvent;
88
+ }
89
+ /**
90
+ * Unified gamepad input state with object literals instead of Maps
91
+ */
92
+ export interface GamepadInputState extends BaseInputState {
93
+ type: 'gamepad';
94
+ buttons: Record<string, ButtonState>;
95
+ axes: Record<string, number>;
96
+ event?: GamepadEvent;
97
+ }
98
+ /**
99
+ * Unified input state interface that can represent any input device
100
+ */
101
+ export type InputState = KeyboardInputState | MouseInputState | GamepadInputState;
102
+ /**
103
+ * Base interface for serialized device value readers
104
+ */
105
+ export interface DeviceValueReaderDefinitionBase {
106
+ /**
107
+ * The device type of input source
108
+ */
109
+ type: DeviceType;
110
+ /**
111
+ * The input source type (e.g., 'key', 'button', 'axis')
112
+ */
113
+ sourceType: string;
114
+ /**
115
+ * The specific identifier for this input source (e.g., 'KeyA', '0', 'absolute:x')
116
+ */
117
+ sourceKey: string;
118
+ }
119
+ /**
120
+ * Keyboard value reader definition
121
+ */
122
+ export interface KeyboardValueReaderDefinition extends DeviceValueReaderDefinitionBase {
123
+ type: 'keyboard';
124
+ sourceType: 'key';
125
+ sourceKey: string;
126
+ options?: {
127
+ useDelta?: boolean;
128
+ };
129
+ }
130
+ /**
131
+ * Mouse value reader definition
132
+ */
133
+ export interface MouseValueReaderDefinition extends DeviceValueReaderDefinitionBase {
134
+ type: 'mouse';
135
+ sourceType: string;
136
+ sourceKey: string;
137
+ }
138
+ /**
139
+ * Gamepad value reader definition
140
+ */
141
+ export interface GamepadValueReaderDefinition extends DeviceValueReaderDefinitionBase {
142
+ type: 'gamepad';
143
+ sourceType: string;
144
+ sourceKey: string;
145
+ options?: {
146
+ useAnalogValue?: boolean;
147
+ deadzone?: number;
148
+ invert?: boolean;
149
+ };
150
+ }
151
+ /**
152
+ * Union type of all device value reader definitions
153
+ */
154
+ export type DeviceValueReaderDefinition = KeyboardValueReaderDefinition | MouseValueReaderDefinition | GamepadValueReaderDefinition;
155
+ /**
156
+ * Interface for all device value readers
157
+ * Unified interface for all types of input sources that can extract values from device states
158
+ */
159
+ export interface DeviceValueReader {
160
+ /**
161
+ * The type of input source (e.g., 'key', 'button', 'axis')
162
+ */
163
+ readonly sourceType: string;
164
+ /**
165
+ * The specific identifier for this input source (e.g., 'KeyA', '0', 'absolute:x')
166
+ */
167
+ readonly sourceKey: string;
168
+ /**
169
+ * Gets the value from an input state
170
+ *
171
+ * @param state - The current input state
172
+ * @returns The value from the input (boolean or number) or undefined if not applicable to this state
173
+ */
174
+ getValue(state: InputState): boolean | number | undefined;
175
+ /**
176
+ * Convert the reader to a JSON-serializable object
177
+ *
178
+ * @returns A JSON-serializable representation of the reader
179
+ */
180
+ toJSON(): DeviceValueReaderDefinition;
181
+ }
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Defines the available logging levels as string literals.
3
+ */
4
+ export declare const LogLevels: readonly ["trace", "debug", "info", "warn", "error", "none"];
5
+ /**
6
+ * Type for LogLevel values
7
+ */
8
+ export type LogLevel = typeof LogLevels[number];
9
+ /**
10
+ * Interface for a logging backend implementation.
11
+ * Backends handle the actual output of log messages.
12
+ */
13
+ export interface LoggingBackend {
14
+ /**
15
+ * Log a message at TRACE level
16
+ *
17
+ * @param category - The category for this message (typically class/module name)
18
+ * @param message - The message text to log
19
+ * @param args - Optional additional arguments to include
20
+ */
21
+ trace(category: string, message: string, ...args: any[]): void;
22
+ /**
23
+ * Log a message at DEBUG level
24
+ *
25
+ * @param category - The category for this message (typically class/module name)
26
+ * @param message - The message text to log
27
+ * @param args - Optional additional arguments to include
28
+ */
29
+ debug(category: string, message: string, ...args: any[]): void;
30
+ /**
31
+ * Log a message at INFO level
32
+ *
33
+ * @param category - The category for this message (typically class/module name)
34
+ * @param message - The message text to log
35
+ * @param args - Optional additional arguments to include
36
+ */
37
+ info(category: string, message: string, ...args: any[]): void;
38
+ /**
39
+ * Log a message at WARN level
40
+ *
41
+ * @param category - The category for this message (typically class/module name)
42
+ * @param message - The message text to log
43
+ * @param args - Optional additional arguments to include
44
+ */
45
+ warn(category: string, message: string, ...args: any[]): void;
46
+ /**
47
+ * Log a message at ERROR level
48
+ *
49
+ * @param category - The category for this message (typically class/module name)
50
+ * @param message - The message text to log
51
+ * @param args - Optional additional arguments to include
52
+ */
53
+ error(category: string, message: string, ...args: any[]): void;
54
+ /**
55
+ * Start a timer with the specified label.
56
+ *
57
+ * @param category - The category for this timer (typically class/module name)
58
+ * @param label - A unique label to identify the timer
59
+ */
60
+ time(category: string, label: string): void;
61
+ /**
62
+ * End a timer with the specified label and log the time elapsed.
63
+ *
64
+ * @param category - The category for this timer (typically class/module name)
65
+ * @param label - The label identifying the timer to end
66
+ */
67
+ timeEnd(category: string, label: string): void;
68
+ }
69
+ /**
70
+ * Interface for a logger instance.
71
+ * Each instance is typically associated with a specific category/component.
72
+ */
73
+ export interface LoggerInterface {
74
+ /** Log a message at TRACE level */
75
+ trace(message: string, ...args: any[]): void;
76
+ /** Log a message at DEBUG level */
77
+ debug(message: string, ...args: any[]): void;
78
+ /** Log a message at INFO level */
79
+ info(message: string, ...args: any[]): void;
80
+ /** Log a message at WARN level */
81
+ warn(message: string, ...args: any[]): void;
82
+ /** Log a message at ERROR level */
83
+ error(message: string, ...args: any[]): void;
84
+ /** Start a timer with the given label */
85
+ time(label: string): void;
86
+ /** End a timer and log the elapsed time */
87
+ timeEnd(label: string): void;
88
+ }
@@ -0,0 +1,185 @@
1
+ import { GameEventBus } from '../classes/eventBus.ts';
2
+ import { type Binding, type BindingDefinition, type Context } from '../interfaces/binding.ts';
3
+ import type { InputDevice, InputState } from '../interfaces/input.ts';
4
+ import type { Action } from '../interfaces/action.ts';
5
+ import { LoggingUtility } from '../utils/logger.ts';
6
+ /**
7
+ * Configuration object structure for binding manager
8
+ */
9
+ export interface BindingConfiguration {
10
+ /** All registered actions */
11
+ actions: Action[];
12
+ /** All registered bindings */
13
+ bindings: BindingDefinition[];
14
+ /** All registered contexts */
15
+ contexts: {
16
+ name: string;
17
+ exclusive: boolean;
18
+ active: boolean;
19
+ }[];
20
+ }
21
+ /**
22
+ * Manages input bindings and actions for the game
23
+ */
24
+ export declare class BindingManager {
25
+ /** Map of device IDs to their bindings */
26
+ private _bindings;
27
+ /** Map of action names to their action definitions */
28
+ private _actions;
29
+ /** Map of all registered contexts by name for O(1) lookup */
30
+ private _contexts;
31
+ /**
32
+ * Set of all active contexts (both exclusive and non-exclusive)
33
+ */
34
+ private _activeContexts;
35
+ /** Event bus for handling game events */
36
+ private _eventBus;
37
+ /** Logger instance */
38
+ private _log;
39
+ /**
40
+ * Creates an instance of BindingManager.
41
+ *
42
+ * @param eventBus - The game event bus to publish events to
43
+ * @param logger - The logging utility to use
44
+ */
45
+ constructor(eventBus: GameEventBus, logger?: LoggingUtility);
46
+ /**
47
+ * Checks if a binding's context is currently active
48
+ *
49
+ * @param binding - The binding to check
50
+ * @returns True if binding's context is active or has no context
51
+ */
52
+ private _isBindingContextActive;
53
+ /**
54
+ * Get a context by name, creating it if it doesn't exist
55
+ *
56
+ * @param contextName - The name of the context to get or create
57
+ * @param exclusive - Whether the context is exclusive (only used if creating)
58
+ * @returns The context object
59
+ */
60
+ private _getOrCreateContext;
61
+ /**
62
+ * Deactivate all exclusive contexts except the specified one
63
+ *
64
+ * @param exceptContextName - Name of context to not deactivate
65
+ * @returns Array of deactivated context names
66
+ */
67
+ private _deactivateExclusiveContexts;
68
+ /**
69
+ * Create a binding from a binding definition
70
+ *
71
+ * @param definition - The binding definition to create a binding from
72
+ * @returns A new binding instance or null if the type is not supported
73
+ */
74
+ private _createBindingFromDefinition;
75
+ /**
76
+ * Create a device value reader from a definition object
77
+ *
78
+ * @param definition - The device value reader definition
79
+ * @returns A new device value reader instance
80
+ * @throws Error if the reader type is not supported
81
+ */
82
+ private _createInputSourceFromDefinition;
83
+ /**
84
+ * Handle input from a device and process all relevant bindings
85
+ *
86
+ * @param device - The input device
87
+ * @param state - Current input state
88
+ */
89
+ $handleInput(device: InputDevice, state: InputState): void;
90
+ /**
91
+ * Registers an action
92
+ *
93
+ * @param action - The action to register
94
+ * @throws Error if action is already registered
95
+ */
96
+ registerAction(action: Action): void;
97
+ /**
98
+ * Gets an action by name
99
+ *
100
+ * @param actionName - The name of the action to get
101
+ * @returns The action or null if not found
102
+ */
103
+ getAction(actionName: string): Action | null;
104
+ /**
105
+ * Registers a context with specific options
106
+ *
107
+ * @param contextName - The name of the context to register
108
+ * @param exclusive - Whether the context is exclusive (default: true)
109
+ * @returns The registered context
110
+ */
111
+ registerContext(contextName: string, exclusive?: boolean): Context;
112
+ /**
113
+ * Activates a context, enabling all bindings associated with it.
114
+ * If the context is exclusive, all other exclusive contexts will be deactivated.
115
+ *
116
+ * @param contextName - The name of the context to activate
117
+ */
118
+ activateContext(contextName: string): void;
119
+ /**
120
+ * Deactivates a context, disabling all bindings associated with it
121
+ *
122
+ * @param contextName - The name of the context to deactivate
123
+ */
124
+ deactivateContext(contextName: string): void;
125
+ /**
126
+ * Returns a list of all active contexts
127
+ *
128
+ * @returns Array of active context names
129
+ */
130
+ getActiveContexts(): string[];
131
+ /**
132
+ * Returns whether a context is active
133
+ *
134
+ * @param contextName - The context to check
135
+ * @returns True if the context is active
136
+ */
137
+ isContextActive(contextName: string): boolean;
138
+ /**
139
+ * Gets a context by name
140
+ *
141
+ * @param contextName - The context name to get
142
+ * @returns The context or null if not found
143
+ */
144
+ getContext(contextName: string): Context | null;
145
+ /**
146
+ * Register a binding for an input device
147
+ *
148
+ * @param binding - The binding to register
149
+ * @throws Error if binding type is invalid
150
+ */
151
+ $registerBinding(binding: Binding): void;
152
+ /**
153
+ * Register a binding using a binding definition object
154
+ *
155
+ * @param definition - The binding definition to register
156
+ */
157
+ registerBinding(definition: BindingDefinition): void;
158
+ /**
159
+ * Unregister all bindings for an action within a context
160
+ *
161
+ * @param actionName - The name of the action
162
+ * @param context - The context to unregister from (defaults to null)
163
+ */
164
+ unregisterBindings(actionName: string, context?: string | null): void;
165
+ /**
166
+ * Gets all bindings for a specific action
167
+ *
168
+ * @param actionName - The name of the action
169
+ * @param context - The context to get bindings from (optional)
170
+ * @returns Array of bindings that match the criteria
171
+ */
172
+ getBindingsForAction(actionName: string, context?: string | null): Binding[];
173
+ /**
174
+ * Exports the current configuration to a serializable object
175
+ *
176
+ * @returns A BindingConfiguration object representing the current state
177
+ */
178
+ exportConfiguration(): BindingConfiguration;
179
+ /**
180
+ * Imports a configuration from an object
181
+ *
182
+ * @param config - The configuration to import
183
+ */
184
+ importConfiguration(config: BindingConfiguration): void;
185
+ }
@@ -0,0 +1,70 @@
1
+ import { GameEntity } from '../classes/entity.ts';
2
+ import { GameEventBus } from '../classes/eventBus.ts';
3
+ import type { GameEntityDefinition } from '../interfaces/entity.ts';
4
+ import type { BindingManager } from '../managers/binding.ts';
5
+ import { LoggingUtility } from '../utils/logger.ts';
6
+ export declare class GameEntityManager {
7
+ /** The event bus for the entity manager. */
8
+ private eventBus;
9
+ /** A map of entities managed by the entity manager. */
10
+ private entities;
11
+ /** A map of entity definitions registered with the entity manager. */
12
+ private entityDefinitions;
13
+ /** Reference to the binding manager for registering actions */
14
+ private bindingManager;
15
+ /** Logger instance */
16
+ private _log;
17
+ /**
18
+ * Creates an instance of EntityManager.
19
+ * @param eventBus - The event bus for the entity manager.
20
+ * @param logger - The logging utility to use
21
+ * @param bindingManager - The binding manager for registering actions
22
+ */
23
+ constructor(eventBus: GameEventBus, logger: LoggingUtility | undefined, bindingManager: BindingManager);
24
+ /**
25
+ * Checks if two actions are compatible
26
+ * @param existingAction - The action already registered
27
+ * @param newAction - The action being registered
28
+ * @returns true if the actions are compatible, false if they have conflicting options
29
+ */
30
+ private areActionsCompatible;
31
+ /**
32
+ * Registers actions defined in the entity definition with the binding manager
33
+ * @param entityDef - The entity definition containing actions to register
34
+ */
35
+ private registerEntityActions;
36
+ $frameUpdate(dt: number): void;
37
+ /**
38
+ * Registers a new entity definition.
39
+ * @param entityDef - The definition of the entity.
40
+ */
41
+ registerEntityDefinition(entityDef: GameEntityDefinition): void;
42
+ /**
43
+ * Creates a new entity of the given type.
44
+ * @param type - The type of the entity to create.
45
+ * @param initialState - The initial state of the entity.
46
+ * @returns The created entity.
47
+ */
48
+ createEntity<State extends object = object>(type: string, initialState?: Partial<State>): GameEntity<State>;
49
+ /**
50
+ * Destroys the entity with the given ID.
51
+ * @param entityID - The ID of the entity to destroy.
52
+ */
53
+ destroyEntity(entityID: string): void;
54
+ /**
55
+ * Gets the entity with the given ID.
56
+ * @param entityID - The ID of the entity to get.
57
+ * @returns The entity with the given ID, or null if it does not exist.
58
+ */
59
+ getEntity(entityID: string): GameEntity | null;
60
+ /**
61
+ * Adds an existing entity to the entity manager.
62
+ * @param entity - The entity to add.
63
+ */
64
+ addEntity(entity: GameEntity): void;
65
+ /**
66
+ * Removes the entity with the given ID, without destroying it.
67
+ * @param entityID - The ID of the entity to remove.
68
+ */
69
+ removeEntity(entityID: string): void;
70
+ }
@@ -0,0 +1,20 @@
1
+ import { AbstractEngine } from '@babylonjs/core';
2
+ import { GameCanvas } from '../interfaces/game.ts';
3
+ import { GameEntityManager } from './entity.ts';
4
+ import { UserInputManager } from './input.ts';
5
+ import { SceneEngine } from '../engines/scene.ts';
6
+ import { LoggingUtility } from '../utils/logger.ts';
7
+ export declare class GameManager {
8
+ private _engine;
9
+ private _entityManager;
10
+ private _inputManager;
11
+ private _sceneEngine;
12
+ private _currentScene;
13
+ private _log;
14
+ started: boolean;
15
+ constructor(engine: AbstractEngine, sceneEngine: SceneEngine, entityManager: GameEntityManager, inputManager: UserInputManager, logger?: LoggingUtility);
16
+ private _renderLoop;
17
+ private _resizeHandler;
18
+ start(canvas: GameCanvas): Promise<void>;
19
+ stop(): Promise<void>;
20
+ }
@@ -0,0 +1,56 @@
1
+ import type { InputDevice } from '../interfaces/input.ts';
2
+ import { GameEventBus } from '../classes/eventBus.ts';
3
+ import { LoggingUtility } from '../utils/logger.ts';
4
+ /**
5
+ * Manager for handling user input from various devices (keyboard, mouse, gamepad)
6
+ */
7
+ export declare class UserInputManager {
8
+ private _eventBus;
9
+ private _keyboardRA;
10
+ private _mouseRA;
11
+ private _gamepadRA;
12
+ /** Logger instance */
13
+ private _log;
14
+ /**
15
+ * Create a new UserInputManager
16
+ *
17
+ * @param eventBus - The game event bus to publish events to
18
+ * @param canvas - The DOM element to attach input listeners to
19
+ * @param logger - The logging utility to use
20
+ */
21
+ constructor(eventBus: GameEventBus, canvas: HTMLElement, logger?: LoggingUtility);
22
+ /**
23
+ * Publish device connected event to the event bus
24
+ */
25
+ private _publishDeviceConnected;
26
+ /**
27
+ * Publish device disconnected event to the event bus
28
+ */
29
+ private _publishDeviceDisconnected;
30
+ /**
31
+ * Publish input changed event to the event bus, used by all device types
32
+ */
33
+ private _publishInputChanged;
34
+ /**
35
+ * Destroy the input manager and clean up event listeners
36
+ */
37
+ $destroy(): void;
38
+ /**
39
+ * Get all input devices
40
+ *
41
+ * @return An array of input devices
42
+ */
43
+ listDevices(): InputDevice[];
44
+ /**
45
+ * Get a specific input device by ID
46
+ *
47
+ * @param deviceId - The ID of the device to get
48
+ *
49
+ * @return The input device, or null if not found
50
+ */
51
+ getDevice(deviceId: string): InputDevice | null;
52
+ /**
53
+ * Poll for gamepad state updates - call this in your game loop
54
+ */
55
+ pollGamepads(): void;
56
+ }
@@ -0,0 +1,55 @@
1
+ import { Engine, Scene } from '@babylonjs/core';
2
+ import '@babylonjs/loaders';
3
+ import { GameEntityManager } from './entity.ts';
4
+ export interface LevelLoadOptions {
5
+ rootUrl: string;
6
+ filename: string;
7
+ useAssetContainer?: boolean;
8
+ showLoadingUI?: boolean;
9
+ onProgress?: (percent: number) => void;
10
+ onSuccess?: (scene: Scene) => void;
11
+ onError?: (message: string, exception?: any) => void;
12
+ }
13
+ /**
14
+ /**
15
+ * Manages level loading and streaming using BabylonJS SceneLoader and AssetContainer.
16
+ * Also includes tagging for auto-detection (e.g. "Door", "Trigger", "Enemy"),
17
+ * and automatically spawns entities via an entity manager if an 'entityType' is found.
18
+ *
19
+ * Additionally, this version checks for audio metadata (e.g. sound files) and automatically
20
+ * creates BabylonJS Sound objects when found.
21
+ */
22
+ export declare class LevelManager {
23
+ private engine;
24
+ private currentScene;
25
+ private activeContainer;
26
+ private entityManager;
27
+ constructor(engine: Engine, entityManager: GameEntityManager);
28
+ /**
29
+ * Loads a level, either as a full scene or into a container.
30
+ * @param options - Specifies rootUrl, filename, and optional callbacks.
31
+ */
32
+ loadLevel(options: LevelLoadOptions): Promise<void>;
33
+ /**
34
+ * Disposes the current scene and container (if any), freeing up memory.
35
+ */
36
+ disposeCurrentScene(): void;
37
+ /**
38
+ * Returns the current active scene, if one is loaded.
39
+ */
40
+ getScene(): Scene | null;
41
+ /**
42
+ * Internal helper: Reports loading progress as a percentage.
43
+ * @param evt ISceneLoaderProgressEvent data
44
+ * @param callback optional progress callback
45
+ */
46
+ private reportProgress;
47
+ /**
48
+ * Automatically tag loaded meshes and create entities based on metadata.
49
+ * Also, if audio metadata is present, create spatial sounds.
50
+ *
51
+ * @param meshes An array of loaded AbstractMesh objects.
52
+ * @param scene The scene into which these meshes have been loaded.
53
+ */
54
+ private autoTagAndEntityHook;
55
+ }
package/dist/sage.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ import { GameCanvas, RenderEngineOptions, SageOptions } from './interfaces/game.ts';
2
+ import { SkewedAspectGameEngine } from './classes/gameEngine.ts';
3
+ import { GameEventBus } from './classes/eventBus.ts';
4
+ /**
5
+ * Creates an instance of SkewedAspectGameEngine.
6
+ * @param canvas - The game canvas.
7
+ * @param options - The game engine options including rendering options and log level.
8
+ * @returns A promise that resolves to an instance of SkewedAspectGameEngine.
9
+ */
10
+ export declare function createGameEngine(canvas: GameCanvas, options?: SageOptions): Promise<SkewedAspectGameEngine>;
11
+ export type { GameCanvas, RenderEngineOptions, SageOptions };
12
+ export type { GameEvent, GameEventCallback } from './classes/eventBus.ts';
13
+ export type { Action, AnalogAction, DigitalAction } from './interfaces/action.ts';
14
+ export type { GameEntityDefinition, GameEntityBehaviorConstructor } from './interfaces/entity.ts';
15
+ export type { LogLevel, LoggerInterface } from './interfaces/logger.ts';
16
+ export { GameEventBus, SkewedAspectGameEngine };
17
+ export { GameEntity } from './classes/entity.ts';
18
+ export { LoggingUtility, ConsoleBackend, NullBackend } from './utils/logger.ts';
19
+ export { GameEntityBehavior } from './classes/entity.ts';
20
+ export { VERSION } from './utils/version.ts';