like2d 1.0.0 → 2.0.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.
- package/LICENSE +22 -0
- package/README.md +67 -43
- package/dist/adapters/callback/index.d.ts +43 -0
- package/dist/adapters/callback/index.d.ts.map +1 -0
- package/dist/adapters/callback/index.js +80 -0
- package/dist/adapters/scene/index.d.ts +42 -0
- package/dist/adapters/scene/index.d.ts.map +1 -0
- package/dist/adapters/scene/index.js +112 -0
- package/dist/adapters/scene/scene.d.ts +18 -0
- package/dist/adapters/scene/scene.d.ts.map +1 -0
- package/dist/adapters/scene/startup-scene.d.ts +17 -0
- package/dist/adapters/scene/startup-scene.d.ts.map +1 -0
- package/dist/adapters/scene/startup-scene.js +41 -0
- package/dist/core/audio.d.ts +61 -0
- package/dist/core/audio.d.ts.map +1 -0
- package/dist/core/audio.js +226 -0
- package/dist/core/canvas-config.d.ts +22 -0
- package/dist/core/canvas-config.d.ts.map +1 -0
- package/dist/core/canvas-config.js +14 -0
- package/dist/core/canvas-manager.d.ts +26 -0
- package/dist/core/canvas-manager.d.ts.map +1 -0
- package/dist/core/canvas-manager.js +197 -0
- package/dist/core/events.d.ts +52 -0
- package/dist/core/events.d.ts.map +1 -0
- package/dist/core/gamepad-button-map.d.ts.map +1 -0
- package/dist/core/gamepad-buttons.d.ts +23 -0
- package/dist/core/gamepad-buttons.d.ts.map +1 -0
- package/dist/core/gamepad-buttons.js +36 -0
- package/dist/core/gamepad-db.d.ts.map +1 -0
- package/dist/{gamepad-mapping.d.ts → core/gamepad-mapping.d.ts} +3 -15
- package/dist/core/gamepad-mapping.d.ts.map +1 -0
- package/dist/core/gamepad-mapping.js +223 -0
- package/dist/{gamepad.d.ts → core/gamepad.d.ts} +22 -17
- package/dist/core/gamepad.d.ts.map +1 -0
- package/dist/{gamepad.js → core/gamepad.js} +91 -70
- package/dist/{graphics.d.ts → core/graphics.d.ts} +2 -8
- package/dist/core/graphics.d.ts.map +1 -0
- package/dist/{graphics.js → core/graphics.js} +4 -41
- package/dist/core/input-state.d.ts.map +1 -0
- package/dist/{input.d.ts → core/input.d.ts} +11 -14
- package/dist/core/input.d.ts.map +1 -0
- package/dist/{input.js → core/input.js} +31 -41
- package/dist/core/keyboard.d.ts +15 -0
- package/dist/core/keyboard.d.ts.map +1 -0
- package/dist/core/keyboard.js +70 -0
- package/dist/core/mouse.d.ts +29 -0
- package/dist/core/mouse.d.ts.map +1 -0
- package/dist/core/mouse.js +130 -0
- package/dist/{rect.d.ts → core/rect.d.ts} +1 -2
- package/dist/core/rect.d.ts.map +1 -0
- package/dist/{rect.js → core/rect.js} +24 -28
- package/dist/{timer.d.ts → core/timer.d.ts} +0 -1
- package/dist/core/timer.d.ts.map +1 -0
- package/dist/{timer.js → core/timer.js} +0 -1
- package/dist/{vector2.d.ts → core/vector2.d.ts} +4 -10
- package/dist/core/vector2.d.ts.map +1 -0
- package/dist/{vector2.js → core/vector2.js} +40 -40
- package/dist/engine.d.ts +42 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +154 -0
- package/dist/index.d.ts +38 -44
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +24 -250
- package/package.json +8 -23
- package/dist/audio.d.ts +0 -52
- package/dist/audio.d.ts.map +0 -1
- package/dist/audio.js +0 -250
- package/dist/events.d.ts +0 -36
- package/dist/events.d.ts.map +0 -1
- package/dist/gamepad-button-map.d.ts.map +0 -1
- package/dist/gamepad-db.d.ts.map +0 -1
- package/dist/gamepad-mapping.d.ts.map +0 -1
- package/dist/gamepad-mapping.js +0 -191
- package/dist/gamepad.d.ts.map +0 -1
- package/dist/graphics.d.ts.map +0 -1
- package/dist/input-state.d.ts.map +0 -1
- package/dist/input.d.ts.map +0 -1
- package/dist/keyboard.d.ts +0 -9
- package/dist/keyboard.d.ts.map +0 -1
- package/dist/keyboard.js +0 -33
- package/dist/mouse.d.ts +0 -20
- package/dist/mouse.d.ts.map +0 -1
- package/dist/mouse.js +0 -84
- package/dist/rect.d.ts.map +0 -1
- package/dist/scene.d.ts +0 -10
- package/dist/scene.d.ts.map +0 -1
- package/dist/timer.d.ts.map +0 -1
- package/dist/vector2.d.ts.map +0 -1
- /package/dist/{scene.js → adapters/scene/scene.js} +0 -0
- /package/dist/{events.js → core/events.js} +0 -0
- /package/dist/{gamepad-button-map.d.ts → core/gamepad-button-map.d.ts} +0 -0
- /package/dist/{gamepad-button-map.js → core/gamepad-button-map.js} +0 -0
- /package/dist/{gamepad-db.d.ts → core/gamepad-db.d.ts} +0 -0
- /package/dist/{gamepad-db.js → core/gamepad-db.js} +0 -0
- /package/dist/{input-state.d.ts → core/input-state.d.ts} +0 -0
- /package/dist/{input-state.js → core/input-state.js} +0 -0
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { keyboard } from "./keyboard";
|
|
2
|
-
import { mouse } from "./mouse";
|
|
3
|
-
import { gamepad } from "./gamepad";
|
|
4
1
|
import { InputStateTracker } from './input-state';
|
|
5
|
-
import {
|
|
2
|
+
import { GP_NAME_MAP } from './gamepad-buttons';
|
|
6
3
|
const buttonMap = {
|
|
7
4
|
'Left': 1,
|
|
8
5
|
'Right': 3,
|
|
@@ -14,7 +11,7 @@ const buttonMap = {
|
|
|
14
11
|
'5': 5,
|
|
15
12
|
};
|
|
16
13
|
export class Input {
|
|
17
|
-
constructor() {
|
|
14
|
+
constructor(deps) {
|
|
18
15
|
Object.defineProperty(this, "actionMap", {
|
|
19
16
|
enumerable: true,
|
|
20
17
|
configurable: true,
|
|
@@ -27,6 +24,27 @@ export class Input {
|
|
|
27
24
|
writable: true,
|
|
28
25
|
value: new InputStateTracker()
|
|
29
26
|
});
|
|
27
|
+
Object.defineProperty(this, "keyboard", {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
configurable: true,
|
|
30
|
+
writable: true,
|
|
31
|
+
value: void 0
|
|
32
|
+
});
|
|
33
|
+
Object.defineProperty(this, "mouse", {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
configurable: true,
|
|
36
|
+
writable: true,
|
|
37
|
+
value: void 0
|
|
38
|
+
});
|
|
39
|
+
Object.defineProperty(this, "gamepad", {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
configurable: true,
|
|
42
|
+
writable: true,
|
|
43
|
+
value: void 0
|
|
44
|
+
});
|
|
45
|
+
this.keyboard = deps.keyboard;
|
|
46
|
+
this.mouse = deps.mouse;
|
|
47
|
+
this.gamepad = deps.gamepad;
|
|
30
48
|
}
|
|
31
49
|
map(action, inputs) {
|
|
32
50
|
const bindings = inputs.map(input => this.parseInput(input));
|
|
@@ -49,7 +67,7 @@ export class Input {
|
|
|
49
67
|
return this.actionStateTracker.justReleased(action);
|
|
50
68
|
}
|
|
51
69
|
update() {
|
|
52
|
-
|
|
70
|
+
this.gamepad.update();
|
|
53
71
|
const activeActions = new Set();
|
|
54
72
|
for (const [action] of this.actionMap) {
|
|
55
73
|
if (this.isDown(action)) {
|
|
@@ -57,12 +75,7 @@ export class Input {
|
|
|
57
75
|
}
|
|
58
76
|
}
|
|
59
77
|
const { justPressed, justReleased } = this.actionStateTracker.update(activeActions);
|
|
60
|
-
return {
|
|
61
|
-
pressed: justPressed,
|
|
62
|
-
released: justReleased,
|
|
63
|
-
gamepadPressed,
|
|
64
|
-
gamepadReleased,
|
|
65
|
-
};
|
|
78
|
+
return { pressed: justPressed, released: justReleased };
|
|
66
79
|
}
|
|
67
80
|
parseInput(input) {
|
|
68
81
|
const normalized = input.trim();
|
|
@@ -70,48 +83,26 @@ export class Input {
|
|
|
70
83
|
const buttonCode = normalized.replace('Mouse', '');
|
|
71
84
|
return { type: 'mouse', code: buttonCode };
|
|
72
85
|
}
|
|
73
|
-
if (normalized.startsWith('
|
|
74
|
-
|
|
75
|
-
// Format: GP0 ButtonBottom, GP1 LB, etc. - specific gamepad
|
|
76
|
-
const rest = normalized.slice(2); // Remove "GP" prefix
|
|
77
|
-
// Check if there's a gamepad index
|
|
78
|
-
const match = rest.match(/^(\d+)\s+(.+)$/);
|
|
79
|
-
if (match) {
|
|
80
|
-
// Specific gamepad: GP0 ButtonBottom
|
|
81
|
-
const gamepadIndex = parseInt(match[1], 10);
|
|
82
|
-
const buttonName = match[2].trim();
|
|
83
|
-
return { type: 'gamepad', code: buttonName, gamepadIndex };
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
// Any gamepad: GP ButtonBottom
|
|
87
|
-
const buttonName = rest.trim();
|
|
88
|
-
return { type: 'gamepad', code: buttonName };
|
|
89
|
-
}
|
|
86
|
+
if (normalized.startsWith('Button') || normalized.startsWith('DP')) {
|
|
87
|
+
return { type: 'gamepad', code: normalized };
|
|
90
88
|
}
|
|
91
89
|
return { type: 'keyboard', code: normalized };
|
|
92
90
|
}
|
|
93
91
|
isBindingActive(binding) {
|
|
94
92
|
switch (binding.type) {
|
|
95
93
|
case 'keyboard':
|
|
96
|
-
return keyboard.isDown(binding.code);
|
|
94
|
+
return this.keyboard.isDown(binding.code);
|
|
97
95
|
case 'mouse': {
|
|
98
96
|
const button = buttonMap[binding.code];
|
|
99
97
|
if (button !== undefined) {
|
|
100
|
-
return mouse.isDown(button);
|
|
98
|
+
return this.mouse.isDown(button);
|
|
101
99
|
}
|
|
102
100
|
return false;
|
|
103
101
|
}
|
|
104
102
|
case 'gamepad': {
|
|
105
|
-
const buttonIndex =
|
|
103
|
+
const buttonIndex = GP_NAME_MAP[binding.code];
|
|
106
104
|
if (buttonIndex !== undefined) {
|
|
107
|
-
|
|
108
|
-
// Check specific gamepad
|
|
109
|
-
return gamepad.isButtonDown(binding.gamepadIndex, buttonIndex);
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
// Check any gamepad
|
|
113
|
-
return gamepad.isButtonDownOnAny(buttonIndex);
|
|
114
|
-
}
|
|
105
|
+
return this.gamepad.isButtonDownOnAny(buttonIndex);
|
|
115
106
|
}
|
|
116
107
|
return false;
|
|
117
108
|
}
|
|
@@ -124,4 +115,3 @@ export class Input {
|
|
|
124
115
|
this.actionStateTracker.clear();
|
|
125
116
|
}
|
|
126
117
|
}
|
|
127
|
-
export const input = new Input();
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare class Keyboard {
|
|
2
|
+
private pressedScancodes;
|
|
3
|
+
onKeyEvent?: (scancode: string, keycode: string, type: 'keydown' | 'keyup') => void;
|
|
4
|
+
private keydownHandler;
|
|
5
|
+
private keyupHandler;
|
|
6
|
+
private blurHandler;
|
|
7
|
+
constructor();
|
|
8
|
+
private handleKeyDown;
|
|
9
|
+
private handleKeyUp;
|
|
10
|
+
private handleBlur;
|
|
11
|
+
dispose(): void;
|
|
12
|
+
isDown(scancode: string): boolean;
|
|
13
|
+
isAnyDown(...scancodes: string[]): boolean;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=keyboard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyboard.d.ts","sourceRoot":"","sources":["../../src/core/keyboard.ts"],"names":[],"mappings":"AAAA,qBAAa,QAAQ;IACnB,OAAO,CAAC,gBAAgB,CAAqB;IACtC,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,GAAG,OAAO,KAAK,IAAI,CAAC;IAG3F,OAAO,CAAC,cAAc,CAAwC;IAC9D,OAAO,CAAC,YAAY,CAAwC;IAC5D,OAAO,CAAC,WAAW,CAAa;;IAchC,OAAO,CAAC,aAAa;IAOrB,OAAO,CAAC,WAAW;IAOnB,OAAO,CAAC,UAAU;IAIlB,OAAO,IAAI,IAAI;IAOf,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAIjC,SAAS,CAAC,GAAG,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO;CAG3C"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export class Keyboard {
|
|
2
|
+
constructor() {
|
|
3
|
+
Object.defineProperty(this, "pressedScancodes", {
|
|
4
|
+
enumerable: true,
|
|
5
|
+
configurable: true,
|
|
6
|
+
writable: true,
|
|
7
|
+
value: new Set()
|
|
8
|
+
});
|
|
9
|
+
Object.defineProperty(this, "onKeyEvent", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
configurable: true,
|
|
12
|
+
writable: true,
|
|
13
|
+
value: void 0
|
|
14
|
+
});
|
|
15
|
+
// Event handler references for cleanup
|
|
16
|
+
Object.defineProperty(this, "keydownHandler", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
configurable: true,
|
|
19
|
+
writable: true,
|
|
20
|
+
value: void 0
|
|
21
|
+
});
|
|
22
|
+
Object.defineProperty(this, "keyupHandler", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
writable: true,
|
|
26
|
+
value: void 0
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(this, "blurHandler", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
configurable: true,
|
|
31
|
+
writable: true,
|
|
32
|
+
value: void 0
|
|
33
|
+
});
|
|
34
|
+
// Bind event handlers
|
|
35
|
+
this.keydownHandler = this.handleKeyDown.bind(this);
|
|
36
|
+
this.keyupHandler = this.handleKeyUp.bind(this);
|
|
37
|
+
this.blurHandler = this.handleBlur.bind(this);
|
|
38
|
+
// Register event listeners
|
|
39
|
+
window.addEventListener('keydown', this.keydownHandler);
|
|
40
|
+
window.addEventListener('keyup', this.keyupHandler);
|
|
41
|
+
window.addEventListener('blur', this.blurHandler);
|
|
42
|
+
}
|
|
43
|
+
handleKeyDown(e) {
|
|
44
|
+
if (e.code) {
|
|
45
|
+
this.pressedScancodes.add(e.code);
|
|
46
|
+
}
|
|
47
|
+
this.onKeyEvent?.(e.code, e.key, 'keydown');
|
|
48
|
+
}
|
|
49
|
+
handleKeyUp(e) {
|
|
50
|
+
if (e.code) {
|
|
51
|
+
this.pressedScancodes.delete(e.code);
|
|
52
|
+
}
|
|
53
|
+
this.onKeyEvent?.(e.code, e.key, 'keyup');
|
|
54
|
+
}
|
|
55
|
+
handleBlur() {
|
|
56
|
+
this.pressedScancodes.clear();
|
|
57
|
+
}
|
|
58
|
+
dispose() {
|
|
59
|
+
window.removeEventListener('keydown', this.keydownHandler);
|
|
60
|
+
window.removeEventListener('keyup', this.keyupHandler);
|
|
61
|
+
window.removeEventListener('blur', this.blurHandler);
|
|
62
|
+
this.pressedScancodes.clear();
|
|
63
|
+
}
|
|
64
|
+
isDown(scancode) {
|
|
65
|
+
return this.pressedScancodes.has(scancode);
|
|
66
|
+
}
|
|
67
|
+
isAnyDown(...scancodes) {
|
|
68
|
+
return scancodes.some(code => this.pressedScancodes.has(code));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Vector2 } from './vector2';
|
|
2
|
+
export type MousePositionTransform = (cssX: number, cssY: number) => Vector2;
|
|
3
|
+
export declare class Mouse {
|
|
4
|
+
private x;
|
|
5
|
+
private y;
|
|
6
|
+
private buttons;
|
|
7
|
+
onMouseEvent?: (clientX: number, clientY: number, button: number | undefined, type: 'mousemove' | 'mousedown' | 'mouseup') => void;
|
|
8
|
+
private transformFn?;
|
|
9
|
+
private mousemoveHandler;
|
|
10
|
+
private mousedownHandler;
|
|
11
|
+
private mouseupHandler;
|
|
12
|
+
private blurHandler;
|
|
13
|
+
constructor(transformFn?: MousePositionTransform);
|
|
14
|
+
setTransform(transformFn: MousePositionTransform | undefined): void;
|
|
15
|
+
private handleMouseMove;
|
|
16
|
+
private handleMouseDown;
|
|
17
|
+
private handleMouseUp;
|
|
18
|
+
private handleBlur;
|
|
19
|
+
dispose(): void;
|
|
20
|
+
getPosition(): Vector2;
|
|
21
|
+
getX(): number;
|
|
22
|
+
getY(): number;
|
|
23
|
+
isDown(button: number): boolean;
|
|
24
|
+
getPressedButtons(): Set<number>;
|
|
25
|
+
isVisible(): boolean;
|
|
26
|
+
setVisible(visible: boolean, canvas?: HTMLCanvasElement): void;
|
|
27
|
+
getRelativeMode(): boolean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M,CAAC,EAAE,iBAAiB,GAAG,IAAI;IAQ9D,eAAe,IAAI,OAAO;CAG3B"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
export class Mouse {
|
|
2
|
+
constructor(transformFn) {
|
|
3
|
+
Object.defineProperty(this, "x", {
|
|
4
|
+
enumerable: true,
|
|
5
|
+
configurable: true,
|
|
6
|
+
writable: true,
|
|
7
|
+
value: 0
|
|
8
|
+
});
|
|
9
|
+
Object.defineProperty(this, "y", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
configurable: true,
|
|
12
|
+
writable: true,
|
|
13
|
+
value: 0
|
|
14
|
+
});
|
|
15
|
+
Object.defineProperty(this, "buttons", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
configurable: true,
|
|
18
|
+
writable: true,
|
|
19
|
+
value: new Set()
|
|
20
|
+
});
|
|
21
|
+
Object.defineProperty(this, "onMouseEvent", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
configurable: true,
|
|
24
|
+
writable: true,
|
|
25
|
+
value: void 0
|
|
26
|
+
});
|
|
27
|
+
Object.defineProperty(this, "transformFn", {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
configurable: true,
|
|
30
|
+
writable: true,
|
|
31
|
+
value: void 0
|
|
32
|
+
});
|
|
33
|
+
// Event handler references for cleanup
|
|
34
|
+
Object.defineProperty(this, "mousemoveHandler", {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
configurable: true,
|
|
37
|
+
writable: true,
|
|
38
|
+
value: void 0
|
|
39
|
+
});
|
|
40
|
+
Object.defineProperty(this, "mousedownHandler", {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
configurable: true,
|
|
43
|
+
writable: true,
|
|
44
|
+
value: void 0
|
|
45
|
+
});
|
|
46
|
+
Object.defineProperty(this, "mouseupHandler", {
|
|
47
|
+
enumerable: true,
|
|
48
|
+
configurable: true,
|
|
49
|
+
writable: true,
|
|
50
|
+
value: void 0
|
|
51
|
+
});
|
|
52
|
+
Object.defineProperty(this, "blurHandler", {
|
|
53
|
+
enumerable: true,
|
|
54
|
+
configurable: true,
|
|
55
|
+
writable: true,
|
|
56
|
+
value: void 0
|
|
57
|
+
});
|
|
58
|
+
this.transformFn = transformFn;
|
|
59
|
+
// Bind event handlers
|
|
60
|
+
this.mousemoveHandler = this.handleMouseMove.bind(this);
|
|
61
|
+
this.mousedownHandler = this.handleMouseDown.bind(this);
|
|
62
|
+
this.mouseupHandler = this.handleMouseUp.bind(this);
|
|
63
|
+
this.blurHandler = this.handleBlur.bind(this);
|
|
64
|
+
// Register event listeners
|
|
65
|
+
window.addEventListener('mousemove', this.mousemoveHandler);
|
|
66
|
+
window.addEventListener('mousedown', this.mousedownHandler);
|
|
67
|
+
window.addEventListener('mouseup', this.mouseupHandler);
|
|
68
|
+
window.addEventListener('blur', this.blurHandler);
|
|
69
|
+
}
|
|
70
|
+
setTransform(transformFn) {
|
|
71
|
+
this.transformFn = transformFn;
|
|
72
|
+
}
|
|
73
|
+
handleMouseMove(e) {
|
|
74
|
+
// Store raw CSS coordinates - transformation to game coordinates
|
|
75
|
+
// should be done by the consumer using engine.transformMousePosition()
|
|
76
|
+
this.x = e.clientX;
|
|
77
|
+
this.y = e.clientY;
|
|
78
|
+
this.onMouseEvent?.(e.clientX, e.clientY, undefined, 'mousemove');
|
|
79
|
+
}
|
|
80
|
+
handleMouseDown(e) {
|
|
81
|
+
this.buttons.add(e.button + 1);
|
|
82
|
+
this.onMouseEvent?.(e.clientX, e.clientY, e.button, 'mousedown');
|
|
83
|
+
}
|
|
84
|
+
handleMouseUp(e) {
|
|
85
|
+
this.buttons.delete(e.button + 1);
|
|
86
|
+
this.onMouseEvent?.(e.clientX, e.clientY, e.button, 'mouseup');
|
|
87
|
+
}
|
|
88
|
+
handleBlur() {
|
|
89
|
+
this.buttons.clear();
|
|
90
|
+
}
|
|
91
|
+
dispose() {
|
|
92
|
+
window.removeEventListener('mousemove', this.mousemoveHandler);
|
|
93
|
+
window.removeEventListener('mousedown', this.mousedownHandler);
|
|
94
|
+
window.removeEventListener('mouseup', this.mouseupHandler);
|
|
95
|
+
window.removeEventListener('blur', this.blurHandler);
|
|
96
|
+
this.buttons.clear();
|
|
97
|
+
}
|
|
98
|
+
getPosition() {
|
|
99
|
+
if (this.transformFn) {
|
|
100
|
+
return this.transformFn(this.x, this.y);
|
|
101
|
+
}
|
|
102
|
+
return [this.x, this.y];
|
|
103
|
+
}
|
|
104
|
+
getX() {
|
|
105
|
+
return this.x;
|
|
106
|
+
}
|
|
107
|
+
getY() {
|
|
108
|
+
return this.y;
|
|
109
|
+
}
|
|
110
|
+
isDown(button) {
|
|
111
|
+
return this.buttons.has(button);
|
|
112
|
+
}
|
|
113
|
+
getPressedButtons() {
|
|
114
|
+
return new Set(this.buttons);
|
|
115
|
+
}
|
|
116
|
+
isVisible() {
|
|
117
|
+
return document.pointerLockElement === null;
|
|
118
|
+
}
|
|
119
|
+
setVisible(visible, canvas) {
|
|
120
|
+
if (!visible && canvas) {
|
|
121
|
+
canvas.requestPointerLock();
|
|
122
|
+
}
|
|
123
|
+
else if (visible && canvas && document.pointerLockElement === canvas) {
|
|
124
|
+
document.exitPointerLock();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
getRelativeMode() {
|
|
128
|
+
return document.pointerLockElement !== null;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { Vector2 } from './vector2';
|
|
2
2
|
export type Rect = [number, number, number, number];
|
|
3
|
-
export declare namespace
|
|
4
|
-
function create(x: number, y: number, w: number, h: number): Rect;
|
|
3
|
+
export declare namespace Rect {
|
|
5
4
|
function fromPoints(a: Vector2, b: Vector2): Rect;
|
|
6
5
|
function fromCenter(center: Vector2, size: Vector2): Rect;
|
|
7
6
|
function position(r: Rect): Vector2;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rect.d.ts","sourceRoot":"","sources":["../../src/core/rect.ts"],"names":[],"mappings":"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AWvD;IAED,SAAgB,KAAK,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,GAAG,IAAI,CAMhD;IAED,SAAgB,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAOrD;IAED,SAAgB,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAEpD;IAED,SAAgB,WAAW,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,GAAG,IAAI,CAEvD;IAED,SAAgB,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,CAEpD;IAED,SAAgB,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI,CAOxD;CACF"}
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
export var
|
|
2
|
-
(function (
|
|
3
|
-
function create(x, y, w, h) {
|
|
4
|
-
return [x, y, w, h];
|
|
5
|
-
}
|
|
6
|
-
R.create = create;
|
|
1
|
+
export var Rect;
|
|
2
|
+
(function (Rect) {
|
|
7
3
|
function fromPoints(a, b) {
|
|
8
4
|
const minX = Math.min(a[0], b[0]);
|
|
9
5
|
const minY = Math.min(a[1], b[1]);
|
|
@@ -11,7 +7,7 @@ export var R;
|
|
|
11
7
|
const maxY = Math.max(a[1], b[1]);
|
|
12
8
|
return [minX, minY, maxX - minX, maxY - minY];
|
|
13
9
|
}
|
|
14
|
-
|
|
10
|
+
Rect.fromPoints = fromPoints;
|
|
15
11
|
function fromCenter(center, size) {
|
|
16
12
|
return [
|
|
17
13
|
center[0] - size[0] / 2,
|
|
@@ -20,64 +16,64 @@ export var R;
|
|
|
20
16
|
size[1],
|
|
21
17
|
];
|
|
22
18
|
}
|
|
23
|
-
|
|
19
|
+
Rect.fromCenter = fromCenter;
|
|
24
20
|
function position(r) {
|
|
25
21
|
return [r[0], r[1]];
|
|
26
22
|
}
|
|
27
|
-
|
|
23
|
+
Rect.position = position;
|
|
28
24
|
function size(r) {
|
|
29
25
|
return [r[2], r[3]];
|
|
30
26
|
}
|
|
31
|
-
|
|
27
|
+
Rect.size = size;
|
|
32
28
|
function center(r) {
|
|
33
29
|
return [r[0] + r[2] / 2, r[1] + r[3] / 2];
|
|
34
30
|
}
|
|
35
|
-
|
|
31
|
+
Rect.center = center;
|
|
36
32
|
function topLeft(r) {
|
|
37
33
|
return [r[0], r[1]];
|
|
38
34
|
}
|
|
39
|
-
|
|
35
|
+
Rect.topLeft = topLeft;
|
|
40
36
|
function topRight(r) {
|
|
41
37
|
return [r[0] + r[2], r[1]];
|
|
42
38
|
}
|
|
43
|
-
|
|
39
|
+
Rect.topRight = topRight;
|
|
44
40
|
function bottomLeft(r) {
|
|
45
41
|
return [r[0], r[1] + r[3]];
|
|
46
42
|
}
|
|
47
|
-
|
|
43
|
+
Rect.bottomLeft = bottomLeft;
|
|
48
44
|
function bottomRight(r) {
|
|
49
45
|
return [r[0] + r[2], r[1] + r[3]];
|
|
50
46
|
}
|
|
51
|
-
|
|
47
|
+
Rect.bottomRight = bottomRight;
|
|
52
48
|
function area(r) {
|
|
53
49
|
return r[2] * r[3];
|
|
54
50
|
}
|
|
55
|
-
|
|
51
|
+
Rect.area = area;
|
|
56
52
|
function isEmpty(r) {
|
|
57
53
|
return r[2] <= 0 || r[3] <= 0;
|
|
58
54
|
}
|
|
59
|
-
|
|
55
|
+
Rect.isEmpty = isEmpty;
|
|
60
56
|
function containsPoint(r, point) {
|
|
61
57
|
return (point[0] >= r[0] &&
|
|
62
58
|
point[0] <= r[0] + r[2] &&
|
|
63
59
|
point[1] >= r[1] &&
|
|
64
60
|
point[1] <= r[1] + r[3]);
|
|
65
61
|
}
|
|
66
|
-
|
|
62
|
+
Rect.containsPoint = containsPoint;
|
|
67
63
|
function containsRect(r, other) {
|
|
68
64
|
return (other[0] >= r[0] &&
|
|
69
65
|
other[0] + other[2] <= r[0] + r[2] &&
|
|
70
66
|
other[1] >= r[1] &&
|
|
71
67
|
other[1] + other[3] <= r[1] + r[3]);
|
|
72
68
|
}
|
|
73
|
-
|
|
69
|
+
Rect.containsRect = containsRect;
|
|
74
70
|
function intersects(r, other) {
|
|
75
71
|
return (r[0] < other[0] + other[2] &&
|
|
76
72
|
r[0] + r[2] > other[0] &&
|
|
77
73
|
r[1] < other[1] + other[3] &&
|
|
78
74
|
r[1] + r[3] > other[1]);
|
|
79
75
|
}
|
|
80
|
-
|
|
76
|
+
Rect.intersects = intersects;
|
|
81
77
|
function intersection(r, other) {
|
|
82
78
|
const x1 = Math.max(r[0], other[0]);
|
|
83
79
|
const y1 = Math.max(r[1], other[1]);
|
|
@@ -90,7 +86,7 @@ export var R;
|
|
|
90
86
|
}
|
|
91
87
|
return [x1, y1, w, h];
|
|
92
88
|
}
|
|
93
|
-
|
|
89
|
+
Rect.intersection = intersection;
|
|
94
90
|
function union(r, other) {
|
|
95
91
|
const x1 = Math.min(r[0], other[0]);
|
|
96
92
|
const y1 = Math.min(r[1], other[1]);
|
|
@@ -98,7 +94,7 @@ export var R;
|
|
|
98
94
|
const y2 = Math.max(r[1] + r[3], other[1] + other[3]);
|
|
99
95
|
return [x1, y1, x2 - x1, y2 - y1];
|
|
100
96
|
}
|
|
101
|
-
|
|
97
|
+
Rect.union = union;
|
|
102
98
|
function inflate(r, amount) {
|
|
103
99
|
return [
|
|
104
100
|
r[0] - amount,
|
|
@@ -107,19 +103,19 @@ export var R;
|
|
|
107
103
|
r[3] + amount * 2,
|
|
108
104
|
];
|
|
109
105
|
}
|
|
110
|
-
|
|
106
|
+
Rect.inflate = inflate;
|
|
111
107
|
function offset(r, delta) {
|
|
112
108
|
return [r[0] + delta[0], r[1] + delta[1], r[2], r[3]];
|
|
113
109
|
}
|
|
114
|
-
|
|
110
|
+
Rect.offset = offset;
|
|
115
111
|
function setPosition(r, pos) {
|
|
116
112
|
return [pos[0], pos[1], r[2], r[3]];
|
|
117
113
|
}
|
|
118
|
-
|
|
114
|
+
Rect.setPosition = setPosition;
|
|
119
115
|
function setSize(r, size) {
|
|
120
116
|
return [r[0], r[1], size[0], size[1]];
|
|
121
117
|
}
|
|
122
|
-
|
|
118
|
+
Rect.setSize = setSize;
|
|
123
119
|
function setCenter(r, center) {
|
|
124
120
|
return [
|
|
125
121
|
center[0] - r[2] / 2,
|
|
@@ -128,5 +124,5 @@ export var R;
|
|
|
128
124
|
r[3],
|
|
129
125
|
];
|
|
130
126
|
}
|
|
131
|
-
|
|
132
|
-
})(
|
|
127
|
+
Rect.setCenter = setCenter;
|
|
128
|
+
})(Rect || (Rect = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timer.d.ts","sourceRoot":"","sources":["../../src/core/timer.ts"],"names":[],"mappings":"AAAA,qBAAa,KAAK;IAChB,OAAO,CAAC,YAAY,CAAK;IACzB,OAAO,CAAC,SAAS,CAAK;IACtB,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,GAAG,CAAK;IAChB,OAAO,CAAC,cAAc,CAAK;IAC3B,OAAO,CAAC,UAAU,CAAuB;IACzC,OAAO,CAAC,cAAc,CAAK;IAE3B,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAaxB,cAAc,IAAI,IAAI;IAItB,QAAQ,IAAI,MAAM;IAIlB,MAAM,IAAI,MAAM;IAIhB,OAAO,IAAI,MAAM;IAIjB,YAAY,IAAI,MAAM;IAItB,UAAU,IAAI,OAAO;IAUrB,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;CAG9B"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export type Vector2 = [number, number];
|
|
2
|
-
export declare namespace
|
|
2
|
+
export declare namespace Vec2 {
|
|
3
3
|
function add(a: Vector2, b: Vector2): Vector2;
|
|
4
4
|
function sub(a: Vector2, b: Vector2): Vector2;
|
|
5
|
-
function mul(v: Vector2,
|
|
6
|
-
function div(v: Vector2,
|
|
5
|
+
function mul(v: Vector2, other: Vector2 | number): Vector2;
|
|
6
|
+
function div(v: Vector2, other: Vector2 | number): Vector2;
|
|
7
7
|
function dot(a: Vector2, b: Vector2): number;
|
|
8
8
|
function cross(a: Vector2, b: Vector2): number;
|
|
9
9
|
function lengthSq(v: Vector2): number;
|
|
@@ -13,7 +13,6 @@ export declare namespace V2 {
|
|
|
13
13
|
function lerp(a: Vector2, b: Vector2, t: number): Vector2;
|
|
14
14
|
function angle(v: Vector2): number;
|
|
15
15
|
function rotate(v: Vector2, angle: number): Vector2;
|
|
16
|
-
function perpendicular(v: Vector2): Vector2;
|
|
17
16
|
function negate(v: Vector2): Vector2;
|
|
18
17
|
function floor(v: Vector2): Vector2;
|
|
19
18
|
function ceil(v: Vector2): Vector2;
|
|
@@ -22,11 +21,6 @@ export declare namespace V2 {
|
|
|
22
21
|
function max(a: Vector2, b: Vector2): Vector2;
|
|
23
22
|
function clamp(v: Vector2, min: Vector2, max: Vector2): Vector2;
|
|
24
23
|
function fromAngle(angle: number, len?: number): Vector2;
|
|
25
|
-
|
|
26
|
-
const one: Vector2;
|
|
27
|
-
const up: Vector2;
|
|
28
|
-
const down: Vector2;
|
|
29
|
-
const left: Vector2;
|
|
30
|
-
const right: Vector2;
|
|
24
|
+
function zero(): Vector2;
|
|
31
25
|
}
|
|
32
26
|
//# sourceMappingURL=vector2.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vector2.d.ts","sourceRoot":"","sources":["../../src/core/vector2.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,OAAO,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAEvC,yBAAiB,IAAI,CAAC;IACpB,SAAgB,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAEnD;IAED,SAAgB,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAEnD;IAED,SAAgB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