like2d 2.9.0 → 2.10.1
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/README.md +21 -17
- package/dist/__benchmarks__/vector2.bench.d.ts +2 -0
- package/dist/__benchmarks__/vector2.bench.d.ts.map +1 -0
- package/dist/__benchmarks__/vector2.bench.js +74 -0
- package/dist/{core → audio}/audio.d.ts +12 -3
- package/dist/audio/audio.d.ts.map +1 -0
- package/dist/{core → audio}/audio.js +10 -2
- package/dist/audio/index.d.ts +2 -0
- package/dist/audio/index.d.ts.map +1 -0
- package/dist/audio/index.js +1 -0
- package/dist/engine.d.ts +12 -42
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +34 -76
- package/dist/{core/events.d.ts → events.d.ts} +27 -50
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +5 -0
- package/dist/{core → graphics}/canvas.d.ts +18 -11
- package/dist/graphics/canvas.d.ts.map +1 -0
- package/dist/{core → graphics}/canvas.js +73 -58
- package/dist/{core/graphics.d.ts → graphics/drawing.d.ts} +25 -25
- package/dist/graphics/drawing.d.ts.map +1 -0
- package/dist/{core/graphics.js → graphics/drawing.js} +59 -52
- package/dist/graphics/index.d.ts +19 -0
- package/dist/graphics/index.d.ts.map +1 -0
- package/dist/graphics/index.js +13 -0
- package/dist/index.d.ts +3 -30
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -21
- package/dist/input/controllerdb.json +1 -0
- package/dist/input/gamepad-mapping.d.ts +119 -0
- package/dist/input/gamepad-mapping.d.ts.map +1 -0
- package/dist/input/gamepad-mapping.js +114 -0
- package/dist/input/gamepad.d.ts +73 -0
- package/dist/input/gamepad.d.ts.map +1 -0
- package/dist/input/gamepad.js +291 -0
- package/dist/input/index.d.ts +6 -0
- package/dist/input/index.d.ts.map +1 -0
- package/dist/input/index.js +1 -0
- package/dist/input/input.d.ts +76 -0
- package/dist/input/input.d.ts.map +1 -0
- package/dist/input/input.js +163 -0
- package/dist/input/keyboard.d.ts +15 -0
- package/dist/input/keyboard.d.ts.map +1 -0
- package/dist/{core → input}/keyboard.js +11 -21
- package/dist/input/mouse.d.ts +108 -0
- package/dist/input/mouse.d.ts.map +1 -0
- package/dist/input/mouse.js +241 -0
- package/dist/like.d.ts +80 -0
- package/dist/like.d.ts.map +1 -0
- package/dist/like.js +5 -0
- package/dist/math/index.d.ts +16 -0
- package/dist/math/index.d.ts.map +1 -1
- package/dist/math/index.js +16 -0
- package/dist/math/rect.d.ts +24 -27
- package/dist/math/rect.d.ts.map +1 -1
- package/dist/math/rect.js +47 -73
- package/dist/math/vector2.d.ts +87 -32
- package/dist/math/vector2.d.ts.map +1 -1
- package/dist/math/vector2.js +92 -110
- package/dist/prefab-scenes/index.d.ts +1 -0
- package/dist/prefab-scenes/index.d.ts.map +1 -1
- package/dist/prefab-scenes/index.js +1 -0
- package/dist/prefab-scenes/mapGamepad.d.ts +30 -0
- package/dist/prefab-scenes/mapGamepad.d.ts.map +1 -0
- package/dist/prefab-scenes/mapGamepad.js +192 -0
- package/dist/prefab-scenes/startScreen.d.ts +2 -2
- package/dist/prefab-scenes/startScreen.js +2 -2
- package/dist/scene.d.ts +2 -2
- package/dist/scene.d.ts.map +1 -1
- package/dist/timer/index.d.ts +2 -0
- package/dist/timer/index.d.ts.map +1 -0
- package/dist/timer/index.js +1 -0
- package/dist/timer/timer.d.ts +32 -0
- package/dist/timer/timer.d.ts.map +1 -0
- package/dist/{core → timer}/timer.js +20 -3
- package/package.json +21 -12
- package/dist/core/audio.d.ts.map +0 -1
- package/dist/core/canvas.d.ts.map +0 -1
- package/dist/core/events.d.ts.map +0 -1
- package/dist/core/events.js +0 -21
- package/dist/core/gamepad-mapping.d.ts +0 -58
- package/dist/core/gamepad-mapping.d.ts.map +0 -1
- package/dist/core/gamepad-mapping.js +0 -23
- package/dist/core/gamepad.d.ts +0 -37
- package/dist/core/gamepad.d.ts.map +0 -1
- package/dist/core/gamepad.js +0 -103
- package/dist/core/graphics.d.ts.map +0 -1
- package/dist/core/input-state.d.ts +0 -14
- package/dist/core/input-state.d.ts.map +0 -1
- package/dist/core/input-state.js +0 -50
- package/dist/core/input.d.ts +0 -40
- package/dist/core/input.d.ts.map +0 -1
- package/dist/core/input.js +0 -105
- package/dist/core/keyboard.d.ts +0 -15
- package/dist/core/keyboard.d.ts.map +0 -1
- package/dist/core/like.d.ts +0 -113
- package/dist/core/like.d.ts.map +0 -1
- package/dist/core/like.js +0 -9
- package/dist/core/mouse.d.ts +0 -52
- package/dist/core/mouse.d.ts.map +0 -1
- package/dist/core/mouse.js +0 -142
- package/dist/core/timer.d.ts +0 -15
- package/dist/core/timer.d.ts.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "like2d",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.10.1",
|
|
4
4
|
"description": "A web-native game framework inspired by Love2D",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -11,21 +11,29 @@
|
|
|
11
11
|
"import": "./dist/index.js",
|
|
12
12
|
"types": "./dist/index.d.ts"
|
|
13
13
|
},
|
|
14
|
-
"./
|
|
15
|
-
"import": "./dist/
|
|
16
|
-
"types": "./dist/
|
|
17
|
-
},
|
|
18
|
-
"./math/*": {
|
|
19
|
-
"import": "./dist/math/*.js",
|
|
20
|
-
"types": "./dist/math/*.d.ts"
|
|
14
|
+
"./math": {
|
|
15
|
+
"import": "./dist/math/index.js",
|
|
16
|
+
"types": "./dist/math/index.d.ts"
|
|
21
17
|
},
|
|
22
18
|
"./prefab-scenes": {
|
|
23
19
|
"import": "./dist/prefab-scenes/index.js",
|
|
24
20
|
"types": "./dist/prefab-scenes/index.d.ts"
|
|
25
21
|
},
|
|
26
|
-
"./
|
|
27
|
-
"import": "./dist/
|
|
28
|
-
"types": "./dist/
|
|
22
|
+
"./graphics": {
|
|
23
|
+
"import": "./dist/graphics/index.js",
|
|
24
|
+
"types": "./dist/graphics/index.d.ts"
|
|
25
|
+
},
|
|
26
|
+
"./audio": {
|
|
27
|
+
"import": "./dist/audio/index.js",
|
|
28
|
+
"types": "./dist/audio/index.d.ts"
|
|
29
|
+
},
|
|
30
|
+
"./input": {
|
|
31
|
+
"import": "./dist/input/index.js",
|
|
32
|
+
"types": "./dist/input/index.d.ts"
|
|
33
|
+
},
|
|
34
|
+
"./timer": {
|
|
35
|
+
"import": "./dist/timer/index.js",
|
|
36
|
+
"types": "./dist/timer/index.d.ts"
|
|
29
37
|
}
|
|
30
38
|
},
|
|
31
39
|
"files": [
|
|
@@ -39,7 +47,8 @@
|
|
|
39
47
|
"typecheck": "tsc --noEmit",
|
|
40
48
|
"lint": "echo 'No linting configured'",
|
|
41
49
|
"clean": "rm -rf dist",
|
|
42
|
-
"test": "vitest run"
|
|
50
|
+
"test": "vitest run",
|
|
51
|
+
"bench": "vitest bench"
|
|
43
52
|
},
|
|
44
53
|
"keywords": [
|
|
45
54
|
"game",
|
package/dist/core/audio.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"audio.d.ts","sourceRoot":"","sources":["../../src/core/audio.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAA;AAMD;;;;;;GAMG;AACH,qBAAa,WAAW;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,6IAA6I;IAC7I,QAAQ,CAAC,KAAK,EAAE,gBAAgB,CAAC;IACjC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,kBAAkB,CAAC,CAAC;IAC/C,2DAA2D;IAC3D,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9B,OAAO,CAAC,SAAS,CAAoE;IACrF,OAAO,CAAC,QAAQ,CAAgB;gBAEpB,IAAI,EAAE,MAAM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AAW,CAAC,CAAC;IAEnD,gEAAgE;IAChE,cAAc,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC;IAEhE,+BAA+B;IAC/B,eAAe,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC;IAEjE,qEAAqE;IACrE,aAAa,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEhC,8BAA8B;IAC9B,cAAc,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,MAAM,QAAQ,CAAC;AAEvC;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,SAAS,GAAG;KACrB,CAAC,IAAI,SAAS,GAAG;QAAE,IAAI,EAAE,CAAC,CAAC;QAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE;CACpE,CAAC,SAAS,CAAC,CAAC"}
|
package/dist/core/events.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module events
|
|
3
|
-
* @description All events that flow through the engine.
|
|
4
|
-
*
|
|
5
|
-
* ## Overview
|
|
6
|
-
*
|
|
7
|
-
* LIKE uses events at its core.
|
|
8
|
-
* These pass through the engine and down to your
|
|
9
|
-
* callbacks or scene.
|
|
10
|
-
*
|
|
11
|
-
* This module is the single source of truth for what
|
|
12
|
-
* events are possible.
|
|
13
|
-
*
|
|
14
|
-
* Use it as a reference.
|
|
15
|
-
*
|
|
16
|
-
* @see {@link EventMap} lists every event.
|
|
17
|
-
* @see {@link Scene} for implementing callbacks in a class
|
|
18
|
-
* @see {@link Like} for global callback assignment
|
|
19
|
-
* @see {@link Input} for action mapping
|
|
20
|
-
*/
|
|
21
|
-
export {};
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
declare const buttonMap: readonly [{
|
|
2
|
-
readonly like: "ButtonBottom";
|
|
3
|
-
readonly num: number;
|
|
4
|
-
}, {
|
|
5
|
-
readonly like: "ButtonRight";
|
|
6
|
-
readonly num: 1;
|
|
7
|
-
}, {
|
|
8
|
-
readonly like: "ButtonLeft";
|
|
9
|
-
readonly num: 2;
|
|
10
|
-
}, {
|
|
11
|
-
readonly like: "ButtonTop";
|
|
12
|
-
readonly num: 3;
|
|
13
|
-
}, {
|
|
14
|
-
readonly like: "ButtonL1";
|
|
15
|
-
readonly num: 4;
|
|
16
|
-
}, {
|
|
17
|
-
readonly like: "ButtonR1";
|
|
18
|
-
readonly num: 5;
|
|
19
|
-
}, {
|
|
20
|
-
readonly like: "ButtonL2";
|
|
21
|
-
readonly num: 6;
|
|
22
|
-
}, {
|
|
23
|
-
readonly like: "ButtonR2";
|
|
24
|
-
readonly num: 7;
|
|
25
|
-
}, {
|
|
26
|
-
readonly like: "ButtonMenuLeft";
|
|
27
|
-
readonly num: 8;
|
|
28
|
-
}, {
|
|
29
|
-
readonly like: "ButtonMenuRight";
|
|
30
|
-
readonly num: 9;
|
|
31
|
-
}, {
|
|
32
|
-
readonly like: "ButtonMenuCenter";
|
|
33
|
-
readonly num: 16;
|
|
34
|
-
}, {
|
|
35
|
-
readonly like: "ButtonLeftStick";
|
|
36
|
-
readonly num: 10;
|
|
37
|
-
}, {
|
|
38
|
-
readonly like: "ButtonRightStick";
|
|
39
|
-
readonly num: 11;
|
|
40
|
-
}, {
|
|
41
|
-
readonly like: "DPadUp";
|
|
42
|
-
readonly num: 12;
|
|
43
|
-
}, {
|
|
44
|
-
readonly like: "DPadDown";
|
|
45
|
-
readonly num: 13;
|
|
46
|
-
}, {
|
|
47
|
-
readonly like: "DPadLeft";
|
|
48
|
-
readonly num: 14;
|
|
49
|
-
}, {
|
|
50
|
-
readonly like: "DPadRight";
|
|
51
|
-
readonly num: 15;
|
|
52
|
-
}];
|
|
53
|
-
type extraButton = `Button${number}`;
|
|
54
|
-
export type LikeButton = (typeof buttonMap)[number]["like"] | extraButton;
|
|
55
|
-
export declare const numberToName: Map<number, LikeButton>;
|
|
56
|
-
export declare const nameToNumber: Map<LikeButton, number>;
|
|
57
|
-
export {};
|
|
58
|
-
//# sourceMappingURL=gamepad-mapping.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"gamepad-mapping.d.ts","sourceRoot":"","sources":["../../src/core/gamepad-mapping.ts"],"names":[],"mappings":"AAGA,QAAA,MAAM,SAAS;;kBACqB,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqBhC,CAAC;AAEX,KAAK,WAAW,GAAG,SAAS,MAAM,EAAE,CAAC;AAErC,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,GAAG,WAAW,CAAC;AAE1E,eAAO,MAAM,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAEhD,CAAC;AACF,eAAO,MAAM,YAAY,EAAE,GAAG,CAAC,UAAU,EAAE,MAAM,CAEhD,CAAC"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
// Friendlier names for the buttons.
|
|
2
|
-
// https://www.w3.org/TR/gamepad/#dfn-standard-gamepad
|
|
3
|
-
const buttonMap = [
|
|
4
|
-
{ like: "ButtonBottom", num: 0 },
|
|
5
|
-
{ like: "ButtonRight", num: 1 },
|
|
6
|
-
{ like: "ButtonLeft", num: 2 },
|
|
7
|
-
{ like: "ButtonTop", num: 3 },
|
|
8
|
-
{ like: "ButtonL1", num: 4 },
|
|
9
|
-
{ like: "ButtonR1", num: 5 },
|
|
10
|
-
{ like: "ButtonL2", num: 6 },
|
|
11
|
-
{ like: "ButtonR2", num: 7 },
|
|
12
|
-
{ like: "ButtonMenuLeft", num: 8 },
|
|
13
|
-
{ like: "ButtonMenuRight", num: 9 },
|
|
14
|
-
{ like: "ButtonMenuCenter", num: 16 },
|
|
15
|
-
{ like: "ButtonLeftStick", num: 10 },
|
|
16
|
-
{ like: "ButtonRightStick", num: 11 },
|
|
17
|
-
{ like: "DPadUp", num: 12 },
|
|
18
|
-
{ like: "DPadDown", num: 13 },
|
|
19
|
-
{ like: "DPadLeft", num: 14 },
|
|
20
|
-
{ like: "DPadRight", num: 15 },
|
|
21
|
-
];
|
|
22
|
-
export const numberToName = new Map(buttonMap.map(({ like, num }) => [num, like]));
|
|
23
|
-
export const nameToNumber = new Map(buttonMap.map(({ like, num }) => [like, num]));
|
package/dist/core/gamepad.d.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { LikeButton } from './gamepad-mapping';
|
|
2
|
-
import { EngineDispatch } from '../engine';
|
|
3
|
-
export type { LikeButton };
|
|
4
|
-
/** A selector for a gamepad. */
|
|
5
|
-
export type GamepadTarget = number;
|
|
6
|
-
export type ButtonTracker = {
|
|
7
|
-
prev: Set<number>;
|
|
8
|
-
current: Set<number>;
|
|
9
|
-
};
|
|
10
|
-
/** LIKE Gamepad Wrapper
|
|
11
|
-
*
|
|
12
|
-
* - Allows events/callbacks to be sent from joy buttons
|
|
13
|
-
* - Extends stateful API with justPressed
|
|
14
|
-
*
|
|
15
|
-
* # Examples
|
|
16
|
-
*
|
|
17
|
-
* ### Binding events
|
|
18
|
-
* ```ts
|
|
19
|
-
* like.gamepadpressed = (idx: number, _num: number, button: string) => {
|
|
20
|
-
* console.log(`Button ${button} pressed on controller ${idx}`);
|
|
21
|
-
* }
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
export declare class GamepadInternal {
|
|
25
|
-
private dispatch;
|
|
26
|
-
private buttonTrackers;
|
|
27
|
-
private abort;
|
|
28
|
-
constructor(dispatch: EngineDispatch);
|
|
29
|
-
_update(): void;
|
|
30
|
-
isButtonDown(target: GamepadTarget, buttonRaw: number | LikeButton): boolean | undefined;
|
|
31
|
-
isButtonJustPressed(target: GamepadTarget, buttonRaw: LikeButton): boolean | undefined;
|
|
32
|
-
getGamepad(target: number): Gamepad | null;
|
|
33
|
-
_dispose(): void;
|
|
34
|
-
static getButtonName(button: number | LikeButton): LikeButton;
|
|
35
|
-
static getButtonNumber(button: number | LikeButton): number;
|
|
36
|
-
}
|
|
37
|
-
//# sourceMappingURL=gamepad.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"gamepad.d.ts","sourceRoot":"","sources":["../../src/core/gamepad.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA8B,MAAM,mBAAmB,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAE3C,YAAY,EAAE,UAAU,EAAE,CAAC;AAE3B,gCAAgC;AAChC,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC;AAEnC,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAClB,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CACtB,CAAA;AAKD;;;;;;;;;;;;;GAaG;AACH,qBAAa,eAAe;IAId,OAAO,CAAC,QAAQ;IAH5B,OAAO,CAAC,cAAc,CAAoC;IAC1D,OAAO,CAAC,KAAK,CAAyB;gBAElB,QAAQ,EAAE,cAAc;IAwB5C,OAAO,IAAI,IAAI;IA4Bf,YAAY,CAAC,MAAM,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,GAAG,SAAS;IAKxF,mBAAmB,CAAC,MAAM,EAAE,aAAa,EAAE,SAAS,EAAE,UAAU,GAAG,OAAO,GAAG,SAAS;IAQtF,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI;IAI1C,QAAQ,IAAI,IAAI;WAIF,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,GAAG,UAAU;WAMtD,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,GAAG,MAAM;CAMnE"}
|
package/dist/core/gamepad.js
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { nameToNumber, numberToName } from './gamepad-mapping';
|
|
2
|
-
const newButtonTracker = () => ({ prev: new Set(), current: new Set() });
|
|
3
|
-
/** LIKE Gamepad Wrapper
|
|
4
|
-
*
|
|
5
|
-
* - Allows events/callbacks to be sent from joy buttons
|
|
6
|
-
* - Extends stateful API with justPressed
|
|
7
|
-
*
|
|
8
|
-
* # Examples
|
|
9
|
-
*
|
|
10
|
-
* ### Binding events
|
|
11
|
-
* ```ts
|
|
12
|
-
* like.gamepadpressed = (idx: number, _num: number, button: string) => {
|
|
13
|
-
* console.log(`Button ${button} pressed on controller ${idx}`);
|
|
14
|
-
* }
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
export class GamepadInternal {
|
|
18
|
-
constructor(dispatch) {
|
|
19
|
-
Object.defineProperty(this, "dispatch", {
|
|
20
|
-
enumerable: true,
|
|
21
|
-
configurable: true,
|
|
22
|
-
writable: true,
|
|
23
|
-
value: dispatch
|
|
24
|
-
});
|
|
25
|
-
Object.defineProperty(this, "buttonTrackers", {
|
|
26
|
-
enumerable: true,
|
|
27
|
-
configurable: true,
|
|
28
|
-
writable: true,
|
|
29
|
-
value: new Map()
|
|
30
|
-
});
|
|
31
|
-
Object.defineProperty(this, "abort", {
|
|
32
|
-
enumerable: true,
|
|
33
|
-
configurable: true,
|
|
34
|
-
writable: true,
|
|
35
|
-
value: new AbortController()
|
|
36
|
-
});
|
|
37
|
-
// Register event listeners
|
|
38
|
-
window.addEventListener("gamepadconnected", (ev) => {
|
|
39
|
-
if (ev.gamepad.mapping == "standard") {
|
|
40
|
-
console.log(`[Gamepad] Connected standard gamepad ${ev.gamepad.id}.`);
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
console.log(`[Gamepad] Connected non-standard gamepad ${ev.gamepad.id}. Consider remapping.`);
|
|
44
|
-
}
|
|
45
|
-
console.log(`[Gamepad] buttons: ${ev.gamepad.buttons.length}, axes: ${ev.gamepad.axes.length}`);
|
|
46
|
-
this.buttonTrackers.set(ev.gamepad.index, newButtonTracker());
|
|
47
|
-
}, { signal: this.abort.signal });
|
|
48
|
-
window.addEventListener("gamepaddisconnected", (ev) => {
|
|
49
|
-
console.log(`[Gamepad] Disconnected ${ev.gamepad.id}`);
|
|
50
|
-
this.buttonTrackers.delete(ev.gamepad.index);
|
|
51
|
-
}, { signal: this.abort.signal });
|
|
52
|
-
window.addEventListener("blur", () => {
|
|
53
|
-
this.buttonTrackers.forEach(({ current, prev }) => { current.clear(); prev.clear(); });
|
|
54
|
-
}, { signal: this.abort.signal });
|
|
55
|
-
}
|
|
56
|
-
_update() {
|
|
57
|
-
const gamepads = navigator.getGamepads().filter((v) => v !== null);
|
|
58
|
-
gamepads.forEach((domGp, gpIndex) => {
|
|
59
|
-
const tracker = this.buttonTrackers.get(gpIndex);
|
|
60
|
-
if (!tracker)
|
|
61
|
-
return;
|
|
62
|
-
const prev = tracker.current;
|
|
63
|
-
tracker.current = new Set(domGp.buttons
|
|
64
|
-
.map((btn, i) => (btn.pressed ? i : null))
|
|
65
|
-
.filter((v) => v != null));
|
|
66
|
-
domGp.buttons.forEach((_, i) => {
|
|
67
|
-
if (i > 15)
|
|
68
|
-
return;
|
|
69
|
-
if (tracker.prev.has(i) != tracker.current.has(i)) {
|
|
70
|
-
this.dispatch(tracker.prev.has(i) ? "gamepadreleased" : "gamepadpressed", [gpIndex, i, GamepadInternal.getButtonName(i)]);
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
tracker.prev = prev;
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
isButtonDown(target, buttonRaw) {
|
|
77
|
-
const btn = GamepadInternal.getButtonNumber(buttonRaw);
|
|
78
|
-
return this.buttonTrackers.get(target)?.current.has(btn);
|
|
79
|
-
}
|
|
80
|
-
isButtonJustPressed(target, buttonRaw) {
|
|
81
|
-
const btn = GamepadInternal.getButtonNumber(buttonRaw);
|
|
82
|
-
const bt = this.buttonTrackers.get(target);
|
|
83
|
-
if (bt) {
|
|
84
|
-
return !bt.prev.has(btn) && bt.current.has(btn);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
getGamepad(target) {
|
|
88
|
-
return navigator.getGamepads()?.[target] ?? null;
|
|
89
|
-
}
|
|
90
|
-
_dispose() {
|
|
91
|
-
this.abort.abort();
|
|
92
|
-
}
|
|
93
|
-
static getButtonName(button) {
|
|
94
|
-
return typeof button == "number"
|
|
95
|
-
? (numberToName.get(button) ?? `Button${button}`)
|
|
96
|
-
: button;
|
|
97
|
-
}
|
|
98
|
-
static getButtonNumber(button) {
|
|
99
|
-
return typeof button == "number"
|
|
100
|
-
? button
|
|
101
|
-
: (nameToNumber.get(button) ?? Number(button.substring(6)));
|
|
102
|
-
}
|
|
103
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"graphics.d.ts","sourceRoot":"","sources":["../../src/core/graphics.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,KAAK,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;AAEhC;;;;GAIG;AACH,MAAM,MAAM,KAAK,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC;AAE/D,MAAM,MAAM,UAAU,GAAG;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG;IACnC,I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ressedKeys: Set<T>): {
|
|
5
|
-
justPressed: T[];
|
|
6
|
-
justReleased: T[];
|
|
7
|
-
};
|
|
8
|
-
isDown(key: T): boolean;
|
|
9
|
-
justPressed(key: T): boolean;
|
|
10
|
-
justReleased(key: T): boolean;
|
|
11
|
-
getCurrentState(): Set<T>;
|
|
12
|
-
clear(): void;
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=input-state.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"input-state.d.ts","sourceRoot":"","sources":["../../src/core/input-state.ts"],"names":[],"mappings":"AAAA,qBAAa,iBAAiB,CAAC,CAAC;IACvB,SAAS,SAAgB;IACzB,SAAS,SAAgB;IAEhC,MAAM,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,CAAC,GAAG;QAAE,WAAW,EAAE,CAAC,EAAE,CAAC;QAAC,YAAY,EAAE,CAAC,EAAE,CAAA;KAAE;IAuBpE,MAAM,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO;IAIvB,WAAW,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO;IAI5B,YAAY,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO;IAI7B,eAAe,IAAI,GAAG,CAAC,CAAC,CAAC;IAIzB,KAAK,IAAI,IAAI;CAId"}
|
package/dist/core/input-state.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
export class InputStateTracker {
|
|
2
|
-
constructor() {
|
|
3
|
-
Object.defineProperty(this, "prevState", {
|
|
4
|
-
enumerable: true,
|
|
5
|
-
configurable: true,
|
|
6
|
-
writable: true,
|
|
7
|
-
value: new Set()
|
|
8
|
-
});
|
|
9
|
-
Object.defineProperty(this, "currState", {
|
|
10
|
-
enumerable: true,
|
|
11
|
-
configurable: true,
|
|
12
|
-
writable: true,
|
|
13
|
-
value: new Set()
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
update(pressedKeys) {
|
|
17
|
-
const justPressed = [];
|
|
18
|
-
const justReleased = [];
|
|
19
|
-
const nextState = new Set(pressedKeys);
|
|
20
|
-
for (const key of nextState) {
|
|
21
|
-
if (!this.currState.has(key)) {
|
|
22
|
-
justPressed.push(key);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
for (const key of this.currState) {
|
|
26
|
-
if (!nextState.has(key)) {
|
|
27
|
-
justReleased.push(key);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
this.prevState = new Set(this.currState);
|
|
31
|
-
this.currState = nextState;
|
|
32
|
-
return { justPressed, justReleased };
|
|
33
|
-
}
|
|
34
|
-
isDown(key) {
|
|
35
|
-
return this.currState.has(key);
|
|
36
|
-
}
|
|
37
|
-
justPressed(key) {
|
|
38
|
-
return !this.prevState.has(key) && this.currState.has(key);
|
|
39
|
-
}
|
|
40
|
-
justReleased(key) {
|
|
41
|
-
return this.prevState.has(key) && !this.currState.has(key);
|
|
42
|
-
}
|
|
43
|
-
getCurrentState() {
|
|
44
|
-
return new Set(this.currState);
|
|
45
|
-
}
|
|
46
|
-
clear() {
|
|
47
|
-
this.prevState.clear();
|
|
48
|
-
this.currState.clear();
|
|
49
|
-
}
|
|
50
|
-
}
|
package/dist/core/input.d.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import type { KeyboardInternal } from './keyboard';
|
|
2
|
-
import type { MouseInternal } from './mouse';
|
|
3
|
-
import { GamepadTarget, GamepadInternal } from './gamepad';
|
|
4
|
-
import { MouseButton } from './events';
|
|
5
|
-
export type InputType = InputBinding['type'];
|
|
6
|
-
export type InputBinding = {
|
|
7
|
-
type: 'keyboard';
|
|
8
|
-
scancode: string;
|
|
9
|
-
} | {
|
|
10
|
-
type: 'mouse';
|
|
11
|
-
button: MouseButton;
|
|
12
|
-
} | {
|
|
13
|
-
type: 'gamepad';
|
|
14
|
-
gamepad: GamepadTarget;
|
|
15
|
-
button: number;
|
|
16
|
-
};
|
|
17
|
-
export declare class InputInternal {
|
|
18
|
-
private actionMap;
|
|
19
|
-
private actionStateTracker;
|
|
20
|
-
private keyboard;
|
|
21
|
-
private mouse;
|
|
22
|
-
private gamepad;
|
|
23
|
-
constructor(deps: {
|
|
24
|
-
keyboard: KeyboardInternal;
|
|
25
|
-
mouse: MouseInternal;
|
|
26
|
-
gamepad: GamepadInternal;
|
|
27
|
-
});
|
|
28
|
-
setAction(action: string, inputs?: string[]): void;
|
|
29
|
-
isDown(action: string): boolean;
|
|
30
|
-
justPressed(action: string): boolean;
|
|
31
|
-
justReleased(action: string): boolean;
|
|
32
|
-
_update(): {
|
|
33
|
-
pressed: string[];
|
|
34
|
-
released: string[];
|
|
35
|
-
};
|
|
36
|
-
private parseInput;
|
|
37
|
-
private isBindingActive;
|
|
38
|
-
clear(): void;
|
|
39
|
-
}
|
|
40
|
-
//# sourceMappingURL=input.d.ts.map
|
package/dist/core/input.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../../src/core/input.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAG3D,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,MAAM,MAAM,SAAS,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;AAC7C,MAAM,MAAM,YAAY,GACpB;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GACtC;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,WAAW,CAAA;CAAE,GACtC;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,aAAa,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhE,qBAAa,aAAa;IACxB,OAAO,CAAC,SAAS,CAAqC;IACtD,OAAO,CAAC,kBAAkB,CAAmC;IAC7D,OAAO,CAAC,QAAQ,CAAmB;IACnC,OAAO,CAAC,KAAK,CAAgB;IAC7B,OAAO,CAAC,OAAO,CAAkB;gBAErB,IAAI,EAAE;QAAE,QAAQ,EAAE,gBAAgB,CAAC;QAAC,KAAK,EAAE,aAAa,CAAC;QAAC,OAAO,EAAE,eAAe,CAAA;KAAE;IAMhG,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,GAAE,MAAM,EAAO,GAAG,IAAI;IAWtD,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAO/B,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAIpC,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAIrC,OAAO,IAAI;QAAE,OAAO,EAAE,MAAM,EAAE,CAAC;QAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;KAAE;IAgBpD,OAAO,CAAC,UAAU;IAmBlB,OAAO,CAAC,eAAe;IAcvB,KAAK,IAAI,IAAI;CAId"}
|
package/dist/core/input.js
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { GamepadInternal } from './gamepad';
|
|
2
|
-
import { InputStateTracker } from './input-state';
|
|
3
|
-
export class InputInternal {
|
|
4
|
-
constructor(deps) {
|
|
5
|
-
Object.defineProperty(this, "actionMap", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
configurable: true,
|
|
8
|
-
writable: true,
|
|
9
|
-
value: new Map()
|
|
10
|
-
});
|
|
11
|
-
Object.defineProperty(this, "actionStateTracker", {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
configurable: true,
|
|
14
|
-
writable: true,
|
|
15
|
-
value: new InputStateTracker()
|
|
16
|
-
});
|
|
17
|
-
Object.defineProperty(this, "keyboard", {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
configurable: true,
|
|
20
|
-
writable: true,
|
|
21
|
-
value: void 0
|
|
22
|
-
});
|
|
23
|
-
Object.defineProperty(this, "mouse", {
|
|
24
|
-
enumerable: true,
|
|
25
|
-
configurable: true,
|
|
26
|
-
writable: true,
|
|
27
|
-
value: void 0
|
|
28
|
-
});
|
|
29
|
-
Object.defineProperty(this, "gamepad", {
|
|
30
|
-
enumerable: true,
|
|
31
|
-
configurable: true,
|
|
32
|
-
writable: true,
|
|
33
|
-
value: void 0
|
|
34
|
-
});
|
|
35
|
-
this.keyboard = deps.keyboard;
|
|
36
|
-
this.mouse = deps.mouse;
|
|
37
|
-
this.gamepad = deps.gamepad;
|
|
38
|
-
}
|
|
39
|
-
setAction(action, inputs = []) {
|
|
40
|
-
if (inputs.length) {
|
|
41
|
-
const bindings = inputs.map(input => this.parseInput(input));
|
|
42
|
-
this.actionMap.set(action, bindings);
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
this.actionMap.delete(action);
|
|
46
|
-
this.actionStateTracker.currState.delete(action);
|
|
47
|
-
this.actionStateTracker.prevState.delete(action);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
isDown(action) {
|
|
51
|
-
const bindings = this.actionMap.get(action);
|
|
52
|
-
if (!bindings)
|
|
53
|
-
return false;
|
|
54
|
-
return bindings.some(binding => this.isBindingActive(binding));
|
|
55
|
-
}
|
|
56
|
-
justPressed(action) {
|
|
57
|
-
return this.actionStateTracker.justPressed(action);
|
|
58
|
-
}
|
|
59
|
-
justReleased(action) {
|
|
60
|
-
return this.actionStateTracker.justReleased(action);
|
|
61
|
-
}
|
|
62
|
-
_update() {
|
|
63
|
-
this.gamepad._update();
|
|
64
|
-
const activeActions = new Set();
|
|
65
|
-
for (const [action] of this.actionMap) {
|
|
66
|
-
if (this.isDown(action)) {
|
|
67
|
-
activeActions.add(action);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
const { justPressed, justReleased } = this.actionStateTracker.update(activeActions);
|
|
71
|
-
return { pressed: justPressed, released: justReleased };
|
|
72
|
-
}
|
|
73
|
-
parseInput(input) {
|
|
74
|
-
const normalized = input.trim();
|
|
75
|
-
if (normalized.startsWith('Mouse')) {
|
|
76
|
-
const buttonCode = normalized.replace('Mouse', '');
|
|
77
|
-
return { type: 'mouse', button: buttonCode };
|
|
78
|
-
}
|
|
79
|
-
if (normalized.startsWith('Button') || normalized.startsWith('DP')) {
|
|
80
|
-
return {
|
|
81
|
-
type: "gamepad",
|
|
82
|
-
gamepad: 0,
|
|
83
|
-
button: GamepadInternal.getButtonNumber(normalized),
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
return { type: 'keyboard', scancode: normalized };
|
|
87
|
-
}
|
|
88
|
-
isBindingActive(binding) {
|
|
89
|
-
switch (binding.type) {
|
|
90
|
-
case 'keyboard':
|
|
91
|
-
return this.keyboard.isDown(binding.scancode);
|
|
92
|
-
case 'mouse':
|
|
93
|
-
return this.mouse.isDown(binding.button);
|
|
94
|
-
case 'gamepad': {
|
|
95
|
-
return !!this.gamepad.isButtonDown(binding.gamepad, binding.button);
|
|
96
|
-
}
|
|
97
|
-
default:
|
|
98
|
-
return false;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
clear() {
|
|
102
|
-
this.actionMap.clear();
|
|
103
|
-
this.actionStateTracker.clear();
|
|
104
|
-
}
|
|
105
|
-
}
|
package/dist/core/keyboard.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { EngineDispatch } from "../engine";
|
|
2
|
-
export declare class KeyboardInternal {
|
|
3
|
-
private dispatch;
|
|
4
|
-
private pressedScancodes;
|
|
5
|
-
private canvas;
|
|
6
|
-
private abort;
|
|
7
|
-
constructor(canvas: HTMLCanvasElement | null, dispatch: EngineDispatch);
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"keyboard.d.ts","sourceRoot":"","sources":["../../src/core/keyboard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAE3C,qBAAa,gBAAgB;IAKmB,OAAO,CAAC,QAAQ;IAJ9D,OAAO,CAAC,gBAAgB,CAAqB;IAC7C,OAAO,CAAC,MAAM,CAAkC;IAChD,OAAO,CAAC,KAAK,CAAyB;gBAE1B,MAAM,EAAE,iBAAiB,GAAG,IAAI,EAAU,QAAQ,EAAE,cAAc;IAU9E,OAAO,CAAC,aAAa;IAYrB,OAAO,CAAC,WAAW;IAOnB,OAAO,CAAC,UAAU;IAIlB,QAAQ,IAAI,IAAI;IAKhB,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAIjC,SAAS,CAAC,GAAG,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO;CAG3C"}
|