like2d 2.10.2 → 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.
Files changed (62) hide show
  1. package/README.md +6 -4
  2. package/dist/audio/index.d.ts +1 -1
  3. package/dist/audio/index.d.ts.map +1 -1
  4. package/dist/engine.d.ts +5 -10
  5. package/dist/engine.d.ts.map +1 -1
  6. package/dist/engine.js +5 -14
  7. package/dist/events.d.ts +38 -21
  8. package/dist/events.d.ts.map +1 -1
  9. package/dist/graphics/canvas.d.ts +12 -4
  10. package/dist/graphics/canvas.d.ts.map +1 -1
  11. package/dist/graphics/canvas.js +13 -5
  12. package/dist/graphics/{drawing.d.ts → graphics.d.ts} +71 -50
  13. package/dist/graphics/graphics.d.ts.map +1 -0
  14. package/dist/graphics/{drawing.js → graphics.js} +156 -168
  15. package/dist/graphics/image.d.ts +22 -0
  16. package/dist/graphics/image.d.ts.map +1 -0
  17. package/dist/graphics/image.js +62 -0
  18. package/dist/graphics/index.d.ts +6 -15
  19. package/dist/graphics/index.d.ts.map +1 -1
  20. package/dist/graphics/index.js +2 -10
  21. package/dist/index.d.ts +6 -4
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +9 -2
  24. package/dist/input/gamepad-mapping.d.ts +4 -4
  25. package/dist/input/gamepad-mapping.d.ts.map +1 -1
  26. package/dist/input/gamepad-mapping.js +4 -4
  27. package/dist/input/gamepad.d.ts +11 -1
  28. package/dist/input/gamepad.d.ts.map +1 -1
  29. package/dist/input/gamepad.js +11 -1
  30. package/dist/input/index.d.ts +13 -5
  31. package/dist/input/index.d.ts.map +1 -1
  32. package/dist/input/index.js +5 -1
  33. package/dist/input/input.d.ts +56 -5
  34. package/dist/input/input.d.ts.map +1 -1
  35. package/dist/input/input.js +61 -7
  36. package/dist/input/keyboard.d.ts +26 -3
  37. package/dist/input/keyboard.d.ts.map +1 -1
  38. package/dist/input/keyboard.js +24 -0
  39. package/dist/input/mouse.d.ts +34 -6
  40. package/dist/input/mouse.d.ts.map +1 -1
  41. package/dist/input/mouse.js +33 -4
  42. package/dist/like.d.ts +9 -9
  43. package/dist/like.d.ts.map +1 -1
  44. package/dist/like.js +0 -4
  45. package/dist/math/index.d.ts +8 -9
  46. package/dist/math/index.d.ts.map +1 -1
  47. package/dist/math/index.js +8 -9
  48. package/dist/math/vector2.d.ts +1 -0
  49. package/dist/math/vector2.d.ts.map +1 -1
  50. package/dist/prefab-scenes/index.d.ts +5 -3
  51. package/dist/prefab-scenes/index.d.ts.map +1 -1
  52. package/dist/prefab-scenes/index.js +4 -2
  53. package/dist/prefab-scenes/mapGamepad.d.ts +13 -0
  54. package/dist/prefab-scenes/mapGamepad.d.ts.map +1 -1
  55. package/dist/prefab-scenes/mapGamepad.js +13 -0
  56. package/dist/scene.d.ts +1 -6
  57. package/dist/scene.d.ts.map +1 -1
  58. package/dist/scene.js +0 -5
  59. package/dist/timer/timer.d.ts.map +1 -1
  60. package/dist/timer/timer.js +1 -2
  61. package/package.json +1 -2
  62. package/dist/graphics/drawing.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 +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;;kBACgB,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,CA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  * 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) => {
@@ -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;;;;;;;;;;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,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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"}
@@ -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) {
@@ -1,6 +1,14 @@
1
- export type { Input, InputType, InputBinding, } from "./input";
2
- export type { GamepadTarget, Gamepad, } from "./gamepad";
3
- export type { LikeButton, GamepadMapping, StickMapping, StickAxisMapping, } from "./gamepad-mapping";
4
- export { defaultMapping, allButtons } from "./gamepad-mapping";
5
- export type { MouseSetMode, Mouse, } from "./mouse";
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,EACV,KAAK,EACL,SAAS,EACT,YAAY,GACb,MAAM,SAAS,CAAC;AAEjB,YAAY,EACV,aAAa,EACb,OAAO,GACR,MAAM,WAAW,CAAA;AAElB,YAAY,EACV,UAAU,EACV,cAAc,EACd,YAAY,EACZ,gBAAgB,GACjB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/D,YAAY,EACV,YAAY,EACZ,KAAK,GACN,MAAM,SAAS,CAAC"}
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"}
@@ -1 +1,5 @@
1
- export { defaultMapping, allButtons } from "./gamepad-mapping";
1
+ /**
2
+ * Where {@link Keyboard}, {@link Mouse}, {@link Gamepad}, and actions in {@link Input} reside.
3
+ * @module input
4
+ */
5
+ export { defaultMapping, allButtons, buttonMap } from "./gamepad-mapping";
@@ -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 { MouseButton, Dispatcher } from '../events';
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
- constructor(dispatch: Dispatcher<'actionpressed' | 'actionreleased'>, deps: {
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(): void;
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":["../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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"}
@@ -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(dispatch, deps) {
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`
@@ -1,15 +1,38 @@
1
1
  import { EngineProps } from "../engine";
2
- type KEvent = 'keypressed' | 'keyreleased';
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<KEvent>);
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;AAGxC,KAAK,MAAM,GAAG,YAAY,GAAG,aAAa,CAAC;AAE3C,qBAAa,QAAQ;IACnB,OAAO,CAAC,gBAAgB,CAAqB;IAC7C,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,QAAQ,CAAqB;gBAEzB,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC;IAUtC,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"}
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"}
@@ -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", {
@@ -1,7 +1,8 @@
1
1
  import { type Vector2 } from '../math/vector2';
2
- import { type MouseButton, type LikeMouseEvent } from '../events';
2
+ import { type LikeMouseEvent } from '../events';
3
3
  import { EngineProps } from '../engine';
4
- type MouseMode = {
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
- * Mouse input handling. Bound to canvas. Emits relative movement when pointer locked.
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
@@ -1 +1 @@
1
- {"version":3,"file":"mouse.d.ts","sourceRoot":"","sources":["../../src/input/mouse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,OAAO,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,KAAK,WAAW,EAAmB,KAAK,cAAc,EAAE,MAAM,WAAW,CAAC;AACnF,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAMxC,KAAK,SAAS,GACV;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,OAAO,CAAC;IAAC,WAAW,EAAE,OAAO,CAAA;CAAE,GACvD;IAAE,IAAI,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAElC,MAAM,MAAM,YAAY,GAAG,OAAO,CAAC,SAAS,CAAC,GAAG;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC;AAElE;;GAEG;AACH,qBAAa,KAAK;IAChB,OAAO,CAAC,QAAQ,CAA6B;IAC7C,OAAO,CAAC,GAAG,CAAmB;IAC9B,OAAO,CAAC,OAAO,CAAmB;IAClC,OAAO,CAAC,OAAO,CAA0B;IACzC;;OAEG;IACH,OAAO,CAAC,UAAU,CAAuB;IACzC,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  const mouseButtons = ["left", "middle", "right"];
3
3
  const numToButton = (i) => mouseButtons[i];
4
4
  /**
5
- * Mouse input handling. Bound to canvas. Emits relative movement when pointer locked.
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) {
@@ -91,7 +119,8 @@ export class Mouse {
91
119
  this.canvas.addEventListener("mouseleave", () => this.buttons.clear(), {
92
120
  signal: abort,
93
121
  });
94
- this.canvas.addEventListener("pointerlockchanged", () => {
122
+ this.canvas.addEventListener("pointerlockchange", // unsupported on mobile, will have to test.
123
+ () => {
95
124
  if (!this.isPointerLocked())
96
125
  this.enableLock = false;
97
126
  }, { signal: abort });
@@ -160,7 +189,7 @@ export class Mouse {
160
189
  * In locked mode, the cursor cannot escape the canvas.
161
190
  * It also becomes invisible.
162
191
  * However, it can move infinitely, sensitivity can be controlled,
163
- * 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.
164
193
  *
165
194
  * ```ts
166
195
  * {
@@ -172,7 +201,7 @@ export class Mouse {
172
201
  * reset mode to default.
173
202
  *
174
203
  * ### Note on `pos` vs `delta`
175
- * Event {@link mousemoved} passes both `pos` and `delta` args.
204
+ * Event {@link index.EventMap.mousemoved} passes both `pos` and `delta` args.
176
205
  *
177
206
  * Though the emulated cursor in locked mode
178
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';
@@ -9,12 +5,15 @@ import type { Keyboard } from './input/keyboard';
9
5
  import type { Mouse } from './input/mouse';
10
6
  import type { Gamepad } from './input/gamepad';
11
7
  import type { Canvas } from './graphics/canvas';
12
- import type { BoundGraphics } from './graphics/index';
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
- type Callback<K extends EventType> = (...args: EventMap[K]) => void;
17
- type Callbacks = {
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
  /**
@@ -38,9 +37,11 @@ export type Like = Callbacks & {
38
37
  /** Get and set screen size, choosing between native and pixel perfect prescaling. Plus fullscreen control. */
39
38
  readonly canvas: Canvas;
40
39
  /** Graphics module: LOVE-style rendering, plus a pseudo-synchronous way to load images. */
41
- gfx: BoundGraphics;
40
+ readonly gfx: Graphics;
42
41
  /** I think you meant to type `canvas`. */
43
42
  window?: never;
43
+ /** Shortened to `like.gfx`. */
44
+ graphics?: never;
44
45
  /**
45
46
  * Start the game loop. Call this only once.
46
47
  * @returns Promise that resolves when the engine is ready
@@ -76,5 +77,4 @@ export type Like = Callbacks & {
76
77
  */
77
78
  callOwnHandlers(event: LikeEvent): void;
78
79
  };
79
- export {};
80
80
  //# sourceMappingURL=like.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"like.d.ts","sourceRoot":"","sources":["../src/like.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,MAAM,MAAM,oBAAoB,GAAG,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAC;AAE9D,KAAK,QAAQ,CAAC,CAAC,SAAS,SAAS,IAAI,CAAC,GAAG,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;AAEpE,KAAK,SAAS,GAAG;KACd,CAAC,IAAI,SAAS,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC;CAC/B,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,IAAI,GAAG,SAAS,GAAG;IAC7B,6FAA6F;IAC7F,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,6DAA6D;IAC7D,QAAQ,CAAC,KAAK,E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