like2d 2.12.1 → 2.13.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 +17 -27
- package/assets/logo-banner-optimized.svg +1 -1
- package/dist/engine.d.ts +13 -7
- package/dist/engine.js +21 -46
- package/dist/events.d.ts +61 -59
- package/dist/graphics/graphics.d.ts +2 -1
- package/dist/graphics/index.d.ts +1 -1
- package/dist/index.d.ts +3 -4
- package/dist/index.js +1 -0
- package/dist/input/gamepad.d.ts +2 -2
- package/dist/input/gamepad.js +2 -2
- package/dist/input/mouse.d.ts +2 -2
- package/dist/input/mouse.js +2 -2
- package/dist/like.d.ts +37 -66
- package/dist/scene/index.d.ts +368 -0
- package/dist/scene/index.js +204 -0
- package/dist/scene/prefab/fadeTransition.d.ts +25 -0
- package/dist/scene/prefab/fadeTransition.js +55 -0
- package/dist/scene/prefab/mapGamepad.d.ts +47 -0
- package/dist/scene/prefab/mapGamepad.js +189 -0
- package/dist/scene/prefab/startScreen.d.ts +47 -0
- package/dist/{prefab-scenes → scene/prefab}/startScreen.js +25 -84
- package/package.json +10 -5
- package/dist/prefab-scenes/index.d.ts +0 -10
- package/dist/prefab-scenes/index.js +0 -9
- package/dist/prefab-scenes/mapGamepad.d.ts +0 -42
- package/dist/prefab-scenes/mapGamepad.js +0 -199
- package/dist/prefab-scenes/startScreen.d.ts +0 -58
- package/dist/scene.d.ts +0 -145
- package/dist/scene.js +0 -23
package/README.md
CHANGED
|
@@ -1,33 +1,23 @@
|
|
|
1
1
|
# LÏKE2D
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
<
|
|
3
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
4
|
+
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
|
5
|
+
<svg version="1.1" viewBox="0 0 256 85" xmlns="http://www.w3.org/2000/svg">
|
|
6
|
+
<rect x="8.4949" y="14.841" width="239.13" height="60.337" ry="14.369"/>
|
|
7
|
+
<path d="m49.519 2.1933-22.841 22.854-0.01193 0.01193a16.159 16.168 0 0 0 0 22.866 16.159 16.168 0 0 0 20.539 1.9189 16.159 16.168 0 0 1 0.0048 0.39055 16.159 16.168 0 0 1-16.159 16.169h36.935a16.159 16.168 0 0 1-16.159-16.169 16.159 16.168 0 0 1 0.0054-0.39055 16.159 16.168 0 0 0 20.539-1.9193 16.159 16.168 0 0 0-4.76e-4 -22.866z" fill="#ba2b2b" stroke="#ffcf42" stroke-linejoin="round" stroke-width=".5"/>
|
|
8
|
+
<g fill="none" stroke="#ffcf42" stroke-width=".5">
|
|
9
|
+
<circle transform="matrix(-.7069 .70731 -.7069 -.70731 0 0)" cx="-17.311" cy="-68.903" r="16.164"/>
|
|
10
|
+
<circle transform="matrix(-.7069 .70731 -.7069 -.70731 0 0)" cx="-1.147" cy="-52.739" r="16.164"/>
|
|
11
|
+
<ellipse cx="67.986" cy="50.234" rx="16.159" ry="16.168"/>
|
|
12
|
+
<ellipse cx="31.051" cy="50.234" rx="16.159" ry="16.168"/>
|
|
10
13
|
</g>
|
|
11
|
-
<g>
|
|
12
|
-
<
|
|
13
|
-
<
|
|
14
|
-
<
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
<g>
|
|
19
|
-
<path d="m237.53 38.691-17.505-9.3882 17.505-18.073z"/>
|
|
20
|
-
<rect x="202.88" y="48.079" width="16.772" height="9.3882"/>
|
|
21
|
-
<rect x="272.54" y="20.266" width="16.772" height="9.3882"/>
|
|
22
|
-
<rect x="272.54" y="38.691" width="16.772" height="9.3882"/>
|
|
23
|
-
<path d="m202.52 29.302 0.36685-18.073h17.139z"/>
|
|
24
|
-
</g>
|
|
25
|
-
<path d="m64.078 1.0042-33.375 33.375-0.01743 0.0174a23.612 23.612 0 0 0 0 33.392 23.612 23.612 0 0 0 30.012 2.8022 23.612 23.612 0 0 1 7e-3 0.57034 23.612 23.612 0 0 1-23.612 23.612h53.97a23.612 23.612 0 0 1-23.611-23.612 23.612 23.612 0 0 1 7e-3 -0.57034 23.612 23.612 0 0 0 30.012-2.8029 23.612 23.612 0 0 0-6.88e-4 -33.392z" fill="#80c3e4" stroke="#000" stroke-linejoin="round"/>
|
|
26
|
-
<g fill="none" stroke="#000" stroke-width=".5">
|
|
27
|
-
<circle transform="rotate(135)" cx="-20.988" cy="-93.243" r="23.612"/>
|
|
28
|
-
<circle transform="rotate(135)" cx="2.6238" cy="-69.632" r="23.612"/>
|
|
29
|
-
<circle cx="91.062" cy="71.161" r="23.612"/>
|
|
30
|
-
<circle cx="37.093" cy="71.161" r="23.612"/>
|
|
14
|
+
<g fill="#ffcf42" stroke="#000" stroke-width=".5">
|
|
15
|
+
<path d="m89.924 21.979v36.375h28.103v-14.771h-12.029v-21.604z"/>
|
|
16
|
+
<path d="m127.94 24.678v7.665h5.0453v11.046h-5.0453v14.966h24.748v-14.966h-5.048v-11.046h5.048v-7.665h-12.377z"/>
|
|
17
|
+
<path d="m206.89 22.088v36.375h33.739v-13.179h-10.908v-5.0678h10.908v-7.109h-10.908v-5.069h10.908v-5.9504z"/>
|
|
18
|
+
<path d="m162.76 19.77v38.693h12.281v-5.069h11.523v5.069h12.281s1.0482-15.115-2.2012-18.768c-3.4704-3.9018-6.3723-4.5209-6.3723-4.5209l8.8848-13.087h-13.615l-6.4108 13.022-4.3423 0.03698-8e-3 -15.377z"/>
|
|
19
|
+
<ellipse cx="132.99" cy="16.122" rx="6.0221" ry="6.1182"/>
|
|
20
|
+
<ellipse cx="147.49" cy="16.122" rx="6.0221" ry="6.1182"/>
|
|
31
21
|
</g>
|
|
32
22
|
</svg>
|
|
33
23
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
2
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
|
3
|
-
<svg
|
|
3
|
+
<svg version="1.1" viewBox="0 0 256 85" xmlns="http://www.w3.org/2000/svg">
|
|
4
4
|
<rect x="8.4949" y="14.841" width="239.13" height="60.337" ry="14.369"/>
|
|
5
5
|
<path d="m49.519 2.1933-22.841 22.854-0.01193 0.01193a16.159 16.168 0 0 0 0 22.866 16.159 16.168 0 0 0 20.539 1.9189 16.159 16.168 0 0 1 0.0048 0.39055 16.159 16.168 0 0 1-16.159 16.169h36.935a16.159 16.168 0 0 1-16.159-16.169 16.159 16.168 0 0 1 0.0054-0.39055 16.159 16.168 0 0 0 20.539-1.9193 16.159 16.168 0 0 0-4.76e-4 -22.866z" fill="#ba2b2b" stroke="#ffcf42" stroke-linejoin="round" stroke-width=".5"/>
|
|
6
6
|
<g fill="none" stroke="#ffcf42" stroke-width=".5">
|
package/dist/engine.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type
|
|
1
|
+
import type { LikeEvent, LikeEventHandlers, Dispatcher, LikeCanvasElement } from './events';
|
|
2
|
+
import { LikeHandlers, type Like } from './like';
|
|
3
3
|
/** @private */
|
|
4
|
-
export type EngineDispatcher = Dispatcher<
|
|
4
|
+
export type EngineDispatcher = Dispatcher<keyof LikeEventHandlers>;
|
|
5
5
|
/** @private */
|
|
6
|
-
export type EngineProps<
|
|
6
|
+
export type EngineProps<K extends keyof LikeEventHandlers> = {
|
|
7
7
|
canvas: LikeCanvasElement;
|
|
8
8
|
abort: AbortSignal;
|
|
9
|
-
dispatch: Dispatcher<
|
|
9
|
+
dispatch: Dispatcher<K>;
|
|
10
10
|
};
|
|
11
11
|
/** @private */
|
|
12
12
|
export declare class Engine {
|
|
@@ -17,13 +17,11 @@ export declare class Engine {
|
|
|
17
17
|
private isRunning;
|
|
18
18
|
private lastTime;
|
|
19
19
|
private abort;
|
|
20
|
-
private sceneStack;
|
|
21
20
|
/**
|
|
22
21
|
* The Like interface providing access to all engine subsystems.
|
|
23
22
|
*/
|
|
24
23
|
readonly like: Like;
|
|
25
24
|
constructor(container: HTMLElement);
|
|
26
|
-
private refreshScene;
|
|
27
25
|
private dispatch;
|
|
28
26
|
/**
|
|
29
27
|
* Start the game loop.
|
|
@@ -34,4 +32,12 @@ export declare class Engine {
|
|
|
34
32
|
*/
|
|
35
33
|
dispose(): void;
|
|
36
34
|
}
|
|
35
|
+
export declare function likeDispatch(obj: LikeHandlers, event: LikeEvent): void;
|
|
36
|
+
/**
|
|
37
|
+
* Call event handlers from an event. For example, an event with `.type = update, .args = [dt]`
|
|
38
|
+
* translates to calling `obj.draw(dt)`.
|
|
39
|
+
*
|
|
40
|
+
* Typically used at the end of a custom {@link LikeHandlers.handleEvent | handleEvent}.
|
|
41
|
+
*/
|
|
42
|
+
export declare function callOwnHandlers(obj: LikeHandlers, event: LikeEvent): void;
|
|
37
43
|
//# sourceMappingURL=engine.d.ts.map
|
package/dist/engine.js
CHANGED
|
@@ -6,7 +6,6 @@ import { Mouse } from './input/mouse';
|
|
|
6
6
|
import { Gamepad } from './input/gamepad';
|
|
7
7
|
import { Graphics } from './graphics/graphics';
|
|
8
8
|
import { Canvas } from './graphics/canvas';
|
|
9
|
-
import { sceneDispatch } from './scene';
|
|
10
9
|
/** @private */
|
|
11
10
|
export class Engine {
|
|
12
11
|
constructor(container) {
|
|
@@ -42,12 +41,6 @@ export class Engine {
|
|
|
42
41
|
writable: true,
|
|
43
42
|
value: new AbortController()
|
|
44
43
|
});
|
|
45
|
-
Object.defineProperty(this, "sceneStack", {
|
|
46
|
-
enumerable: true,
|
|
47
|
-
configurable: true,
|
|
48
|
-
writable: true,
|
|
49
|
-
value: []
|
|
50
|
-
});
|
|
51
44
|
/**
|
|
52
45
|
* The Like interface providing access to all engine subsystems.
|
|
53
46
|
*/
|
|
@@ -83,52 +76,15 @@ export class Engine {
|
|
|
83
76
|
canvas,
|
|
84
77
|
start: this.start.bind(this),
|
|
85
78
|
dispose: this.dispose.bind(this),
|
|
86
|
-
|
|
87
|
-
return this.sceneStack.at(pos);
|
|
88
|
-
},
|
|
89
|
-
pushScene: (scene, _overlay) => {
|
|
90
|
-
this.sceneStack.push(scene);
|
|
91
|
-
this.refreshScene();
|
|
92
|
-
},
|
|
93
|
-
popScene: () => {
|
|
94
|
-
const s = this.sceneStack.pop();
|
|
95
|
-
this.refreshScene();
|
|
96
|
-
return s;
|
|
97
|
-
},
|
|
98
|
-
setScene: (scene) => {
|
|
99
|
-
const idx = Math.max(0, this.sceneStack.length - 1);
|
|
100
|
-
this.sceneStack[idx] = scene;
|
|
101
|
-
this.refreshScene();
|
|
102
|
-
},
|
|
103
|
-
callOwnHandlers: (event) => {
|
|
104
|
-
if (event.type in this.like)
|
|
105
|
-
this.like[event.type](...event.args);
|
|
106
|
-
}
|
|
79
|
+
callOwnHandlers: (ev) => callOwnHandlers(this.like, ev),
|
|
107
80
|
};
|
|
108
81
|
window.addEventListener('focus', () => this.dispatch('focus', ['tab']));
|
|
109
82
|
window.addEventListener('blur', () => this.dispatch('blur', ['tab']));
|
|
110
83
|
this.canvas.addEventListener('focus', () => this.dispatch('focus', ['canvas']));
|
|
111
84
|
}
|
|
112
|
-
refreshScene() {
|
|
113
|
-
const topScene = this.sceneStack.at(-1);
|
|
114
|
-
if (topScene) {
|
|
115
|
-
this.like.handleEvent = (event) => sceneDispatch(topScene, this.like, event);
|
|
116
|
-
if (this.isRunning) {
|
|
117
|
-
this.dispatch("load", []);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
this.like.handleEvent = undefined;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
85
|
dispatch(type, args) {
|
|
125
86
|
const event = { type, args, timestamp: this.like.timer.getTime() };
|
|
126
|
-
|
|
127
|
-
this.like.handleEvent(event);
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
this.like.callOwnHandlers(event);
|
|
131
|
-
}
|
|
87
|
+
likeDispatch(this.like, event);
|
|
132
88
|
}
|
|
133
89
|
/**
|
|
134
90
|
* Start the game loop.
|
|
@@ -158,7 +114,26 @@ export class Engine {
|
|
|
158
114
|
* Clean up all resources and stop the engine.
|
|
159
115
|
*/
|
|
160
116
|
dispose() {
|
|
117
|
+
this.dispatch('quit', []);
|
|
161
118
|
this.isRunning = false;
|
|
162
119
|
this.abort.abort();
|
|
163
120
|
}
|
|
164
121
|
}
|
|
122
|
+
export function likeDispatch(obj, event) {
|
|
123
|
+
if (obj.handleEvent) {
|
|
124
|
+
obj.handleEvent(event);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
callOwnHandlers(obj, event);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Call event handlers from an event. For example, an event with `.type = update, .args = [dt]`
|
|
132
|
+
* translates to calling `obj.draw(dt)`.
|
|
133
|
+
*
|
|
134
|
+
* Typically used at the end of a custom {@link LikeHandlers.handleEvent | handleEvent}.
|
|
135
|
+
*/
|
|
136
|
+
export function callOwnHandlers(obj, event) {
|
|
137
|
+
if (event.type in obj)
|
|
138
|
+
obj[event.type](...event.args);
|
|
139
|
+
}
|
package/dist/events.d.ts
CHANGED
|
@@ -2,78 +2,54 @@
|
|
|
2
2
|
* @module events
|
|
3
3
|
* @description All events that flow through the engine.
|
|
4
4
|
*/
|
|
5
|
+
import type { LikeButton } from './input/';
|
|
6
|
+
import type { MouseButton } from './input/mouse';
|
|
5
7
|
import type { Vector2 } from './math/vector2';
|
|
6
|
-
|
|
7
|
-
import { MouseButton } from './input/mouse';
|
|
8
|
-
/** @private */
|
|
9
|
-
export type LikeCanvasEventMap = HTMLElementEventMap & {
|
|
10
|
-
'like:mousemoved': CustomEvent<{
|
|
11
|
-
pos: Vector2;
|
|
12
|
-
delta: Vector2;
|
|
13
|
-
}>;
|
|
14
|
-
'like:resizeCanvas': CustomEvent<{
|
|
15
|
-
size: Vector2;
|
|
16
|
-
}>;
|
|
17
|
-
'like:preDraw': CustomEvent<{}>;
|
|
18
|
-
'like:postDraw': CustomEvent<{}>;
|
|
19
|
-
'like:update': CustomEvent<{
|
|
20
|
-
dt: number;
|
|
21
|
-
}>;
|
|
22
|
-
};
|
|
23
|
-
/** @private Custom canvas type that uses our event map as the single source of truth */
|
|
24
|
-
export interface LikeCanvasElement extends HTMLCanvasElement {
|
|
25
|
-
addEventListener<K extends keyof LikeCanvasEventMap>(type: K, listener: (this: LikeCanvasElement, ev: LikeCanvasEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* It's a list of every possible event in like2d!
|
|
29
|
-
*
|
|
30
|
-
* Not just that, but these events translate directly into `like` callbacks.
|
|
31
|
-
*
|
|
32
|
-
* For example: `keypressed: [scancode: string, keycode: string]` translates to
|
|
33
|
-
* setting `like.keypressed = (scancode, keycode) => { ... }`!
|
|
34
|
-
*
|
|
35
|
-
*/
|
|
36
|
-
export type EventMap = {
|
|
8
|
+
export type LikeEventHandlers = {
|
|
37
9
|
/** Game initialization. Called once before the first frame. */
|
|
38
|
-
load:
|
|
10
|
+
load: () => void;
|
|
11
|
+
/**
|
|
12
|
+
* Game deinit. Called when like is disposed.
|
|
13
|
+
*
|
|
14
|
+
* Use case: you're using native event handlers or global resource
|
|
15
|
+
* allocations that need to be cleared out to avoid memory leaks,
|
|
16
|
+
* regardless of what called like.dispose().
|
|
17
|
+
*/
|
|
18
|
+
quit: () => void;
|
|
39
19
|
/** Frame update. dt is delta time in seconds (time since last frame). */
|
|
40
|
-
update:
|
|
20
|
+
update: (dt: number) => void;
|
|
41
21
|
/** Render frame. Clear the screen and draw your game here. */
|
|
42
|
-
draw:
|
|
22
|
+
draw: () => void;
|
|
43
23
|
/** Canvas was resized. Used mostly in native mode, though setMode may send it too. */
|
|
44
|
-
resize:
|
|
24
|
+
resize: (size: Vector2) => void;
|
|
45
25
|
/** Physical key pressed. scancode is the physical key, keycode is the character. */
|
|
46
|
-
keypressed:
|
|
26
|
+
keypressed: (scancode: string, keycode: string) => void;
|
|
47
27
|
/** Physical key released. */
|
|
48
|
-
keyreleased:
|
|
28
|
+
keyreleased: (scancode: string, keycode: string) => void;
|
|
49
29
|
/** Canvas or tab gained focus. Game may resume audio/updates. */
|
|
50
|
-
focus:
|
|
30
|
+
focus: (source: 'canvas' | 'tab') => void;
|
|
51
31
|
/** Canvas or tab lost focus. Game may pause audio/updates. */
|
|
52
|
-
blur:
|
|
32
|
+
blur: (source: 'canvas' | 'tab') => void;
|
|
53
33
|
/** Mouse moved event. `pos` is absolute, `delta` is relative. */
|
|
54
|
-
mousemoved:
|
|
34
|
+
mousemoved: (pos: Vector2, delta: Vector2) => void;
|
|
55
35
|
/** Mouse button pressed. pos in canvas pixels. Button: 1=left, 2=middle, 3=right. */
|
|
56
|
-
mousepressed:
|
|
36
|
+
mousepressed: (pos: Vector2, button: MouseButton) => void;
|
|
57
37
|
/** Mouse button released. */
|
|
58
|
-
mousereleased:
|
|
38
|
+
mousereleased: (pos: Vector2, button: MouseButton) => void;
|
|
59
39
|
/** Gamepad button pressed. `source` is controller index, `name` is derived from a mapping on the raw `num` */
|
|
60
|
-
gamepadpressed:
|
|
40
|
+
gamepadpressed: (source: number, name: LikeButton, num: number) => void;
|
|
61
41
|
/** Gamepad button released. `source` is controller index, `name` is derived from a mapping on the raw `num` */
|
|
62
|
-
gamepadreleased:
|
|
63
|
-
/**
|
|
64
|
-
|
|
65
|
-
*/
|
|
66
|
-
gamepadconnected: [index: number];
|
|
42
|
+
gamepadreleased: (source: number, name: LikeButton, num: number) => void;
|
|
43
|
+
/** Fires when a gamepad is connected. */
|
|
44
|
+
gamepadconnected: (index: number) => void;
|
|
67
45
|
/** Fires when a gamepad is disconnected. */
|
|
68
|
-
gamepaddisconnected:
|
|
46
|
+
gamepaddisconnected: (index: number) => void;
|
|
69
47
|
/** Mapped action triggered. See {@link input.Input} for action mapping. */
|
|
70
|
-
actionpressed:
|
|
48
|
+
actionpressed: (action: string) => void;
|
|
71
49
|
/** Mapped action released. */
|
|
72
|
-
actionreleased:
|
|
50
|
+
actionreleased: (action: string) => void;
|
|
73
51
|
};
|
|
74
52
|
/** @private */
|
|
75
|
-
export type EventType = keyof EventMap;
|
|
76
|
-
/** @private */
|
|
77
53
|
export type LikeMouseEvent = 'mousemoved' | 'mousepressed' | 'mousereleased';
|
|
78
54
|
/** @private */
|
|
79
55
|
export type LikeKeyboardEvent = 'keypressed' | 'keyreleased';
|
|
@@ -85,16 +61,42 @@ export type LikeActionEvent = 'actionpressed' | 'actionreleased';
|
|
|
85
61
|
* @private
|
|
86
62
|
* Generic dispatcher - each module defines its own event subset
|
|
87
63
|
*/
|
|
88
|
-
export type Dispatcher<
|
|
64
|
+
export type Dispatcher<K extends keyof LikeEventHandlers> = (type: K, args: Parameters<LikeEventHandlers[K]>) => void;
|
|
89
65
|
/**
|
|
90
|
-
* @
|
|
91
|
-
*
|
|
66
|
+
* This is what gets passed into {@link LikeHandlers.handleEvent} functions, which are
|
|
67
|
+
* used to filter event streams.
|
|
68
|
+
*
|
|
69
|
+
* Example:
|
|
70
|
+
* ```ts
|
|
71
|
+
* { type: 'mousemoved', args: [ [100, 250], [-5, -5] ], timestamp: 2.56 }
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* {@link LikeHandlers} has the full list.
|
|
92
75
|
*/
|
|
93
76
|
export type LikeEvent = {
|
|
94
|
-
[K in
|
|
77
|
+
[K in keyof LikeEventHandlers]: {
|
|
95
78
|
type: K;
|
|
96
|
-
args:
|
|
79
|
+
args: Parameters<LikeEventHandlers[K]>;
|
|
97
80
|
timestamp: number;
|
|
98
81
|
};
|
|
99
|
-
}[
|
|
82
|
+
}[keyof LikeEventHandlers];
|
|
83
|
+
/** @private */
|
|
84
|
+
export type LikeCanvasEventMap = HTMLElementEventMap & {
|
|
85
|
+
'like:mousemoved': CustomEvent<{
|
|
86
|
+
pos: Vector2;
|
|
87
|
+
delta: Vector2;
|
|
88
|
+
}>;
|
|
89
|
+
'like:resizeCanvas': CustomEvent<{
|
|
90
|
+
size: Vector2;
|
|
91
|
+
}>;
|
|
92
|
+
'like:preDraw': CustomEvent<{}>;
|
|
93
|
+
'like:postDraw': CustomEvent<{}>;
|
|
94
|
+
'like:update': CustomEvent<{
|
|
95
|
+
dt: number;
|
|
96
|
+
}>;
|
|
97
|
+
};
|
|
98
|
+
/** @private Custom canvas type that uses our event map as the single source of truth */
|
|
99
|
+
export interface LikeCanvasElement extends HTMLCanvasElement {
|
|
100
|
+
addEventListener<K extends keyof LikeCanvasEventMap>(type: K, listener: (this: LikeCanvasElement, ev: LikeCanvasEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
|
|
101
|
+
}
|
|
100
102
|
//# sourceMappingURL=events.d.ts.map
|
|
@@ -35,7 +35,8 @@ export type DrawMode = "fill" | "line";
|
|
|
35
35
|
* - Alpha defaults to 1 if omitted
|
|
36
36
|
* - CSS color strings also accepted: `"red"`, `"#ff0000"`, `"rgb(255,0,0)"`
|
|
37
37
|
*/
|
|
38
|
-
export type
|
|
38
|
+
export type ColorNum = [number, number, number, number?];
|
|
39
|
+
export type Color = ColorNum | string;
|
|
39
40
|
export type TransformProps = {
|
|
40
41
|
angle?: number;
|
|
41
42
|
scale?: number | Vector2;
|
package/dist/graphics/index.d.ts
CHANGED
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
export type { Graphics } from "./graphics";
|
|
6
6
|
export type { Canvas } from "./canvas";
|
|
7
7
|
export type { ImageHandle } from './image';
|
|
8
|
-
export type { Color, DrawMode, ShapeProps, DrawProps, PrintProps, TransformProps, } from "./graphics";
|
|
8
|
+
export type { Color, ColorNum, DrawMode, ShapeProps, DrawProps, PrintProps, TransformProps, } from "./graphics";
|
|
9
9
|
export type { CanvasSize, CanvasModeOptions, } from "./canvas";
|
|
10
10
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -3,10 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
*/
|
|
5
5
|
import type { Like } from './like';
|
|
6
|
-
export type { Like, LikeBase, TopLevelEventHandler
|
|
7
|
-
export type { LikeEvent,
|
|
8
|
-
export
|
|
9
|
-
export type { EngineProps } from './engine';
|
|
6
|
+
export type { Like, LikeHandlers, LikeBase, TopLevelEventHandler } from './like';
|
|
7
|
+
export type { LikeEvent, LikeCanvasElement } from './events';
|
|
8
|
+
export { callOwnHandlers, likeDispatch } from './engine';
|
|
10
9
|
/**
|
|
11
10
|
* Create a new Like2D game instance attached to a DOM container.
|
|
12
11
|
*
|
package/dist/index.js
CHANGED
package/dist/input/gamepad.d.ts
CHANGED
|
@@ -12,9 +12,9 @@ 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.
|
|
15
|
+
* Perhaps trigger it on {@link index.LikeHandlers.gamepadconnected | gamepadconnected} events.
|
|
16
16
|
*
|
|
17
|
-
* If you don't want to make your own, take a look at {@link prefab
|
|
17
|
+
* If you don't want to make your own, take a look at {@link scene/prefab/mapGamepad}
|
|
18
18
|
*
|
|
19
19
|
* ## When to use gamepad remapping
|
|
20
20
|
*
|
package/dist/input/gamepad.js
CHANGED
|
@@ -7,9 +7,9 @@ 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.
|
|
10
|
+
* Perhaps trigger it on {@link index.LikeHandlers.gamepadconnected | gamepadconnected} events.
|
|
11
11
|
*
|
|
12
|
-
* If you don't want to make your own, take a look at {@link prefab
|
|
12
|
+
* If you don't want to make your own, take a look at {@link scene/prefab/mapGamepad}
|
|
13
13
|
*
|
|
14
14
|
* ## When to use gamepad remapping
|
|
15
15
|
*
|
package/dist/input/mouse.d.ts
CHANGED
|
@@ -87,7 +87,7 @@ export declare class Mouse {
|
|
|
87
87
|
* In locked mode, the cursor cannot escape the canvas.
|
|
88
88
|
* It also becomes invisible.
|
|
89
89
|
* However, it can move infinitely, sensitivity can be controlled,
|
|
90
|
-
* and the emulated cursor (in `pos` of {@link index.
|
|
90
|
+
* and the emulated cursor (in `pos` of {@link index.LikeHandlers.mousemoved}) can be freely repositioned.
|
|
91
91
|
*
|
|
92
92
|
* ```ts
|
|
93
93
|
* {
|
|
@@ -99,7 +99,7 @@ export declare class Mouse {
|
|
|
99
99
|
* reset mode to default.
|
|
100
100
|
*
|
|
101
101
|
* ### Note on `pos` vs `delta`
|
|
102
|
-
* Event {@link index.
|
|
102
|
+
* Event {@link index.LikeHandlers.mousemoved} passes both `pos` and `delta` args.
|
|
103
103
|
*
|
|
104
104
|
* Though the emulated cursor in locked mode
|
|
105
105
|
* (locked mode doesn't natively track absolute position)
|
package/dist/input/mouse.js
CHANGED
|
@@ -189,7 +189,7 @@ export class Mouse {
|
|
|
189
189
|
* In locked mode, the cursor cannot escape the canvas.
|
|
190
190
|
* It also becomes invisible.
|
|
191
191
|
* However, it can move infinitely, sensitivity can be controlled,
|
|
192
|
-
* and the emulated cursor (in `pos` of {@link index.
|
|
192
|
+
* and the emulated cursor (in `pos` of {@link index.LikeHandlers.mousemoved}) can be freely repositioned.
|
|
193
193
|
*
|
|
194
194
|
* ```ts
|
|
195
195
|
* {
|
|
@@ -201,7 +201,7 @@ export class Mouse {
|
|
|
201
201
|
* reset mode to default.
|
|
202
202
|
*
|
|
203
203
|
* ### Note on `pos` vs `delta`
|
|
204
|
-
* Event {@link index.
|
|
204
|
+
* Event {@link index.LikeHandlers.mousemoved} passes both `pos` and `delta` args.
|
|
205
205
|
*
|
|
206
206
|
* Though the emulated cursor in locked mode
|
|
207
207
|
* (locked mode doesn't natively track absolute position)
|
package/dist/like.d.ts
CHANGED
|
@@ -1,23 +1,45 @@
|
|
|
1
|
-
import type { Audio } from './audio/
|
|
2
|
-
import type { Timer } from './timer/
|
|
3
|
-
import type { Input } from './input/
|
|
1
|
+
import type { Audio } from './audio/';
|
|
2
|
+
import type { Timer } from './timer/';
|
|
3
|
+
import type { Input } from './input/';
|
|
4
4
|
import type { Keyboard } from './input/keyboard';
|
|
5
5
|
import type { Mouse } from './input/mouse';
|
|
6
6
|
import type { Gamepad } from './input/gamepad';
|
|
7
7
|
import type { Canvas } from './graphics/canvas';
|
|
8
|
-
import type { Graphics } from './graphics/
|
|
9
|
-
import {
|
|
10
|
-
import { Scene } from './scene';
|
|
8
|
+
import type { Graphics } from './graphics/';
|
|
9
|
+
import { LikeEvent, LikeEventHandlers } from './events';
|
|
11
10
|
/** @private */
|
|
12
11
|
export type TopLevelEventHandler = (event: LikeEvent) => void;
|
|
13
|
-
/**
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Every possible event handler callback is in this interface.
|
|
14
|
+
*
|
|
15
|
+
* The engine will call these functions when the corresponding
|
|
16
|
+
* events fire unless {@link handleEvent} is customized, for example
|
|
17
|
+
* when the scene system is in use.
|
|
18
|
+
*
|
|
19
|
+
* @interface
|
|
20
|
+
*/
|
|
21
|
+
export type LikeHandlers = Partial<LikeEventHandlers> & {
|
|
22
|
+
/**
|
|
23
|
+
* LIKE's runtime is concentrated into handleEvent.
|
|
24
|
+
*
|
|
25
|
+
* This function recieves all events.
|
|
26
|
+
* {@link callOwnHandlers} is the default behavior.
|
|
27
|
+
*
|
|
28
|
+
* Otherwise, a custom handler will totally override
|
|
29
|
+
* event handler callbacks like `like.draw`,
|
|
30
|
+
* replacing it with a system of your choice.
|
|
31
|
+
*
|
|
32
|
+
* For example, the scene architecture is built around
|
|
33
|
+
* setting this function. Setting to a custom
|
|
34
|
+
* function will disable the scene system.
|
|
35
|
+
*
|
|
36
|
+
* Setting `handleEvent` to `undefined` will revert
|
|
37
|
+
* to default behavior.
|
|
38
|
+
*/
|
|
39
|
+
handleEvent?: TopLevelEventHandler;
|
|
18
40
|
};
|
|
19
41
|
/**
|
|
20
|
-
* The main modules and builtins of `like
|
|
42
|
+
* The main modules and builtins of `like`.
|
|
21
43
|
* @interface
|
|
22
44
|
*/
|
|
23
45
|
export type LikeBase = {
|
|
@@ -37,9 +59,9 @@ export type LikeBase = {
|
|
|
37
59
|
readonly canvas: Canvas;
|
|
38
60
|
/** Graphics module: LOVE-style rendering, plus a pseudo-synchronous way to load images. */
|
|
39
61
|
readonly gfx: Graphics;
|
|
40
|
-
/**
|
|
62
|
+
/** @private Use {@link canvas} instead. */
|
|
41
63
|
window?: never;
|
|
42
|
-
/**
|
|
64
|
+
/** @private Use {@link gfx} instead. */
|
|
43
65
|
graphics?: never;
|
|
44
66
|
/**
|
|
45
67
|
* Start the game loop. Call this only once.
|
|
@@ -51,55 +73,6 @@ export type LikeBase = {
|
|
|
51
73
|
* running, and probably break if you try to use it.
|
|
52
74
|
*/
|
|
53
75
|
dispose(): void;
|
|
54
|
-
/**
|
|
55
|
-
* Push a scene to the scene stack.
|
|
56
|
-
*
|
|
57
|
-
* If the engine is running, this is the new running scene replacing the old one
|
|
58
|
-
* which can, in some cases, call out to the lower scene.
|
|
59
|
-
*
|
|
60
|
-
* @param overlay Set to true, and the current scene (before pushing) will stay loaded. Otherwise not.
|
|
61
|
-
*/
|
|
62
|
-
pushScene(scene: Scene, overlay: boolean): void;
|
|
63
|
-
/**
|
|
64
|
-
* Pop the current scene off the stack.
|
|
65
|
-
*
|
|
66
|
-
* To clear the stack, just run:
|
|
67
|
-
* ```ts
|
|
68
|
-
* while (like.popScene());
|
|
69
|
-
* ```
|
|
70
|
-
*/
|
|
71
|
-
popScene(): Scene | undefined;
|
|
72
|
-
/**
|
|
73
|
-
* Set the current scene at the top of the scene stack.
|
|
74
|
-
* If the stack is empty, push it onto the stack.
|
|
75
|
-
*
|
|
76
|
-
* Equivalent to `popScene` + `pushScene`.
|
|
77
|
-
*
|
|
78
|
-
* Use {@link index.Like | popScene} to clear away the current scene,
|
|
79
|
-
* and to possibly revert to callback mode.
|
|
80
|
-
*/
|
|
81
|
-
setScene(scene: Scene): void;
|
|
82
|
-
/**
|
|
83
|
-
* Get the current scene, or a specific index.
|
|
84
|
-
*
|
|
85
|
-
* Uses `Array.at` under the hood, so -1 is the
|
|
86
|
-
* top scene, -2 is the parent scene, etc.
|
|
87
|
-
*/
|
|
88
|
-
getScene(index?: number): Scene | undefined;
|
|
89
|
-
/**
|
|
90
|
-
* LIKE's runtime is built around calling handleEvent.
|
|
91
|
-
*
|
|
92
|
-
* This function recieves all events. If set to undefined,
|
|
93
|
-
* {@link index.Like | Like.callOwnHandlers} is the default behavior.
|
|
94
|
-
*
|
|
95
|
-
* Otherwise, you can really customize LIKE by setting this
|
|
96
|
-
* to a custom handler.
|
|
97
|
-
*
|
|
98
|
-
* For example, the scene architecture is built around
|
|
99
|
-
* setting this function. Setting it to a custom
|
|
100
|
-
* function will disable the scene system.
|
|
101
|
-
*/
|
|
102
|
-
handleEvent?: TopLevelEventHandler;
|
|
103
76
|
/**
|
|
104
77
|
* Used as the default `like.handleEvent`, simply dispatches
|
|
105
78
|
* an event into LIKE callbacks.
|
|
@@ -111,8 +84,6 @@ export type LikeBase = {
|
|
|
111
84
|
* The main Like instance.
|
|
112
85
|
* Use this object much how you would the `love` object in Love2D.
|
|
113
86
|
* This is the interface returned by {@link createLike}.
|
|
114
|
-
*
|
|
115
|
-
* Check out all the {@link EventMap | callbacks}.
|
|
116
87
|
*/
|
|
117
|
-
export type Like =
|
|
88
|
+
export type Like = LikeHandlers & LikeBase;
|
|
118
89
|
//# sourceMappingURL=like.d.ts.map
|