like2d 2.11.0 → 2.11.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 +6 -4
- package/dist/audio/index.d.ts +1 -1
- package/dist/audio/index.d.ts.map +1 -1
- package/dist/engine.d.ts +3 -8
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +3 -10
- package/dist/events.d.ts +19 -4
- package/dist/events.d.ts.map +1 -1
- package/dist/graphics/canvas.d.ts +8 -0
- package/dist/graphics/canvas.d.ts.map +1 -1
- package/dist/graphics/canvas.js +5 -0
- package/dist/graphics/graphics.d.ts +45 -32
- package/dist/graphics/graphics.d.ts.map +1 -1
- package/dist/graphics/graphics.js +45 -74
- package/dist/graphics/image.d.ts +22 -0
- package/dist/graphics/image.d.ts.map +1 -0
- package/dist/graphics/image.js +62 -0
- package/dist/graphics/index.d.ts +6 -4
- package/dist/graphics/index.d.ts.map +1 -1
- package/dist/graphics/index.js +2 -2
- package/dist/index.d.ts +6 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -2
- package/dist/input/gamepad-mapping.d.ts +4 -4
- package/dist/input/gamepad-mapping.d.ts.map +1 -1
- package/dist/input/gamepad-mapping.js +4 -4
- package/dist/input/gamepad.d.ts +11 -1
- package/dist/input/gamepad.d.ts.map +1 -1
- package/dist/input/gamepad.js +11 -1
- package/dist/input/index.d.ts +13 -5
- package/dist/input/index.d.ts.map +1 -1
- package/dist/input/index.js +5 -1
- package/dist/input/input.d.ts +56 -5
- package/dist/input/input.d.ts.map +1 -1
- package/dist/input/input.js +61 -7
- package/dist/input/keyboard.d.ts +26 -3
- package/dist/input/keyboard.d.ts.map +1 -1
- package/dist/input/keyboard.js +24 -0
- package/dist/input/mouse.d.ts +34 -6
- package/dist/input/mouse.d.ts.map +1 -1
- package/dist/input/mouse.js +31 -3
- package/dist/like.d.ts +5 -7
- package/dist/like.d.ts.map +1 -1
- package/dist/like.js +0 -4
- package/dist/math/index.d.ts +8 -9
- package/dist/math/index.d.ts.map +1 -1
- package/dist/math/index.js +8 -9
- package/dist/math/vector2.d.ts +1 -0
- package/dist/math/vector2.d.ts.map +1 -1
- package/dist/prefab-scenes/index.d.ts +5 -3
- package/dist/prefab-scenes/index.d.ts.map +1 -1
- package/dist/prefab-scenes/index.js +4 -2
- package/dist/prefab-scenes/mapGamepad.d.ts +13 -0
- package/dist/prefab-scenes/mapGamepad.d.ts.map +1 -1
- package/dist/prefab-scenes/mapGamepad.js +13 -0
- package/dist/scene.d.ts +1 -6
- package/dist/scene.d.ts.map +1 -1
- package/dist/scene.js +0 -5
- package/package.json +1 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image.d.ts","sourceRoot":"","sources":["../../src/graphics/image.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC;;;;;;;;GAQG;AACH,qBAAa,WAAW;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,OAAO,CAAiC;IAChD,OAAO,CAAC,WAAW,CAAgB;IACnC,OAAO,CAAC,QAAQ,CAAS;gBAEb,IAAI,EAAE,MAAM;IAiBxB,OAAO,IAAI,OAAO;IAIlB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAItB,IAAI,IAAI,IAAI,OAAO,CAElB;IAED,UAAU,IAAI,gBAAgB,GAAG,IAAI;CAGtC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An image that can be drawn using {@link Graphics.draw}
|
|
3
|
+
*
|
|
4
|
+
* Unlike raw HTMLImageElement, there is no need to wait for it to load.
|
|
5
|
+
* If the image isn't loaded, it simply won't draw it at all.
|
|
6
|
+
*
|
|
7
|
+
* If you're planning on loading many large images, simply preload
|
|
8
|
+
* these image handles beforehand so that they're ready.
|
|
9
|
+
*/
|
|
10
|
+
export class ImageHandle {
|
|
11
|
+
constructor(path) {
|
|
12
|
+
Object.defineProperty(this, "path", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
configurable: true,
|
|
15
|
+
writable: true,
|
|
16
|
+
value: void 0
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(this, "element", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
configurable: true,
|
|
21
|
+
writable: true,
|
|
22
|
+
value: null
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(this, "loadPromise", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
configurable: true,
|
|
27
|
+
writable: true,
|
|
28
|
+
value: void 0
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(this, "isLoaded", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
configurable: true,
|
|
33
|
+
writable: true,
|
|
34
|
+
value: false
|
|
35
|
+
});
|
|
36
|
+
this.path = path;
|
|
37
|
+
this.loadPromise = new Promise((resolve, reject) => {
|
|
38
|
+
const img = new Image();
|
|
39
|
+
img.onload = () => {
|
|
40
|
+
this.element = img;
|
|
41
|
+
this.isLoaded = true;
|
|
42
|
+
resolve();
|
|
43
|
+
};
|
|
44
|
+
img.onerror = () => {
|
|
45
|
+
reject(new Error(`Failed to load image: ${path}`));
|
|
46
|
+
};
|
|
47
|
+
img.src = path;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
isReady() {
|
|
51
|
+
return this.isLoaded;
|
|
52
|
+
}
|
|
53
|
+
ready() {
|
|
54
|
+
return this.loadPromise;
|
|
55
|
+
}
|
|
56
|
+
get size() {
|
|
57
|
+
return [this.element?.width ?? 0, this.element?.height ?? 0];
|
|
58
|
+
}
|
|
59
|
+
getElement() {
|
|
60
|
+
return this.element;
|
|
61
|
+
}
|
|
62
|
+
}
|
package/dist/graphics/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* Where we draw with {@link Graphics} on to the {@link Canvas}.
|
|
2
3
|
* @module graphics
|
|
3
|
-
* @description a reduced-state, Love2D-like wrapper around browser canvas
|
|
4
4
|
*/
|
|
5
|
-
export type {
|
|
6
|
-
export {
|
|
7
|
-
export type {
|
|
5
|
+
export type { Graphics } from "./graphics";
|
|
6
|
+
export type { Canvas } from "./canvas";
|
|
7
|
+
export type { ImageHandle } from './image';
|
|
8
|
+
export type { Color, DrawMode, ShapeProps, DrawProps, PrintProps, } from "./graphics";
|
|
9
|
+
export type { CanvasSize, CanvasModeOptions, } from "./canvas";
|
|
8
10
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/graphics/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/graphics/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,YAAY,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,YAAY,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC,YAAY,EACV,WAAW,EACZ,MAAM,SAAS,CAAC;AAEjB,YAAY,EACV,KAAK,EACL,QAAQ,EACR,UAAU,EACV,SAAS,EACT,UAAU,GACX,MAAM,YAAY,CAAC;AAEpB,YAAY,EACV,UAAU,EACV,iBAAiB,GAClB,MAAM,UAAU,CAAC"}
|
package/dist/graphics/index.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* A cozy web-native 2D game framework.
|
|
3
|
+
*
|
|
4
4
|
*/
|
|
5
5
|
import type { Like } from './like';
|
|
6
|
-
export type { Like, TopLevelEventHandler } from './like';
|
|
7
|
-
export type { LikeEvent, EventType, EventMap } from './events';
|
|
6
|
+
export type { Like, TopLevelEventHandler, Callbacks, Callback } from './like';
|
|
7
|
+
export type { LikeEvent, EventType, EventMap, LikeCanvasElement, Dispatcher, LikeCanvasEventMap, LikeKeyboardEvent } from './events';
|
|
8
|
+
export type { Scene } from './scene';
|
|
9
|
+
export type { EngineProps } from './engine';
|
|
8
10
|
/**
|
|
9
11
|
* Create a new Like2D game instance attached to a DOM container.
|
|
10
12
|
*
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAYH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEnC,YAAY,EAAE,IAAI,EAAE,oBAAoB,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAC9E,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,iBAAiB,EAAE,UAAU,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AACrI,YAAY,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,SAAS,EAAE,WAAW,GAAG,IAAI,CAGvD"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* A cozy web-native 2D game framework.
|
|
3
|
+
*
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Here are the top-level events, modules, and the scene system.
|
|
7
|
+
*
|
|
8
|
+
* See {@link createLike} to get started.
|
|
9
|
+
*
|
|
10
|
+
* @module like
|
|
4
11
|
*/
|
|
5
12
|
import { Engine } from './engine';
|
|
6
13
|
/**
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @module GamepadMapping
|
|
3
|
-
*
|
|
4
2
|
* A database, generated on module load,
|
|
5
3
|
* which uses SDL's database to coerce
|
|
6
4
|
* browser APIs into physical gamepad button
|
|
7
5
|
* mappings.
|
|
8
6
|
*
|
|
9
|
-
*
|
|
10
7
|
* Browser API shortcomings:
|
|
11
8
|
* - [No standard way of exposing vendor/product, Safari doesn't even do it.](https://github.com/w3c/gamepad/issues/199)
|
|
12
9
|
* - Vendor and product alone doesn't suffice for GUID -- Different controllers have the same, it's good-enough.
|
|
@@ -19,13 +16,14 @@
|
|
|
19
16
|
*/
|
|
20
17
|
import type { Vector2 } from "../math";
|
|
21
18
|
/**
|
|
19
|
+
* @private
|
|
22
20
|
* ref: https://www.w3.org/TR/gamepad/#dfn-standard-gamepad
|
|
23
21
|
* note: `num` is only the corresponding number on standard mapping above.
|
|
24
22
|
*
|
|
25
23
|
* The point of the mapping system is to apply that _or_ non-standard mappings,
|
|
26
24
|
* Which are exceedingly common.
|
|
27
25
|
*/
|
|
28
|
-
declare const buttonMap: readonly [{
|
|
26
|
+
export declare const buttonMap: readonly [{
|
|
29
27
|
readonly like: "BBottom";
|
|
30
28
|
readonly num: number;
|
|
31
29
|
readonly name: "Bottom Face Button";
|
|
@@ -101,8 +99,10 @@ export type StickAxisMapping = {
|
|
|
101
99
|
index: number;
|
|
102
100
|
invert: boolean;
|
|
103
101
|
};
|
|
102
|
+
/** @private Get an empty mapping for a gamepad. Good for binding from scratch. */
|
|
104
103
|
export declare const defaultMapping: (stickCount: number) => GamepadMapping;
|
|
105
104
|
export declare const standardButtonMapping: () => ButtonMapping;
|
|
105
|
+
/** @private */
|
|
106
106
|
export declare const allButtons: Set<string>;
|
|
107
107
|
export declare const fullButtonName: Map<"BBottom" | "BRight" | "BLeft" | "BTop" | "L1" | "R1" | "L2" | "R2" | "MenuLeft" | "MenuRight" | "LeftStick" | "RightStick" | "Up" | "Down" | "Left" | "Right", "Bottom Face Button" | "Right Face Button" | "Left Face Button" | "Top Face Button" | "Left shoulder (front)" | "Right shoulder (front)" | "Left shoulder (rear)" | "Right shoulder (rear)" | "Left Menu Button" | "Right Menu Button" | "Left Stick Button" | "Right Stick Button" | "D-Pad Up" | "D-Pad Down" | "D-Pad Left" | "D-Pad right">;
|
|
108
108
|
export declare const mapStick: (gp: Gamepad, mapping: StickMapping) => Vector2;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gamepad-mapping.d.ts","sourceRoot":"","sources":["../../src/input/gamepad-mapping.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"gamepad-mapping.d.ts","sourceRoot":"","sources":["../../src/input/gamepad-mapping.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAEvC;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS;;kBACS,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoB3B,CAAC;AAUX,MAAM,MAAM,UAAU,GAClB,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,GAClC,SAAS,MAAM,EAAE,GACjB,OAAO,MAAM,GAAG,GAChB,OAAO,MAAM,GAAG,CAAC;AAIrB,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,EAAE,aAAa,CAAC;IACvB,MAAM,EAAE,YAAY,EAAE,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;AACvD,MAAM,MAAM,YAAY,GAAG,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,CAAC;AAChE,MAAM,MAAM,gBAAgB,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,CAAC;AAElE,kFAAkF;AAClF,eAAO,MAAM,cAAc,GAAI,YAAY,MAAM,KAAG,cAQlD,CAAC;AAEH,eAAO,MAAM,qBAAqB,QAAO,aAC0B,CAAC;AACpE,eAAe;AACf,eAAO,MAAM,UAAU,aAAqD,CAAC;AAC7E,eAAO,MAAM,cAAc,qfAE1B,CAAC;AAEF,eAAO,MAAM,QAAQ,GAAI,IAAI,OAAO,EAAE,SAAS,YAAY,KAAG,OAK7D,CAAC;AAkBF,KAAK,UAAU,GAAG;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACpC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,UAAU,GAAG,SAAS,CAwBtE"}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @module GamepadMapping
|
|
3
|
-
*
|
|
4
2
|
* A database, generated on module load,
|
|
5
3
|
* which uses SDL's database to coerce
|
|
6
4
|
* browser APIs into physical gamepad button
|
|
7
5
|
* mappings.
|
|
8
6
|
*
|
|
9
|
-
*
|
|
10
7
|
* Browser API shortcomings:
|
|
11
8
|
* - [No standard way of exposing vendor/product, Safari doesn't even do it.](https://github.com/w3c/gamepad/issues/199)
|
|
12
9
|
* - Vendor and product alone doesn't suffice for GUID -- Different controllers have the same, it's good-enough.
|
|
@@ -18,13 +15,14 @@
|
|
|
18
15
|
* - We go with best-match and always fall back on manual mapping.
|
|
19
16
|
*/
|
|
20
17
|
/**
|
|
18
|
+
* @private
|
|
21
19
|
* ref: https://www.w3.org/TR/gamepad/#dfn-standard-gamepad
|
|
22
20
|
* note: `num` is only the corresponding number on standard mapping above.
|
|
23
21
|
*
|
|
24
22
|
* The point of the mapping system is to apply that _or_ non-standard mappings,
|
|
25
23
|
* Which are exceedingly common.
|
|
26
24
|
*/
|
|
27
|
-
const buttonMap = [
|
|
25
|
+
export const buttonMap = [
|
|
28
26
|
{ like: "BBottom", num: 0, name: "Bottom Face Button" },
|
|
29
27
|
{ like: "BRight", num: 1, name: "Right Face Button" },
|
|
30
28
|
{ like: "BLeft", num: 2, name: "Left Face Button" },
|
|
@@ -49,6 +47,7 @@ const detectedOs = ((s) => [
|
|
|
49
47
|
["Win", "Windows"],
|
|
50
48
|
["Mac", "Mac OS X"],
|
|
51
49
|
].find(([ss]) => s.includes(ss))?.[1] ?? "Linux")(navigator.userAgent);
|
|
50
|
+
/** @private Get an empty mapping for a gamepad. Good for binding from scratch. */
|
|
52
51
|
export const defaultMapping = (stickCount) => ({
|
|
53
52
|
buttons: {},
|
|
54
53
|
sticks: Array(stickCount)
|
|
@@ -59,6 +58,7 @@ export const defaultMapping = (stickCount) => ({
|
|
|
59
58
|
]),
|
|
60
59
|
});
|
|
61
60
|
export const standardButtonMapping = () => Object.fromEntries(buttonMap.map(({ like, num }) => [num, like]));
|
|
61
|
+
/** @private */
|
|
62
62
|
export const allButtons = new Set(buttonMap.map(({ like }) => like));
|
|
63
63
|
export const fullButtonName = new Map(buttonMap.map(({ like, name }) => [like, name]));
|
|
64
64
|
export const mapStick = (gp, mapping) => {
|
package/dist/input/gamepad.d.ts
CHANGED
|
@@ -12,8 +12,18 @@ export type GamepadTarget = number | "any";
|
|
|
12
12
|
*
|
|
13
13
|
* If you're planning on supporting gamepads, please include a
|
|
14
14
|
* way to generate {@link GamepadMapping} and set it with {@link Gamepad.setMapping}.
|
|
15
|
+
* Perhaps trigger it on {@link index.EventMap.gamepadconnected} events.
|
|
16
|
+
*
|
|
17
|
+
* If you don't want to make your own, take a look at {@link prefab-scenes.MapGamepad}
|
|
18
|
+
*
|
|
19
|
+
* ## When to use gamepad remapping
|
|
20
|
+
*
|
|
21
|
+
* For games with heavy and varied gamepad use, mapping buttons is essential.
|
|
22
|
+
*
|
|
23
|
+
* But if your game relies on a small set of logical actions like 'accept' or 'jump', don't hesitate to
|
|
24
|
+
* reach for {@link input} in order to map based on actions instead.
|
|
25
|
+
*
|
|
15
26
|
*
|
|
16
|
-
* If you don't want to make your own, take a look at `prefab-scenes/mapGamepad`.
|
|
17
27
|
*/
|
|
18
28
|
export declare class Gamepad {
|
|
19
29
|
private dispatch;
|
|
@@ -1 +1 @@
|
|
|
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
|
|
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;;;;;;;;;;;;;;;;;;;;GAoBG;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
|
@@ -7,8 +7,18 @@ import { defaultMapping, fullButtonName, getSdlMapping, mapStick, standardButton
|
|
|
7
7
|
*
|
|
8
8
|
* If you're planning on supporting gamepads, please include a
|
|
9
9
|
* way to generate {@link GamepadMapping} and set it with {@link Gamepad.setMapping}.
|
|
10
|
+
* Perhaps trigger it on {@link index.EventMap.gamepadconnected} events.
|
|
11
|
+
*
|
|
12
|
+
* If you don't want to make your own, take a look at {@link prefab-scenes.MapGamepad}
|
|
13
|
+
*
|
|
14
|
+
* ## When to use gamepad remapping
|
|
15
|
+
*
|
|
16
|
+
* For games with heavy and varied gamepad use, mapping buttons is essential.
|
|
17
|
+
*
|
|
18
|
+
* But if your game relies on a small set of logical actions like 'accept' or 'jump', don't hesitate to
|
|
19
|
+
* reach for {@link input} in order to map based on actions instead.
|
|
20
|
+
*
|
|
10
21
|
*
|
|
11
|
-
* If you don't want to make your own, take a look at `prefab-scenes/mapGamepad`.
|
|
12
22
|
*/
|
|
13
23
|
export class Gamepad {
|
|
14
24
|
constructor(props) {
|
package/dist/input/index.d.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export type {
|
|
1
|
+
/**
|
|
2
|
+
* Where {@link Keyboard}, {@link Mouse}, {@link Gamepad}, and actions in {@link Input} reside.
|
|
3
|
+
* @module input
|
|
4
|
+
*/
|
|
5
|
+
export type { Keyboard } from "./keyboard";
|
|
6
|
+
export type { Mouse } from "./mouse";
|
|
7
|
+
export type { Gamepad } from "./gamepad";
|
|
8
|
+
export type { Input } from "./input";
|
|
9
|
+
export type { MouseSetMode, MouseMode, MouseButton, } from "./mouse";
|
|
10
|
+
export type { GamepadTarget, } from "./gamepad";
|
|
11
|
+
export type { LikeButton, GamepadMapping, ButtonMapping, StickMapping, StickAxisMapping, } from "./gamepad-mapping";
|
|
12
|
+
export type { InputType, InputBinding, } from "./input";
|
|
13
|
+
export { defaultMapping, allButtons, buttonMap } from "./gamepad-mapping";
|
|
6
14
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/input/index.ts"],"names":[],"mappings":"AAAA,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/input/index.ts"],"names":[],"mappings":"AAAA;;;EAGE;AAEF,YAAY,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,YAAY,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,YAAY,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,YAAY,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAErC,YAAY,EACV,YAAY,EACZ,SAAS,EACT,WAAW,GACZ,MAAM,SAAS,CAAC;AAEjB,YAAY,EACV,aAAa,GACd,MAAM,WAAW,CAAA;AAElB,YAAY,EACV,UAAU,EACV,cAAc,EACd,aAAa,EACb,YAAY,EACZ,gBAAgB,GACjB,MAAM,mBAAmB,CAAC;AAE3B,YAAY,EACV,SAAS,EACT,YAAY,GACb,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/input/index.js
CHANGED
package/dist/input/input.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { Keyboard } from './keyboard';
|
|
2
|
-
import type { Mouse } from './mouse';
|
|
2
|
+
import type { Mouse, MouseButton } from './mouse';
|
|
3
3
|
import { Gamepad, GamepadTarget } from './gamepad';
|
|
4
4
|
import { LikeButton } from './gamepad-mapping';
|
|
5
|
-
import {
|
|
5
|
+
import { LikeActionEvent } from '../events';
|
|
6
|
+
import { EngineProps } from '../engine';
|
|
6
7
|
export type InputType = InputBinding['type'];
|
|
7
8
|
export type InputBinding = {
|
|
8
9
|
type: 'keyboard';
|
|
@@ -15,15 +16,64 @@ export type InputBinding = {
|
|
|
15
16
|
gamepad: GamepadTarget;
|
|
16
17
|
button: LikeButton;
|
|
17
18
|
};
|
|
19
|
+
/**
|
|
20
|
+
* Used to map inputs (from keyboard, mouse, or gamepad) into actions.
|
|
21
|
+
*
|
|
22
|
+
* {@link setAction} allows for set-and-forget mappings. Good for one-off games.
|
|
23
|
+
*
|
|
24
|
+
* Example:
|
|
25
|
+
* ```js
|
|
26
|
+
* // bind action jump
|
|
27
|
+
* like.load() {
|
|
28
|
+
* like.input.setAction('jump', ['KeyX', 'Space', 'ButtonBottom'])
|
|
29
|
+
* }
|
|
30
|
+
*
|
|
31
|
+
* like.actionpressed(action) {
|
|
32
|
+
* if (action == 'jump') {
|
|
33
|
+
* player.tryJumping();
|
|
34
|
+
* }
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* For more sophisticated games, see also:
|
|
39
|
+
* - {@link appendToAction}
|
|
40
|
+
* - {@link getActionMapping}
|
|
41
|
+
*
|
|
42
|
+
* These allow for programmatic binding based on events. For example:
|
|
43
|
+
* ```js
|
|
44
|
+
* let currentlyMapping = 'jump';
|
|
45
|
+
*
|
|
46
|
+
* // Watch for gamepad and keyboard events
|
|
47
|
+
* like.keypressed = (code) => {
|
|
48
|
+
* if (currentlyMapping) {
|
|
49
|
+
* like.input.appendToAction(currentlyMapping, code);
|
|
50
|
+
* }
|
|
51
|
+
* }
|
|
52
|
+
* like.gamepadpressed = (name) => {
|
|
53
|
+
* if (currentlyMapping) {
|
|
54
|
+
* like.input.appendToAction(currentlyMapping, name);
|
|
55
|
+
* }
|
|
56
|
+
* }
|
|
57
|
+
*
|
|
58
|
+
* // Print some info about the current mapping
|
|
59
|
+
* like.draw = () => {
|
|
60
|
+
* if (currentlyMapping) {
|
|
61
|
+
* myGame.statusLine =
|
|
62
|
+
* `Mapped ${like.input.getActionMapping(currentlyMapping)} to ${currentlyMapping}`
|
|
63
|
+
* }
|
|
64
|
+
* }
|
|
65
|
+
*
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
18
68
|
export declare class Input {
|
|
19
|
-
private dispatch;
|
|
20
69
|
private currState;
|
|
21
70
|
private prevState;
|
|
22
71
|
private actionTable;
|
|
23
72
|
private keyboard;
|
|
24
73
|
private mouse;
|
|
25
74
|
private gamepad;
|
|
26
|
-
|
|
75
|
+
private dispatch;
|
|
76
|
+
constructor(props: EngineProps<LikeActionEvent>, deps: {
|
|
27
77
|
keyboard: Keyboard;
|
|
28
78
|
mouse: Mouse;
|
|
29
79
|
gamepad: Gamepad;
|
|
@@ -42,6 +92,7 @@ export declare class Input {
|
|
|
42
92
|
* - Numeric: `Digit0`, `Digit1`, ...
|
|
43
93
|
* - `ArrowLeft`, `ArrowRight`, `ArrowUp`, `ArrowDown`
|
|
44
94
|
* - `ShiftLeft`, `ShiftRight`
|
|
95
|
+
* - `Space`
|
|
45
96
|
* - `Minus`
|
|
46
97
|
* - `Equal` (also has a plus sign)
|
|
47
98
|
* - `BracketLeft` and `BracketRight`
|
|
@@ -70,7 +121,7 @@ export declare class Input {
|
|
|
70
121
|
isDown(action: string): boolean;
|
|
71
122
|
justPressed(action: string): boolean;
|
|
72
123
|
justReleased(action: string): boolean;
|
|
73
|
-
update
|
|
124
|
+
private update;
|
|
74
125
|
private isBindingActive;
|
|
75
126
|
}
|
|
76
127
|
//# sourceMappingURL=input.d.ts.map
|
|
@@ -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;
|
|
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,WAAW,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAc,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAc,eAAe,EAAE,MAAM,WAAW,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAgDE;AACF,qBAAa,KAAK;IAChB,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;IACzB,OAAO,CAAC,QAAQ,CAA6B;gBAG3C,KAAK,EAAE,WAAW,CAAC,eAAe,CAAC,EACnC,IAAI,EAAE;QACJ,QAAQ,EAAE,QAAQ,CAAC;QACnB,KAAK,EAAE,KAAK,CAAC;QACb,OAAO,EAAE,OAAO,CAAC;KAClB;IAYH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;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,OAAO,CAAC,MAAM;IAgBd,OAAO,CAAC,eAAe;CAaxB"}
|
package/dist/input/input.js
CHANGED
|
@@ -1,12 +1,55 @@
|
|
|
1
1
|
import { allButtons } from './gamepad-mapping';
|
|
2
|
+
/**
|
|
3
|
+
* Used to map inputs (from keyboard, mouse, or gamepad) into actions.
|
|
4
|
+
*
|
|
5
|
+
* {@link setAction} allows for set-and-forget mappings. Good for one-off games.
|
|
6
|
+
*
|
|
7
|
+
* Example:
|
|
8
|
+
* ```js
|
|
9
|
+
* // bind action jump
|
|
10
|
+
* like.load() {
|
|
11
|
+
* like.input.setAction('jump', ['KeyX', 'Space', 'ButtonBottom'])
|
|
12
|
+
* }
|
|
13
|
+
*
|
|
14
|
+
* like.actionpressed(action) {
|
|
15
|
+
* if (action == 'jump') {
|
|
16
|
+
* player.tryJumping();
|
|
17
|
+
* }
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* For more sophisticated games, see also:
|
|
22
|
+
* - {@link appendToAction}
|
|
23
|
+
* - {@link getActionMapping}
|
|
24
|
+
*
|
|
25
|
+
* These allow for programmatic binding based on events. For example:
|
|
26
|
+
* ```js
|
|
27
|
+
* let currentlyMapping = 'jump';
|
|
28
|
+
*
|
|
29
|
+
* // Watch for gamepad and keyboard events
|
|
30
|
+
* like.keypressed = (code) => {
|
|
31
|
+
* if (currentlyMapping) {
|
|
32
|
+
* like.input.appendToAction(currentlyMapping, code);
|
|
33
|
+
* }
|
|
34
|
+
* }
|
|
35
|
+
* like.gamepadpressed = (name) => {
|
|
36
|
+
* if (currentlyMapping) {
|
|
37
|
+
* like.input.appendToAction(currentlyMapping, name);
|
|
38
|
+
* }
|
|
39
|
+
* }
|
|
40
|
+
*
|
|
41
|
+
* // Print some info about the current mapping
|
|
42
|
+
* like.draw = () => {
|
|
43
|
+
* if (currentlyMapping) {
|
|
44
|
+
* myGame.statusLine =
|
|
45
|
+
* `Mapped ${like.input.getActionMapping(currentlyMapping)} to ${currentlyMapping}`
|
|
46
|
+
* }
|
|
47
|
+
* }
|
|
48
|
+
*
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
2
51
|
export class Input {
|
|
3
|
-
constructor(
|
|
4
|
-
Object.defineProperty(this, "dispatch", {
|
|
5
|
-
enumerable: true,
|
|
6
|
-
configurable: true,
|
|
7
|
-
writable: true,
|
|
8
|
-
value: dispatch
|
|
9
|
-
});
|
|
52
|
+
constructor(props, deps) {
|
|
10
53
|
Object.defineProperty(this, "currState", {
|
|
11
54
|
enumerable: true,
|
|
12
55
|
configurable: true,
|
|
@@ -43,9 +86,19 @@ export class Input {
|
|
|
43
86
|
writable: true,
|
|
44
87
|
value: void 0
|
|
45
88
|
});
|
|
89
|
+
Object.defineProperty(this, "dispatch", {
|
|
90
|
+
enumerable: true,
|
|
91
|
+
configurable: true,
|
|
92
|
+
writable: true,
|
|
93
|
+
value: void 0
|
|
94
|
+
});
|
|
46
95
|
this.keyboard = deps.keyboard;
|
|
47
96
|
this.mouse = deps.mouse;
|
|
48
97
|
this.gamepad = deps.gamepad;
|
|
98
|
+
this.dispatch = props.dispatch;
|
|
99
|
+
props.canvas.addEventListener("like:update", () => this.update(), {
|
|
100
|
+
signal: props.abort,
|
|
101
|
+
});
|
|
49
102
|
}
|
|
50
103
|
/**
|
|
51
104
|
* This is the easiest way to set-and-forget input => action mapping.
|
|
@@ -61,6 +114,7 @@ export class Input {
|
|
|
61
114
|
* - Numeric: `Digit0`, `Digit1`, ...
|
|
62
115
|
* - `ArrowLeft`, `ArrowRight`, `ArrowUp`, `ArrowDown`
|
|
63
116
|
* - `ShiftLeft`, `ShiftRight`
|
|
117
|
+
* - `Space`
|
|
64
118
|
* - `Minus`
|
|
65
119
|
* - `Equal` (also has a plus sign)
|
|
66
120
|
* - `BracketLeft` and `BracketRight`
|
package/dist/input/keyboard.d.ts
CHANGED
|
@@ -1,15 +1,38 @@
|
|
|
1
1
|
import { EngineProps } from "../engine";
|
|
2
|
-
type
|
|
2
|
+
import { type LikeKeyboardEvent } from "../events";
|
|
3
|
+
/**
|
|
4
|
+
* A basic wrapper around keyboard.
|
|
5
|
+
*
|
|
6
|
+
* Keyboard uses scancodes by default, which are based on physical key
|
|
7
|
+
* positions rather than the logical (letter) meaning of the key.
|
|
8
|
+
*
|
|
9
|
+
* ## When to use Keyboard
|
|
10
|
+
*
|
|
11
|
+
* Using keyboard directly is discouraged, but of course allowed.
|
|
12
|
+
* Take a look at the actions system in {@link input} for a better solution.
|
|
13
|
+
*
|
|
14
|
+
* Also where there's text input such as `enter your name`, use the key code.
|
|
15
|
+
* This allows the user to use their intended keyboard layout.
|
|
16
|
+
*
|
|
17
|
+
* ```
|
|
18
|
+
* like.keypressed = (_code, key) => {
|
|
19
|
+
* name += key;
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* Even if your game is heavily keyboard-reliant (like nethack), it is best to avoid mapping directly.
|
|
24
|
+
* Referring to action `drink` instead of code `KeyD` is also more programmer-ergonomic.
|
|
25
|
+
*
|
|
26
|
+
*/
|
|
3
27
|
export declare class Keyboard {
|
|
4
28
|
private pressedScancodes;
|
|
5
29
|
private canvas;
|
|
6
30
|
private dispatch;
|
|
7
|
-
constructor(props: EngineProps<
|
|
31
|
+
constructor(props: EngineProps<LikeKeyboardEvent>);
|
|
8
32
|
private handleKeyDown;
|
|
9
33
|
private handleKeyUp;
|
|
10
34
|
private handleBlur;
|
|
11
35
|
isDown(scancode: string): boolean;
|
|
12
36
|
isAnyDown(...scancodes: string[]): boolean;
|
|
13
37
|
}
|
|
14
|
-
export {};
|
|
15
38
|
//# sourceMappingURL=keyboard.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyboard.d.ts","sourceRoot":"","sources":["../../src/input/keyboard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"keyboard.d.ts","sourceRoot":"","sources":["../../src/input/keyboard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAsC,KAAK,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAGvF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,QAAQ;IACnB,OAAO,CAAC,gBAAgB,CAAqB;IAC7C,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,QAAQ,CAAgC;gBAEpC,KAAK,EAAE,WAAW,CAAC,iBAAiB,CAAC;IAUjD,OAAO,CAAC,aAAa;IAYrB,OAAO,CAAC,WAAW;IAOnB,OAAO,CAAC,UAAU;IAIlB,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAIjC,SAAS,CAAC,GAAG,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO;CAG3C"}
|
package/dist/input/keyboard.js
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A basic wrapper around keyboard.
|
|
3
|
+
*
|
|
4
|
+
* Keyboard uses scancodes by default, which are based on physical key
|
|
5
|
+
* positions rather than the logical (letter) meaning of the key.
|
|
6
|
+
*
|
|
7
|
+
* ## When to use Keyboard
|
|
8
|
+
*
|
|
9
|
+
* Using keyboard directly is discouraged, but of course allowed.
|
|
10
|
+
* Take a look at the actions system in {@link input} for a better solution.
|
|
11
|
+
*
|
|
12
|
+
* Also where there's text input such as `enter your name`, use the key code.
|
|
13
|
+
* This allows the user to use their intended keyboard layout.
|
|
14
|
+
*
|
|
15
|
+
* ```
|
|
16
|
+
* like.keypressed = (_code, key) => {
|
|
17
|
+
* name += key;
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* Even if your game is heavily keyboard-reliant (like nethack), it is best to avoid mapping directly.
|
|
22
|
+
* Referring to action `drink` instead of code `KeyD` is also more programmer-ergonomic.
|
|
23
|
+
*
|
|
24
|
+
*/
|
|
1
25
|
export class Keyboard {
|
|
2
26
|
constructor(props) {
|
|
3
27
|
Object.defineProperty(this, "pressedScancodes", {
|