-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.d.ts
358 lines (352 loc) · 8.43 KB
/
main.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
declare module "phaser3-merged-input" {
import * as Phaser from "phaser";
export type KeyCode = keyof typeof Phaser.Input.Keyboard.KeyCodes;
export type Bearing =
| ""
| "W"
| "NW"
| "N"
| "NE"
| "E"
| "SE"
| "S"
| "SW";
export interface Player {
direction: {
UP: 0 | 1;
DOWN: 0 | 1;
LEFT: 0 | 1;
RIGHT: 0 | 1;
BEARING: Bearing;
BEARING_LAST: Bearing;
DEGREES: number;
DEGREES_LAST: number;
TIMESTAMP: number;
};
direction_secondary: {
UP: 0 | 1;
DOWN: 0 | 1;
LEFT: 0 | 1;
RIGHT: 0 | 1;
BEARING: Bearing;
BEARING_LAST: Bearing;
DEGREES: number;
DEGREES_LAST: number;
TIMESTAMP: number;
};
buttons: {
B1: 0 | 1;
B2: 0 | 1;
B3: 0 | 1;
B4: 0 | 1;
B5: 0 | 1;
B6: 0 | 1;
B7: 0 | 1;
B8: 0 | 1;
B9: 0 | 1;
B10: 0 | 1;
B11: 0 | 1;
B12: 0 | 1;
B13: 0 | 1;
B14: 0 | 1;
B15: 0 | 1;
B16: 0 | 1;
};
pointer: {
M1: 0 | 1;
M2: 0 | 1;
M3: 0 | 1;
M4: 0 | 1;
M5: 0 | 1;
BEARING: Bearing;
BEARING_DEGREES: number;
ANGLE: number;
TIMESTAMP: number;
};
position: {};
interaction: {
buffer: string[];
device: string;
pressed: string[];
released: string[];
lastPressed: string;
lastReleased: string;
};
interaction_mapped: {
isPressed: (button: string | string[]) => boolean;
};
gamepad: {
id: number;
index: number;
};
keys: {
UP: [];
DOWN: [];
LEFT: [];
RIGHT: [];
B1: [];
B2: [];
B3: [];
B4: [];
B5: [];
B6: [];
B7: [];
B8: [];
B9: [];
B10: [];
B11: [];
B12: [];
B13: [];
B14: [];
B15: [];
B16: [];
};
setPosition: (x: number, y: number) => void;
internal: {
fakedpadBuffer: string[];
fakedpadPressed: string[];
fakedpadReleased: string[];
};
}
export default class MergedInput {
/**
* The Merged Input plugin is designed to run in the background and handle input.
* Upon detecting a keypress or gamepad interaction, the plugin will update a player object and emit global events.
*
* @extends Phaser.Scene
* @param {*} scene
* @param {*} pluginManager
*/
constructor(scene: any, pluginManager: any);
scene: any;
players: Player[];
gamepads: any[];
keys: {};
bearings: {
"-180": string;
"-168.75": string;
"-157.5": string;
"-146.25": string;
"-135": string;
"-123.75": string;
"-112.5": string;
"-101.25": string;
"-90": string;
"-78.75": string;
"-67.5": string;
"-56.25": string;
"-45": string;
"-33.75": string;
"-22.5": string;
"-11.25": string;
"0": string;
"11.25": string;
"22.5": string;
"33.75": string;
"45": string;
"56.25": string;
"67.5": string;
"78.75": string;
"90": string;
"101.25": string;
"112.5": string;
"123.75": string;
"135": string;
"146.25": string;
"157.5": string;
"168.75": string;
"180": string;
};
refreshGamepads(): void;
boot(): void;
eventEmitter: any;
preupdate(): void;
postupdate(): void;
/**
* Set up the gamepad and associate with a player object
*/
setupGamepad(thisGamepad: any): void;
/**
* Add a new player object to the players array
* @param {number} index Player index - if a player object at this index already exists, it will be returned instead of creating a new player object
*/
addPlayer(index: number): Player;
/**
* Get player object
* @param {number} index Player index
*/
getPlayer(index: number): any;
getPlayerIndexFromKey(key: any): any;
getPlayerButtonFromKey(key): any;
/**
* Returns a struct to hold input control information
* Set up a struct for each player in the game
* Direction and Buttons contain the input from the devices
* The keys struct contains arrays of keyboard characters that will trigger the action
*/
setupControls(): {
direction: {
UP: number;
DOWN: number;
LEFT: number;
RIGHT: number;
BEARING: string;
BEARING_LAST: string;
DEGREES: number;
DEGREES_LAST: number;
TIMESTAMP: number;
};
direction_secondary: {
UP: number;
DOWN: number;
LEFT: number;
RIGHT: number;
BEARING: string;
DEGREES: number;
BEARING_LAST: string;
DEGREES_LAST: number;
TIMESTAMP: number;
};
buttons: {};
pointer: {
M1: number;
M2: number;
M3: number;
M4: number;
M5: number;
BEARING: string;
BEARING_DEGREES: number;
ANGLE: number;
TIMESTAMP: number;
};
position: {};
interaction: {
buffer: string[];
device: string;
pressed: string[];
released: string[];
lastPressed: string;
lastReleased: string;
};
gamepad: {};
keys: {
UP: any[];
DOWN: any[];
LEFT: any[];
RIGHT: any[];
};
};
/**
* Define a key for a player/action combination
* @param {number} player The player on which we're defining a key
* @param {string} action The action to define
* @param {string} value The key to use
* @param {boolean} append When true, this key definition will be appended to the existing key(s) for this action
*/
defineKey(
player: number,
action: string,
value: KeyCode,
append?: boolean
): MergedInput;
/**
* Iterate through players and check for interaction with defined keys
*/
checkKeyboardInput(): void;
/**
* When a keyboard button is pressed down, this function will emit a mergedInput event in the global registry.
* The event contains a reference to the player assigned to the key, and passes a mapped action and value
*/
keyboardKeyDown(event: KeyboardEvent): void;
/**
* When a keyboard button is released, this function will emit a mergedInput event in the global registry.
* The event contains a reference to the player assigned to the key, and passes a mapped action and value
*/
keyboardKeyUp(event: KeyboardEvent): void;
/**
* Iterate through players and check for interaction with defined pointer buttons
*/
checkPointerInput(): void;
/**
* When a gamepad button is pressed down, this function will emit a mergedInput event in the global registry.
* The event contains a reference to the player assigned to the gamepad, and passes a mapped action and value
* @param {number} index Button index
* @param {number} value Button value
* @param {Phaser.Input.Gamepad.Button} button Phaser Button object
*/
gamepadButtonDown(
pad: any,
button: Phaser.Input.Gamepad.Button,
value: number
): void;
/**
* When a gamepad button is released, this function will emit a mergedInput event in the global registry.
* The event contains a reference to the player assigned to the gamepad, and passes a mapped action and value
* @param {number} index Button index
* @param {number} value Button value
* @param {Phaser.Input.Gamepad.Button} button Phaser Button object
*/
gamepadButtonUp(
pad: any,
button: Phaser.Input.Gamepad.Button,
value: number
): void;
/**
* Iterate through gamepads and handle interactions
*/
checkGamepadInput(): void;
/**
* Function to run on pointer move.
* @param {*} pointer - The pointer object
*/
pointerMove(pointer: any, threshold: any): void;
/**
* Function to run on pointer down. Indicates that Mx has been pressed, which should be listened to by the player object
* @param {*} pointer - The pointer object
*/
pointerDown(pointer: any): void;
/**
* Function to run on pointer up. Indicates that Mx has been released, which should be listened to by the player object
* @param {*} pointer - The pointer object
*/
pointerUp(pointer: any): void;
/**
* Get the bearing from a given angle
* @param {float} angle - Angle to use
* @param {number} numDirections - Number of possible directions (e.g. 4 for N/S/E/W)
*/
getBearingFromAngle(
angle: number,
numDirections: number,
threshold: any
): any;
/**
* Given a bearing, return a direction object containing boolean flags for the four directions
* @param {*} bearing
*/
mapBearingToDirections(bearing: any): {
UP: number;
DOWN: number;
LEFT: number;
RIGHT: number;
BEARING: any;
};
/**
* Given a directions object, return the applicable bearing (8 way only)
* @param {*} directions
*/
mapDirectionsToBearing(directions: any, threshold: any): Bearing;
/**
* Given a bearing, return the snapped angle in degrees
* @param {*} bearing
*/
mapBearingToDegrees(bearing: any): any;
destroy(): void;
/**
* Return debug object
*/
debug(): {
input: {};
};
}
}