like2d 2.9.0 → 2.10.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.
Files changed (103) hide show
  1. package/README.md +21 -17
  2. package/dist/__benchmarks__/vector2.bench.d.ts +2 -0
  3. package/dist/__benchmarks__/vector2.bench.d.ts.map +1 -0
  4. package/dist/__benchmarks__/vector2.bench.js +74 -0
  5. package/dist/{core → audio}/audio.d.ts +12 -3
  6. package/dist/audio/audio.d.ts.map +1 -0
  7. package/dist/{core → audio}/audio.js +10 -2
  8. package/dist/audio/index.d.ts +2 -0
  9. package/dist/audio/index.d.ts.map +1 -0
  10. package/dist/audio/index.js +1 -0
  11. package/dist/engine.d.ts +12 -42
  12. package/dist/engine.d.ts.map +1 -1
  13. package/dist/engine.js +34 -76
  14. package/dist/{core/events.d.ts → events.d.ts} +27 -50
  15. package/dist/events.d.ts.map +1 -0
  16. package/dist/events.js +5 -0
  17. package/dist/gamecontrollerdb.txt +2222 -0
  18. package/dist/{core → graphics}/canvas.d.ts +18 -11
  19. package/dist/graphics/canvas.d.ts.map +1 -0
  20. package/dist/{core → graphics}/canvas.js +73 -58
  21. package/dist/{core/graphics.d.ts → graphics/drawing.d.ts} +25 -25
  22. package/dist/graphics/drawing.d.ts.map +1 -0
  23. package/dist/{core/graphics.js → graphics/drawing.js} +59 -52
  24. package/dist/graphics/index.d.ts +19 -0
  25. package/dist/graphics/index.d.ts.map +1 -0
  26. package/dist/graphics/index.js +13 -0
  27. package/dist/index.d.ts +3 -30
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +0 -21
  30. package/dist/input/gamepad-mapping.d.ts +134 -0
  31. package/dist/input/gamepad-mapping.d.ts.map +1 -0
  32. package/dist/input/gamepad-mapping.js +146 -0
  33. package/dist/input/gamepad.d.ts +74 -0
  34. package/dist/input/gamepad.d.ts.map +1 -0
  35. package/dist/input/gamepad.js +288 -0
  36. package/dist/input/index.d.ts +6 -0
  37. package/dist/input/index.d.ts.map +1 -0
  38. package/dist/input/index.js +1 -0
  39. package/dist/input/input.d.ts +76 -0
  40. package/dist/input/input.d.ts.map +1 -0
  41. package/dist/input/input.js +164 -0
  42. package/dist/input/keyboard.d.ts +15 -0
  43. package/dist/input/keyboard.d.ts.map +1 -0
  44. package/dist/{core → input}/keyboard.js +11 -21
  45. package/dist/input/mouse.d.ts +108 -0
  46. package/dist/input/mouse.d.ts.map +1 -0
  47. package/dist/input/mouse.js +241 -0
  48. package/dist/like.d.ts +80 -0
  49. package/dist/like.d.ts.map +1 -0
  50. package/dist/like.js +5 -0
  51. package/dist/math/index.d.ts +16 -0
  52. package/dist/math/index.d.ts.map +1 -1
  53. package/dist/math/index.js +16 -0
  54. package/dist/math/rect.d.ts +24 -27
  55. package/dist/math/rect.d.ts.map +1 -1
  56. package/dist/math/rect.js +47 -73
  57. package/dist/math/vector2.d.ts +87 -32
  58. package/dist/math/vector2.d.ts.map +1 -1
  59. package/dist/math/vector2.js +92 -110
  60. package/dist/prefab-scenes/index.d.ts +1 -0
  61. package/dist/prefab-scenes/index.d.ts.map +1 -1
  62. package/dist/prefab-scenes/index.js +1 -0
  63. package/dist/prefab-scenes/mapGamepad.d.ts +28 -0
  64. package/dist/prefab-scenes/mapGamepad.d.ts.map +1 -0
  65. package/dist/prefab-scenes/mapGamepad.js +181 -0
  66. package/dist/prefab-scenes/startScreen.d.ts +2 -2
  67. package/dist/prefab-scenes/startScreen.js +2 -2
  68. package/dist/scene.d.ts +2 -2
  69. package/dist/scene.d.ts.map +1 -1
  70. package/dist/timer/index.d.ts +2 -0
  71. package/dist/timer/index.d.ts.map +1 -0
  72. package/dist/timer/index.js +1 -0
  73. package/dist/timer/timer.d.ts +32 -0
  74. package/dist/timer/timer.d.ts.map +1 -0
  75. package/dist/{core → timer}/timer.js +20 -3
  76. package/package.json +22 -13
  77. package/dist/core/audio.d.ts.map +0 -1
  78. package/dist/core/canvas.d.ts.map +0 -1
  79. package/dist/core/events.d.ts.map +0 -1
  80. package/dist/core/events.js +0 -21
  81. package/dist/core/gamepad-mapping.d.ts +0 -58
  82. package/dist/core/gamepad-mapping.d.ts.map +0 -1
  83. package/dist/core/gamepad-mapping.js +0 -23
  84. package/dist/core/gamepad.d.ts +0 -37
  85. package/dist/core/gamepad.d.ts.map +0 -1
  86. package/dist/core/gamepad.js +0 -103
  87. package/dist/core/graphics.d.ts.map +0 -1
  88. package/dist/core/input-state.d.ts +0 -14
  89. package/dist/core/input-state.d.ts.map +0 -1
  90. package/dist/core/input-state.js +0 -50
  91. package/dist/core/input.d.ts +0 -40
  92. package/dist/core/input.d.ts.map +0 -1
  93. package/dist/core/input.js +0 -105
  94. package/dist/core/keyboard.d.ts +0 -15
  95. package/dist/core/keyboard.d.ts.map +0 -1
  96. package/dist/core/like.d.ts +0 -113
  97. package/dist/core/like.d.ts.map +0 -1
  98. package/dist/core/like.js +0 -9
  99. package/dist/core/mouse.d.ts +0 -52
  100. package/dist/core/mouse.d.ts.map +0 -1
  101. package/dist/core/mouse.js +0 -142
  102. package/dist/core/timer.d.ts +0 -15
  103. package/dist/core/timer.d.ts.map +0 -1
@@ -0,0 +1,108 @@
1
+ import { type Vector2 } from '../math/vector2';
2
+ import { type MouseButton, type LikeMouseEvent } from '../events';
3
+ import { EngineProps } from '../engine';
4
+ type MouseMode = {
5
+ lock: false;
6
+ visible: boolean;
7
+ scrollBlock: boolean;
8
+ } | {
9
+ lock: true;
10
+ speed: number;
11
+ };
12
+ export type MouseSetMode = Partial<MouseMode> & {
13
+ lock: boolean;
14
+ };
15
+ /**
16
+ * Mouse input handling. Bound to canvas. Emits relative movement when pointer locked.
17
+ */
18
+ export declare class Mouse {
19
+ private dispatch;
20
+ private pos;
21
+ private lastPos;
22
+ private buttons;
23
+ /** The canvas reference is the DOM / display canvas, this keeps
24
+ * track of the internal (apparent) canvas size.
25
+ */
26
+ private canvasSize;
27
+ private canvas;
28
+ private lockedMode;
29
+ private unlockedMode;
30
+ private enableLock;
31
+ constructor(props: EngineProps<LikeMouseEvent>);
32
+ private handleMouseMove;
33
+ private handleMouseDown;
34
+ private handleMouseUp;
35
+ private handleWheel;
36
+ /** Mouse position, transformed to canvas pixels. */
37
+ getPosition(): Vector2;
38
+ /** Check if button is held. Button 1 = left, 2 = middle, 3 = right. */
39
+ isDown(button: MouseButton): boolean;
40
+ /** All currently held buttons. */
41
+ getPressedButtons(): Set<MouseButton>;
42
+ /**
43
+ * Set the current cursor mode.
44
+ *
45
+ * ### Normal mode
46
+ * Consider setting `scrollBlock` to false (default is true) if you want
47
+ * your element to blend into the webpage for freer scrolling.
48
+ *
49
+ * ```ts
50
+ * {
51
+ * lock: false,
52
+ * visible: true, // disable to hide cursor.
53
+ * scrollBlock: true, // disable scroll while hovering canvas. Default: true
54
+ * }
55
+ * ```
56
+ *
57
+ * ### Captured mode
58
+ * In locked mode, the cursor cannot escape the canvas.
59
+ * It also becomes invisible.
60
+ * However, it can move infinitely, sensitivity can be controlled,
61
+ * and the emulated cursor (in `pos` of {@link mousemoved}) can be freely repositioned.
62
+ *
63
+ * ```ts
64
+ * {
65
+ * lock: true,
66
+ * speed: 1.0, // mouse sensitivity
67
+ * }
68
+ * ```
69
+ * Avoid binding the `ESC` key in captured mode. This will exit the capture and
70
+ * reset mode to default.
71
+ *
72
+ * ### Note on `pos` vs `delta`
73
+ * Event {@link mousemoved} passes both `pos` and `delta` args.
74
+ *
75
+ * Though the emulated cursor in locked mode
76
+ * (locked mode doesn't natively track absolute position)
77
+ * may be stuck on canvas edges, the `delta` field always
78
+ * represents mouse movement, even against edges.
79
+ */
80
+ setMode(mode: MouseSetMode): void;
81
+ getMode(): MouseMode;
82
+ /**
83
+ * Only applicable in capture mode -- sets the position
84
+ * of the emulated mouse.
85
+ */
86
+ setCapturedPos(pos: Vector2): void;
87
+ /**
88
+ * Enable/disable pointer lock (capture).
89
+ *
90
+ * For more fine-grained control, use {@link setMode} which
91
+ * also documents behaviors more thoroughly.
92
+ */
93
+ lockPointer(lock: boolean): void;
94
+ /**
95
+ * True when pointer is locked to canvas.
96
+ */
97
+ isPointerLocked(): boolean;
98
+ /**
99
+ * @returns whether the pointer is visible.
100
+ */
101
+ isCursorVisible(): boolean;
102
+ /** I beleve you wanted to use `like.mouse.setMode({lock: true})`
103
+ * or `like.mouse.lockPointer().
104
+ */
105
+ setRelativeMode?: never;
106
+ }
107
+ export {};
108
+ //# sourceMappingURL=mouse.d.ts.map
@@ -0,0 +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,OAAO,CAAC,MAAM,CAAoB;IAIlC,OAAO,CAAC,UAAU,CAAsD;IACxE,OAAO,CAAC,YAAY,CAAgF;IACpG,OAAO,CAAC,UAAU,CAAS;gBAEf,KAAK,EAAE,WAAW,CAAC,cAAc,CAAC;IAwC9C,OAAO,CAAC,eAAe;IAevB,OAAO,CAAC,eAAe;IAQvB,OAAO,CAAC,aAAa;IAKrB,OAAO,CAAC,WAAW;IAMnB,oDAAoD;IACpD,WAAW,IAAI,OAAO;IAItB,uEAAuE;IACvE,MAAM,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO;IAIpC,kCAAkC;IAClC,iBAAiB,IAAI,GAAG,CAAC,WAAW,CAAC;IAIrC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAqCG;IACH,OAAO,CAAC,IAAI,EAAE,YAAY;IAgB1B,OAAO,IAAI,SAAS;IAIpB;;;OAGG;IACH,cAAc,CAAC,GAAG,EAAE,OAAO;IAQ3B;;;;;OAKG;IACH,WAAW,CAAC,IAAI,EAAE,OAAO;IAUzB;;OAEG;IACH,eAAe,IAAI,OAAO;IAI1B;;OAEG;IACH,eAAe,IAAI,OAAO;IAI1B;;OAEG;IACH,eAAe,CAAC,EAAE,KAAK,CAAC;CACzB"}
@@ -0,0 +1,241 @@
1
+ import { Vec2 } from '../math/vector2';
2
+ const mouseButtons = ["left", "middle", "right"];
3
+ const numToButton = (i) => mouseButtons[i];
4
+ /**
5
+ * Mouse input handling. Bound to canvas. Emits relative movement when pointer locked.
6
+ */
7
+ export class Mouse {
8
+ constructor(props) {
9
+ Object.defineProperty(this, "dispatch", {
10
+ enumerable: true,
11
+ configurable: true,
12
+ writable: true,
13
+ value: void 0
14
+ });
15
+ Object.defineProperty(this, "pos", {
16
+ enumerable: true,
17
+ configurable: true,
18
+ writable: true,
19
+ value: [0, 0]
20
+ });
21
+ Object.defineProperty(this, "lastPos", {
22
+ enumerable: true,
23
+ configurable: true,
24
+ writable: true,
25
+ value: [0, 0]
26
+ });
27
+ Object.defineProperty(this, "buttons", {
28
+ enumerable: true,
29
+ configurable: true,
30
+ writable: true,
31
+ value: new Set()
32
+ });
33
+ /** The canvas reference is the DOM / display canvas, this keeps
34
+ * track of the internal (apparent) canvas size.
35
+ */
36
+ Object.defineProperty(this, "canvasSize", {
37
+ enumerable: true,
38
+ configurable: true,
39
+ writable: true,
40
+ value: [800, 600]
41
+ });
42
+ Object.defineProperty(this, "canvas", {
43
+ enumerable: true,
44
+ configurable: true,
45
+ writable: true,
46
+ value: void 0
47
+ });
48
+ // We keep track of a locked mode and an unlocked mode, so that when capture changes
49
+ // we can use the settings from last time.
50
+ Object.defineProperty(this, "lockedMode", {
51
+ enumerable: true,
52
+ configurable: true,
53
+ writable: true,
54
+ value: { lock: true, speed: 1 }
55
+ });
56
+ Object.defineProperty(this, "unlockedMode", {
57
+ enumerable: true,
58
+ configurable: true,
59
+ writable: true,
60
+ value: { lock: false, visible: true, scrollBlock: true }
61
+ });
62
+ Object.defineProperty(this, "enableLock", {
63
+ enumerable: true,
64
+ configurable: true,
65
+ writable: true,
66
+ value: false
67
+ });
68
+ /** I beleve you wanted to use `like.mouse.setMode({lock: true})`
69
+ * or `like.mouse.lockPointer().
70
+ */
71
+ Object.defineProperty(this, "setRelativeMode", {
72
+ enumerable: true,
73
+ configurable: true,
74
+ writable: true,
75
+ value: void 0
76
+ });
77
+ this.canvas = props.canvas;
78
+ this.dispatch = props.dispatch;
79
+ const { abort } = props;
80
+ this.canvas.addEventListener("like:mousemoved", this.handleMouseMove.bind(this), { signal: abort });
81
+ this.canvas.addEventListener("mousedown", this.handleMouseDown.bind(this), {
82
+ signal: abort,
83
+ });
84
+ window.addEventListener("mouseup", this.handleMouseUp.bind(this), {
85
+ signal: abort,
86
+ });
87
+ this.canvas.addEventListener("wheel", this.handleWheel.bind(this), {
88
+ passive: false,
89
+ signal: abort,
90
+ });
91
+ this.canvas.addEventListener("mouseleave", () => this.buttons.clear(), {
92
+ signal: abort,
93
+ });
94
+ this.canvas.addEventListener("pointerlockchanged", () => {
95
+ if (!this.isPointerLocked())
96
+ this.enableLock = false;
97
+ }, { signal: abort });
98
+ this.canvas.addEventListener("like:resizeCanvas", (e) => {
99
+ this.canvasSize = e.detail.size;
100
+ }, { signal: abort });
101
+ }
102
+ handleMouseMove(e) {
103
+ if (this.isPointerLocked() && this.enableLock) {
104
+ /** In pointer-lock mode, simulate a real cursor bounded by the canvas. */
105
+ this.setCapturedPos(Vec2.add(this.pos, Vec2.mul(e.detail.delta, this.lockedMode.speed)));
106
+ this.dispatch('mousemoved', [this.pos, e.detail.delta]);
107
+ }
108
+ else {
109
+ /** In non-pointer locked mode, calculate deltas ourselves. */
110
+ this.pos = e.detail.pos;
111
+ this.dispatch('mousemoved', [this.pos, Vec2.sub(this.pos, this.lastPos)]);
112
+ }
113
+ this.lastPos = this.pos;
114
+ }
115
+ handleMouseDown(e) {
116
+ // hack: ignore right clicks because they cause a refocus
117
+ if (!this.isPointerLocked() && e.button == 2)
118
+ return;
119
+ this.buttons.add(numToButton(e.button));
120
+ this.dispatch('mousepressed', [[e.offsetX, e.offsetY], numToButton(e.button)]);
121
+ this.canvas?.focus();
122
+ }
123
+ handleMouseUp(e) {
124
+ this.buttons.delete(numToButton(e.button));
125
+ this.dispatch('mousereleased', [[e.offsetX, e.offsetY], numToButton(e.button)]);
126
+ }
127
+ handleWheel(e) {
128
+ if (this.unlockedMode.scrollBlock) {
129
+ e.preventDefault();
130
+ }
131
+ }
132
+ /** Mouse position, transformed to canvas pixels. */
133
+ getPosition() {
134
+ return this.pos;
135
+ }
136
+ /** Check if button is held. Button 1 = left, 2 = middle, 3 = right. */
137
+ isDown(button) {
138
+ return this.buttons.has(button);
139
+ }
140
+ /** All currently held buttons. */
141
+ getPressedButtons() {
142
+ return new Set(this.buttons);
143
+ }
144
+ /**
145
+ * Set the current cursor mode.
146
+ *
147
+ * ### Normal mode
148
+ * Consider setting `scrollBlock` to false (default is true) if you want
149
+ * your element to blend into the webpage for freer scrolling.
150
+ *
151
+ * ```ts
152
+ * {
153
+ * lock: false,
154
+ * visible: true, // disable to hide cursor.
155
+ * scrollBlock: true, // disable scroll while hovering canvas. Default: true
156
+ * }
157
+ * ```
158
+ *
159
+ * ### Captured mode
160
+ * In locked mode, the cursor cannot escape the canvas.
161
+ * It also becomes invisible.
162
+ * However, it can move infinitely, sensitivity can be controlled,
163
+ * and the emulated cursor (in `pos` of {@link mousemoved}) can be freely repositioned.
164
+ *
165
+ * ```ts
166
+ * {
167
+ * lock: true,
168
+ * speed: 1.0, // mouse sensitivity
169
+ * }
170
+ * ```
171
+ * Avoid binding the `ESC` key in captured mode. This will exit the capture and
172
+ * reset mode to default.
173
+ *
174
+ * ### Note on `pos` vs `delta`
175
+ * Event {@link mousemoved} passes both `pos` and `delta` args.
176
+ *
177
+ * Though the emulated cursor in locked mode
178
+ * (locked mode doesn't natively track absolute position)
179
+ * may be stuck on canvas edges, the `delta` field always
180
+ * represents mouse movement, even against edges.
181
+ */
182
+ setMode(mode) {
183
+ this.lockPointer(mode.lock);
184
+ if (mode.lock) {
185
+ this.lockedMode = {
186
+ ...this.lockedMode,
187
+ ...mode,
188
+ };
189
+ }
190
+ else {
191
+ this.unlockedMode = {
192
+ ...this.unlockedMode,
193
+ ...mode
194
+ };
195
+ this.canvas.style.cursor = this.unlockedMode.visible ? 'auto' : 'none';
196
+ }
197
+ }
198
+ getMode() {
199
+ return this.enableLock ? this.lockedMode : this.unlockedMode;
200
+ }
201
+ /**
202
+ * Only applicable in capture mode -- sets the position
203
+ * of the emulated mouse.
204
+ */
205
+ setCapturedPos(pos) {
206
+ if (this.isPointerLocked()) {
207
+ this.pos = Vec2.clamp(pos, [0, 0], this.canvasSize);
208
+ }
209
+ else {
210
+ console.log("[Mouse] Attempt to set cursor position while not captured.");
211
+ }
212
+ }
213
+ /**
214
+ * Enable/disable pointer lock (capture).
215
+ *
216
+ * For more fine-grained control, use {@link setMode} which
217
+ * also documents behaviors more thoroughly.
218
+ */
219
+ lockPointer(lock) {
220
+ this.enableLock = lock;
221
+ const wasLocked = this.isPointerLocked();
222
+ if (lock && !wasLocked) {
223
+ this.canvas.requestPointerLock();
224
+ }
225
+ else if (!lock && wasLocked) {
226
+ document.exitPointerLock();
227
+ }
228
+ }
229
+ /**
230
+ * True when pointer is locked to canvas.
231
+ */
232
+ isPointerLocked() {
233
+ return document.pointerLockElement == this.canvas;
234
+ }
235
+ /**
236
+ * @returns whether the pointer is visible.
237
+ */
238
+ isCursorVisible() {
239
+ return this.enableLock || !this.unlockedMode.visible;
240
+ }
241
+ }
package/dist/like.d.ts ADDED
@@ -0,0 +1,80 @@
1
+ /**
2
+ * @module like
3
+ * @description A catalogue of subsystems
4
+ */
5
+ import type { Audio } from './audio/index';
6
+ import type { Timer } from './timer/index';
7
+ import type { Input } from './input/index';
8
+ import type { Keyboard } from './input/keyboard';
9
+ import type { Mouse } from './input/mouse';
10
+ import type { Gamepad } from './input/gamepad';
11
+ import type { Canvas } from './graphics/canvas';
12
+ import type { BoundGraphics } from './graphics/index';
13
+ import { EventMap, EventType, LikeEvent } from './events';
14
+ import { Scene } from './scene';
15
+ export type TopLevelEventHandler = (event: LikeEvent) => void;
16
+ type Callback<K extends EventType> = (...args: EventMap[K]) => void;
17
+ type Callbacks = {
18
+ [K in EventType]?: Callback<K>;
19
+ };
20
+ /**
21
+ * The main Like instance.
22
+ * Use this object much how you would the `love` object in Love2D.
23
+ * This is the interface returned by {@link createLike}.
24
+ */
25
+ export type Like = Callbacks & {
26
+ /** Handle a pool of pseudo-synchronous audio sources with global volume control and more. */
27
+ readonly audio: Audio;
28
+ /** Misc. time functions, including sleeping the game. ZZZ */
29
+ readonly timer: Timer;
30
+ /** Bind inputs to actions that call `like.actionpressed`, or query them here also. */
31
+ readonly input: Input;
32
+ /** Check if scancodes are down / pressed. */
33
+ readonly keyboard: Keyboard;
34
+ /** Mouse module: Get a properly scaled mouse position, set capture and more. */
35
+ readonly mouse: Mouse;
36
+ /** Gamepad module: Map gamepads and check their buttons. */
37
+ readonly gamepad: Gamepad;
38
+ /** Get and set screen size, choosing between native and pixel perfect prescaling. Plus fullscreen control. */
39
+ readonly canvas: Canvas;
40
+ /** Graphics module: LOVE-style rendering, plus a pseudo-synchronous way to load images. */
41
+ gfx: BoundGraphics;
42
+ /** I think you meant to type `canvas`. */
43
+ window?: never;
44
+ /**
45
+ * Start the game loop. Call this only once.
46
+ * @returns Promise that resolves when the engine is ready
47
+ */
48
+ start(): Promise<void>;
49
+ /**
50
+ * Only call this when you're done with LIKE. Everything will stop
51
+ * running, and probably break if you try to use it.
52
+ */
53
+ dispose(): void;
54
+ /**
55
+ * A simple way to set the current scene, which acts like a pluggable
56
+ * set of callbacks.
57
+ */
58
+ setScene(scene?: Scene): void;
59
+ /**
60
+ * LIKE's runtime is built around calling handleEvent.
61
+ *
62
+ * This function recieves all events. If set to undefined,
63
+ * `like.callOwnHandlers(ev)` is the default behavior.
64
+ *
65
+ * Otherwise, you can really customize LIKE by setting this
66
+ * to a custom handler.
67
+ *
68
+ * For example, the scene architecture is built around
69
+ * setting this function.
70
+ */
71
+ handleEvent?: TopLevelEventHandler;
72
+ /**
73
+ * Used as the default `like.handleEvent`, simply dispatches
74
+ * an event into LIKE callbacks.
75
+ * @param event
76
+ */
77
+ callOwnHandlers(event: LikeEvent): void;
78
+ };
79
+ export {};
80
+ //# sourceMappingURL=like.d.ts.map
@@ -0,0 +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,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;;;OAIG;IACH,eAAe,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;CACzC,CAAA"}
package/dist/like.js ADDED
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @module like
3
+ * @description A catalogue of subsystems
4
+ */
5
+ export {};
@@ -1,2 +1,18 @@
1
+ /**
2
+ * @module math
3
+ *
4
+ * A purely functional math library, mostly for 2d.
5
+ *
6
+ * Check out {@link vector2} and {@link rect}
7
+ *
8
+ * Why purely functional?
9
+ * 1. About as fast as it can get -- the JIT will pick up on these.
10
+ * 2. Plays nice with stream iterators.
11
+ * 3. JS is likely to add a pipe operator in the future.
12
+ * 4. Construction is as easy as building an array.
13
+ */
14
+ /** True modulus, conspicuously missing from JS */
1
15
  export declare const mod: (a: number, b: number) => number;
16
+ export { type Vector2, Vec2 } from "./vector2";
17
+ export { type Rectangle, Rect } from "./rect";
2
18
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/math/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,GAAG,GAAI,GAAG,MAAM,EAAE,GAAG,MAAM,WAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/math/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,kDAAkD;AAClD,eAAO,MAAM,GAAG,GAAI,GAAG,MAAM,EAAE,GAAG,MAAM,WAAsB,CAAC;AAE/D,OAAO,EAAE,KAAK,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,KAAK,SAAS,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC"}
@@ -1 +1,17 @@
1
+ /**
2
+ * @module math
3
+ *
4
+ * A purely functional math library, mostly for 2d.
5
+ *
6
+ * Check out {@link vector2} and {@link rect}
7
+ *
8
+ * Why purely functional?
9
+ * 1. About as fast as it can get -- the JIT will pick up on these.
10
+ * 2. Plays nice with stream iterators.
11
+ * 3. JS is likely to add a pipe operator in the future.
12
+ * 4. Construction is as easy as building an array.
13
+ */
14
+ /** True modulus, conspicuously missing from JS */
1
15
  export const mod = (a, b) => ((a % b) + b) % b;
16
+ export { Vec2 } from "./vector2";
17
+ export { Rect } from "./rect";
@@ -41,31 +41,28 @@ import { type Vector2 } from '../math/vector2';
41
41
  *
42
42
  * */
43
43
  export type Rectangle = [number, number, number, number];
44
- /**
45
- * A set of
46
- */
47
- export declare namespace Rect {
48
- function fromPoints(a: Vector2, b: Vector2): Rectangle;
49
- function fromCenter(center: Vector2, size: Vector2): Rectangle;
50
- function position(r: Rectangle): Vector2;
51
- function size(r: Rectangle): Vector2;
52
- function center(r: Rectangle): Vector2;
53
- function topLeft(r: Rectangle): Vector2;
54
- function topRight(r: Rectangle): Vector2;
55
- function bottomLeft(r: Rectangle): Vector2;
56
- function bottomRight(r: Rectangle): Vector2;
57
- function area(r: Rectangle): number;
58
- function isEmpty(r: Rectangle): boolean;
59
- function clampPoint(r: Rectangle, point: Vector2): Vector2;
60
- function containsPoint(r: Rectangle, point: Vector2): boolean;
61
- function containsRect(r: Rectangle, other: Rectangle): boolean;
62
- function intersects(r: Rectangle, other: Rectangle): boolean;
63
- function intersection(r: Rectangle, other: Rectangle): Rectangle;
64
- function union(r: Rectangle, other: Rectangle): Rectangle;
65
- function inflate(r: Rectangle, amount: number): Rectangle;
66
- function offset(r: Rectangle, delta: Vector2): Rectangle;
67
- function setPosition(r: Rectangle, pos: Vector2): Rectangle;
68
- function setSize(r: Rectangle, size: Vector2): Rectangle;
69
- function setCenter(r: Rectangle, center: Vector2): Rectangle;
70
- }
44
+ export declare const Rect: {
45
+ fromPoints(a: Vector2, b: Vector2): Rectangle;
46
+ fromCenter(center: Vector2, size: Vector2): Rectangle;
47
+ position(r: Rectangle): Vector2;
48
+ size(r: Rectangle): Vector2;
49
+ center(r: Rectangle): Vector2;
50
+ topLeft(r: Rectangle): Vector2;
51
+ topRight(r: Rectangle): Vector2;
52
+ bottomLeft(r: Rectangle): Vector2;
53
+ bottomRight(r: Rectangle): Vector2;
54
+ area(r: Rectangle): number;
55
+ isEmpty(r: Rectangle): boolean;
56
+ clampPoint(r: Rectangle, point: Vector2): Vector2;
57
+ containsPoint(r: Rectangle, point: Vector2): boolean;
58
+ containsRect(r: Rectangle, other: Rectangle): boolean;
59
+ intersects(r: Rectangle, other: Rectangle): boolean;
60
+ intersection(r: Rectangle, other: Rectangle): Rectangle;
61
+ union(r: Rectangle, other: Rectangle): Rectangle;
62
+ inflate(r: Rectangle, amount: number): Rectangle;
63
+ offset(r: Rectangle, delta: Vector2): Rectangle;
64
+ setPosition(r: Rectangle, pos: Vector2): Rectangle;
65
+ setSize(r: Rectangle, size: Vector2): Rectangle;
66
+ setCenter(r: Rectangle, center: Vector2): Rectangle;
67
+ };
71
68
  //# sourceMappingURL=rect.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"rect.d.ts","sourceRoot":"","sources":["../../src/math/rect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAErD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAwCK;AACL,MAAM,MAAM,SAAS,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAEzD;;GAEG;AACH,yBAAiB,IAAI,CAAC;IACpB,SAAgB,UAAU,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,SAAS,CAM5D;IAED,SAAgB,UAAU,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,GAAG,SAAS,CAOpE;IAED,SAAgB,QAAQ,CAAC,CAAC,EAAE,SAAS,GAAG,OAAO,CAE9C;IAED,SAAgB,IAAI,CAAC,CAAC,EAAE,SAAS,GAAG,OAAO,CAE1C;IAED,SAAgB,MAAM,CAAC,CAAC,EAAE,SAAS,GAAG,OAAO,CAE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