@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,94 @@
1
+ import type { GamepadDevice, GamepadInputState } from '../../interfaces/input.ts';
2
+ /**
3
+ * Callback type for gamepad device connection events
4
+ */
5
+ export type GamepadDeviceCallback = (device: GamepadDevice) => void;
6
+ /**
7
+ * Callback type for gamepad input events
8
+ */
9
+ export type GamepadInputCallback = (device: GamepadDevice, state: GamepadInputState) => void;
10
+ /**
11
+ * Responsible for tracking gamepad state and notifying subscribers of changes.
12
+ */
13
+ export declare class GamepadInputPlugin {
14
+ private _gamepadDevices;
15
+ private _buttonStates;
16
+ private _axesStates;
17
+ private _onDeviceConnected?;
18
+ private _onDeviceDisconnected?;
19
+ private _onInputChanged?;
20
+ /**
21
+ * Create a new GamepadResourceAccess
22
+ */
23
+ constructor();
24
+ /**
25
+ * Register a callback for device connected events
26
+ *
27
+ * @param callback - The callback to register
28
+ */
29
+ onDeviceConnected(callback: GamepadDeviceCallback): void;
30
+ /**
31
+ * Register a callback for device disconnected events
32
+ *
33
+ * @param callback - The callback to register
34
+ */
35
+ onDeviceDisconnected(callback: GamepadDeviceCallback): void;
36
+ /**
37
+ * Register a callback for input changed events
38
+ *
39
+ * @param callback - The callback to register
40
+ */
41
+ onInputChanged(callback: GamepadInputCallback): void;
42
+ /**
43
+ * Get all connected gamepad devices
44
+ */
45
+ getDevices(): GamepadDevice[];
46
+ /**
47
+ * Get all connected gamepad states
48
+ */
49
+ getStates(): Record<number, GamepadInputState>;
50
+ /**
51
+ * Get a specific gamepad device by index
52
+ *
53
+ * @param index - The index of the gamepad to get
54
+ */
55
+ getDevice(index: number): GamepadDevice | null;
56
+ /**
57
+ * Get a specific gamepad state by index
58
+ *
59
+ * @param index - The index of the gamepad state to get
60
+ */
61
+ getState(index: number): GamepadInputState | null;
62
+ /**
63
+ * Poll for gamepad state updates - call this in your game loop
64
+ */
65
+ pollGamepads(): void;
66
+ /**
67
+ * Destroy the gamepad resource access and clean up event listeners
68
+ */
69
+ destroy(): void;
70
+ /**
71
+ * Set up gamepad event listeners
72
+ */
73
+ private _setupGamepadEvents;
74
+ /**
75
+ * Handle gamepad connected event
76
+ */
77
+ private _handleGamepadConnected;
78
+ /**
79
+ * Handle gamepad disconnected event
80
+ */
81
+ private _handleGamepadDisconnected;
82
+ /**
83
+ * Notify subscribers of device connected event
84
+ */
85
+ private _notifyDeviceConnected;
86
+ /**
87
+ * Notify subscribers of device disconnected event
88
+ */
89
+ private _notifyDeviceDisconnected;
90
+ /**
91
+ * Notify subscribers of input changed event
92
+ */
93
+ private _notifyInputChanged;
94
+ }
@@ -0,0 +1,66 @@
1
+ import type { KeyboardDevice, KeyboardInputState } from '../../interfaces/input.ts';
2
+ /**
3
+ * Callback type for keyboard device connection events
4
+ */
5
+ export type KeyboardDeviceCallback = (device: KeyboardDevice) => void;
6
+ /**
7
+ * Callback type for keyboard input events
8
+ */
9
+ export type KeyboardInputCallback = (device: KeyboardDevice, state: KeyboardInputState) => void;
10
+ /**
11
+ * Responsible for tracking keyboard state and notifying subscribers of changes.
12
+ */
13
+ export declare class KeyboardInputPlugin {
14
+ private _keyboardDevice;
15
+ private _keysState;
16
+ private _onDeviceConnected?;
17
+ private _onInputChanged?;
18
+ /**
19
+ * Create a new KeyboardResourceAccess
20
+ */
21
+ constructor();
22
+ /**
23
+ * Register a callback for device connected events
24
+ *
25
+ * @param callback - The callback to register
26
+ */
27
+ onDeviceConnected(callback: KeyboardDeviceCallback): void;
28
+ /**
29
+ * Register a callback for input changed events
30
+ *
31
+ * @param callback - The callback to register
32
+ */
33
+ onInputChanged(callback: KeyboardInputCallback): void;
34
+ /**
35
+ * Get the current keyboard state
36
+ */
37
+ getState(): KeyboardInputState;
38
+ /**
39
+ * Get the keyboard device
40
+ */
41
+ getDevice(): KeyboardDevice;
42
+ /**
43
+ * Destroy the keyboard resource access and clean up event listeners
44
+ */
45
+ destroy(): void;
46
+ /**
47
+ * Set up keyboard event listeners
48
+ */
49
+ private _setupKeyboardEvents;
50
+ /**
51
+ * Handle keyboard key down events
52
+ */
53
+ private _handleKeyDown;
54
+ /**
55
+ * Handle keyboard key up events
56
+ */
57
+ private _handleKeyUp;
58
+ /**
59
+ * Notify subscribers of device connected event
60
+ */
61
+ private _notifyDeviceConnected;
62
+ /**
63
+ * Notify subscribers of input changed event
64
+ */
65
+ private _notifyInputChanged;
66
+ }
@@ -0,0 +1,80 @@
1
+ import type { MouseDevice, MouseInputState } from '../../interfaces/input.ts';
2
+ /**
3
+ * Callback type for mouse device connection events
4
+ */
5
+ export type MouseDeviceCallback = (device: MouseDevice) => void;
6
+ /**
7
+ * Callback type for mouse input events
8
+ */
9
+ export type MouseInputCallback = (device: MouseDevice, state: MouseInputState) => void;
10
+ /**
11
+ * Responsible for tracking mouse state and notifying subscribers of changes.
12
+ */
13
+ export declare class MouseInputPlugin {
14
+ private _targetElement;
15
+ private _mouseDevice;
16
+ private _buttonState;
17
+ private _axesState;
18
+ private _position;
19
+ private _wheelState;
20
+ private _onDeviceConnected?;
21
+ private _onInputChanged?;
22
+ /**
23
+ * Create a new MouseResourceAccess
24
+ *
25
+ * @param targetElement - The DOM element to attach mouse listeners to (defaults to document.body)
26
+ */
27
+ constructor(targetElement?: HTMLElement);
28
+ /**
29
+ * Register a callback for device connected events
30
+ *
31
+ * @param callback - The callback to register
32
+ */
33
+ onDeviceConnected(callback: MouseDeviceCallback): void;
34
+ /**
35
+ * Register a callback for input changed events
36
+ *
37
+ * @param callback - The callback to register
38
+ */
39
+ onInputChanged(callback: MouseInputCallback): void;
40
+ /**
41
+ * Get the current mouse state
42
+ */
43
+ getState(): MouseInputState;
44
+ /**
45
+ * Get the mouse device
46
+ */
47
+ getDevice(): MouseDevice;
48
+ /**
49
+ * Destroy the mouse resource access and clean up event listeners
50
+ */
51
+ destroy(): void;
52
+ /**
53
+ * Set up mouse event listeners
54
+ */
55
+ private _setupMouseEvents;
56
+ /**
57
+ * Handle mouse button down events
58
+ */
59
+ private _handleMouseDown;
60
+ /**
61
+ * Handle mouse button up events
62
+ */
63
+ private _handleMouseUp;
64
+ /**
65
+ * Handle mouse move events
66
+ */
67
+ private _handleMouseMove;
68
+ /**
69
+ * Handle mouse wheel events
70
+ */
71
+ private _handleMouseWheel;
72
+ /**
73
+ * Notify subscribers of device connected event
74
+ */
75
+ private _notifyDeviceConnected;
76
+ /**
77
+ * Notify subscribers of input changed event
78
+ */
79
+ private _notifyInputChanged;
80
+ }
@@ -0,0 +1,77 @@
1
+ import type { DeviceValueReader, GamepadValueReaderDefinition, InputState } from '../../../interfaces/input.ts';
2
+ /**
3
+ * Types of gamepad input sources
4
+ */
5
+ export type GamepadSourceType = 'button' | 'axis';
6
+ /**
7
+ * Options for configuring a gamepad value reader
8
+ */
9
+ export interface GamepadReaderOptions {
10
+ /**
11
+ * Whether to use the analog value instead of boolean pressed state for buttons
12
+ */
13
+ useAnalogValue?: boolean;
14
+ /**
15
+ * Deadzone value (0.0 - 1.0) for analog axes
16
+ * Input values below this threshold will be treated as 0
17
+ */
18
+ deadzone?: number;
19
+ /**
20
+ * Whether to invert the axis values
21
+ */
22
+ invert?: boolean;
23
+ }
24
+ /**
25
+ * Reads values from gamepad input states
26
+ */
27
+ export declare class GamepadValueReader implements DeviceValueReader {
28
+ /**
29
+ * The type of gamepad input
30
+ */
31
+ readonly sourceType: GamepadSourceType;
32
+ /**
33
+ * The specific key for this input
34
+ */
35
+ readonly sourceKey: string;
36
+ /**
37
+ * Whether to use analog value for buttons
38
+ */
39
+ private readonly useAnalogValue;
40
+ /**
41
+ * Deadzone value for axes
42
+ */
43
+ private readonly deadzone;
44
+ /**
45
+ * Whether to invert axis values
46
+ */
47
+ private readonly invert;
48
+ /**
49
+ * Creates a new GamepadValueReader
50
+ *
51
+ * @param sourceType - Type of gamepad input to monitor (button or axis)
52
+ * @param sourceKey - The specific key for this input type
53
+ * @param options - Configuration options
54
+ */
55
+ constructor(sourceType: GamepadSourceType, sourceKey: string, options?: GamepadReaderOptions);
56
+ /**
57
+ * Gets the value of the input source based on the current state
58
+ *
59
+ * @param state - The current input state
60
+ * @returns The value of the input source
61
+ */
62
+ getValue(state: InputState): boolean | number | undefined;
63
+ /**
64
+ * Creates a GamepadValueReader from a string representation
65
+ *
66
+ * @param sourceTypeString - String in format "sourceType:sourceKey" (e.g., "button:0", "axis:1")
67
+ * @param options - Optional configuration options
68
+ * @returns A new GamepadValueReader instance
69
+ */
70
+ static fromString(sourceTypeString: string, options?: GamepadReaderOptions): GamepadValueReader;
71
+ /**
72
+ * Returns a JSON-serializable representation of this gamepad value reader
73
+ *
74
+ * @returns A simple object representation that can be converted to JSON
75
+ */
76
+ toJSON(): GamepadValueReaderDefinition;
77
+ }
@@ -0,0 +1,60 @@
1
+ import type { DeviceValueReader, InputState, KeyboardValueReaderDefinition } from '../../../interfaces/input.ts';
2
+ /**
3
+ * Types of keyboard input sources
4
+ */
5
+ export type KeyboardSourceType = 'key';
6
+ /**
7
+ * Options for configuring a keyboard value reader
8
+ */
9
+ export interface KeyboardReaderOptions {
10
+ /**
11
+ * Whether to use delta state instead of current state
12
+ * When true, the source will only return true on the initial key press
13
+ */
14
+ useDelta?: boolean;
15
+ }
16
+ /**
17
+ * Reads values from keyboard input states
18
+ */
19
+ export declare class KeyboardValueReader implements DeviceValueReader {
20
+ /**
21
+ * The type of keyboard input (always 'key')
22
+ */
23
+ readonly sourceType: KeyboardSourceType;
24
+ /**
25
+ * The key code to monitor (e.g., "KeyA", "Space")
26
+ */
27
+ readonly sourceKey: string;
28
+ /**
29
+ * Whether to use delta state instead of current state
30
+ */
31
+ private readonly useDelta;
32
+ /**
33
+ * Creates a new KeyboardValueReader
34
+ *
35
+ * @param keyCode - The key code to monitor (e.g., "KeyA", "Space")
36
+ * @param options - Configuration options
37
+ */
38
+ constructor(keyCode: string, options?: KeyboardReaderOptions);
39
+ /**
40
+ * Gets the value of the key state
41
+ *
42
+ * @param state - The input state
43
+ * @returns The key state value or undefined if the state type is not keyboard
44
+ */
45
+ getValue(state: InputState): boolean | undefined;
46
+ /**
47
+ * Creates a KeyboardValueReader from a string representation
48
+ *
49
+ * @param sourceKey - The key code (e.g., "KeyA", "Space")
50
+ * @param options - Optional configuration
51
+ * @returns A new KeyboardValueReader instance
52
+ */
53
+ static fromString(sourceKey: string, options?: KeyboardReaderOptions): KeyboardValueReader;
54
+ /**
55
+ * Returns a JSON-serializable representation of this keyboard value reader
56
+ *
57
+ * @returns A simple object representation that can be converted to JSON
58
+ */
59
+ toJSON(): KeyboardValueReaderDefinition;
60
+ }
@@ -0,0 +1,45 @@
1
+ import type { DeviceValueReader, InputState, MouseValueReaderDefinition } from '../../../interfaces/input.ts';
2
+ /**
3
+ * Types of mouse input sources
4
+ */
5
+ export type MouseSourceType = 'button' | 'position' | 'wheel';
6
+ /**
7
+ * Reads values from mouse input states
8
+ */
9
+ export declare class MouseValueReader implements DeviceValueReader {
10
+ /**
11
+ * The type of mouse input
12
+ */
13
+ readonly sourceType: MouseSourceType;
14
+ /**
15
+ * The specific key for this input
16
+ */
17
+ readonly sourceKey: string;
18
+ /**
19
+ * Creates a new MouseValueReader
20
+ *
21
+ * @param sourceType - Type of mouse input to monitor (button, position, wheel)
22
+ * @param sourceKey - The specific key for this input type
23
+ */
24
+ constructor(sourceType: MouseSourceType, sourceKey: string);
25
+ /**
26
+ * Gets the value of the mouse input source
27
+ *
28
+ * @param state - The current input state
29
+ * @returns The value of the input source
30
+ */
31
+ getValue(state: InputState): boolean | number | undefined;
32
+ /**
33
+ * Creates a MouseValueReader from a string representation
34
+ *
35
+ * @param sourceTypeString - String in format "sourceType:sourceKey" (e.g., "button:0", "position:absolute:x")
36
+ * @returns A new MouseValueReader instance
37
+ */
38
+ static fromString(sourceTypeString: string): MouseValueReader;
39
+ /**
40
+ * Returns a JSON-serializable representation of this mouse value reader
41
+ *
42
+ * @returns A simple object representation that can be converted to JSON
43
+ */
44
+ toJSON(): MouseValueReaderDefinition;
45
+ }
@@ -0,0 +1,29 @@
1
+ import type { LoggingBackend } from '../../interfaces/logger.ts';
2
+ /**
3
+ * A logging backend that logs to the console.
4
+ */
5
+ export declare class ConsoleBackend implements LoggingBackend {
6
+ private timers;
7
+ constructor();
8
+ /**
9
+ * Get the CSS style for a specific log level
10
+ */
11
+ private getStyleForLevel;
12
+ /**
13
+ * Format a log message with category, timestamp and log level
14
+ */
15
+ private formatMessage;
16
+ trace(category: string, message: string, ...args: any[]): void;
17
+ debug(category: string, message: string, ...args: any[]): void;
18
+ info(category: string, message: string, ...args: any[]): void;
19
+ warn(category: string, message: string, ...args: any[]): void;
20
+ error(category: string, message: string, ...args: any[]): void;
21
+ /**
22
+ * Start a timer with the specified label.
23
+ */
24
+ time(category: string, label: string): void;
25
+ /**
26
+ * End a timer and log the elapsed time.
27
+ */
28
+ timeEnd(category: string, label: string): void;
29
+ }
@@ -0,0 +1,14 @@
1
+ import type { LoggingBackend } from '../../interfaces/logger.ts';
2
+ /**
3
+ * A logging backend that does nothing (discards all logs).
4
+ * Useful for production environments or when you want to completely disable logging.
5
+ */
6
+ export declare class NullBackend implements LoggingBackend {
7
+ trace(_category: string, _message: string, ..._args: any[]): void;
8
+ debug(_category: string, _message: string, ..._args: any[]): void;
9
+ info(_category: string, _message: string, ..._args: any[]): void;
10
+ warn(_category: string, _message: string, ..._args: any[]): void;
11
+ error(_category: string, _message: string, ..._args: any[]): void;
12
+ time(_category: string, _label: string): void;
13
+ timeEnd(_category: string, _label: string): void;
14
+ }
@@ -0,0 +1,11 @@
1
+ import { AbstractEngine, HavokPlugin, Scene } from '@babylonjs/core';
2
+ import type { GameCanvas } from '../interfaces/game.ts';
3
+ import { type LoggingUtility } from '../utils/logger.ts';
4
+ export declare class SceneEngine {
5
+ private _engine;
6
+ private _physics;
7
+ private _log;
8
+ constructor(engine: AbstractEngine, physics: HavokPlugin, logger?: LoggingUtility);
9
+ private _buildDemoScene;
10
+ loadScene(canvas: GameCanvas): Promise<Scene>;
11
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Digital action (boolean)
3
+ */
4
+ export interface DigitalAction {
5
+ type: 'digital';
6
+ name: string;
7
+ }
8
+ /**
9
+ * Analog action (numeric)
10
+ */
11
+ export interface AnalogAction {
12
+ type: 'analog';
13
+ name: string;
14
+ minValue?: number;
15
+ maxValue?: number;
16
+ }
17
+ /**
18
+ * Action types
19
+ */
20
+ export type Action = DigitalAction | AnalogAction;
@@ -0,0 +1,144 @@
1
+ import type { GameEventBus } from '../classes/eventBus.ts';
2
+ import type { DeviceValueReader, DeviceValueReaderDefinition, InputState } from './input.ts';
3
+ import type { Action } from './action.ts';
4
+ /**
5
+ * Types of bindings supported by the system
6
+ */
7
+ export type BindingType = 'trigger' | 'toggle' | 'value';
8
+ /**
9
+ * Array of all supported binding types for validation
10
+ */
11
+ export declare const bindingTypes: BindingType[];
12
+ /**
13
+ * Context for organizing bindings into groups that can be activated/deactivated together
14
+ */
15
+ export interface Context {
16
+ /**
17
+ * Name of the context for identification
18
+ */
19
+ name: string;
20
+ /**
21
+ * Whether this context is exclusive (only one exclusive context can be active at a time)
22
+ */
23
+ exclusive: boolean;
24
+ }
25
+ /**
26
+ * Input definition that combines device ID and reader configuration into a single object
27
+ */
28
+ export type InputDefinition = DeviceValueReaderDefinition & {
29
+ deviceID: string;
30
+ };
31
+ /**
32
+ * Base interface for binding definitions with object-based sources
33
+ */
34
+ export interface BindingDefinitionBase {
35
+ /**
36
+ * Type of binding
37
+ */
38
+ type: BindingType;
39
+ /**
40
+ * Name of the (already registered) action this binding triggers
41
+ */
42
+ action: string;
43
+ /**
44
+ * Input definition combining device ID and reader configuration
45
+ */
46
+ input: InputDefinition;
47
+ /**
48
+ * Optional context name this binding belongs to
49
+ */
50
+ context?: string;
51
+ /**
52
+ * Optional options for the binding
53
+ */
54
+ options?: Record<string, any>;
55
+ }
56
+ /**
57
+ * Trigger binding definition
58
+ */
59
+ export interface TriggerBindingDefinition extends BindingDefinitionBase {
60
+ type: 'trigger';
61
+ options?: {
62
+ edgeMode?: 'rising' | 'falling' | 'both';
63
+ threshold?: number;
64
+ passthrough?: boolean;
65
+ };
66
+ }
67
+ /**
68
+ * Toggle binding definition
69
+ */
70
+ export interface ToggleBindingDefinition extends BindingDefinitionBase {
71
+ type: 'toggle';
72
+ state?: boolean;
73
+ options?: {
74
+ invert?: boolean;
75
+ initialState?: boolean;
76
+ threshold?: number;
77
+ onValue?: boolean | number;
78
+ offValue?: boolean | number;
79
+ };
80
+ }
81
+ /**
82
+ * Value binding definition
83
+ */
84
+ export interface ValueBindingDefinition extends BindingDefinitionBase {
85
+ type: 'value';
86
+ options?: {
87
+ scale?: number;
88
+ offset?: number;
89
+ min?: number;
90
+ max?: number;
91
+ invert?: boolean;
92
+ emitOnChange?: boolean;
93
+ deadzone?: number;
94
+ };
95
+ }
96
+ /**
97
+ * Generic binding definition (for any other binding types)
98
+ */
99
+ export interface GenericBindingDefinition extends BindingDefinitionBase {
100
+ type: Exclude<BindingType, 'trigger' | 'toggle' | 'value'>;
101
+ options?: Record<string, any>;
102
+ }
103
+ /**
104
+ * Union type of all binding definitions
105
+ */
106
+ export type BindingDefinition = TriggerBindingDefinition | ToggleBindingDefinition | ValueBindingDefinition | GenericBindingDefinition;
107
+ /**
108
+ * Base interface for all input bindings
109
+ */
110
+ export interface Binding {
111
+ /**
112
+ * Type of binding
113
+ */
114
+ readonly type: BindingType;
115
+ /**
116
+ * Action object this binding triggers
117
+ */
118
+ readonly action: Action;
119
+ /**
120
+ * Optional context name this binding belongs to
121
+ */
122
+ readonly context?: string;
123
+ /**
124
+ * Device ID this binding is associated with
125
+ */
126
+ readonly deviceID: string;
127
+ /**
128
+ * Input source that provides values for this binding
129
+ */
130
+ readonly reader: DeviceValueReader;
131
+ /**
132
+ * Process input state and potentially emit an action event
133
+ *
134
+ * @param state - Current input state for the device
135
+ * @param eventBus - Event bus to emit action events to
136
+ */
137
+ process(state: InputState, eventBus: GameEventBus): void;
138
+ /**
139
+ * Convert the binding to a JSON-serializable object
140
+ *
141
+ * @returns A JSON-serializable representation of the binding
142
+ */
143
+ toJSON(): BindingDefinition;
144
+ }
@@ -0,0 +1,9 @@
1
+ import { GameEntityBehavior } from '../classes/entity.ts';
2
+ import { Action } from './action.ts';
3
+ export type GameEntityBehaviorConstructor<RequiredState extends object = object> = new () => GameEntityBehavior<RequiredState>;
4
+ export interface GameEntityDefinition {
5
+ type: string;
6
+ defaultState: Record<string, any>;
7
+ behaviors: GameEntityBehaviorConstructor[];
8
+ actions?: Action[];
9
+ }
@@ -0,0 +1,26 @@
1
+ import { EngineOptions, NullEngineOptions, WebGPUEngineOptions } from '@babylonjs/core';
2
+ import type { LogLevel } from './logger.ts';
3
+ import { BindingDefinition } from './binding.ts';
4
+ export type GameCanvas = HTMLCanvasElement | OffscreenCanvas | null;
5
+ /** Specifies which rendering engine to force using */
6
+ export type EngineType = 'webgl' | 'webgpu' | 'auto';
7
+ export interface BabylonEngineOptions {
8
+ antialias?: boolean;
9
+ adaptToDeviceRatio?: boolean;
10
+ options?: EngineOptions;
11
+ }
12
+ export type RenderEngineOptions = (BabylonEngineOptions | NullEngineOptions | WebGPUEngineOptions) & {
13
+ /** Force a specific engine type, overriding automatic detection */
14
+ forceEngine?: EngineType;
15
+ };
16
+ /**
17
+ * SAGE Engine options for configuring the game engine
18
+ */
19
+ export interface SageOptions {
20
+ /** Render engine options for BabylonJS */
21
+ renderOptions?: RenderEngineOptions;
22
+ /** Input bindings to be registered at startup */
23
+ bindings?: BindingDefinition[];
24
+ /** Logging level for the engine */
25
+ logLevel?: LogLevel;
26
+ }