like2d 2.11.0 → 2.12.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/README.md +36 -6
- package/assets/logo-banner-optimized.svg +15 -27
- package/assets/logo-banner.svg +76 -132
- package/assets/logo-icon.svg +33 -23
- package/assets/logo.svg +78 -123
- package/dist/audio/index.d.ts +1 -1
- package/dist/engine.d.ts +5 -8
- package/dist/engine.js +37 -22
- package/dist/events.d.ts +19 -7
- package/dist/graphics/canvas.d.ts +23 -7
- package/dist/graphics/canvas.js +69 -68
- package/dist/graphics/graphics.d.ts +83 -55
- package/dist/graphics/graphics.js +128 -129
- package/dist/graphics/image.d.ts +22 -0
- package/dist/graphics/image.js +62 -0
- package/dist/graphics/index.d.ts +6 -4
- package/dist/graphics/index.js +2 -2
- package/dist/index.d.ts +6 -4
- package/dist/index.js +9 -2
- package/dist/input/controllerdb.json +1 -1
- package/dist/input/gamepad-mapping.d.ts +4 -4
- package/dist/input/gamepad-mapping.js +6 -5
- package/dist/input/gamepad.d.ts +11 -1
- package/dist/input/gamepad.js +11 -1
- package/dist/input/index.d.ts +13 -5
- package/dist/input/index.js +5 -1
- package/dist/input/input.d.ts +58 -7
- package/dist/input/input.js +63 -9
- package/dist/input/keyboard.d.ts +26 -3
- package/dist/input/keyboard.js +24 -0
- package/dist/input/mouse.d.ts +34 -6
- package/dist/input/mouse.js +31 -3
- package/dist/like.d.ts +41 -12
- package/dist/like.js +0 -4
- package/dist/math/index.d.ts +8 -9
- package/dist/math/index.js +8 -9
- package/dist/math/vector2.d.ts +2 -1
- package/dist/prefab-scenes/index.d.ts +5 -3
- package/dist/prefab-scenes/index.js +4 -2
- package/dist/prefab-scenes/mapGamepad.d.ts +14 -2
- package/dist/prefab-scenes/mapGamepad.js +29 -22
- package/dist/prefab-scenes/startScreen.d.ts +2 -3
- package/dist/prefab-scenes/startScreen.js +41 -12
- package/dist/scene.d.ts +48 -13
- package/dist/scene.js +0 -5
- package/package.json +2 -2
- package/dist/__benchmarks__/vector2.bench.d.ts +0 -2
- package/dist/__benchmarks__/vector2.bench.d.ts.map +0 -1
- package/dist/__benchmarks__/vector2.bench.js +0 -74
- package/dist/audio/audio.d.ts.map +0 -1
- package/dist/audio/index.d.ts.map +0 -1
- package/dist/engine.d.ts.map +0 -1
- package/dist/events.d.ts.map +0 -1
- package/dist/graphics/canvas.d.ts.map +0 -1
- package/dist/graphics/graphics.d.ts.map +0 -1
- package/dist/graphics/index.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/input/gamepad-mapping.d.ts.map +0 -1
- package/dist/input/gamepad.d.ts.map +0 -1
- package/dist/input/index.d.ts.map +0 -1
- package/dist/input/input.d.ts.map +0 -1
- package/dist/input/keyboard.d.ts.map +0 -1
- package/dist/input/mouse.d.ts.map +0 -1
- package/dist/like.d.ts.map +0 -1
- package/dist/math/index.d.ts.map +0 -1
- package/dist/math/rect.d.ts.map +0 -1
- package/dist/math/vector2.d.ts.map +0 -1
- package/dist/prefab-scenes/index.d.ts.map +0 -1
- package/dist/prefab-scenes/mapGamepad.d.ts.map +0 -1
- package/dist/prefab-scenes/startScreen.d.ts.map +0 -1
- package/dist/scene.d.ts.map +0 -1
- package/dist/timer/index.d.ts.map +0 -1
- package/dist/timer/timer.d.ts.map +0 -1
|
@@ -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,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,8 @@ export const defaultMapping = (stickCount) => ({
|
|
|
59
58
|
]),
|
|
60
59
|
});
|
|
61
60
|
export const standardButtonMapping = () => Object.fromEntries(buttonMap.map(({ like, num }) => [num, like]));
|
|
61
|
+
const numToName = standardButtonMapping();
|
|
62
|
+
/** @private */
|
|
62
63
|
export const allButtons = new Set(buttonMap.map(({ like }) => like));
|
|
63
64
|
export const fullButtonName = new Map(buttonMap.map(({ like, name }) => [like, name]));
|
|
64
65
|
export const mapStick = (gp, mapping) => {
|
|
@@ -70,7 +71,7 @@ const mappingDb = new Map(Object.entries(mappingDbRaw[detectedOs]).map(([k, v])
|
|
|
70
71
|
Number(k),
|
|
71
72
|
{
|
|
72
73
|
...v,
|
|
73
|
-
mapping: Object.fromEntries(Object.entries(v.mapping).map(([k, v]) => [Number(k), v])),
|
|
74
|
+
mapping: Object.fromEntries(Object.entries(v.mapping).map(([k, v]) => [Number(k), numToName[Number(v)]])),
|
|
74
75
|
},
|
|
75
76
|
]));
|
|
76
77
|
export function getSdlMapping(gamepad) {
|
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;
|
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
|
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;
|
|
@@ -31,7 +81,7 @@ export declare class Input {
|
|
|
31
81
|
/**
|
|
32
82
|
* This is the easiest way to set-and-forget input => action mapping.
|
|
33
83
|
*
|
|
34
|
-
* Or, it's a helper to remove actions -- `setAction(action)`
|
|
84
|
+
* Or, it's a helper to remove actions -- `setAction(action, [])`
|
|
35
85
|
* will simply clear the action away.
|
|
36
86
|
*
|
|
37
87
|
* For input strings:
|
|
@@ -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`
|
|
@@ -58,7 +109,7 @@ export declare class Input {
|
|
|
58
109
|
* @param action
|
|
59
110
|
* @param inputs
|
|
60
111
|
*/
|
|
61
|
-
setAction(action: string, inputs
|
|
112
|
+
setAction(action: string, inputs: (string | InputBinding)[]): void;
|
|
62
113
|
/**
|
|
63
114
|
* Map a single input onto an action.
|
|
64
115
|
*/
|
|
@@ -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
|
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,14 +86,24 @@ 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.
|
|
52
105
|
*
|
|
53
|
-
* Or, it's a helper to remove actions -- `setAction(action)`
|
|
106
|
+
* Or, it's a helper to remove actions -- `setAction(action, [])`
|
|
54
107
|
* will simply clear the action away.
|
|
55
108
|
*
|
|
56
109
|
* For input strings:
|
|
@@ -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`
|
|
@@ -77,7 +131,7 @@ export class Input {
|
|
|
77
131
|
* @param action
|
|
78
132
|
* @param inputs
|
|
79
133
|
*/
|
|
80
|
-
setAction(action, inputs
|
|
134
|
+
setAction(action, inputs) {
|
|
81
135
|
if (inputs.length) {
|
|
82
136
|
this.actionTable[action] = inputs.map(parseInput);
|
|
83
137
|
}
|
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
|
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", {
|
package/dist/input/mouse.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { type Vector2 } from '../math/vector2';
|
|
2
|
-
import { type
|
|
2
|
+
import { type LikeMouseEvent } from '../events';
|
|
3
3
|
import { EngineProps } from '../engine';
|
|
4
|
-
type
|
|
4
|
+
export type MouseButton = 'left' | 'middle' | 'right';
|
|
5
|
+
export type MouseMode = {
|
|
5
6
|
lock: false;
|
|
6
7
|
visible: boolean;
|
|
7
8
|
scrollBlock: boolean;
|
|
@@ -13,7 +14,35 @@ export type MouseSetMode = Partial<MouseMode> & {
|
|
|
13
14
|
lock: boolean;
|
|
14
15
|
};
|
|
15
16
|
/**
|
|
16
|
-
*
|
|
17
|
+
* LIKE's mouse wrapper.
|
|
18
|
+
*
|
|
19
|
+
* Mouse coordinates are scaled for convenience. For example call:
|
|
20
|
+
* ```
|
|
21
|
+
* like.canvas.setMode([240, 160])
|
|
22
|
+
* ```
|
|
23
|
+
* and your game will now be 240x160 pixels.
|
|
24
|
+
*
|
|
25
|
+
* Your mouse coords will stay within the rectangle `[0, 0]` and `[240, 160]`.
|
|
26
|
+
*
|
|
27
|
+
* If you intend to allow scrolling on your page while the mouse is above the game, use:
|
|
28
|
+
* ```
|
|
29
|
+
* like.mouse.setMode({ lock: false, scrollBlock: false })
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* ### Capture
|
|
33
|
+
*
|
|
34
|
+
* Some games benefit from capture aka pointer lock. Call
|
|
35
|
+
* ```ts
|
|
36
|
+
* like.mouse.setMode({ lock: true, speed: 1 })
|
|
37
|
+
* ```
|
|
38
|
+
* to use capture, and now the mouse is locked to the game.
|
|
39
|
+
*
|
|
40
|
+
* When you enter capture, the mouse `pos` becomes virtual, bounded to canvas edges, plus controlled via the speed setting and teleport-able via {@link setCapturedPos}.
|
|
41
|
+
*
|
|
42
|
+
* When you exit capture, the mouse will be in the same spot the capture was started in.
|
|
43
|
+
*
|
|
44
|
+
* Note that your mode settings from non-capture mode are preserved in capture mode and vice-versa.
|
|
45
|
+
*
|
|
17
46
|
*/
|
|
18
47
|
export declare class Mouse {
|
|
19
48
|
private dispatch;
|
|
@@ -58,7 +87,7 @@ export declare class Mouse {
|
|
|
58
87
|
* In locked mode, the cursor cannot escape the canvas.
|
|
59
88
|
* It also becomes invisible.
|
|
60
89
|
* However, it can move infinitely, sensitivity can be controlled,
|
|
61
|
-
* and the emulated cursor (in `pos` of {@link mousemoved}) can be freely repositioned.
|
|
90
|
+
* and the emulated cursor (in `pos` of {@link index.EventMap.mousemoved}) can be freely repositioned.
|
|
62
91
|
*
|
|
63
92
|
* ```ts
|
|
64
93
|
* {
|
|
@@ -70,7 +99,7 @@ export declare class Mouse {
|
|
|
70
99
|
* reset mode to default.
|
|
71
100
|
*
|
|
72
101
|
* ### Note on `pos` vs `delta`
|
|
73
|
-
* Event {@link mousemoved} passes both `pos` and `delta` args.
|
|
102
|
+
* Event {@link index.EventMap.mousemoved} passes both `pos` and `delta` args.
|
|
74
103
|
*
|
|
75
104
|
* Though the emulated cursor in locked mode
|
|
76
105
|
* (locked mode doesn't natively track absolute position)
|
|
@@ -104,5 +133,4 @@ export declare class Mouse {
|
|
|
104
133
|
*/
|
|
105
134
|
setRelativeMode?: never;
|
|
106
135
|
}
|
|
107
|
-
export {};
|
|
108
136
|
//# sourceMappingURL=mouse.d.ts.map
|
package/dist/input/mouse.js
CHANGED
|
@@ -2,7 +2,35 @@ import { Vec2 } from '../math/vector2';
|
|
|
2
2
|
const mouseButtons = ["left", "middle", "right"];
|
|
3
3
|
const numToButton = (i) => mouseButtons[i];
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* LIKE's mouse wrapper.
|
|
6
|
+
*
|
|
7
|
+
* Mouse coordinates are scaled for convenience. For example call:
|
|
8
|
+
* ```
|
|
9
|
+
* like.canvas.setMode([240, 160])
|
|
10
|
+
* ```
|
|
11
|
+
* and your game will now be 240x160 pixels.
|
|
12
|
+
*
|
|
13
|
+
* Your mouse coords will stay within the rectangle `[0, 0]` and `[240, 160]`.
|
|
14
|
+
*
|
|
15
|
+
* If you intend to allow scrolling on your page while the mouse is above the game, use:
|
|
16
|
+
* ```
|
|
17
|
+
* like.mouse.setMode({ lock: false, scrollBlock: false })
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* ### Capture
|
|
21
|
+
*
|
|
22
|
+
* Some games benefit from capture aka pointer lock. Call
|
|
23
|
+
* ```ts
|
|
24
|
+
* like.mouse.setMode({ lock: true, speed: 1 })
|
|
25
|
+
* ```
|
|
26
|
+
* to use capture, and now the mouse is locked to the game.
|
|
27
|
+
*
|
|
28
|
+
* When you enter capture, the mouse `pos` becomes virtual, bounded to canvas edges, plus controlled via the speed setting and teleport-able via {@link setCapturedPos}.
|
|
29
|
+
*
|
|
30
|
+
* When you exit capture, the mouse will be in the same spot the capture was started in.
|
|
31
|
+
*
|
|
32
|
+
* Note that your mode settings from non-capture mode are preserved in capture mode and vice-versa.
|
|
33
|
+
*
|
|
6
34
|
*/
|
|
7
35
|
export class Mouse {
|
|
8
36
|
constructor(props) {
|
|
@@ -161,7 +189,7 @@ export class Mouse {
|
|
|
161
189
|
* In locked mode, the cursor cannot escape the canvas.
|
|
162
190
|
* It also becomes invisible.
|
|
163
191
|
* However, it can move infinitely, sensitivity can be controlled,
|
|
164
|
-
* and the emulated cursor (in `pos` of {@link mousemoved}) can be freely repositioned.
|
|
192
|
+
* and the emulated cursor (in `pos` of {@link index.EventMap.mousemoved}) can be freely repositioned.
|
|
165
193
|
*
|
|
166
194
|
* ```ts
|
|
167
195
|
* {
|
|
@@ -173,7 +201,7 @@ export class Mouse {
|
|
|
173
201
|
* reset mode to default.
|
|
174
202
|
*
|
|
175
203
|
* ### Note on `pos` vs `delta`
|
|
176
|
-
* Event {@link mousemoved} passes both `pos` and `delta` args.
|
|
204
|
+
* Event {@link index.EventMap.mousemoved} passes both `pos` and `delta` args.
|
|
177
205
|
*
|
|
178
206
|
* Though the emulated cursor in locked mode
|
|
179
207
|
* (locked mode doesn't natively track absolute position)
|
package/dist/like.d.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module like
|
|
3
|
-
* @description A catalogue of subsystems
|
|
4
|
-
*/
|
|
5
1
|
import type { Audio } from './audio/index';
|
|
6
2
|
import type { Timer } from './timer/index';
|
|
7
3
|
import type { Input } from './input/index';
|
|
@@ -12,9 +8,12 @@ import type { Canvas } from './graphics/canvas';
|
|
|
12
8
|
import type { Graphics } from './graphics/index';
|
|
13
9
|
import { EventMap, EventType, LikeEvent } from './events';
|
|
14
10
|
import { Scene } from './scene';
|
|
11
|
+
/** @private */
|
|
15
12
|
export type TopLevelEventHandler = (event: LikeEvent) => void;
|
|
16
|
-
|
|
17
|
-
type
|
|
13
|
+
/** @private */
|
|
14
|
+
export type Callback<K extends EventType> = (...args: EventMap[K]) => void;
|
|
15
|
+
/** @private */
|
|
16
|
+
export type Callbacks = {
|
|
18
17
|
[K in EventType]?: Callback<K>;
|
|
19
18
|
};
|
|
20
19
|
/**
|
|
@@ -54,21 +53,52 @@ export type Like = Callbacks & {
|
|
|
54
53
|
*/
|
|
55
54
|
dispose(): void;
|
|
56
55
|
/**
|
|
57
|
-
*
|
|
58
|
-
*
|
|
56
|
+
* Push a scene to the scene stack.
|
|
57
|
+
*
|
|
58
|
+
* If the engine is running, this is the new running scene replacing the old one
|
|
59
|
+
* which can, in some cases, call out to the lower scene.
|
|
60
|
+
*
|
|
61
|
+
* @param overlay Set to true, and the current scene (before pushing) will stay loaded. Otherwise not.
|
|
62
|
+
*/
|
|
63
|
+
pushScene(scene: Scene, overlay: boolean): void;
|
|
64
|
+
/**
|
|
65
|
+
* Pop the current scene off the stack.
|
|
66
|
+
*
|
|
67
|
+
* To clear the stack, just run:
|
|
68
|
+
* ```ts
|
|
69
|
+
* while (like.popScene());
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
popScene(): Scene | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* Set the current scene at the top of the scene stack.
|
|
75
|
+
* If the stack is empty, push it onto the stack.
|
|
76
|
+
*
|
|
77
|
+
* Equivalent to `popScene` + `pushScene`.
|
|
78
|
+
*
|
|
79
|
+
* Use {@link popScene} to clear away the current scene,
|
|
80
|
+
* and to possibly revert to callback mode.
|
|
81
|
+
*/
|
|
82
|
+
setScene(scene: Scene): void;
|
|
83
|
+
/**
|
|
84
|
+
* Get the current scene, or a specific index.
|
|
85
|
+
*
|
|
86
|
+
* Uses `Array.at` under the hood, so -1 is the
|
|
87
|
+
* top scene, -2 is the parent scene, etc.
|
|
59
88
|
*/
|
|
60
|
-
|
|
89
|
+
getScene(index?: number): Scene | undefined;
|
|
61
90
|
/**
|
|
62
91
|
* LIKE's runtime is built around calling handleEvent.
|
|
63
92
|
*
|
|
64
93
|
* This function recieves all events. If set to undefined,
|
|
65
|
-
*
|
|
94
|
+
* {@link callOwnHandlers} is the default behavior.
|
|
66
95
|
*
|
|
67
96
|
* Otherwise, you can really customize LIKE by setting this
|
|
68
97
|
* to a custom handler.
|
|
69
98
|
*
|
|
70
99
|
* For example, the scene architecture is built around
|
|
71
|
-
* setting this function.
|
|
100
|
+
* setting this function. Setting it to a custom
|
|
101
|
+
* function will disable the scene system.
|
|
72
102
|
*/
|
|
73
103
|
handleEvent?: TopLevelEventHandler;
|
|
74
104
|
/**
|
|
@@ -78,5 +108,4 @@ export type Like = Callbacks & {
|
|
|
78
108
|
*/
|
|
79
109
|
callOwnHandlers(event: LikeEvent): void;
|
|
80
110
|
};
|
|
81
|
-
export {};
|
|
82
111
|
//# sourceMappingURL=like.d.ts.map
|