canvasengine 2.0.0-beta.5 → 2.0.0-beta.51

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 (172) hide show
  1. package/dist/components/Button.d.ts +185 -0
  2. package/dist/components/Button.d.ts.map +1 -0
  3. package/dist/components/Canvas.d.ts +17 -0
  4. package/dist/components/Canvas.d.ts.map +1 -0
  5. package/dist/components/Container.d.ts +86 -0
  6. package/dist/components/Container.d.ts.map +1 -0
  7. package/dist/components/DOMContainer.d.ts +98 -0
  8. package/dist/components/DOMContainer.d.ts.map +1 -0
  9. package/dist/components/DOMElement.d.ts +54 -0
  10. package/dist/components/DOMElement.d.ts.map +1 -0
  11. package/dist/components/DOMSprite.d.ts +127 -0
  12. package/dist/components/DOMSprite.d.ts.map +1 -0
  13. package/dist/components/DisplayObject.d.ts +94 -0
  14. package/dist/components/DisplayObject.d.ts.map +1 -0
  15. package/dist/components/FocusContainer.d.ts +129 -0
  16. package/dist/components/FocusContainer.d.ts.map +1 -0
  17. package/dist/components/Graphic.d.ts +64 -0
  18. package/dist/components/Graphic.d.ts.map +1 -0
  19. package/dist/components/Joystick.d.ts +36 -0
  20. package/dist/components/Joystick.d.ts.map +1 -0
  21. package/dist/components/Mesh.d.ts +208 -0
  22. package/dist/components/Mesh.d.ts.map +1 -0
  23. package/dist/components/NineSliceSprite.d.ts +16 -0
  24. package/dist/components/NineSliceSprite.d.ts.map +1 -0
  25. package/dist/components/ParticleEmitter.d.ts +4 -0
  26. package/dist/components/ParticleEmitter.d.ts.map +1 -0
  27. package/dist/components/Scene.d.ts +2 -0
  28. package/dist/components/Scene.d.ts.map +1 -0
  29. package/dist/components/Sprite.d.ts +242 -0
  30. package/dist/components/Sprite.d.ts.map +1 -0
  31. package/dist/components/Text.d.ts +25 -0
  32. package/dist/components/Text.d.ts.map +1 -0
  33. package/dist/components/TilingSprite.d.ts +17 -0
  34. package/dist/components/TilingSprite.d.ts.map +1 -0
  35. package/dist/components/Video.d.ts +14 -0
  36. package/dist/components/Video.d.ts.map +1 -0
  37. package/dist/components/Viewport.d.ts +121 -0
  38. package/dist/components/Viewport.d.ts.map +1 -0
  39. package/dist/components/index.d.ts +20 -0
  40. package/dist/components/index.d.ts.map +1 -0
  41. package/dist/components/types/DisplayObject.d.ts +106 -0
  42. package/dist/components/types/DisplayObject.d.ts.map +1 -0
  43. package/dist/components/types/MouseEvent.d.ts +4 -0
  44. package/dist/components/types/MouseEvent.d.ts.map +1 -0
  45. package/dist/components/types/Spritesheet.d.ts +248 -0
  46. package/dist/components/types/Spritesheet.d.ts.map +1 -0
  47. package/dist/components/types/index.d.ts +4 -0
  48. package/dist/components/types/index.d.ts.map +1 -0
  49. package/dist/directives/Controls.d.ts +112 -0
  50. package/dist/directives/Controls.d.ts.map +1 -0
  51. package/dist/directives/ControlsBase.d.ts +199 -0
  52. package/dist/directives/ControlsBase.d.ts.map +1 -0
  53. package/dist/directives/Drag.d.ts +69 -0
  54. package/dist/directives/Drag.d.ts.map +1 -0
  55. package/dist/directives/Flash.d.ts +116 -0
  56. package/dist/directives/Flash.d.ts.map +1 -0
  57. package/dist/directives/FocusNavigation.d.ts +52 -0
  58. package/dist/directives/FocusNavigation.d.ts.map +1 -0
  59. package/dist/directives/GamepadControls.d.ts +224 -0
  60. package/dist/directives/GamepadControls.d.ts.map +1 -0
  61. package/dist/directives/JoystickControls.d.ts +171 -0
  62. package/dist/directives/JoystickControls.d.ts.map +1 -0
  63. package/dist/directives/KeyboardControls.d.ts +219 -0
  64. package/dist/directives/KeyboardControls.d.ts.map +1 -0
  65. package/dist/directives/Scheduler.d.ts +35 -0
  66. package/dist/directives/Scheduler.d.ts.map +1 -0
  67. package/dist/directives/Shake.d.ts +98 -0
  68. package/dist/directives/Shake.d.ts.map +1 -0
  69. package/dist/directives/Sound.d.ts +25 -0
  70. package/dist/directives/Sound.d.ts.map +1 -0
  71. package/dist/directives/Transition.d.ts +10 -0
  72. package/dist/directives/Transition.d.ts.map +1 -0
  73. package/dist/directives/ViewportCull.d.ts +11 -0
  74. package/dist/directives/ViewportCull.d.ts.map +1 -0
  75. package/dist/directives/ViewportFollow.d.ts +18 -0
  76. package/dist/directives/ViewportFollow.d.ts.map +1 -0
  77. package/dist/directives/index.d.ts +13 -0
  78. package/dist/directives/index.d.ts.map +1 -0
  79. package/dist/engine/FocusManager.d.ts +174 -0
  80. package/dist/engine/FocusManager.d.ts.map +1 -0
  81. package/dist/engine/animation.d.ts +72 -0
  82. package/dist/engine/animation.d.ts.map +1 -0
  83. package/dist/engine/bootstrap.d.ts +48 -0
  84. package/dist/engine/bootstrap.d.ts.map +1 -0
  85. package/dist/engine/directive.d.ts +13 -0
  86. package/dist/engine/directive.d.ts.map +1 -0
  87. package/dist/engine/reactive.d.ts +134 -0
  88. package/dist/engine/reactive.d.ts.map +1 -0
  89. package/dist/engine/signal.d.ts +71 -0
  90. package/dist/engine/signal.d.ts.map +1 -0
  91. package/dist/engine/trigger.d.ts +54 -0
  92. package/dist/engine/trigger.d.ts.map +1 -0
  93. package/dist/engine/utils.d.ts +89 -0
  94. package/dist/engine/utils.d.ts.map +1 -0
  95. package/dist/hooks/addContext.d.ts +2 -0
  96. package/dist/hooks/addContext.d.ts.map +1 -0
  97. package/dist/hooks/useFocus.d.ts +60 -0
  98. package/dist/hooks/useFocus.d.ts.map +1 -0
  99. package/dist/hooks/useProps.d.ts +42 -0
  100. package/dist/hooks/useProps.d.ts.map +1 -0
  101. package/dist/hooks/useRef.d.ts +4 -0
  102. package/dist/hooks/useRef.d.ts.map +1 -0
  103. package/dist/index-DaGekQUW.js +2218 -0
  104. package/dist/index-DaGekQUW.js.map +1 -0
  105. package/dist/index.d.ts +19 -1099
  106. package/dist/index.d.ts.map +1 -0
  107. package/dist/index.global.js +5 -0
  108. package/dist/index.global.js.map +1 -0
  109. package/dist/index.js +11749 -2901
  110. package/dist/index.js.map +1 -1
  111. package/dist/utils/Ease.d.ts +17 -0
  112. package/dist/utils/Ease.d.ts.map +1 -0
  113. package/dist/utils/GlobalAssetLoader.d.ts +141 -0
  114. package/dist/utils/GlobalAssetLoader.d.ts.map +1 -0
  115. package/dist/utils/RadialGradient.d.ts +57 -0
  116. package/dist/utils/RadialGradient.d.ts.map +1 -0
  117. package/dist/utils/functions.d.ts +2 -0
  118. package/dist/utils/functions.d.ts.map +1 -0
  119. package/dist/utils/tabindex.d.ts +16 -0
  120. package/dist/utils/tabindex.d.ts.map +1 -0
  121. package/package.json +13 -7
  122. package/src/components/Button.ts +399 -0
  123. package/src/components/Canvas.ts +62 -46
  124. package/src/components/Container.ts +21 -2
  125. package/src/components/DOMContainer.ts +379 -0
  126. package/src/components/DOMElement.ts +556 -0
  127. package/src/components/DOMSprite.ts +1040 -0
  128. package/src/components/DisplayObject.ts +392 -201
  129. package/src/components/FocusContainer.ts +368 -0
  130. package/src/components/Graphic.ts +227 -66
  131. package/src/components/Joystick.ts +363 -0
  132. package/src/components/Mesh.ts +222 -0
  133. package/src/components/NineSliceSprite.ts +4 -1
  134. package/src/components/ParticleEmitter.ts +12 -8
  135. package/src/components/Sprite.ts +297 -31
  136. package/src/components/Text.ts +125 -18
  137. package/src/components/Video.ts +2 -2
  138. package/src/components/Viewport.ts +118 -63
  139. package/src/components/index.ts +9 -2
  140. package/src/components/types/DisplayObject.ts +41 -4
  141. package/src/components/types/Spritesheet.ts +0 -118
  142. package/src/directives/Controls.ts +254 -0
  143. package/src/directives/ControlsBase.ts +267 -0
  144. package/src/directives/Drag.ts +357 -52
  145. package/src/directives/Flash.ts +419 -0
  146. package/src/directives/FocusNavigation.ts +113 -0
  147. package/src/directives/GamepadControls.ts +537 -0
  148. package/src/directives/JoystickControls.ts +396 -0
  149. package/src/directives/KeyboardControls.ts +85 -430
  150. package/src/directives/Scheduler.ts +12 -4
  151. package/src/directives/Shake.ts +298 -0
  152. package/src/directives/Sound.ts +94 -31
  153. package/src/directives/ViewportFollow.ts +40 -9
  154. package/src/directives/index.ts +12 -6
  155. package/src/engine/FocusManager.ts +510 -0
  156. package/src/engine/animation.ts +175 -21
  157. package/src/engine/bootstrap.ts +93 -3
  158. package/src/engine/directive.ts +4 -4
  159. package/src/engine/reactive.ts +901 -161
  160. package/src/engine/signal.ts +113 -25
  161. package/src/engine/trigger.ts +34 -7
  162. package/src/engine/utils.ts +19 -3
  163. package/src/hooks/useFocus.ts +91 -0
  164. package/src/hooks/useProps.ts +1 -1
  165. package/src/index.ts +8 -2
  166. package/src/types/pixi-cull.d.ts +7 -0
  167. package/src/utils/GlobalAssetLoader.ts +257 -0
  168. package/src/utils/functions.ts +7 -0
  169. package/src/utils/tabindex.ts +70 -0
  170. package/testing/index.ts +35 -4
  171. package/tsconfig.json +18 -0
  172. package/vite.config.ts +39 -0
@@ -0,0 +1,116 @@
1
+ import { Container } from 'pixi.js';
2
+ import { Directive } from '../engine/directive';
3
+ import { Element } from '../engine/reactive';
4
+ import { Trigger } from '../engine/trigger';
5
+ import { SignalOrPrimitive } from '../components/types';
6
+ export type FlashType = 'alpha' | 'tint' | 'both';
7
+ export type FlashProps = {
8
+ /**
9
+ * Trigger that activates the flash animation
10
+ * When the trigger is activated, the flash animation will start
11
+ */
12
+ trigger?: Trigger<any>;
13
+ /**
14
+ * Type of flash effect: 'alpha' (opacity), 'tint' (color), or 'both'
15
+ * @default 'alpha'
16
+ */
17
+ type?: SignalOrPrimitive<FlashType>;
18
+ /**
19
+ * Duration of the flash animation in milliseconds
20
+ * @default 300
21
+ */
22
+ duration?: SignalOrPrimitive<number>;
23
+ /**
24
+ * Number of flash cycles (flash on/off)
25
+ * @default 1
26
+ */
27
+ cycles?: SignalOrPrimitive<number>;
28
+ /**
29
+ * Alpha value when flashing (0 to 1)
30
+ * Only used when type is 'alpha' or 'both'
31
+ * @default 0.3
32
+ */
33
+ alpha?: SignalOrPrimitive<number>;
34
+ /**
35
+ * Tint color when flashing (hex color value)
36
+ * Only used when type is 'tint' or 'both'
37
+ * @default 0xffffff (white)
38
+ */
39
+ tint?: SignalOrPrimitive<number>;
40
+ /**
41
+ * Original alpha value to restore after flash
42
+ * If not provided, uses the current alpha value
43
+ */
44
+ originalAlpha?: number;
45
+ /**
46
+ * Original tint value to restore after flash
47
+ * If not provided, uses the current tint value
48
+ */
49
+ originalTint?: number;
50
+ /**
51
+ * Callback function called when flash starts
52
+ */
53
+ onStart?: () => void;
54
+ /**
55
+ * Callback function called when flash completes
56
+ */
57
+ onComplete?: () => void;
58
+ };
59
+ /**
60
+ * Flash directive that animates a display object's alpha and/or tint when a trigger is activated.
61
+ * Creates a flash effect by rapidly changing opacity or color.
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * // Basic usage with trigger
66
+ * const flashTrigger = trigger();
67
+ *
68
+ * onMount(element) {
69
+ * // Element will flash when trigger is activated
70
+ * element.props.flash = { trigger: flashTrigger };
71
+ * }
72
+ *
73
+ * // Trigger the flash
74
+ * flashTrigger.start();
75
+ * ```
76
+ */
77
+ export declare class Flash extends Directive {
78
+ private elementRef;
79
+ private progressSignal;
80
+ private flashSubscription;
81
+ private alphaEffect;
82
+ private tintEffect;
83
+ private originalAlpha;
84
+ private originalTint;
85
+ private currentFlashConfig;
86
+ /**
87
+ * Initializes the flash directive
88
+ * @param element - The element to attach the flash effect to
89
+ */
90
+ onInit(element: Element<Container>): void;
91
+ /**
92
+ * Mounts the flash directive and sets up trigger listener
93
+ * @param element - The element being mounted
94
+ */
95
+ onMount(element: Element<Container>): void;
96
+ /**
97
+ * Gets the flash props with default values
98
+ * @returns FlashProps with defaults applied
99
+ */
100
+ get flashProps(): FlashProps;
101
+ /**
102
+ * Performs the flash animation using animatedSignal
103
+ * @param data - Optional data passed from the trigger that can override default options
104
+ */
105
+ private performFlash;
106
+ /**
107
+ * Updates the flash directive when props change
108
+ * @param props - Updated props
109
+ */
110
+ onUpdate(props: any): void;
111
+ /**
112
+ * Cleans up the flash directive
113
+ */
114
+ onDestroy(): void;
115
+ }
116
+ //# sourceMappingURL=Flash.d.ts.map
@@ -0,0 +1 @@
1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,OAAO,CAAC,WAAW,CAA6B;IAChD,OAAO,CAAC,UAAU,CAA6B;IAC/C,OAAO,CAAC,aAAa,CAAa;IAClC,OAAO,CAAC,YAAY,CAAoB;IACxC,OAAO,CAAC,kBAAkB,CAMV;IAEhB;;;OAGG;IACH,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC;IAIlC;;;OAGG;IACH,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC;IAgCnC;;;OAGG;IACH,IAAI,UAAU,IAAI,UAAU,CAS3B;IAED;;;OAGG;YACW,YAAY;IAgM1B;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,GAAG;IAUnB;;OAEG;IACH,SAAS;CA4CZ"}
@@ -0,0 +1,52 @@
1
+ import { Directive } from '../engine/directive';
2
+ import { Element } from '../engine/reactive';
3
+ import { CanvasFocusContainer } from '../components/FocusContainer';
4
+ /**
5
+ * FocusNavigation directive for wiring Controls with FocusContainer
6
+ *
7
+ * This directive integrates with the Controls system and lets external
8
+ * control handlers update the FocusContainer tabindex signal.
9
+ *
10
+ * The directive is automatically applied when a FocusContainer has a `controls` prop.
11
+ * It keeps the Controls directive in sync with the provided controls config.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * // Automatic navigation with Controls
16
+ * <FocusContainer tabindex={0} controls={controlsConfig}>
17
+ * <Button tabindex={0} text="Button 1" />
18
+ * <Button tabindex={1} text="Button 2" />
19
+ * </FocusContainer>
20
+ * ```
21
+ */
22
+ export declare class FocusNavigationDirective extends Directive {
23
+ private element;
24
+ private controlsDirective;
25
+ private controlsSubscription;
26
+ /**
27
+ * Initialize the focus navigation directive
28
+ *
29
+ * @param element - FocusContainer element
30
+ */
31
+ onInit(element: Element<CanvasFocusContainer>): void;
32
+ /**
33
+ * Mount hook
34
+ *
35
+ * @param element - FocusContainer element
36
+ */
37
+ onMount(element: Element<CanvasFocusContainer>): void;
38
+ /**
39
+ * Update hook
40
+ *
41
+ * @param props - Updated properties
42
+ * @param element - FocusContainer element
43
+ */
44
+ onUpdate(props: any, element: Element<CanvasFocusContainer>): void;
45
+ /**
46
+ * Destroy hook
47
+ *
48
+ * @param element - FocusContainer element
49
+ */
50
+ onDestroy(element: Element<CanvasFocusContainer>): void;
51
+ }
52
+ //# sourceMappingURL=FocusNavigation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FocusNavigation.d.ts","sourceRoot":"","sources":["../../src/directives/FocusNavigation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAqC,MAAM,qBAAqB,CAAC;AACnF,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAIlD,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAEpE;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,wBAAyB,SAAQ,SAAS;IACrD,OAAO,CAAC,OAAO,CAA8C;IAC7D,OAAO,CAAC,iBAAiB,CAAkC;IAC3D,OAAO,CAAC,oBAAoB,CAAa;IAEzC;;;;OAIG;IACH,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,oBAAoB,CAAC;IAI7C;;;;OAIG;IACH,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,oBAAoB,CAAC;IAmC9C;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,CAAC,oBAAoB,CAAC;IAU3D;;;;OAIG;IACH,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,oBAAoB,CAAC;CAUjD"}
@@ -0,0 +1,224 @@
1
+ import { ControlsBase, Controls } from './ControlsBase';
2
+ import { WritableSignal } from '@signe/reactive';
3
+ /**
4
+ * Gamepad configuration interface
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * const gamepadConfig: GamepadConfig = {
9
+ * enabled: true,
10
+ * buttonMapping: {
11
+ * 'button_0': 'action',
12
+ * 'button_1': 'back'
13
+ * },
14
+ * axisMapping: {
15
+ * 'top': 'up',
16
+ * 'bottom': 'down',
17
+ * 'left': 'left',
18
+ * 'right': 'right'
19
+ * },
20
+ * moveInterval: 400,
21
+ * onConnect: () => console.log('Gamepad connected!'),
22
+ * onDisconnect: () => console.log('Gamepad disconnected!')
23
+ * };
24
+ * ```
25
+ */
26
+ export interface GamepadConfig {
27
+ /** Whether gamepad is enabled (default: true) */
28
+ enabled?: boolean;
29
+ /** Mapping of gamepad button names to control names */
30
+ buttonMapping?: {
31
+ [buttonName: string]: string;
32
+ };
33
+ /** Mapping of axis directions to control directions */
34
+ axisMapping?: {
35
+ [axisDirection: string]: string;
36
+ };
37
+ /** Threshold for axis movement detection (default: 0.5) */
38
+ axisThreshold?: number;
39
+ /** Interval in milliseconds for repeating movement actions (default: 400) */
40
+ moveInterval?: number;
41
+ /** Callback called when a gamepad is connected */
42
+ onConnect?: () => void;
43
+ /** Callback called when a gamepad is disconnected */
44
+ onDisconnect?: () => void;
45
+ /** Signal that tracks gamepad connection status (optional) */
46
+ gamepadConnected?: WritableSignal<boolean>;
47
+ }
48
+ /**
49
+ * Gamepad input controls implementation
50
+ *
51
+ * Handles gamepad input events using joypad.js library and maps them to control actions.
52
+ * Supports button presses and analog stick movement with configurable mappings.
53
+ *
54
+ * The gamepad controls are automatically activated when joypad.js is available and enabled.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * const gamepadControls = new GamepadControls();
59
+ * gamepadControls.setInputs({
60
+ * up: {
61
+ * repeat: true,
62
+ * bind: 'up',
63
+ * keyDown() {
64
+ * console.log('Up pressed');
65
+ * }
66
+ * }
67
+ * });
68
+ * gamepadControls.updateGamepadConfig({
69
+ * enabled: true,
70
+ * buttonMapping: {
71
+ * 'button_0': 'action'
72
+ * }
73
+ * });
74
+ * gamepadControls.start();
75
+ * ```
76
+ */
77
+ export declare class GamepadControls extends ControlsBase {
78
+ private gamepadEnabled;
79
+ private gamepadConfig;
80
+ private gamepadMoving;
81
+ private gamepadDirections;
82
+ private gamepadAxisDate;
83
+ private gamepadMoveInterval;
84
+ private joypad;
85
+ private connectCallbacks;
86
+ private disconnectCallbacks;
87
+ private currentPower;
88
+ /**
89
+ * Setup gamepad event listeners
90
+ * Initializes joypad.js if available
91
+ */
92
+ protected setupListeners(): void;
93
+ /**
94
+ * Cleanup gamepad event listeners and intervals
95
+ */
96
+ protected cleanup(): void;
97
+ /**
98
+ * Initialize joypad.js library if available
99
+ */
100
+ private initGamepad;
101
+ /**
102
+ * Handle gamepad connection event
103
+ */
104
+ private handleGamepadConnect;
105
+ /**
106
+ * Handle gamepad disconnection event
107
+ */
108
+ private handleGamepadDisconnect;
109
+ /**
110
+ * Handle gamepad button press event
111
+ *
112
+ * @param e - Button press event from joypad.js
113
+ */
114
+ private handleGamepadButtonPress;
115
+ /**
116
+ * Handle gamepad axis movement event
117
+ *
118
+ * @param e - Axis move event from joypad.js
119
+ */
120
+ private handleGamepadAxisMove;
121
+ /**
122
+ * Process continuous gamepad movement
123
+ * Called at intervals to repeat movement actions while axes are active
124
+ */
125
+ private processGamepadMovement;
126
+ /**
127
+ * Process gamepad inputs each step
128
+ * Handles timeout for stopping movements after axis inactivity
129
+ */
130
+ protected preStep(): void;
131
+ /**
132
+ * Update gamepad configuration
133
+ * Merges provided config with defaults
134
+ * Automatically registers callbacks from config
135
+ *
136
+ * @param config - Partial gamepad configuration
137
+ */
138
+ updateGamepadConfig(config: Partial<GamepadConfig>): void;
139
+ /**
140
+ * Extract gamepad config from controls configuration and update
141
+ * Note: Callbacks are stored but not automatically registered, they should be registered in mount()
142
+ *
143
+ * @param inputs - Controls configuration that may contain a 'gamepad' property
144
+ */
145
+ extractGamepadConfig(inputs: Controls & {
146
+ gamepad?: GamepadConfig;
147
+ }): void;
148
+ /**
149
+ * Get the current gamepad configuration
150
+ *
151
+ * @returns The gamepad configuration object
152
+ */
153
+ getGamepadConfig(): GamepadConfig;
154
+ /**
155
+ * Apply a control action programmatically
156
+ * Uses the bound controls to trigger actions
157
+ *
158
+ * @param controlName - Name of the control
159
+ * @param isDown - Whether the control is pressed (true) or released (false)
160
+ * @param payload - Optional payload to pass to keyDown/keyUp callbacks (e.g., { power: 0.8 })
161
+ * @returns Promise that resolves when the action is complete
162
+ */
163
+ applyControl(controlName: string | number, isDown?: boolean, payload?: any): Promise<void>;
164
+ /**
165
+ * Override setInputs to extract gamepad config
166
+ */
167
+ setInputs(inputs: Controls & {
168
+ gamepad?: GamepadConfig;
169
+ }): void;
170
+ /**
171
+ * Register a callback to be called when a gamepad is connected
172
+ *
173
+ * @param callback - Function to call when gamepad connects
174
+ * @example
175
+ * ```ts
176
+ * gamepadControls.onConnect(() => {
177
+ * console.log('Gamepad connected!');
178
+ * });
179
+ * ```
180
+ */
181
+ onConnect(callback: () => void): void;
182
+ /**
183
+ * Register a callback to be called when a gamepad is disconnected
184
+ *
185
+ * @param callback - Function to call when gamepad disconnects
186
+ * @example
187
+ * ```ts
188
+ * gamepadControls.onDisconnect(() => {
189
+ * console.log('Gamepad disconnected!');
190
+ * });
191
+ * ```
192
+ */
193
+ onDisconnect(callback: () => void): void;
194
+ /**
195
+ * Remove a connect callback
196
+ *
197
+ * @param callback - Callback to remove
198
+ */
199
+ offConnect(callback: () => void): void;
200
+ /**
201
+ * Remove a disconnect callback
202
+ *
203
+ * @param callback - Callback to remove
204
+ */
205
+ offDisconnect(callback: () => void): void;
206
+ /**
207
+ * Check if gamepad is currently connected
208
+ *
209
+ * @returns true if gamepad is connected, false otherwise
210
+ */
211
+ isConnected(): boolean;
212
+ /**
213
+ * Reinitialize gamepad listeners
214
+ * Useful if joypad.js becomes available after initialization
215
+ *
216
+ * @example
217
+ * ```ts
218
+ * // If joypad.js loads later
219
+ * gamepadControls.reinit();
220
+ * ```
221
+ */
222
+ reinit(): void;
223
+ }
224
+ //# sourceMappingURL=GamepadControls.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GamepadControls.d.ts","sourceRoot":"","sources":["../../src/directives/GamepadControls.ts"],"names":[],"mappings":"AAAA,OAAO,EAA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sBase, Controls } from './ControlsBase';
2
+ /**
3
+ * Joystick directions reported by the Joystick component
4
+ */
5
+ export type JoystickDirection = 'left' | 'right' | 'top' | 'bottom' | 'top_left' | 'top_right' | 'bottom_left' | 'bottom_right';
6
+ /**
7
+ * Joystick change event payload
8
+ */
9
+ export interface JoystickChangeEvent {
10
+ angle: number;
11
+ direction: JoystickDirection;
12
+ power: number;
13
+ }
14
+ /**
15
+ * Joystick configuration interface
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * const joystickConfig: JoystickConfig = {
20
+ * enabled: true,
21
+ * directionMapping: {
22
+ * 'top': 'up',
23
+ * 'bottom': 'down',
24
+ * 'left': 'left',
25
+ * 'right': 'right',
26
+ * 'top_left': ['up', 'left'],
27
+ * 'top_right': ['up', 'right'],
28
+ * 'bottom_left': ['down', 'left'],
29
+ * 'bottom_right': ['down', 'right']
30
+ * },
31
+ * moveInterval: 50,
32
+ * threshold: 0.1
33
+ * };
34
+ * ```
35
+ */
36
+ export interface JoystickConfig {
37
+ /** Whether joystick is enabled (default: true) */
38
+ enabled?: boolean;
39
+ /** Mapping of joystick direction names to control names (can be single string or array for diagonals) */
40
+ directionMapping?: {
41
+ [joystickDirection: string]: string | string[];
42
+ };
43
+ /** Interval in milliseconds for repeating movement actions (default: 50) */
44
+ moveInterval?: number;
45
+ /** Threshold for power value to trigger movement (default: 0.1) */
46
+ threshold?: number;
47
+ }
48
+ /**
49
+ * Joystick input controls implementation
50
+ *
51
+ * Handles joystick input events from the Joystick component and maps them to control actions.
52
+ * Supports directional movement with configurable mappings, including diagonal directions.
53
+ *
54
+ * The joystick controls work by receiving change events from a Joystick component instance.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * const joystickControls = new JoystickControls();
59
+ * joystickControls.setInputs({
60
+ * up: {
61
+ * repeat: true,
62
+ * bind: 'up',
63
+ * keyDown() {
64
+ * console.log('Up pressed');
65
+ * }
66
+ * }
67
+ * });
68
+ * joystickControls.updateJoystickConfig({
69
+ * enabled: true,
70
+ * directionMapping: {
71
+ * 'top': 'up'
72
+ * }
73
+ * });
74
+ * joystickControls.start();
75
+ *
76
+ * // Later, when joystick changes:
77
+ * joystickControls.handleJoystickChange({ angle: 90, direction: Direction.TOP, power: 0.8 });
78
+ * ```
79
+ */
80
+ export declare class JoystickControls extends ControlsBase {
81
+ private joystickEnabled;
82
+ private joystickConfig;
83
+ private joystickMoving;
84
+ private joystickDirections;
85
+ private joystickLastUpdate;
86
+ private joystickMoveInterval;
87
+ private currentPower;
88
+ /**
89
+ * Setup joystick event listeners
90
+ * Note: Joystick events are handled via handleJoystickChange() method
91
+ */
92
+ protected setupListeners(): void;
93
+ /**
94
+ * Cleanup joystick intervals
95
+ */
96
+ protected cleanup(): void;
97
+ /**
98
+ * Process joystick inputs each step
99
+ * Continuous actions are handled by the interval; no inactivity timeout here.
100
+ */
101
+ protected preStep(): void;
102
+ /**
103
+ * Handle joystick change event
104
+ * Called by the Joystick component when its position changes
105
+ *
106
+ * @param event - Joystick change event containing angle, direction, and power
107
+ */
108
+ handleJoystickChange(event: JoystickChangeEvent): void;
109
+ /**
110
+ * Handle joystick start event
111
+ * Called when user starts interacting with the joystick
112
+ */
113
+ handleJoystickStart(): void;
114
+ /**
115
+ * Handle joystick end event
116
+ * Called when user stops interacting with the joystick
117
+ */
118
+ handleJoystickEnd(): void;
119
+ /**
120
+ * Stop all active joystick movements
121
+ */
122
+ private stopAllMovements;
123
+ /**
124
+ * Process continuous joystick movement
125
+ * Called at intervals to repeat movement actions while joystick is active
126
+ */
127
+ private processJoystickMovement;
128
+ /**
129
+ * Update joystick configuration
130
+ * Merges provided config with defaults
131
+ *
132
+ * @param config - Partial joystick configuration
133
+ */
134
+ updateJoystickConfig(config: Partial<JoystickConfig>): void;
135
+ /**
136
+ * Extract joystick config from controls configuration and update
137
+ *
138
+ * @param inputs - Controls configuration that may contain a 'joystick' property
139
+ */
140
+ extractJoystickConfig(inputs: Controls & {
141
+ joystick?: JoystickConfig;
142
+ }): void;
143
+ /**
144
+ * Get the current joystick configuration
145
+ *
146
+ * @returns The joystick configuration object
147
+ */
148
+ getJoystickConfig(): JoystickConfig;
149
+ /**
150
+ * Apply a control action programmatically
151
+ * Uses the bound controls to trigger actions
152
+ *
153
+ * @param controlName - Name of the control
154
+ * @param isDown - Whether the control is pressed (true) or released (false)
155
+ * @returns Promise that resolves when the action is complete
156
+ */
157
+ applyControl(controlName: string | number, isDown?: boolean, payload?: any): Promise<void>;
158
+ /**
159
+ * Override setInputs to extract joystick config
160
+ */
161
+ setInputs(inputs: Controls & {
162
+ joystick?: JoystickConfig;
163
+ }): void;
164
+ /**
165
+ * Check if joystick is currently active
166
+ *
167
+ * @returns true if joystick is moving, false otherwise
168
+ */
169
+ isActive(): boolean;
170
+ }
171
+ //# sourceMappingURL=JoystickControls.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JoystickControls.d.ts","sourceRoot":"","sources":["../../src/directives/JoystickControls.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAExD;;GAEG;AACH,MAAM,MAAM,iBAAiB,GACvB,MAAM,GACN,OAAO,GACP,KAAK,GACL,QAAQ,GACR,UAAU,GACV,WAAW,GACX,aAAa,GACb,cAAc,CAAC;AAErB;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,iBAAiB,CAAC;IAC7B,KAAK,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,WAAW,cAAc;IAC3B,kDAAkD;IAClD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,yGAAyG;IACzG,gBAAgB,CAAC,EAAE;QACf,CAAC,iBAAiB,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC;KAClD,CAAC;IACF,4EAA4E;IAC5E,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,mEAA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