like2d 2.10.0 → 2.10.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/engine.js +1 -1
- package/dist/input/controllerdb.json +1 -0
- package/dist/input/gamepad-mapping.d.ts +5 -20
- package/dist/input/gamepad-mapping.d.ts.map +1 -1
- package/dist/input/gamepad-mapping.js +41 -73
- package/dist/input/gamepad.d.ts +1 -2
- package/dist/input/gamepad.d.ts.map +1 -1
- package/dist/input/gamepad.js +5 -2
- package/dist/input/input.d.ts.map +1 -1
- package/dist/input/input.js +0 -1
- package/dist/prefab-scenes/mapGamepad.d.ts +2 -0
- package/dist/prefab-scenes/mapGamepad.d.ts.map +1 -1
- package/dist/prefab-scenes/mapGamepad.js +14 -3
- package/package.json +2 -2
- package/dist/gamecontrollerdb.txt +0 -2222
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
* browser APIs into physical gamepad button
|
|
7
7
|
* mappings.
|
|
8
8
|
*
|
|
9
|
+
*
|
|
9
10
|
* Browser API shortcomings:
|
|
10
|
-
* - No standard way of exposing vendor
|
|
11
|
-
* -
|
|
12
|
-
* - Vendor and product alone doesn't suffice for GUID -- Different controllers have the same.
|
|
11
|
+
* - [No standard way of exposing vendor/product, Safari doesn't even do it.](https://github.com/w3c/gamepad/issues/199)
|
|
12
|
+
* - Vendor and product alone doesn't suffice for GUID -- Different controllers have the same, it's good-enough.
|
|
13
13
|
* - D-pads either get mapped to an axis (last pair of axes in Chromium) or buttons (Firefox).
|
|
14
14
|
* - Analog axes get mapped differently in Firefox and Chromium.
|
|
15
15
|
*
|
|
@@ -26,82 +26,66 @@ import type { Vector2 } from "../math";
|
|
|
26
26
|
* Which are exceedingly common.
|
|
27
27
|
*/
|
|
28
28
|
declare const buttonMap: readonly [{
|
|
29
|
-
readonly sdl: "a";
|
|
30
29
|
readonly like: "BBottom";
|
|
31
30
|
readonly num: number;
|
|
32
31
|
readonly name: "Bottom Face Button";
|
|
33
32
|
}, {
|
|
34
|
-
readonly sdl: "b";
|
|
35
33
|
readonly like: "BRight";
|
|
36
34
|
readonly num: 1;
|
|
37
35
|
readonly name: "Right Face Button";
|
|
38
36
|
}, {
|
|
39
|
-
readonly sdl: "x";
|
|
40
37
|
readonly like: "BLeft";
|
|
41
38
|
readonly num: 2;
|
|
42
39
|
readonly name: "Left Face Button";
|
|
43
40
|
}, {
|
|
44
|
-
readonly sdl: "y";
|
|
45
41
|
readonly like: "BTop";
|
|
46
42
|
readonly num: 3;
|
|
47
43
|
readonly name: "Top Face Button";
|
|
48
44
|
}, {
|
|
49
|
-
readonly sdl: "leftshoulder";
|
|
50
45
|
readonly like: "L1";
|
|
51
46
|
readonly num: 4;
|
|
52
47
|
readonly name: "Left shoulder (front)";
|
|
53
48
|
}, {
|
|
54
|
-
readonly sdl: "rightshoulder";
|
|
55
49
|
readonly like: "R1";
|
|
56
50
|
readonly num: 5;
|
|
57
51
|
readonly name: "Right shoulder (front)";
|
|
58
52
|
}, {
|
|
59
|
-
readonly sdl: "lefttrigger";
|
|
60
53
|
readonly like: "L2";
|
|
61
54
|
readonly num: 6;
|
|
62
55
|
readonly name: "Left shoulder (rear)";
|
|
63
56
|
}, {
|
|
64
|
-
readonly sdl: "righttrigger";
|
|
65
57
|
readonly like: "R2";
|
|
66
58
|
readonly num: 7;
|
|
67
59
|
readonly name: "Right shoulder (rear)";
|
|
68
60
|
}, {
|
|
69
|
-
readonly sdl: "back";
|
|
70
61
|
readonly like: "MenuLeft";
|
|
71
62
|
readonly num: 8;
|
|
72
63
|
readonly name: "Left Menu Button";
|
|
73
64
|
}, {
|
|
74
|
-
readonly sdl: "start";
|
|
75
65
|
readonly like: "MenuRight";
|
|
76
66
|
readonly num: 9;
|
|
77
67
|
readonly name: "Right Menu Button";
|
|
78
68
|
}, {
|
|
79
|
-
readonly sdl: "leftstick";
|
|
80
69
|
readonly like: "LeftStick";
|
|
81
70
|
readonly num: 10;
|
|
82
71
|
readonly name: "Left Stick Button";
|
|
83
72
|
}, {
|
|
84
|
-
readonly sdl: "rightstick";
|
|
85
73
|
readonly like: "RightStick";
|
|
86
74
|
readonly num: 11;
|
|
87
75
|
readonly name: "Right Stick Button";
|
|
88
76
|
}, {
|
|
89
|
-
readonly sdl: "dpup";
|
|
90
77
|
readonly like: "Up";
|
|
91
78
|
readonly num: 12;
|
|
92
79
|
readonly name: "D-Pad Up";
|
|
93
80
|
}, {
|
|
94
|
-
readonly sdl: "dpdown";
|
|
95
81
|
readonly like: "Down";
|
|
96
82
|
readonly num: 13;
|
|
97
83
|
readonly name: "D-Pad Down";
|
|
98
84
|
}, {
|
|
99
|
-
readonly sdl: "dpleft";
|
|
100
85
|
readonly like: "Left";
|
|
101
86
|
readonly num: 14;
|
|
102
87
|
readonly name: "D-Pad Left";
|
|
103
88
|
}, {
|
|
104
|
-
readonly sdl: "dpright";
|
|
105
89
|
readonly like: "Right";
|
|
106
90
|
readonly num: 15;
|
|
107
91
|
readonly name: "D-Pad right";
|
|
@@ -126,8 +110,9 @@ type SdlMapping = {
|
|
|
126
110
|
vendor: number;
|
|
127
111
|
product: number;
|
|
128
112
|
name: string;
|
|
129
|
-
sdlName: string;
|
|
130
113
|
mapping: Record<number, LikeButton>;
|
|
114
|
+
browserName?: string;
|
|
115
|
+
id?: string;
|
|
131
116
|
};
|
|
132
117
|
export declare function getSdlMapping(gamepad: Gamepad): SdlMapping | undefined;
|
|
133
118
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gamepad-mapping.d.ts","sourceRoot":"","sources":["../../src/input/gamepad-mapping.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAEvC;;;;;;GAMG;AACH,QAAA,MAAM,SAAS
|
|
1
|
+
{"version":3,"file":"gamepad-mapping.d.ts","sourceRoot":"","sources":["../../src/input/gamepad-mapping.ts"],"names":[],"mappings":"AAAA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B,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,UAAU,GAAG,SAAS,CAwBtE"}
|
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
* browser APIs into physical gamepad button
|
|
7
7
|
* mappings.
|
|
8
8
|
*
|
|
9
|
+
*
|
|
9
10
|
* Browser API shortcomings:
|
|
10
|
-
* - No standard way of exposing vendor
|
|
11
|
-
* -
|
|
12
|
-
* - Vendor and product alone doesn't suffice for GUID -- Different controllers have the same.
|
|
11
|
+
* - [No standard way of exposing vendor/product, Safari doesn't even do it.](https://github.com/w3c/gamepad/issues/199)
|
|
12
|
+
* - Vendor and product alone doesn't suffice for GUID -- Different controllers have the same, it's good-enough.
|
|
13
13
|
* - D-pads either get mapped to an axis (last pair of axes in Chromium) or buttons (Firefox).
|
|
14
14
|
* - Analog axes get mapped differently in Firefox and Chromium.
|
|
15
15
|
*
|
|
@@ -25,31 +25,33 @@
|
|
|
25
25
|
* Which are exceedingly common.
|
|
26
26
|
*/
|
|
27
27
|
const buttonMap = [
|
|
28
|
-
{
|
|
29
|
-
{
|
|
30
|
-
{
|
|
31
|
-
{
|
|
32
|
-
{
|
|
33
|
-
{
|
|
34
|
-
{
|
|
35
|
-
{
|
|
36
|
-
{
|
|
37
|
-
{
|
|
38
|
-
{
|
|
39
|
-
{
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
},
|
|
45
|
-
{ sdl: "dpup", like: "Up", num: 12, name: "D-Pad Up" },
|
|
46
|
-
{ sdl: "dpdown", like: "Down", num: 13, name: "D-Pad Down" },
|
|
47
|
-
{ sdl: "dpleft", like: "Left", num: 14, name: "D-Pad Left" },
|
|
48
|
-
{ sdl: "dpright", like: "Right", num: 15, name: "D-Pad right" },
|
|
28
|
+
{ like: "BBottom", num: 0, name: "Bottom Face Button" },
|
|
29
|
+
{ like: "BRight", num: 1, name: "Right Face Button" },
|
|
30
|
+
{ like: "BLeft", num: 2, name: "Left Face Button" },
|
|
31
|
+
{ like: "BTop", num: 3, name: "Top Face Button" },
|
|
32
|
+
{ like: "L1", num: 4, name: "Left shoulder (front)" },
|
|
33
|
+
{ like: "R1", num: 5, name: "Right shoulder (front)" },
|
|
34
|
+
{ like: "L2", num: 6, name: "Left shoulder (rear)" },
|
|
35
|
+
{ like: "R2", num: 7, name: "Right shoulder (rear)" },
|
|
36
|
+
{ like: "MenuLeft", num: 8, name: "Left Menu Button" },
|
|
37
|
+
{ like: "MenuRight", num: 9, name: "Right Menu Button" },
|
|
38
|
+
{ like: "LeftStick", num: 10, name: "Left Stick Button" },
|
|
39
|
+
{ like: "RightStick", num: 11, name: "Right Stick Button" },
|
|
40
|
+
{ like: "Up", num: 12, name: "D-Pad Up" },
|
|
41
|
+
{ like: "Down", num: 13, name: "D-Pad Down" },
|
|
42
|
+
{ like: "Left", num: 14, name: "D-Pad Left" },
|
|
43
|
+
{ like: "Right", num: 15, name: "D-Pad right" },
|
|
49
44
|
];
|
|
45
|
+
const detectedOs = ((s) => [
|
|
46
|
+
["Android", "Android"],
|
|
47
|
+
["iPhone", "iOS"],
|
|
48
|
+
["iPad", "iOS"],
|
|
49
|
+
["Win", "Windows"],
|
|
50
|
+
["Mac", "Mac OS X"],
|
|
51
|
+
].find(([ss]) => s.includes(ss))?.[1] ?? "Linux")(navigator.userAgent);
|
|
50
52
|
export const defaultMapping = (stickCount) => ({
|
|
51
53
|
buttons: {},
|
|
52
|
-
sticks: Array(stickCount
|
|
54
|
+
sticks: Array(stickCount)
|
|
53
55
|
.fill(0)
|
|
54
56
|
.map((_, i) => [
|
|
55
57
|
{ index: i * 2, invert: false },
|
|
@@ -63,62 +65,28 @@ export const mapStick = (gp, mapping) => {
|
|
|
63
65
|
return mapping.map((axis) => (axis.invert ? -1 : 1) * (gp.axes[axis.index] ?? 0));
|
|
64
66
|
};
|
|
65
67
|
//// ************* SDL Gamepad auto-binding system ******************* ////
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
.map((l) => l.trim())
|
|
75
|
-
.filter((line) => line !== "" && !line.startsWith("#"))
|
|
76
|
-
.map(parseDbLine);
|
|
77
|
-
console.log(`[Gamepad] Parsed ${dbEntries.length} entries from DB`);
|
|
78
|
-
const mappingDb = Object.fromEntries(dbEntries);
|
|
79
|
-
console.log(`[Gamepad] Final entry count: ${Object.keys(mappingDb).length}`);
|
|
80
|
-
return mappingDb;
|
|
81
|
-
}
|
|
82
|
-
function parseDbLine(line) {
|
|
83
|
-
const [guid, name, ...mappings] = line.split(",");
|
|
84
|
-
mappings.pop();
|
|
85
|
-
const vpNum = 0x1 * parseInt(guid.substring(16, 18), 16) +
|
|
86
|
-
0x100 * parseInt(guid.substring(18, 20), 16) +
|
|
87
|
-
0x10000 * parseInt(guid.substring(8, 10), 16) +
|
|
88
|
-
0x1000000 * parseInt(guid.substring(10, 12), 16);
|
|
89
|
-
const mapping = Object.fromEntries(mappings
|
|
90
|
-
.map((s) => {
|
|
91
|
-
const [sdl, bname] = s.split(":");
|
|
92
|
-
const browserIndex = sdlRawButtonToBrowser(bname);
|
|
93
|
-
return (browserIndex !== undefined &&
|
|
94
|
-
sdlButtonSet.has(sdl) && [browserIndex, sdlToLikeMap.get(sdl)]);
|
|
95
|
-
})
|
|
96
|
-
.filter((v) => !!v));
|
|
97
|
-
return [vpNum, { name, mapping }];
|
|
98
|
-
}
|
|
99
|
-
function sdlRawButtonToBrowser(btn) {
|
|
100
|
-
return btn.startsWith("b")
|
|
101
|
-
? Number(btn.substring(1))
|
|
102
|
-
: btn.startsWith("h")
|
|
103
|
-
? { 1: 12, 2: 13, 4: 14, 8: 15 }[Number(btn.substring(3))]
|
|
104
|
-
: undefined;
|
|
105
|
-
}
|
|
68
|
+
import mappingDbRaw from "./controllerdb.json" with { type: 'json' };
|
|
69
|
+
const mappingDb = new Map(Object.entries(mappingDbRaw[detectedOs]).map(([k, v]) => [
|
|
70
|
+
Number(k),
|
|
71
|
+
{
|
|
72
|
+
...v,
|
|
73
|
+
mapping: Object.fromEntries(Object.entries(v.mapping).map(([k, v]) => [Number(k), v])),
|
|
74
|
+
},
|
|
75
|
+
]));
|
|
106
76
|
export function getSdlMapping(gamepad) {
|
|
107
|
-
const parsed =
|
|
77
|
+
const parsed = trySplitId(gamepad.id);
|
|
108
78
|
if (parsed) {
|
|
109
79
|
const [vendorStr, productStr, nameStr] = parsed;
|
|
110
80
|
const vendor = parseInt(vendorStr, 16);
|
|
111
81
|
const product = parseInt(productStr, 16);
|
|
112
82
|
const name = nameStr.trim();
|
|
113
|
-
const mapping = mappingDb
|
|
83
|
+
const mapping = mappingDb.get(vendor * 0x10000 + product);
|
|
114
84
|
if (mapping) {
|
|
115
85
|
console.log(`[Gamepad] Found SDL db mapping for '${name}'`);
|
|
116
86
|
return {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
sdlName: mapping.name,
|
|
121
|
-
mapping: mapping.mapping,
|
|
87
|
+
...mapping,
|
|
88
|
+
browserName: name,
|
|
89
|
+
id: gamepad.id,
|
|
122
90
|
};
|
|
123
91
|
}
|
|
124
92
|
else {
|
|
@@ -129,7 +97,7 @@ export function getSdlMapping(gamepad) {
|
|
|
129
97
|
console.log(`[Gamepad] Failed to parse id: ${gamepad.id}. Please report this bug with the name of your web browser.`);
|
|
130
98
|
}
|
|
131
99
|
}
|
|
132
|
-
function
|
|
100
|
+
function trySplitId(id) {
|
|
133
101
|
const infoC = id.match(/^([^(]+)\(Vendor: ([0-9a-f]+) Product: ([0-9a-f]+)/i);
|
|
134
102
|
if (infoC) {
|
|
135
103
|
// chrome pattern: Name(Vendor: VEND Product: PROD)
|
package/dist/input/gamepad.d.ts
CHANGED
|
@@ -22,10 +22,9 @@ export declare class Gamepad {
|
|
|
22
22
|
constructor(props: EngineProps<LikeGamepadEvent>);
|
|
23
23
|
private onGamepadConnected;
|
|
24
24
|
/**
|
|
25
|
-
* @private
|
|
26
25
|
* Called by the engine every frame.
|
|
27
26
|
*/
|
|
28
|
-
update
|
|
27
|
+
private update;
|
|
29
28
|
/**
|
|
30
29
|
*
|
|
31
30
|
* @param target Which controller?
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gamepad.d.ts","sourceRoot":"","sources":["../../src/input/gamepad.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkC,cAAc,EAAiB,UAAU,
|
|
1
|
+
{"version":3,"file":"gamepad.d.ts","sourceRoot":"","sources":["../../src/input/gamepad.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkC,cAAc,EAAiB,UAAU,EAAmC,MAAM,mBAAmB,CAAC;AAC/I,OAAO,EAAmB,KAAK,gBAAgB,EAAE,MAAM,WAAW,CAAC;AACnE,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC,gCAAgC;AAChC,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,KAAK,CAAC;AAE3C;;;;;;;;;;GAUG;AACH,qBAAa,OAAO;IAClB,OAAO,CAAC,QAAQ,CAA+B;IAC/C,OAAO,CAAC,QAAQ,CAAoC;IACpD,OAAO,CAAC,eAAe,CAAQ;gBAEnB,KAAK,EAAE,WAAW,CAAC,gBAAgB,CAAC;IAmChD,OAAO,CAAC,kBAAkB;IAgC1B;;OAEG;IACH,OAAO,CAAC,MAAM;IAId;;;;OAIG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,EAAE;IAQpC,cAAc,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM;IAIxC,OAAO,CAAC,WAAW;IAYnB,yCAAyC;IACzC,MAAM,CACJ,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,UAAU,GAAG,MAAM,GAC1B,OAAO,GAAG,SAAS;IAItB;;;OAGG;IACH,WAAW,CACT,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,UAAU,GAAG,MAAM,GAC1B,OAAO,GAAG,SAAS;IAItB;;;;OAIG;IACH,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS;IAIrD;;;;OAIG;IACH,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,IAAI,UAAO;IAU9D;;OAEG;IACH,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS;IAYtD;;OAEG;IACH,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc;IASlD;;;;;;;OAOG;IACH,qBAAqB,CAAC,MAAM,EAAE,OAAO;CAGtC"}
|
package/dist/input/gamepad.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defaultMapping, fullButtonName, getSdlMapping, mapStick } from './gamepad-mapping';
|
|
1
|
+
import { defaultMapping, fullButtonName, getSdlMapping, mapStick, standardButtonMapping } from './gamepad-mapping';
|
|
2
2
|
/** LIKE Gamepad Wrapper
|
|
3
3
|
*
|
|
4
4
|
* - Allows events/callbacks to be sent from joy buttons.
|
|
@@ -46,6 +46,9 @@ export class Gamepad {
|
|
|
46
46
|
gps.clear();
|
|
47
47
|
}
|
|
48
48
|
}, { signal: abort });
|
|
49
|
+
props.canvas.addEventListener("like:update", this.update.bind(this), {
|
|
50
|
+
signal: abort,
|
|
51
|
+
});
|
|
49
52
|
}
|
|
50
53
|
onGamepadConnected(ev) {
|
|
51
54
|
const gps = new GamepadState(ev.gamepad.index);
|
|
@@ -58,6 +61,7 @@ export class Gamepad {
|
|
|
58
61
|
}
|
|
59
62
|
else if (ev.gamepad.mapping == 'standard') {
|
|
60
63
|
gps.mapping = defaultMapping(ev.gamepad.axes.length / 2);
|
|
64
|
+
gps.mapping.buttons = standardButtonMapping();
|
|
61
65
|
console.log(`Loaded standard mapping.`);
|
|
62
66
|
}
|
|
63
67
|
else {
|
|
@@ -73,7 +77,6 @@ export class Gamepad {
|
|
|
73
77
|
this.dispatch("gamepadconnected", [ev.gamepad.index]);
|
|
74
78
|
}
|
|
75
79
|
/**
|
|
76
|
-
* @private
|
|
77
80
|
* Called by the engine every frame.
|
|
78
81
|
*/
|
|
79
82
|
update() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../../src/input/input.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAc,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEpD,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,UAAU,CAAA;CAAE,CAAC;AAEpE,qBAAa,KAAK;IASd,OAAO,CAAC,QAAQ;IARlB,OAAO,CAAC,SAAS,CAAqB;IACtC,OAAO,CAAC,SAAS,CAAqB;IACtC,OAAO,CAAC,WAAW,CAAsC;IACzD,OAAO,CAAC,QAAQ,CAAW;IAC3B,OAAO,CAAC,KAAK,CAAQ;IACrB,OAAO,CAAC,OAAO,CAAU;gBAGf,QAAQ,EAAE,UAAU,CAAC,eAAe,GAAG,gBAAgB,CAAC,EAChE,IAAI,EAAE;QACJ,QAAQ,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AAA;CAAE,CAAC;AAEpE,qBAAa,KAAK;IASd,OAAO,CAAC,QAAQ;IARlB,OAAO,CAAC,SAAS,CAAqB;IACtC,OAAO,CAAC,SAAS,CAAqB;IACtC,OAAO,CAAC,WAAW,CAAsC;IACzD,OAAO,CAAC,QAAQ,CAAW;IAC3B,OAAO,CAAC,KAAK,CAAQ;IACrB,OAAO,CAAC,OAAO,CAAU;gBAGf,QAAQ,EAAE,UAAU,CAAC,eAAe,GAAG,gBAAgB,CAAC,EAChE,IAAI,EAAE;QACJ,QAAQ,EAAE,QAAQ,CAAC;QACnB,KAAK,EAAE,KAAK,CAAC;QACb,OAAO,EAAE,OAAO,CAAC;KAClB;IAOH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,GAAE,CAAC,MAAM,GAAG,YAAY,CAAC,EAAO,GAAG,IAAI;IAUvE;;OAEG;IACH,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,MAAM;IAM3D;;OAEG;IACH,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,EAAE;IAIhD,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAM/B,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAIpC,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAIrC,MAAM;IAgBN,OAAO,CAAC,eAAe;CAaxB"}
|
package/dist/input/input.js
CHANGED
|
@@ -114,7 +114,6 @@ export class Input {
|
|
|
114
114
|
return !this.currState.has(action) && this.prevState.has(action);
|
|
115
115
|
}
|
|
116
116
|
update() {
|
|
117
|
-
this.gamepad.update();
|
|
118
117
|
[this.prevState, this.currState] = [this.currState, this.prevState];
|
|
119
118
|
this.currState.clear();
|
|
120
119
|
for (const action of Object.keys(this.actionTable)) {
|
|
@@ -18,8 +18,10 @@ export declare class MapGamepad implements Scene {
|
|
|
18
18
|
private mapping;
|
|
19
19
|
private held?;
|
|
20
20
|
private alreadyMapped;
|
|
21
|
+
private frameWait;
|
|
21
22
|
constructor(mapMode: MapMode, targetPad: number, next?: Scene | undefined);
|
|
22
23
|
load(like: Like): void;
|
|
24
|
+
update(): void;
|
|
23
25
|
draw(like: Like): void;
|
|
24
26
|
gamepadpressed(like: Like, source: number, _name: LikeButton, num: number): void;
|
|
25
27
|
gamepadreleased(_like: Like, source: number, _name: LikeButton, num: number): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mapGamepad.d.ts","sourceRoot":"","sources":["../../src/prefab-scenes/mapGamepad.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAE/B,OAAO,EAAE,KAAK,UAAU,EAAkC,MAAM,UAAU,CAAC;AAE3E,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAyBjC,eAAO,MAAM,YAAY,iBAA4C,CAAC;AACtE,eAAO,MAAM,YAAY,iBAA6C,CAAC;AACvE,eAAO,MAAM,aAAa,iBAA6C,CAAC;AACxE,eAAO,MAAM,YAAY,iBAA6C,CAAC;AACvE,eAAO,MAAM,YAAY,iBAAgC,CAAC;AA6D1D,MAAM,MAAM,OAAO,GAAG;IACpB,OAAO,EAAE,GAAG,CAAC,UAAU,CAAC,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,qBAAa,UAAW,YAAW,KAAK;
|
|
1
|
+
{"version":3,"file":"mapGamepad.d.ts","sourceRoot":"","sources":["../../src/prefab-scenes/mapGamepad.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAE/B,OAAO,EAAE,KAAK,UAAU,EAAkC,MAAM,UAAU,CAAC;AAE3E,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAyBjC,eAAO,MAAM,YAAY,iBAA4C,CAAC;AACtE,eAAO,MAAM,YAAY,iBAA6C,CAAC;AACvE,eAAO,MAAM,aAAa,iBAA6C,CAAC;AACxE,eAAO,MAAM,YAAY,iBAA6C,CAAC;AACvE,eAAO,MAAM,YAAY,iBAAgC,CAAC;AA6D1D,MAAM,MAAM,OAAO,GAAG;IACpB,OAAO,EAAE,GAAG,CAAC,UAAU,CAAC,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,qBAAa,UAAW,YAAW,KAAK;IAQpC,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,IAAI,CAAC;IATf,OAAO,CAAC,iBAAiB,CAAoB;IAC7C,OAAO,CAAC,OAAO,CAAkB;IACjC,OAAO,CAAC,IAAI,CAAC,CAAa;IAC1B,OAAO,CAAC,aAAa,CAAqB;IAC1C,OAAO,CAAC,SAAS,CAAK;gBAGZ,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,MAAM,EACjB,IAAI,CAAC,EAAE,KAAK,YAAA;IAGtB,IAAI,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IActB,MAAM,IAAI,IAAI;IAId,IAAI,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAqCtB,cAAc,CACZ,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,UAAU,EACjB,GAAG,EAAE,MAAM,GACV,IAAI;IAaP,eAAe,CACb,KAAK,EAAE,IAAI,EACX,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,UAAU,EACjB,GAAG,EAAE,MAAM,GACV,IAAI;IAOP,YAAY,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;CAG/B"}
|
|
@@ -119,16 +119,27 @@ export class MapGamepad {
|
|
|
119
119
|
writable: true,
|
|
120
120
|
value: new Set()
|
|
121
121
|
});
|
|
122
|
+
Object.defineProperty(this, "frameWait", {
|
|
123
|
+
enumerable: true,
|
|
124
|
+
configurable: true,
|
|
125
|
+
writable: true,
|
|
126
|
+
value: 0
|
|
127
|
+
});
|
|
122
128
|
}
|
|
123
129
|
load(like) {
|
|
130
|
+
this.frameWait = 10;
|
|
124
131
|
this.mapping = like.gamepad.getMapping(this.targetPad) ?? defaultMapping(2);
|
|
132
|
+
const alreadyMapped = new Set(Object.values(this.mapping.buttons));
|
|
125
133
|
for (const btn of mapOrder.reverse()) {
|
|
126
|
-
if (this.mapMode.buttons.has(btn)) {
|
|
134
|
+
if (this.mapMode.buttons.has(btn) && !alreadyMapped.has(btn)) {
|
|
127
135
|
this.currentlyUnmapped.push(btn);
|
|
128
136
|
}
|
|
129
137
|
}
|
|
130
138
|
like.canvas.setMode([320, 240]);
|
|
131
139
|
}
|
|
140
|
+
update() {
|
|
141
|
+
this.frameWait--;
|
|
142
|
+
}
|
|
132
143
|
draw(like) {
|
|
133
144
|
const centerText = {
|
|
134
145
|
font: "1px sans-serif",
|
|
@@ -139,7 +150,7 @@ export class MapGamepad {
|
|
|
139
150
|
like.gfx.clear();
|
|
140
151
|
like.gfx.scale(20);
|
|
141
152
|
like.gfx.translate([0, 1]);
|
|
142
|
-
like.gfx.print("white",
|
|
153
|
+
like.gfx.print("white", `Map gamepad ${this.targetPad}`, [8, 0.0], centerText);
|
|
143
154
|
for (const prop of this.mapMode.buttons.keys()) {
|
|
144
155
|
const color = this.held == prop
|
|
145
156
|
? "green"
|
|
@@ -155,7 +166,7 @@ export class MapGamepad {
|
|
|
155
166
|
: "Press any button to resume.", [2, 10], { font: "1px sans-serif" });
|
|
156
167
|
}
|
|
157
168
|
gamepadpressed(like, source, _name, num) {
|
|
158
|
-
if (source !== this.targetPad || this.held)
|
|
169
|
+
if (source !== this.targetPad || this.held || this.frameWait > 0)
|
|
159
170
|
return;
|
|
160
171
|
const active = this.currentlyUnmapped.pop();
|
|
161
172
|
if (active && !this.alreadyMapped.has(num)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "like2d",
|
|
3
|
-
"version": "2.10.
|
|
3
|
+
"version": "2.10.2",
|
|
4
4
|
"description": "A web-native game framework inspired by Love2D",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"LICENSE"
|
|
44
44
|
],
|
|
45
45
|
"scripts": {
|
|
46
|
-
"build": "tsc
|
|
46
|
+
"build": "tsc",
|
|
47
47
|
"typecheck": "tsc --noEmit",
|
|
48
48
|
"lint": "echo 'No linting configured'",
|
|
49
49
|
"clean": "rm -rf dist",
|