@myeiter/mcy-web 1.0.1 → 1.0.2
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/app/canvas_loop.d.ts.map +1 -1
- package/dist/app/canvas_loop.js +2 -2
- package/dist/app/canvas_loop.js.map +1 -1
- package/dist/app/input.d.ts +141 -134
- package/dist/app/input.d.ts.map +1 -1
- package/dist/app/input.js +284 -291
- package/dist/app/input.js.map +1 -1
- package/package.json +1 -1
- package/dist/app/drawing.d.ts +0 -35
- package/dist/app/drawing.d.ts.map +0 -1
- package/dist/app/drawing.js +0 -173
- package/dist/app/drawing.js.map +0 -1
- package/dist/core/math.d.ts +0 -21
- package/dist/core/math.d.ts.map +0 -1
- package/dist/core/math.js +0 -53
- package/dist/core/math.js.map +0 -1
package/dist/app/input.js
CHANGED
|
@@ -1,57 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// noinspection JSUnusedGlobalSymbols
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.
|
|
5
|
-
exports.InputInit = InputInit;
|
|
6
|
-
exports.InputEndFrame = InputEndFrame;
|
|
7
|
-
exports.InputMouseDelta = InputMouseDelta;
|
|
8
|
-
exports.InputMouseDeltaX = InputMouseDeltaX;
|
|
9
|
-
exports.InputMouseDeltaY = InputMouseDeltaY;
|
|
10
|
-
exports.InputKeyDown = InputKeyDown;
|
|
11
|
-
exports.InputKeyDownThisFrame = InputKeyDownThisFrame;
|
|
12
|
-
exports.InputKeyUpThisFrame = InputKeyUpThisFrame;
|
|
13
|
-
exports.InputMouseDown = InputMouseDown;
|
|
14
|
-
exports.InputMouseDownThisFrame = InputMouseDownThisFrame;
|
|
15
|
-
exports.InputMouseUpThisFrame = InputMouseUpThisFrame;
|
|
16
|
-
exports.InputMousePos = InputMousePos;
|
|
3
|
+
exports.Input = exports.InputFlags = exports.MouseButton = exports.KeyKeyCodeMap = exports.KeyCode = void 0;
|
|
17
4
|
var KeyCode;
|
|
18
5
|
(function (KeyCode) {
|
|
19
|
-
KeyCode["A"] = "
|
|
20
|
-
KeyCode["B"] = "
|
|
21
|
-
KeyCode["C"] = "
|
|
22
|
-
KeyCode["D"] = "
|
|
23
|
-
KeyCode["E"] = "
|
|
24
|
-
KeyCode["F"] = "
|
|
25
|
-
KeyCode["G"] = "
|
|
26
|
-
KeyCode["H"] = "
|
|
27
|
-
KeyCode["I"] = "
|
|
28
|
-
KeyCode["J"] = "
|
|
29
|
-
KeyCode["K"] = "
|
|
30
|
-
KeyCode["L"] = "
|
|
31
|
-
KeyCode["M"] = "
|
|
32
|
-
KeyCode["N"] = "
|
|
33
|
-
KeyCode["O"] = "
|
|
34
|
-
KeyCode["P"] = "
|
|
35
|
-
KeyCode["Q"] = "
|
|
36
|
-
KeyCode["R"] = "
|
|
37
|
-
KeyCode["S"] = "
|
|
38
|
-
KeyCode["T"] = "
|
|
39
|
-
KeyCode["U"] = "
|
|
40
|
-
KeyCode["V"] = "
|
|
41
|
-
KeyCode["W"] = "
|
|
42
|
-
KeyCode["X"] = "
|
|
43
|
-
KeyCode["Y"] = "
|
|
44
|
-
KeyCode["Z"] = "
|
|
45
|
-
KeyCode["Digit0"] = "
|
|
46
|
-
KeyCode["Digit1"] = "
|
|
47
|
-
KeyCode["Digit2"] = "
|
|
48
|
-
KeyCode["Digit3"] = "
|
|
49
|
-
KeyCode["Digit4"] = "
|
|
50
|
-
KeyCode["Digit5"] = "
|
|
51
|
-
KeyCode["Digit6"] = "
|
|
52
|
-
KeyCode["Digit7"] = "
|
|
53
|
-
KeyCode["Digit8"] = "
|
|
54
|
-
KeyCode["Digit9"] = "
|
|
6
|
+
KeyCode["A"] = "KeyA";
|
|
7
|
+
KeyCode["B"] = "KeyB";
|
|
8
|
+
KeyCode["C"] = "KeyC";
|
|
9
|
+
KeyCode["D"] = "KeyD";
|
|
10
|
+
KeyCode["E"] = "KeyE";
|
|
11
|
+
KeyCode["F"] = "KeyF";
|
|
12
|
+
KeyCode["G"] = "KeyG";
|
|
13
|
+
KeyCode["H"] = "KeyH";
|
|
14
|
+
KeyCode["I"] = "KeyI";
|
|
15
|
+
KeyCode["J"] = "KeyJ";
|
|
16
|
+
KeyCode["K"] = "KeyK";
|
|
17
|
+
KeyCode["L"] = "KeyL";
|
|
18
|
+
KeyCode["M"] = "KeyM";
|
|
19
|
+
KeyCode["N"] = "KeyN";
|
|
20
|
+
KeyCode["O"] = "KeyO";
|
|
21
|
+
KeyCode["P"] = "KeyP";
|
|
22
|
+
KeyCode["Q"] = "KeyQ";
|
|
23
|
+
KeyCode["R"] = "KeyR";
|
|
24
|
+
KeyCode["S"] = "KeyS";
|
|
25
|
+
KeyCode["T"] = "KeyT";
|
|
26
|
+
KeyCode["U"] = "KeyU";
|
|
27
|
+
KeyCode["V"] = "KeyV";
|
|
28
|
+
KeyCode["W"] = "KeyW";
|
|
29
|
+
KeyCode["X"] = "KeyX";
|
|
30
|
+
KeyCode["Y"] = "KeyY";
|
|
31
|
+
KeyCode["Z"] = "KeyZ";
|
|
32
|
+
KeyCode["Digit0"] = "Digit0";
|
|
33
|
+
KeyCode["Digit1"] = "Digit1";
|
|
34
|
+
KeyCode["Digit2"] = "Digit2";
|
|
35
|
+
KeyCode["Digit3"] = "Digit3";
|
|
36
|
+
KeyCode["Digit4"] = "Digit4";
|
|
37
|
+
KeyCode["Digit5"] = "Digit5";
|
|
38
|
+
KeyCode["Digit6"] = "Digit6";
|
|
39
|
+
KeyCode["Digit7"] = "Digit7";
|
|
40
|
+
KeyCode["Digit8"] = "Digit8";
|
|
41
|
+
KeyCode["Digit9"] = "Digit9";
|
|
55
42
|
KeyCode["F1"] = "F1";
|
|
56
43
|
KeyCode["F2"] = "F2";
|
|
57
44
|
KeyCode["F3"] = "F3";
|
|
@@ -68,61 +55,75 @@ var KeyCode;
|
|
|
68
55
|
KeyCode["ArrowDown"] = "ArrowDown";
|
|
69
56
|
KeyCode["ArrowLeft"] = "ArrowLeft";
|
|
70
57
|
KeyCode["ArrowRight"] = "ArrowRight";
|
|
71
|
-
KeyCode["ShiftLeft"] = "
|
|
72
|
-
KeyCode["ControlLeft"] = "
|
|
73
|
-
KeyCode["AltLeft"] = "
|
|
74
|
-
KeyCode["MetaLeft"] = "
|
|
75
|
-
KeyCode["
|
|
58
|
+
KeyCode["ShiftLeft"] = "ShiftLeft";
|
|
59
|
+
KeyCode["ControlLeft"] = "ControlLeft";
|
|
60
|
+
KeyCode["AltLeft"] = "AltLeft";
|
|
61
|
+
KeyCode["MetaLeft"] = "MetaLeft";
|
|
62
|
+
KeyCode["ShiftRight"] = "ShiftRight";
|
|
63
|
+
KeyCode["ControlRight"] = "ControlRight";
|
|
64
|
+
KeyCode["AltRight"] = "AltRight";
|
|
65
|
+
KeyCode["MetaRight"] = "MetaRight";
|
|
66
|
+
KeyCode["Space"] = "Space";
|
|
76
67
|
KeyCode["Enter"] = "Enter";
|
|
77
68
|
KeyCode["Escape"] = "Escape";
|
|
78
69
|
KeyCode["Tab"] = "Tab";
|
|
79
70
|
KeyCode["Backspace"] = "Backspace";
|
|
71
|
+
KeyCode["Delete"] = "Delete";
|
|
80
72
|
KeyCode["MouseLeft"] = "MouseLeft";
|
|
81
73
|
KeyCode["MouseRight"] = "MouseRight";
|
|
82
74
|
KeyCode["MouseMiddle"] = "MouseMiddle";
|
|
83
|
-
KeyCode["Period"] = "
|
|
84
|
-
KeyCode["
|
|
85
|
-
KeyCode["
|
|
86
|
-
KeyCode["
|
|
87
|
-
KeyCode["
|
|
75
|
+
KeyCode["Period"] = "Period";
|
|
76
|
+
KeyCode["Minus"] = "Minus";
|
|
77
|
+
KeyCode["Equal"] = "Equal";
|
|
78
|
+
KeyCode["Backquote"] = "Backquote";
|
|
79
|
+
KeyCode["BraceLeft"] = "BracketLeft";
|
|
80
|
+
KeyCode["BraceRight"] = "BracketRight";
|
|
81
|
+
KeyCode["SemiColon"] = "Semicolon";
|
|
82
|
+
KeyCode["Quote"] = "Quote";
|
|
83
|
+
KeyCode["Slash"] = "Slash";
|
|
84
|
+
KeyCode["Comma"] = "Comma";
|
|
85
|
+
KeyCode["Home"] = "Home";
|
|
86
|
+
KeyCode["End"] = "End";
|
|
87
|
+
KeyCode["PageUp"] = "PageUp";
|
|
88
|
+
KeyCode["PageDown"] = "PageDown";
|
|
88
89
|
})(KeyCode || (exports.KeyCode = KeyCode = {}));
|
|
89
90
|
exports.KeyKeyCodeMap = {
|
|
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
|
-
"
|
|
91
|
+
"KeyA": 0,
|
|
92
|
+
"KeyB": 1,
|
|
93
|
+
"KeyC": 2,
|
|
94
|
+
"KeyD": 3,
|
|
95
|
+
"KeyE": 4,
|
|
96
|
+
"KeyF": 5,
|
|
97
|
+
"KeyG": 6,
|
|
98
|
+
"KeyH": 7,
|
|
99
|
+
"KeyI": 8,
|
|
100
|
+
"KeyJ": 9,
|
|
101
|
+
"KeyK": 10,
|
|
102
|
+
"KeyL": 11,
|
|
103
|
+
"KeyM": 12,
|
|
104
|
+
"KeyN": 13,
|
|
105
|
+
"KeyO": 14,
|
|
106
|
+
"KeyP": 15,
|
|
107
|
+
"KeyQ": 16,
|
|
108
|
+
"KeyR": 17,
|
|
109
|
+
"KeyS": 18,
|
|
110
|
+
"KeyT": 19,
|
|
111
|
+
"KeyU": 20,
|
|
112
|
+
"KeyV": 21,
|
|
113
|
+
"KeyW": 22,
|
|
114
|
+
"KeyX": 23,
|
|
115
|
+
"KeyY": 24,
|
|
116
|
+
"KeyZ": 25,
|
|
117
|
+
"Digit0": 26,
|
|
118
|
+
"Digit1": 27,
|
|
119
|
+
"Digit2": 28,
|
|
120
|
+
"Digit3": 29,
|
|
121
|
+
"Digit4": 30,
|
|
122
|
+
"Digit5": 31,
|
|
123
|
+
"Digit6": 32,
|
|
124
|
+
"Digit7": 33,
|
|
125
|
+
"Digit8": 34,
|
|
126
|
+
"Digit9": 35,
|
|
126
127
|
"F1": 36,
|
|
127
128
|
"F2": 37,
|
|
128
129
|
"F3": 38,
|
|
@@ -139,23 +140,37 @@ exports.KeyKeyCodeMap = {
|
|
|
139
140
|
"ArrowDown": 49,
|
|
140
141
|
"ArrowLeft": 50,
|
|
141
142
|
"ArrowRight": 51,
|
|
142
|
-
"
|
|
143
|
-
"
|
|
144
|
-
"
|
|
145
|
-
"
|
|
146
|
-
"
|
|
147
|
-
"
|
|
148
|
-
"
|
|
149
|
-
"
|
|
150
|
-
"
|
|
151
|
-
"
|
|
152
|
-
"
|
|
153
|
-
"
|
|
154
|
-
"
|
|
155
|
-
"
|
|
156
|
-
"
|
|
157
|
-
"
|
|
158
|
-
"
|
|
143
|
+
"ShiftLeft": 52,
|
|
144
|
+
"ControlLeft": 53,
|
|
145
|
+
"AltLeft": 54,
|
|
146
|
+
"MetaLeft": 55,
|
|
147
|
+
"ShiftRight": 56,
|
|
148
|
+
"ControlRight": 57,
|
|
149
|
+
"AltRight": 58,
|
|
150
|
+
"MetaRight": 59,
|
|
151
|
+
"Space": 60,
|
|
152
|
+
"Enter": 61,
|
|
153
|
+
"Escape": 62,
|
|
154
|
+
"Tab": 63,
|
|
155
|
+
"Backspace": 64,
|
|
156
|
+
"Delete": 65,
|
|
157
|
+
"MouseLeft": 66,
|
|
158
|
+
"MouseRight": 67,
|
|
159
|
+
"MouseMiddle": 68,
|
|
160
|
+
"Period": 69,
|
|
161
|
+
"Minus": 70,
|
|
162
|
+
"Equal": 71,
|
|
163
|
+
"Backquote": 72,
|
|
164
|
+
"BracketLeft": 73,
|
|
165
|
+
"BracketRight": 74,
|
|
166
|
+
"Semicolon": 75,
|
|
167
|
+
"Quote": 76,
|
|
168
|
+
"Slash": 77,
|
|
169
|
+
"Comma": 78,
|
|
170
|
+
"Home": 79,
|
|
171
|
+
"End": 80,
|
|
172
|
+
"PageUp": 81,
|
|
173
|
+
"PageDown": 82,
|
|
159
174
|
};
|
|
160
175
|
var MouseButton;
|
|
161
176
|
(function (MouseButton) {
|
|
@@ -163,8 +178,14 @@ var MouseButton;
|
|
|
163
178
|
MouseButton[MouseButton["MIDDLE"] = 1] = "MIDDLE";
|
|
164
179
|
MouseButton[MouseButton["RIGHT"] = 2] = "RIGHT";
|
|
165
180
|
})(MouseButton || (exports.MouseButton = MouseButton = {}));
|
|
166
|
-
|
|
167
|
-
|
|
181
|
+
var InputFlags;
|
|
182
|
+
(function (InputFlags) {
|
|
183
|
+
InputFlags[InputFlags["None"] = 0] = "None";
|
|
184
|
+
InputFlags[InputFlags["PreventWindowDefault"] = 2] = "PreventWindowDefault";
|
|
185
|
+
InputFlags[InputFlags["AllowStringDefault"] = 4] = "AllowStringDefault";
|
|
186
|
+
})(InputFlags || (exports.InputFlags = InputFlags = {}));
|
|
187
|
+
class Input {
|
|
188
|
+
constructor(target, inputFlags) {
|
|
168
189
|
Object.defineProperty(this, "_target", {
|
|
169
190
|
enumerable: true,
|
|
170
191
|
configurable: true,
|
|
@@ -189,6 +210,12 @@ class InputClass {
|
|
|
189
210
|
writable: true,
|
|
190
211
|
value: new Set()
|
|
191
212
|
});
|
|
213
|
+
Object.defineProperty(this, "_printableKeysThisFrame", {
|
|
214
|
+
enumerable: true,
|
|
215
|
+
configurable: true,
|
|
216
|
+
writable: true,
|
|
217
|
+
value: []
|
|
218
|
+
});
|
|
192
219
|
Object.defineProperty(this, "_mouseDownLeft", {
|
|
193
220
|
enumerable: true,
|
|
194
221
|
configurable: true,
|
|
@@ -273,17 +300,51 @@ class InputClass {
|
|
|
273
300
|
writable: true,
|
|
274
301
|
value: 0
|
|
275
302
|
});
|
|
303
|
+
Object.defineProperty(this, "_inputFlags", {
|
|
304
|
+
enumerable: true,
|
|
305
|
+
configurable: true,
|
|
306
|
+
writable: true,
|
|
307
|
+
value: InputFlags.None
|
|
308
|
+
});
|
|
309
|
+
Object.defineProperty(this, "_onWindowKeyDown", {
|
|
310
|
+
enumerable: true,
|
|
311
|
+
configurable: true,
|
|
312
|
+
writable: true,
|
|
313
|
+
value: (e) => {
|
|
314
|
+
let shouldPreventDefault = false;
|
|
315
|
+
if (e.altKey &&
|
|
316
|
+
!e.ctrlKey &&
|
|
317
|
+
!e.metaKey &&
|
|
318
|
+
!e.shiftKey &&
|
|
319
|
+
(e.code === KeyCode.ArrowLeft || e.code === KeyCode.ArrowRight)) {
|
|
320
|
+
shouldPreventDefault = true;
|
|
321
|
+
}
|
|
322
|
+
if (shouldPreventDefault)
|
|
323
|
+
e.preventDefault();
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
Object.defineProperty(this, "_onWindowContextMenu", {
|
|
327
|
+
enumerable: true,
|
|
328
|
+
configurable: true,
|
|
329
|
+
writable: true,
|
|
330
|
+
value: (e) => {
|
|
331
|
+
e.preventDefault();
|
|
332
|
+
}
|
|
333
|
+
});
|
|
276
334
|
Object.defineProperty(this, "_onKeyDown", {
|
|
277
335
|
enumerable: true,
|
|
278
336
|
configurable: true,
|
|
279
337
|
writable: true,
|
|
280
338
|
value: (e) => {
|
|
281
339
|
const keyboardEvent = e;
|
|
282
|
-
|
|
340
|
+
if ((this._inputFlags & InputFlags.AllowStringDefault) == 0)
|
|
341
|
+
keyboardEvent.preventDefault();
|
|
283
342
|
if (!keyboardEvent.repeat) {
|
|
284
|
-
const key = keyboardEvent.
|
|
343
|
+
const key = keyboardEvent.code;
|
|
285
344
|
this._keysDownThisFrame.push(key);
|
|
286
345
|
this._keysDown.add(key);
|
|
346
|
+
if (keyboardEvent.key.length === 1 || keyboardEvent.key === " ")
|
|
347
|
+
this._printableKeysThisFrame.push(keyboardEvent.key);
|
|
287
348
|
}
|
|
288
349
|
}
|
|
289
350
|
});
|
|
@@ -292,7 +353,7 @@ class InputClass {
|
|
|
292
353
|
configurable: true,
|
|
293
354
|
writable: true,
|
|
294
355
|
value: (e) => {
|
|
295
|
-
const key = e.
|
|
356
|
+
const key = e.code;
|
|
296
357
|
this._keysDown.delete(key);
|
|
297
358
|
this._keysUpThisFrame.add(key);
|
|
298
359
|
}
|
|
@@ -306,6 +367,7 @@ class InputClass {
|
|
|
306
367
|
if (mouseEvent.button !== 0) {
|
|
307
368
|
e.preventDefault();
|
|
308
369
|
}
|
|
370
|
+
this._target.focus();
|
|
309
371
|
if (mouseEvent.button === 0 && !this._mouseDownLeft) {
|
|
310
372
|
this._mouseDownLeft = true;
|
|
311
373
|
this._mouseDownThisFrameLeft = true;
|
|
@@ -367,6 +429,48 @@ class InputClass {
|
|
|
367
429
|
this._dWheel = wheelEvent.deltaY;
|
|
368
430
|
}
|
|
369
431
|
});
|
|
432
|
+
Object.defineProperty(this, "_onBlur", {
|
|
433
|
+
enumerable: true,
|
|
434
|
+
configurable: true,
|
|
435
|
+
writable: true,
|
|
436
|
+
value: (e) => {
|
|
437
|
+
{
|
|
438
|
+
this._keysDown.clear();
|
|
439
|
+
this._keysDownThisFrame = [];
|
|
440
|
+
this._keysUpThisFrame.clear();
|
|
441
|
+
this._mouseDownLeft = false;
|
|
442
|
+
this._mouseDownThisFrameLeft = false;
|
|
443
|
+
this._mouseUpThisFrameLeft = false;
|
|
444
|
+
this._mouseDownMiddle = false;
|
|
445
|
+
this._mouseDownThisFrameMiddle = false;
|
|
446
|
+
this._mouseUpThisFrameMiddle = false;
|
|
447
|
+
this._mouseDownRight = false;
|
|
448
|
+
this._mouseDownThisFrameRight = false;
|
|
449
|
+
this._mouseUpThisFrameRight = false;
|
|
450
|
+
this._dWheel = 0;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
});
|
|
454
|
+
Object.defineProperty(this, "_onMouseLeave", {
|
|
455
|
+
enumerable: true,
|
|
456
|
+
configurable: true,
|
|
457
|
+
writable: true,
|
|
458
|
+
value: (e) => {
|
|
459
|
+
this._keysDown.clear();
|
|
460
|
+
this._keysDownThisFrame = [];
|
|
461
|
+
this._keysUpThisFrame.clear();
|
|
462
|
+
this._mouseDownLeft = false;
|
|
463
|
+
this._mouseDownThisFrameLeft = false;
|
|
464
|
+
this._mouseUpThisFrameLeft = false;
|
|
465
|
+
this._mouseDownMiddle = false;
|
|
466
|
+
this._mouseDownThisFrameMiddle = false;
|
|
467
|
+
this._mouseUpThisFrameMiddle = false;
|
|
468
|
+
this._mouseDownRight = false;
|
|
469
|
+
this._mouseDownThisFrameRight = false;
|
|
470
|
+
this._mouseUpThisFrameRight = false;
|
|
471
|
+
this._dWheel = 0;
|
|
472
|
+
}
|
|
473
|
+
});
|
|
370
474
|
this._target = target;
|
|
371
475
|
this._target.addEventListener("keydown", this._onKeyDown);
|
|
372
476
|
this._target.addEventListener("keyup", this._onKeyUp);
|
|
@@ -375,10 +479,18 @@ class InputClass {
|
|
|
375
479
|
this._target.addEventListener('mousemove', this._onMouseMove);
|
|
376
480
|
this._target.addEventListener('contextmenu', this._onContext);
|
|
377
481
|
this._target.addEventListener('wheel', this._onWheel);
|
|
482
|
+
this._target.addEventListener("blur", this._onBlur);
|
|
483
|
+
this._target.addEventListener("mouseleave", this._onMouseLeave);
|
|
484
|
+
this._inputFlags = inputFlags;
|
|
485
|
+
if (this._inputFlags & InputFlags.PreventWindowDefault) {
|
|
486
|
+
window.addEventListener("keydown", this._onWindowKeyDown, { capture: true });
|
|
487
|
+
window.addEventListener("contextmenu", this._onWindowContextMenu, { capture: true });
|
|
488
|
+
}
|
|
378
489
|
}
|
|
379
490
|
InputEndFrame() {
|
|
380
491
|
this._keysDownThisFrame = [];
|
|
381
492
|
this._keysUpThisFrame.clear();
|
|
493
|
+
this._printableKeysThisFrame.length = 0;
|
|
382
494
|
this._mouseDownThisFrameLeft = false;
|
|
383
495
|
this._mouseUpThisFrameLeft = false;
|
|
384
496
|
this._mouseDownThisFrameMiddle = false;
|
|
@@ -411,6 +523,27 @@ class InputClass {
|
|
|
411
523
|
KeyUpThisFrame(key) {
|
|
412
524
|
return this._keysUpThisFrame.has(key);
|
|
413
525
|
}
|
|
526
|
+
AlphaCharsThisFrame() {
|
|
527
|
+
let result = "";
|
|
528
|
+
for (const key of this._keysDownThisFrame) {
|
|
529
|
+
if (key.startsWith("Key")) {
|
|
530
|
+
result += key.substring(3); // "KeyA" -> "A"
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
return result;
|
|
534
|
+
}
|
|
535
|
+
NumericCharsThisFrame() {
|
|
536
|
+
let result = "";
|
|
537
|
+
for (const key of this._keysDownThisFrame) {
|
|
538
|
+
if (key.startsWith("Digit")) {
|
|
539
|
+
result += key.substring(5); // "Digit1" -> "1"
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
return result;
|
|
543
|
+
}
|
|
544
|
+
PrintableCharsThisFrame() {
|
|
545
|
+
return [...this._printableKeysThisFrame];
|
|
546
|
+
}
|
|
414
547
|
MouseDown(mouseButton) {
|
|
415
548
|
if (mouseButton == MouseButton.LEFT)
|
|
416
549
|
return this._mouseDownLeft;
|
|
@@ -444,6 +577,18 @@ class InputClass {
|
|
|
444
577
|
const elementMouseY = this._mouseY - elementRect.top;
|
|
445
578
|
return { x: elementMouseX, y: elementMouseY };
|
|
446
579
|
}
|
|
580
|
+
IsShiftDown() {
|
|
581
|
+
return this.KeyDown(KeyCode.ShiftLeft) || this.KeyDown(KeyCode.ShiftRight);
|
|
582
|
+
}
|
|
583
|
+
IsPrimaryModDown() {
|
|
584
|
+
if (Input.isMac)
|
|
585
|
+
return this.KeyDown(KeyCode.MetaLeft) || this.KeyDown(KeyCode.MetaRight);
|
|
586
|
+
else
|
|
587
|
+
return this.KeyDown(KeyCode.ControlLeft) || this.KeyDown(KeyCode.ControlRight);
|
|
588
|
+
}
|
|
589
|
+
IsAltDown() {
|
|
590
|
+
return this.KeyDown(KeyCode.AltLeft) || this.KeyDown(KeyCode.AltRight);
|
|
591
|
+
}
|
|
447
592
|
Destroy() {
|
|
448
593
|
this._target.removeEventListener("keydown", this._onKeyDown);
|
|
449
594
|
this._target.removeEventListener("keyup", this._onKeyUp);
|
|
@@ -451,7 +596,13 @@ class InputClass {
|
|
|
451
596
|
this._target.removeEventListener("mouseup", this._onMouseUp);
|
|
452
597
|
this._target.removeEventListener("mousemove", this._onMouseMove);
|
|
453
598
|
this._target.removeEventListener('contextmenu', this._onContext);
|
|
454
|
-
this._target.removeEventListener('wheel', this.
|
|
599
|
+
this._target.removeEventListener('wheel', this._onWheel);
|
|
600
|
+
this._target.removeEventListener("blur", this._onBlur);
|
|
601
|
+
this._target.removeEventListener("mouseleave", this._onMouseLeave);
|
|
602
|
+
if (this._inputFlags & InputFlags.PreventWindowDefault) {
|
|
603
|
+
window.removeEventListener("keydown", this._onWindowKeyDown, { capture: true });
|
|
604
|
+
window.removeEventListener("contextmenu", this._onWindowContextMenu, { capture: true });
|
|
605
|
+
}
|
|
455
606
|
this._keysDown.clear();
|
|
456
607
|
this._keysDownThisFrame.length = 0;
|
|
457
608
|
this._keysUpThisFrame.clear();
|
|
@@ -464,179 +615,21 @@ class InputClass {
|
|
|
464
615
|
this._mouseDownRight = false;
|
|
465
616
|
this._mouseDownThisFrameRight = false;
|
|
466
617
|
this._mouseUpThisFrameRight = false;
|
|
618
|
+
this._printableKeysThisFrame.length = 0;
|
|
467
619
|
}
|
|
468
620
|
}
|
|
469
|
-
exports.
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
_mouseDownRight: false,
|
|
479
|
-
_mouseDownThisFrameLeft: false,
|
|
480
|
-
_mouseDownThisFrameMiddle: false,
|
|
481
|
-
_mouseDownThisFrameRight: false,
|
|
482
|
-
_mouseUpThisFrameLeft: false,
|
|
483
|
-
_mouseUpThisFrameMiddle: false,
|
|
484
|
-
_mouseUpThisFrameRight: false,
|
|
485
|
-
_mouseX: 0,
|
|
486
|
-
_mouseY: 0,
|
|
487
|
-
_onContext(e) {
|
|
488
|
-
},
|
|
489
|
-
_onKeyDown(e) {
|
|
490
|
-
},
|
|
491
|
-
_onKeyUp(e) {
|
|
492
|
-
},
|
|
493
|
-
_onMouseDown(e) {
|
|
494
|
-
},
|
|
495
|
-
_onMouseMove(e) {
|
|
496
|
-
},
|
|
497
|
-
_onMouseUp(e) {
|
|
498
|
-
},
|
|
499
|
-
_onWheel(e) {
|
|
500
|
-
},
|
|
501
|
-
_previousMouseX: 0,
|
|
502
|
-
_previousMouseY: 0,
|
|
503
|
-
_target: target
|
|
504
|
-
};
|
|
505
|
-
result._target = target;
|
|
506
|
-
result._onKeyDown = (e) => {
|
|
507
|
-
const keyboardEvent = e;
|
|
508
|
-
keyboardEvent.preventDefault();
|
|
509
|
-
if (!keyboardEvent.repeat) {
|
|
510
|
-
const key = keyboardEvent.key;
|
|
511
|
-
result._keysDownThisFrame.push(key);
|
|
512
|
-
result._keysDown.add(key);
|
|
513
|
-
}
|
|
514
|
-
};
|
|
515
|
-
result._onKeyUp = (e) => {
|
|
516
|
-
const key = e.key;
|
|
517
|
-
result._keysDown.delete(key);
|
|
518
|
-
result._keysUpThisFrame.add(key);
|
|
519
|
-
};
|
|
520
|
-
result._onMouseDown = (e) => {
|
|
521
|
-
const mouseEvent = e;
|
|
522
|
-
if (mouseEvent.button !== 0) {
|
|
523
|
-
e.preventDefault();
|
|
524
|
-
}
|
|
525
|
-
if (mouseEvent.button === 0 && !result._mouseDownLeft) {
|
|
526
|
-
result._mouseDownLeft = true;
|
|
527
|
-
result._mouseDownThisFrameLeft = true;
|
|
621
|
+
exports.Input = Input;
|
|
622
|
+
Object.defineProperty(Input, "isMac", {
|
|
623
|
+
enumerable: true,
|
|
624
|
+
configurable: true,
|
|
625
|
+
writable: true,
|
|
626
|
+
value: (() => {
|
|
627
|
+
// If browser supports userAgentData
|
|
628
|
+
if (navigator.userAgent) {
|
|
629
|
+
return navigator.userAgent.indexOf("Mac OS X") != -1;
|
|
528
630
|
}
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
else if (mouseEvent.button === 2 && !result._mouseDownRight) {
|
|
534
|
-
result._mouseDownRight = true;
|
|
535
|
-
result._mouseDownThisFrameRight = true;
|
|
536
|
-
}
|
|
537
|
-
};
|
|
538
|
-
result._onMouseUp = (e) => {
|
|
539
|
-
const mouseEvent = e;
|
|
540
|
-
if (mouseEvent.button === 0) {
|
|
541
|
-
result._mouseDownLeft = false;
|
|
542
|
-
result._mouseUpThisFrameLeft = true;
|
|
543
|
-
}
|
|
544
|
-
else if (mouseEvent.button === 1) {
|
|
545
|
-
result._mouseDownMiddle = false;
|
|
546
|
-
result._mouseUpThisFrameMiddle = true;
|
|
547
|
-
}
|
|
548
|
-
else if (mouseEvent.button === 2) {
|
|
549
|
-
result._mouseDownRight = false;
|
|
550
|
-
result._mouseUpThisFrameRight = true;
|
|
551
|
-
}
|
|
552
|
-
};
|
|
553
|
-
result._onMouseMove = (e) => {
|
|
554
|
-
const mouseEvent = e;
|
|
555
|
-
result._mouseX = mouseEvent.clientX;
|
|
556
|
-
result._mouseY = mouseEvent.clientY;
|
|
557
|
-
};
|
|
558
|
-
result._onContext = (e) => {
|
|
559
|
-
e.preventDefault();
|
|
560
|
-
};
|
|
561
|
-
result._onWheel = (e) => {
|
|
562
|
-
const wheelEvent = e;
|
|
563
|
-
result._dWheel = wheelEvent.deltaY;
|
|
564
|
-
};
|
|
565
|
-
result._target.addEventListener("keydown", result._onKeyDown);
|
|
566
|
-
result._target.addEventListener("keyup", result._onKeyUp);
|
|
567
|
-
result._target.addEventListener("mousedown", result._onMouseDown);
|
|
568
|
-
result._target.addEventListener("mouseup", result._onMouseUp);
|
|
569
|
-
result._target.addEventListener('mousemove', result._onMouseMove);
|
|
570
|
-
result._target.addEventListener('contextmenu', result._onContext);
|
|
571
|
-
result._target.addEventListener('wheel', result._onWheel);
|
|
572
|
-
return result;
|
|
573
|
-
}
|
|
574
|
-
function InputEndFrame(input) {
|
|
575
|
-
input._keysDownThisFrame = [];
|
|
576
|
-
input._keysUpThisFrame.clear();
|
|
577
|
-
input._mouseDownThisFrameLeft = false;
|
|
578
|
-
input._mouseUpThisFrameLeft = false;
|
|
579
|
-
input._mouseDownThisFrameMiddle = false;
|
|
580
|
-
input._mouseUpThisFrameMiddle = false;
|
|
581
|
-
input._mouseDownThisFrameRight = false;
|
|
582
|
-
input._mouseUpThisFrameRight = false;
|
|
583
|
-
input._dWheel = 0;
|
|
584
|
-
input._previousMouseX = input._mouseX;
|
|
585
|
-
input._previousMouseY = input._mouseY;
|
|
586
|
-
}
|
|
587
|
-
function InputMouseDelta(input) {
|
|
588
|
-
const dx = input._mouseX - input._previousMouseX;
|
|
589
|
-
const dy = input._mouseY - input._previousMouseY;
|
|
590
|
-
return { x: dx, y: dy };
|
|
591
|
-
}
|
|
592
|
-
function InputMouseDeltaX(input) {
|
|
593
|
-
const dx = input._mouseX - input._previousMouseX;
|
|
594
|
-
return dx;
|
|
595
|
-
}
|
|
596
|
-
function InputMouseDeltaY(input) {
|
|
597
|
-
const dy = input._mouseY - input._previousMouseY;
|
|
598
|
-
return dy;
|
|
599
|
-
}
|
|
600
|
-
function InputKeyDown(input, key) {
|
|
601
|
-
return input._keysDown.has(key);
|
|
602
|
-
}
|
|
603
|
-
function InputKeyDownThisFrame(input, key) {
|
|
604
|
-
return input._keysDownThisFrame.includes(key);
|
|
605
|
-
}
|
|
606
|
-
function InputKeyUpThisFrame(input, key) {
|
|
607
|
-
return input._keysUpThisFrame.has(key);
|
|
608
|
-
}
|
|
609
|
-
function InputMouseDown(input, mouseButton) {
|
|
610
|
-
if (mouseButton == MouseButton.LEFT)
|
|
611
|
-
return input._mouseDownLeft;
|
|
612
|
-
if (mouseButton == MouseButton.MIDDLE)
|
|
613
|
-
return input._mouseDownMiddle;
|
|
614
|
-
if (mouseButton == MouseButton.RIGHT)
|
|
615
|
-
return input._mouseDownRight;
|
|
616
|
-
return false;
|
|
617
|
-
}
|
|
618
|
-
function InputMouseDownThisFrame(input, mouseButton) {
|
|
619
|
-
if (mouseButton == MouseButton.LEFT)
|
|
620
|
-
return input._mouseDownThisFrameLeft;
|
|
621
|
-
if (mouseButton == MouseButton.MIDDLE)
|
|
622
|
-
return input._mouseDownThisFrameMiddle;
|
|
623
|
-
if (mouseButton == MouseButton.RIGHT)
|
|
624
|
-
return input._mouseDownThisFrameRight;
|
|
625
|
-
return false;
|
|
626
|
-
}
|
|
627
|
-
function InputMouseUpThisFrame(input, mouseButton) {
|
|
628
|
-
if (mouseButton == MouseButton.LEFT)
|
|
629
|
-
return input._mouseUpThisFrameLeft;
|
|
630
|
-
if (mouseButton == MouseButton.MIDDLE)
|
|
631
|
-
return input._mouseUpThisFrameMiddle;
|
|
632
|
-
if (mouseButton == MouseButton.RIGHT)
|
|
633
|
-
return input._mouseUpThisFrameRight;
|
|
634
|
-
return false;
|
|
635
|
-
}
|
|
636
|
-
function InputMousePos(input) {
|
|
637
|
-
const elementRect = input._target.getBoundingClientRect();
|
|
638
|
-
const elementMouseX = input._mouseX - elementRect.left;
|
|
639
|
-
const elementMouseY = input._mouseY - elementRect.top;
|
|
640
|
-
return { x: elementMouseX, y: elementMouseY };
|
|
641
|
-
}
|
|
631
|
+
// fallback to deprecated platform or userAgent
|
|
632
|
+
return /Mac|iPhone|iPad|iPod/.test(navigator.platform || navigator.userAgent);
|
|
633
|
+
})()
|
|
634
|
+
});
|
|
642
635
|
//# sourceMappingURL=input.js.map
|