canvasengine 2.0.0-beta.33 → 2.0.0-beta.35
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.
- package/dist/{DebugRenderer-BYa_lwD-.js → DebugRenderer-DMqhoMfE.js} +2 -2
- package/dist/{DebugRenderer-BYa_lwD-.js.map → DebugRenderer-DMqhoMfE.js.map} +1 -1
- package/dist/components/Sprite.d.ts +44 -0
- package/dist/components/Sprite.d.ts.map +1 -1
- package/dist/directives/Controls.d.ts +102 -0
- package/dist/directives/Controls.d.ts.map +1 -0
- package/dist/directives/ControlsBase.d.ts +198 -0
- package/dist/directives/ControlsBase.d.ts.map +1 -0
- package/dist/directives/GamepadControls.d.ts +223 -0
- package/dist/directives/GamepadControls.d.ts.map +1 -0
- package/dist/directives/KeyboardControls.d.ts +55 -366
- package/dist/directives/KeyboardControls.d.ts.map +1 -1
- package/dist/directives/index.d.ts +9 -1
- package/dist/directives/index.d.ts.map +1 -1
- package/dist/{index-BLbc2zG5.js → index-B9ATEmLe.js} +3926 -3564
- package/dist/index-B9ATEmLe.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.global.js +6 -6
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +68 -57
- package/package.json +2 -1
- package/src/components/Sprite.ts +87 -3
- package/src/directives/Controls.ts +182 -0
- package/src/directives/ControlsBase.ts +266 -0
- package/src/directives/GamepadControls.ts +515 -0
- package/src/directives/KeyboardControls.ts +66 -426
- package/src/directives/index.ts +9 -6
- package/src/index.ts +1 -1
- package/dist/index-BLbc2zG5.js.map +0 -1
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { ControlsBase, Controls } from './ControlsBase';
|
|
2
|
+
import { WritableSignal } from '@signe/reactive';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Gamepad configuration interface
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* const gamepadConfig: GamepadConfig = {
|
|
10
|
+
* enabled: true,
|
|
11
|
+
* buttonMapping: {
|
|
12
|
+
* 'button_0': 'action',
|
|
13
|
+
* 'button_1': 'back'
|
|
14
|
+
* },
|
|
15
|
+
* axisMapping: {
|
|
16
|
+
* 'top': 'up',
|
|
17
|
+
* 'bottom': 'down',
|
|
18
|
+
* 'left': 'left',
|
|
19
|
+
* 'right': 'right'
|
|
20
|
+
* },
|
|
21
|
+
* moveInterval: 400,
|
|
22
|
+
* onConnect: () => console.log('Gamepad connected!'),
|
|
23
|
+
* onDisconnect: () => console.log('Gamepad disconnected!')
|
|
24
|
+
* };
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export interface GamepadConfig {
|
|
28
|
+
/** Whether gamepad is enabled (default: true) */
|
|
29
|
+
enabled?: boolean;
|
|
30
|
+
/** Mapping of gamepad button names to control names */
|
|
31
|
+
buttonMapping?: {
|
|
32
|
+
[buttonName: string]: string;
|
|
33
|
+
};
|
|
34
|
+
/** Mapping of axis directions to control directions */
|
|
35
|
+
axisMapping?: {
|
|
36
|
+
[axisDirection: string]: string;
|
|
37
|
+
};
|
|
38
|
+
/** Threshold for axis movement detection (default: 0.5) */
|
|
39
|
+
axisThreshold?: number;
|
|
40
|
+
/** Interval in milliseconds for repeating movement actions (default: 400) */
|
|
41
|
+
moveInterval?: number;
|
|
42
|
+
/** Callback called when a gamepad is connected */
|
|
43
|
+
onConnect?: () => void;
|
|
44
|
+
/** Callback called when a gamepad is disconnected */
|
|
45
|
+
onDisconnect?: () => void;
|
|
46
|
+
/** Signal that tracks gamepad connection status (optional) */
|
|
47
|
+
gamepadConnected?: WritableSignal<boolean>;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Gamepad input controls implementation
|
|
51
|
+
*
|
|
52
|
+
* Handles gamepad input events using joypad.js library and maps them to control actions.
|
|
53
|
+
* Supports button presses and analog stick movement with configurable mappings.
|
|
54
|
+
*
|
|
55
|
+
* The gamepad controls are automatically activated when joypad.js is available and enabled.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* const gamepadControls = new GamepadControls();
|
|
60
|
+
* gamepadControls.setInputs({
|
|
61
|
+
* up: {
|
|
62
|
+
* repeat: true,
|
|
63
|
+
* bind: 'up',
|
|
64
|
+
* keyDown() {
|
|
65
|
+
* console.log('Up pressed');
|
|
66
|
+
* }
|
|
67
|
+
* }
|
|
68
|
+
* });
|
|
69
|
+
* gamepadControls.updateGamepadConfig({
|
|
70
|
+
* enabled: true,
|
|
71
|
+
* buttonMapping: {
|
|
72
|
+
* 'button_0': 'action'
|
|
73
|
+
* }
|
|
74
|
+
* });
|
|
75
|
+
* gamepadControls.start();
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export declare class GamepadControls extends ControlsBase {
|
|
79
|
+
private gamepadEnabled;
|
|
80
|
+
private gamepadConfig;
|
|
81
|
+
private gamepadMoving;
|
|
82
|
+
private gamepadDirections;
|
|
83
|
+
private gamepadAxisDate;
|
|
84
|
+
private gamepadMoveInterval;
|
|
85
|
+
private joypad;
|
|
86
|
+
private connectCallbacks;
|
|
87
|
+
private disconnectCallbacks;
|
|
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
|
+
* @returns Promise that resolves when the action is complete
|
|
161
|
+
*/
|
|
162
|
+
applyControl(controlName: string | number, isDown?: boolean): Promise<void>;
|
|
163
|
+
/**
|
|
164
|
+
* Override setInputs to extract gamepad config
|
|
165
|
+
*/
|
|
166
|
+
setInputs(inputs: Controls & {
|
|
167
|
+
gamepad?: GamepadConfig;
|
|
168
|
+
}): void;
|
|
169
|
+
/**
|
|
170
|
+
* Register a callback to be called when a gamepad is connected
|
|
171
|
+
*
|
|
172
|
+
* @param callback - Function to call when gamepad connects
|
|
173
|
+
* @example
|
|
174
|
+
* ```ts
|
|
175
|
+
* gamepadControls.onConnect(() => {
|
|
176
|
+
* console.log('Gamepad connected!');
|
|
177
|
+
* });
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
onConnect(callback: () => void): void;
|
|
181
|
+
/**
|
|
182
|
+
* Register a callback to be called when a gamepad is disconnected
|
|
183
|
+
*
|
|
184
|
+
* @param callback - Function to call when gamepad disconnects
|
|
185
|
+
* @example
|
|
186
|
+
* ```ts
|
|
187
|
+
* gamepadControls.onDisconnect(() => {
|
|
188
|
+
* console.log('Gamepad disconnected!');
|
|
189
|
+
* });
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
onDisconnect(callback: () => void): void;
|
|
193
|
+
/**
|
|
194
|
+
* Remove a connect callback
|
|
195
|
+
*
|
|
196
|
+
* @param callback - Callback to remove
|
|
197
|
+
*/
|
|
198
|
+
offConnect(callback: () => void): void;
|
|
199
|
+
/**
|
|
200
|
+
* Remove a disconnect callback
|
|
201
|
+
*
|
|
202
|
+
* @param callback - Callback to remove
|
|
203
|
+
*/
|
|
204
|
+
offDisconnect(callback: () => void): void;
|
|
205
|
+
/**
|
|
206
|
+
* Check if gamepad is currently connected
|
|
207
|
+
*
|
|
208
|
+
* @returns true if gamepad is connected, false otherwise
|
|
209
|
+
*/
|
|
210
|
+
isConnected(): boolean;
|
|
211
|
+
/**
|
|
212
|
+
* Reinitialize gamepad listeners
|
|
213
|
+
* Useful if joypad.js becomes available after initialization
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* ```ts
|
|
217
|
+
* // If joypad.js loads later
|
|
218
|
+
* gamepadControls.reinit();
|
|
219
|
+
* ```
|
|
220
|
+
*/
|
|
221
|
+
reinit(): void;
|
|
222
|
+
}
|
|
223
|
+
//# 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,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,WAAW,CAAA;AAElB;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,WAAW,aAAa;IAC1B,iDAAiD;IACjD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,uDAAuD;IACvD,aAAa,CAAC,EAAE;QACZ,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAAC;KAChC,CAAC;IACF,uDAAuD;IACvD,WAAW,CAAC,EAAE;QACV,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAAC;KACnC,CAAC;IACF,2DAA2D;IAC3D,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,6EAA6E;IAC7E,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,kDAAkD;IAClD,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,qDAAqD;IACrD,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;IAC1B,8DAA8D;IAC9D,gBAAgB,CAAC,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC;CAC9C;AAqBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,qBAAa,eAAgB,SAAQ,YAAY;IAC7C,OAAO,CAAC,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IAIrC;;;;;;;;;;OAUG;IACH,YAAY,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI;IAIxC;;;;OAIG;IACH,UAAU,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI;IAOtC;;;;OAIG;IACH,aAAa,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI;IAOzC;;;;OAIG;IACH,WAAW,IAAI,OAAO;IAItB;;;;;;;;;OASG;IACH,MAAM,IAAI,IAAI;CAKjB"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Element } from '../engine/reactive';
|
|
1
|
+
import { ControlsBase, ControlOptions, Controls, BoundKey } from './ControlsBase';
|
|
3
2
|
|
|
4
3
|
export declare enum Input {
|
|
5
4
|
Break = "break",
|
|
@@ -142,42 +141,49 @@ export declare enum Input {
|
|
|
142
141
|
BackQuote = "`",
|
|
143
142
|
Altgr = "altgr"
|
|
144
143
|
}
|
|
145
|
-
export
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
|
|
144
|
+
export type { ControlOptions, Controls, BoundKey };
|
|
145
|
+
/**
|
|
146
|
+
* Keyboard input controls implementation
|
|
147
|
+
*
|
|
148
|
+
* Handles keyboard input events and maps them to control actions.
|
|
149
|
+
* Supports composite directions (diagonal movement) and key repeat functionality.
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```ts
|
|
153
|
+
* const keyboardControls = new KeyboardControls();
|
|
154
|
+
* keyboardControls.setInputs({
|
|
155
|
+
* up: {
|
|
156
|
+
* repeat: true,
|
|
157
|
+
* bind: Input.Up,
|
|
158
|
+
* keyDown() {
|
|
159
|
+
* console.log('Up pressed');
|
|
160
|
+
* }
|
|
161
|
+
* }
|
|
162
|
+
* });
|
|
163
|
+
* keyboardControls.start();
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
export declare class KeyboardControls extends ControlsBase {
|
|
164
167
|
private keyState;
|
|
165
|
-
private boundKeys;
|
|
166
|
-
private stop;
|
|
167
168
|
private lastKeyPressed;
|
|
168
|
-
private _controlsOptions;
|
|
169
|
-
private interval;
|
|
170
|
-
private serverFps;
|
|
171
169
|
private directionState;
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
170
|
+
/**
|
|
171
|
+
* Setup keyboard event listeners
|
|
172
|
+
*/
|
|
173
|
+
protected setupListeners(): void;
|
|
174
|
+
/**
|
|
175
|
+
* Cleanup keyboard event listeners
|
|
176
|
+
*/
|
|
177
|
+
protected cleanup(): void;
|
|
178
|
+
/**
|
|
179
|
+
* Process keyboard inputs each step
|
|
180
|
+
*/
|
|
181
|
+
protected preStep(): void;
|
|
182
|
+
/**
|
|
183
|
+
* Apply input for a keyboard key
|
|
184
|
+
* Overrides base implementation to handle key state and repeat logic
|
|
185
|
+
*/
|
|
186
|
+
protected applyInput(keyName: string): void;
|
|
181
187
|
private applyKeyDown;
|
|
182
188
|
private applyKeyUp;
|
|
183
189
|
private applyKeyPress;
|
|
@@ -185,346 +191,29 @@ export declare class KeyboardControls extends Directive {
|
|
|
185
191
|
private updateDirectionState;
|
|
186
192
|
private getDirection;
|
|
187
193
|
/**
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
* ```ts
|
|
191
|
-
* import { Input, inject, KeyboardControls } from '@rpgjs/client'
|
|
192
|
-
*
|
|
193
|
-
* const controls = inject(KeyboardControls)
|
|
194
|
-
* controls.getControl(Input.Enter)
|
|
195
|
-
|
|
196
|
-
* if (control) {
|
|
197
|
-
* console.log(control.actionName) // action
|
|
198
|
-
* }
|
|
199
|
-
* ```
|
|
200
|
-
* @title Get Control
|
|
201
|
-
* @method getControl(inputName)
|
|
202
|
-
* @param {string} inputName
|
|
203
|
-
* @returns { { actionName: string, options: any } | undefined }
|
|
204
|
-
* @memberof KeyboardControls
|
|
205
|
-
*/
|
|
206
|
-
getControl(inputName: string): BoundKey | undefined;
|
|
207
|
-
/**
|
|
208
|
-
* Returns all controls
|
|
209
|
-
*
|
|
210
|
-
* @method getControls()
|
|
211
|
-
* @since 4.2.0
|
|
212
|
-
* @returns { { [key: string]: BoundKey } }
|
|
213
|
-
* @memberof KeyboardControls
|
|
214
|
-
*/
|
|
215
|
-
getControls(): {
|
|
216
|
-
[key: string]: BoundKey;
|
|
217
|
-
};
|
|
218
|
-
/**
|
|
219
|
-
* Triggers an input according to the name of the control
|
|
194
|
+
* Apply a control action programmatically
|
|
195
|
+
* Triggers keyboard events to simulate key presses
|
|
220
196
|
*
|
|
197
|
+
* @param controlName - Name of the control
|
|
198
|
+
* @param isDown - Whether the key is pressed (true) or released (false)
|
|
199
|
+
* @returns Promise that resolves when the action is complete
|
|
200
|
+
* @example
|
|
221
201
|
* ```ts
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
* const controls = inject(KeyboardControls)
|
|
225
|
-
* controls.applyControl(Control.Action)
|
|
226
|
-
* ```
|
|
227
|
-
*
|
|
228
|
-
* You can put a second parameter or indicate on whether the key is pressed or released
|
|
202
|
+
* // Press a key
|
|
203
|
+
* await keyboardControls.applyControl('action', true);
|
|
229
204
|
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
205
|
+
* // Release a key
|
|
206
|
+
* await keyboardControls.applyControl('action', false);
|
|
232
207
|
*
|
|
233
|
-
*
|
|
234
|
-
*
|
|
235
|
-
* controls.applyControl(Control.Up, false) // keyup
|
|
208
|
+
* // Press and release (default)
|
|
209
|
+
* await keyboardControls.applyControl('action');
|
|
236
210
|
* ```
|
|
237
|
-
* @title Apply Control
|
|
238
|
-
* @method applyControl(controlName,isDown)
|
|
239
|
-
* @param {string} controlName
|
|
240
|
-
* @param {boolean} [isDown]
|
|
241
|
-
* @returns {Promise<void>}
|
|
242
|
-
* @memberof KeyboardControls
|
|
243
211
|
*/
|
|
244
212
|
applyControl(controlName: string | number, isDown?: boolean | undefined): Promise<void>;
|
|
245
213
|
/**
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
* @title Stop Inputs
|
|
249
|
-
* @method stopInputs()
|
|
250
|
-
* @returns {void}
|
|
251
|
-
* @memberof KeyboardControls
|
|
252
|
-
*/
|
|
253
|
-
stopInputs(): void;
|
|
254
|
-
/**
|
|
255
|
-
* Listen to the inputs again
|
|
256
|
-
*
|
|
257
|
-
* @title Listen Inputs
|
|
258
|
-
* @method listenInputs()
|
|
259
|
-
* @returns {void}
|
|
260
|
-
* @memberof KeyboardControls
|
|
214
|
+
* Resume listening to inputs after stopInputs() was called
|
|
215
|
+
* Also resets keyboard state
|
|
261
216
|
*/
|
|
262
217
|
listenInputs(): void;
|
|
263
|
-
/**
|
|
264
|
-
* Assign custom inputs to the scene
|
|
265
|
-
*
|
|
266
|
-
* The object is the following:
|
|
267
|
-
*
|
|
268
|
-
* * the key of the object is the name of the control. Either it is existing controls (Up, Dow, Left, Right, Action, Back) or customized controls
|
|
269
|
-
* * The value is an object representing control information:
|
|
270
|
-
* * repeat {boolean} The key can be held down to repeat the action. (false by default)
|
|
271
|
-
* * bind {string | string[]} To which key is linked the control
|
|
272
|
-
* * method {Function} Function to be triggered. If you do not set this property, the name of the control is sent directly to the server.
|
|
273
|
-
* * delay {object|number} (since v3.2.0) Indicates how long (in milliseconds) the player can press the key again to perform the action
|
|
274
|
-
* * delay.duration
|
|
275
|
-
* * delay.otherControls {string | string[]} Indicates the other controls that will also have the delay at the same time
|
|
276
|
-
*
|
|
277
|
-
* ```ts
|
|
278
|
-
* import { Control, Input, inject, KeyboardControls } from '@rpgjs/client'
|
|
279
|
-
*
|
|
280
|
-
* const controls = inject(KeyboardControls)
|
|
281
|
-
* controls.setInputs({
|
|
282
|
-
[Control.Up]: {
|
|
283
|
-
repeat: true,
|
|
284
|
-
bind: Input.Up
|
|
285
|
-
},
|
|
286
|
-
[Control.Down]: {
|
|
287
|
-
repeat: true,
|
|
288
|
-
bind: Input.Down
|
|
289
|
-
},
|
|
290
|
-
[Control.Right]: {
|
|
291
|
-
repeat: true,
|
|
292
|
-
bind: Input.Right
|
|
293
|
-
},
|
|
294
|
-
[Control.Left]: {
|
|
295
|
-
repeat: true,
|
|
296
|
-
bind: Input.Left
|
|
297
|
-
},
|
|
298
|
-
[Control.Action]: {
|
|
299
|
-
bind: [Input.Space, Input.Enter]
|
|
300
|
-
},
|
|
301
|
-
[Control.Back]: {
|
|
302
|
-
bind: Input.Escape
|
|
303
|
-
},
|
|
304
|
-
|
|
305
|
-
// The myscustom1 control is sent to the server when the A key is pressed.
|
|
306
|
-
mycustom1: {
|
|
307
|
-
bind: Input.A
|
|
308
|
-
},
|
|
309
|
-
|
|
310
|
-
// the myAction method is executed when the B key is pressed
|
|
311
|
-
mycustom2: {
|
|
312
|
-
bind: Input.B,
|
|
313
|
-
method({ actionName }) {
|
|
314
|
-
console.log('cool', actionName)
|
|
315
|
-
}
|
|
316
|
-
},
|
|
317
|
-
|
|
318
|
-
// The player can redo the action after 400ms
|
|
319
|
-
mycustom3: {
|
|
320
|
-
bind: Input.C,
|
|
321
|
-
delay: 400 // ms
|
|
322
|
-
},
|
|
323
|
-
|
|
324
|
-
// The player can redo the action (mycustom4) and the directions after 400ms
|
|
325
|
-
mycustom4: {
|
|
326
|
-
bind: Input.C,
|
|
327
|
-
delay: {
|
|
328
|
-
duration: 400,
|
|
329
|
-
otherControls: [Control.Up, Control.Down, Control.Left, Control.Right]
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
})
|
|
333
|
-
*
|
|
334
|
-
* ```
|
|
335
|
-
* @enum {string} Control
|
|
336
|
-
*
|
|
337
|
-
* Control.Up | up
|
|
338
|
-
* Control.Down | down
|
|
339
|
-
* Control.Left | left
|
|
340
|
-
* Control.Right | right
|
|
341
|
-
* Control.Action | action
|
|
342
|
-
* Control.Back | back
|
|
343
|
-
*
|
|
344
|
-
* @enum {string} Mouse Event
|
|
345
|
-
*
|
|
346
|
-
* click | Click
|
|
347
|
-
* dblclick | Double Click
|
|
348
|
-
* mousedown | Mouse Down
|
|
349
|
-
* mouseup | Mouse Up
|
|
350
|
-
* mouseover | Mouse Over
|
|
351
|
-
* mousemove | Mouse Move
|
|
352
|
-
* mouseout | Mouse Out
|
|
353
|
-
* contextmenu | Context Menu
|
|
354
|
-
*
|
|
355
|
-
*
|
|
356
|
-
* @enum {string} Input
|
|
357
|
-
*
|
|
358
|
-
* break | Pause
|
|
359
|
-
* backspace | Backspace / Delete
|
|
360
|
-
* tab | Tab
|
|
361
|
-
* clear | Clear
|
|
362
|
-
* enter | Enter
|
|
363
|
-
* shift | Shift
|
|
364
|
-
* ctrl | Control
|
|
365
|
-
* alt | Alt
|
|
366
|
-
* pause/break | Pause / Break
|
|
367
|
-
* caps lock | Caps Lock
|
|
368
|
-
* escape | Escape
|
|
369
|
-
* conversion | Conversion
|
|
370
|
-
* non-conversion | Non-conversion
|
|
371
|
-
* space | Space
|
|
372
|
-
* page up | Page Up
|
|
373
|
-
* page down | Page Down
|
|
374
|
-
* end | End
|
|
375
|
-
* home | Home
|
|
376
|
-
* left | Left Arrow
|
|
377
|
-
* up | Up Arrow
|
|
378
|
-
* right | Right Arrow
|
|
379
|
-
* down | Down Arrow
|
|
380
|
-
* select | Select
|
|
381
|
-
* print | Print
|
|
382
|
-
* execute | Execute
|
|
383
|
-
* Print Screen | Print Screen
|
|
384
|
-
* insert | Insert
|
|
385
|
-
* delete | Delete
|
|
386
|
-
* n0 | 0
|
|
387
|
-
* n1 | 1
|
|
388
|
-
* n2 | 2
|
|
389
|
-
* n3 | 3
|
|
390
|
-
* n4 | 4
|
|
391
|
-
* n5 | 5
|
|
392
|
-
* n6 | 6
|
|
393
|
-
* n7 | 7
|
|
394
|
-
* n8 | 8
|
|
395
|
-
* n9 | 9
|
|
396
|
-
* : | Colon
|
|
397
|
-
* semicolon (firefox), equals | Semicolon (Firefox), Equals
|
|
398
|
-
* < | Less Than
|
|
399
|
-
* equals (firefox) | Equals (Firefox)
|
|
400
|
-
* ß | Eszett
|
|
401
|
-
* @ | At
|
|
402
|
-
* a | A
|
|
403
|
-
* b | B
|
|
404
|
-
* c | C
|
|
405
|
-
* d | D
|
|
406
|
-
* e | E
|
|
407
|
-
* f | F
|
|
408
|
-
* g | G
|
|
409
|
-
* h | H
|
|
410
|
-
* i | I
|
|
411
|
-
* j | J
|
|
412
|
-
* k | K
|
|
413
|
-
* l | L
|
|
414
|
-
* m | M
|
|
415
|
-
* n | N
|
|
416
|
-
* o | O
|
|
417
|
-
* p | P
|
|
418
|
-
* q | Q
|
|
419
|
-
* r | R
|
|
420
|
-
* s | S
|
|
421
|
-
* t | T
|
|
422
|
-
* u | U
|
|
423
|
-
* v | V
|
|
424
|
-
* w | W
|
|
425
|
-
* x | X
|
|
426
|
-
* y | Y
|
|
427
|
-
* z | Z
|
|
428
|
-
* Windows Key / Left ⌘ / Chromebook Search key | Windows Key / Left Command ⌘ / Chromebook Search Key
|
|
429
|
-
* right window key | Right Windows Key
|
|
430
|
-
* Windows Menu / Right ⌘ | Windows Menu / Right Command ⌘
|
|
431
|
-
* numpad 0 | Numpad 0
|
|
432
|
-
* numpad 1 | Numpad 1
|
|
433
|
-
* numpad 2 | Numpad 2
|
|
434
|
-
* numpad 3 | Numpad 3
|
|
435
|
-
* numpad 4 | Numpad 4
|
|
436
|
-
* numpad 5 | Numpad 5
|
|
437
|
-
* numpad 6 | Numpad 6
|
|
438
|
-
* numpad 7 | Numpad 7
|
|
439
|
-
* numpad 8 | Numpad 8
|
|
440
|
-
* numpad 9 | Numpad 9
|
|
441
|
-
* multiply | Multiply
|
|
442
|
-
* add | Add
|
|
443
|
-
* numpad period (firefox) | Numpad Period (Firefox)
|
|
444
|
-
* subtract | Subtract
|
|
445
|
-
* decimal point | Decimal Point
|
|
446
|
-
* divide | Divide
|
|
447
|
-
* f1 | F1
|
|
448
|
-
* f2 | F2
|
|
449
|
-
* f3 | F3
|
|
450
|
-
* f4 | F4
|
|
451
|
-
* f5 | F5
|
|
452
|
-
* f6 | F6
|
|
453
|
-
* f7 | F7
|
|
454
|
-
* f8 | F8
|
|
455
|
-
* f9 | F9
|
|
456
|
-
* f10 | F10
|
|
457
|
-
* f11 | F11
|
|
458
|
-
* f12 | F12
|
|
459
|
-
* f13 | F13
|
|
460
|
-
* f14 | F14
|
|
461
|
-
* f15 | F15
|
|
462
|
-
* f16 | F16
|
|
463
|
-
* f17 | F17
|
|
464
|
-
* f18 | F18
|
|
465
|
-
* f19 | F19
|
|
466
|
-
* f20 | F20
|
|
467
|
-
* f21 | F21
|
|
468
|
-
* f22 | F22
|
|
469
|
-
* f23 | F23
|
|
470
|
-
* f24 | F24
|
|
471
|
-
* num lock | Num Lock
|
|
472
|
-
* scroll lock | Scroll Lock
|
|
473
|
-
* ^ | Caret
|
|
474
|
-
* ! | Exclamation Point
|
|
475
|
-
* # | Hash
|
|
476
|
-
* $ | Dollar Sign
|
|
477
|
-
* ù | Grave Accent U
|
|
478
|
-
* page backward | Page Backward
|
|
479
|
-
* page forward | Page Forward
|
|
480
|
-
* closing paren (AZERTY) | Closing Parenthesis (AZERTY)
|
|
481
|
-
* * | Asterisk
|
|
482
|
-
* ~ + * key | Tilde + Asterisk Key
|
|
483
|
-
* minus (firefox), mute/unmute | Minus (Firefox), Mute/Unmute
|
|
484
|
-
* decrease volume level | Decrease Volume Level
|
|
485
|
-
* increase volume level | Increase Volume Level
|
|
486
|
-
* next | Next
|
|
487
|
-
* previous | Previous
|
|
488
|
-
* stop | Stop
|
|
489
|
-
* play/pause | Play/Pause
|
|
490
|
-
* e-mail | Email
|
|
491
|
-
* mute/unmute (firefox) | Mute/Unmute (Firefox)
|
|
492
|
-
* decrease volume level (firefox) | Decrease Volume Level (Firefox)
|
|
493
|
-
* increase volume level (firefox) | Increase Volume Level (Firefox)
|
|
494
|
-
* semi-colon / ñ | Semicolon / ñ
|
|
495
|
-
* equal sign | Equal Sign
|
|
496
|
-
* comma | Comma
|
|
497
|
-
* dash | Dash
|
|
498
|
-
* period | Period
|
|
499
|
-
* forward slash / ç | Forward Slash / ç
|
|
500
|
-
* grave accent / ñ / æ | Grave Accent / ñ / æ
|
|
501
|
-
* ?, / or ° | ?, / or °
|
|
502
|
-
* numpad period (chrome) | Numpad Period (Chrome)
|
|
503
|
-
* open bracket | Open Bracket
|
|
504
|
-
* back slash | Backslash
|
|
505
|
-
* close bracket / å | Close Bracket / å
|
|
506
|
-
* single quote / ø | Single Quote / ø
|
|
507
|
-
* \` | Backtick
|
|
508
|
-
* left or right ⌘ key (firefox) | Left or Right Command Key (Firefox)
|
|
509
|
-
* altgr | AltGr
|
|
510
|
-
* < /git > | < /git >
|
|
511
|
-
* GNOME Compose Key | GNOME Compose Key
|
|
512
|
-
* ç | ç
|
|
513
|
-
* XF86Forward | XF86Forward
|
|
514
|
-
* XF86Back | XF86Back
|
|
515
|
-
* alphanumeric | Alphanumeric
|
|
516
|
-
* hiragana/katakana | Hiragana/Katakana
|
|
517
|
-
* half-width/full-width | Half-Width/Full-Width
|
|
518
|
-
* kanji | Kanji
|
|
519
|
-
* toggle touchpad | Toggle Touchpad
|
|
520
|
-
*
|
|
521
|
-
* @title Set Inputs
|
|
522
|
-
* @method setInputs(inputs)
|
|
523
|
-
* @param {object} inputs
|
|
524
|
-
* @memberof KeyboardControls
|
|
525
|
-
*/
|
|
526
|
-
setInputs(inputs: Controls): void;
|
|
527
|
-
get options(): Controls;
|
|
528
218
|
}
|
|
529
|
-
export {};
|
|
530
219
|
//# sourceMappingURL=KeyboardControls.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KeyboardControls.d.ts","sourceRoot":"","sources":["../../src/directives/KeyboardControls.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"KeyboardControls.d.ts","sourceRoot":"","sources":["../../src/directives/KeyboardControls.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAElF,oBAAY,KAAK;IACb,KAAK,UAAU;IACf,SAAS,cAAc;IACvB,GAAG,QAAQ;IACX,KAAK,UAAU;IACf,KAAK,UAAU;IACf,KAAK,UAAU;IACf,IAAI,SAAS;IACb,GAAG,QAAQ;IACX,KAAK,gBAAgB;IACrB,QAAQ,cAAc;IACtB,MAAM,WAAW;IACjB,UAAU,eAAe;IACzB,aAAa,mBAAmB;IAChC,KAAK,UAAU;IACf,MAAM,YAAY;IAClB,QAAQ,cAAc;IACtB,GAAG,QAAQ;IACX,IAAI,SAAS;IACb,IAAI,IAAI;IACR,EAAE,IAAI;IACN,KAAK,IAAI;IACT,IAAI,IAAI;IACR,MAAM,WAAW;IACjB,KAAK,UAAU;IACf,OAAO,YAAY;IACnB,WAAW,iBAAiB;IAC5B,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,IAAI,MAAM;IACV,GAAG,MAAM;IACT,GAAG,MAAM;IACT,KAAK,MAAM;IACX,IAAI,MAAM;IACV,IAAI,MAAM;IACV,GAAG,MAAM;IACT,KAAK,MAAM;IACX,MAAM,MAAM;IACZ,IAAI,MAAM;IACV,KAAK,MAAM;IACX,SAAS,gCAAgC;IACzC,QAAQ,MAAM;IACd,MAAM,qBAAqB;IAC3B,IAAI,WAAM;IACV,EAAE,MAAM;IACR,CAAC,MAAM;IACP,CAAC,MAAM;IACP,CAAC,MAAM;IACP,CAAC,MAAM;IACP,CAAC,MAAM;IACP,CAAC,MAAM;IACP,CAAC,MAAM;IACP,CAAC,MAAM;IACP,CAAC,MAAM;IACP,CAAC,MAAM;IACP,CAAC,MAAM;IACP,CAAC,MAAM;IACP,CAAC,MAAM;IACP,CAA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