like2d 2.8.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.
- package/README.md +44 -41
- package/dist/__benchmarks__/vector2.bench.d.ts +2 -0
- package/dist/__benchmarks__/vector2.bench.d.ts.map +1 -0
- package/dist/__benchmarks__/vector2.bench.js +74 -0
- package/dist/{core → audio}/audio.d.ts +21 -9
- package/dist/audio/audio.d.ts.map +1 -0
- package/dist/{core → audio}/audio.js +15 -4
- package/dist/audio/index.d.ts +2 -0
- package/dist/audio/index.d.ts.map +1 -0
- package/dist/engine.d.ts +30 -15
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +79 -160
- package/dist/events.d.ts +86 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +5 -0
- package/dist/gamecontrollerdb.txt +9 -8
- package/dist/graphics/canvas.d.ts +65 -0
- package/dist/graphics/canvas.d.ts.map +1 -0
- package/dist/graphics/canvas.js +224 -0
- package/dist/graphics/drawing.d.ts +203 -0
- package/dist/graphics/drawing.d.ts.map +1 -0
- package/dist/graphics/drawing.js +388 -0
- package/dist/graphics/index.d.ts +19 -0
- package/dist/graphics/index.d.ts.map +1 -0
- package/dist/graphics/index.js +13 -0
- package/dist/index.d.ts +18 -24
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -15
- package/dist/input/gamepad-mapping.d.ts +134 -0
- package/dist/input/gamepad-mapping.d.ts.map +1 -0
- package/dist/input/gamepad-mapping.js +146 -0
- package/dist/input/gamepad.d.ts +74 -0
- package/dist/input/gamepad.d.ts.map +1 -0
- package/dist/input/gamepad.js +288 -0
- package/dist/input/index.d.ts +6 -0
- package/dist/input/index.d.ts.map +1 -0
- package/dist/input/index.js +1 -0
- package/dist/input/input.d.ts +76 -0
- package/dist/input/input.d.ts.map +1 -0
- package/dist/input/input.js +164 -0
- package/dist/input/keyboard.d.ts +15 -0
- package/dist/input/keyboard.d.ts.map +1 -0
- package/dist/input/keyboard.js +53 -0
- package/dist/input/mouse.d.ts +108 -0
- package/dist/input/mouse.d.ts.map +1 -0
- package/dist/input/mouse.js +241 -0
- package/dist/like.d.ts +80 -0
- package/dist/like.d.ts.map +1 -0
- package/dist/like.js +5 -0
- package/dist/math/index.d.ts +18 -0
- package/dist/math/index.d.ts.map +1 -0
- package/dist/math/index.js +17 -0
- package/dist/math/rect.d.ts +68 -0
- package/dist/math/rect.d.ts.map +1 -0
- package/dist/{core → math}/rect.js +48 -66
- package/dist/math/vector2.d.ts +133 -0
- package/dist/math/vector2.d.ts.map +1 -0
- package/dist/math/vector2.js +111 -0
- package/dist/prefab-scenes/index.d.ts +8 -0
- package/dist/prefab-scenes/index.d.ts.map +1 -0
- package/dist/prefab-scenes/index.js +7 -0
- package/dist/prefab-scenes/mapGamepad.d.ts +28 -0
- package/dist/prefab-scenes/mapGamepad.d.ts.map +1 -0
- package/dist/prefab-scenes/mapGamepad.js +181 -0
- package/dist/prefab-scenes/startScreen.d.ts +59 -0
- package/dist/prefab-scenes/startScreen.d.ts.map +1 -0
- package/dist/{scenes/startup.js → prefab-scenes/startScreen.js} +48 -8
- package/dist/scene.d.ts +104 -6
- package/dist/scene.d.ts.map +1 -1
- package/dist/scene.js +28 -1
- package/dist/timer/index.d.ts +2 -0
- package/dist/timer/index.d.ts.map +1 -0
- package/dist/timer/timer.d.ts +32 -0
- package/dist/timer/timer.d.ts.map +1 -0
- package/dist/{core → timer}/timer.js +19 -14
- package/package.json +27 -2
- package/dist/core/audio.d.ts.map +0 -1
- package/dist/core/canvas-config.d.ts +0 -22
- package/dist/core/canvas-config.d.ts.map +0 -1
- package/dist/core/canvas-config.js +0 -14
- package/dist/core/canvas-manager.d.ts +0 -32
- package/dist/core/canvas-manager.d.ts.map +0 -1
- package/dist/core/canvas-manager.js +0 -179
- package/dist/core/events.d.ts +0 -31
- package/dist/core/events.d.ts.map +0 -1
- package/dist/core/gamepad-buttons.d.ts +0 -23
- package/dist/core/gamepad-buttons.d.ts.map +0 -1
- package/dist/core/gamepad-buttons.js +0 -36
- package/dist/core/gamepad-mapping.d.ts +0 -19
- package/dist/core/gamepad-mapping.d.ts.map +0 -1
- package/dist/core/gamepad-mapping.js +0 -223
- package/dist/core/gamepad.d.ts +0 -61
- package/dist/core/gamepad.d.ts.map +0 -1
- package/dist/core/gamepad.js +0 -237
- package/dist/core/graphics.d.ts +0 -93
- package/dist/core/graphics.d.ts.map +0 -1
- package/dist/core/graphics.js +0 -289
- package/dist/core/input-state.d.ts +0 -14
- package/dist/core/input-state.d.ts.map +0 -1
- package/dist/core/input-state.js +0 -50
- package/dist/core/input.d.ts +0 -33
- package/dist/core/input.d.ts.map +0 -1
- package/dist/core/input.js +0 -117
- package/dist/core/keyboard.d.ts +0 -16
- package/dist/core/keyboard.d.ts.map +0 -1
- package/dist/core/keyboard.js +0 -83
- package/dist/core/like.d.ts +0 -59
- package/dist/core/like.d.ts.map +0 -1
- package/dist/core/mouse.d.ts +0 -45
- package/dist/core/mouse.d.ts.map +0 -1
- package/dist/core/mouse.js +0 -182
- package/dist/core/rect.d.ts +0 -26
- package/dist/core/rect.d.ts.map +0 -1
- package/dist/core/timer.d.ts +0 -18
- package/dist/core/timer.d.ts.map +0 -1
- package/dist/core/vector2.d.ts +0 -26
- package/dist/core/vector2.d.ts.map +0 -1
- package/dist/core/vector2.js +0 -105
- package/dist/scenes/startup.d.ts +0 -18
- package/dist/scenes/startup.d.ts.map +0 -1
- /package/dist/{core/events.js → audio/index.js} +0 -0
- /package/dist/{core/like.js → timer/index.js} +0 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# LÏKE2D
|
|
2
2
|
|
|
3
|
-
<svg
|
|
3
|
+
<svg version="1.1" viewBox="0 0 300 105" xmlns="http://www.w3.org/2000/svg">
|
|
4
4
|
<rect x="10" y="11.23" width="280" height="83.544" fill="#e48080" stroke="#000" stroke-linejoin="round" stroke-width="2"/>
|
|
5
5
|
<g fill="none" stroke="#000" stroke-linejoin="round">
|
|
6
6
|
<rect x="97.484" y="11.23" width="52.516" height="46.237"/>
|
|
@@ -31,60 +31,70 @@
|
|
|
31
31
|
</g>
|
|
32
32
|
</svg>
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
Lightweight web game framework inspired by [LÖVE](https://love2d.org/).
|
|
35
35
|
|
|
36
|
-
##
|
|
37
|
-
|
|
38
|
-
LIKE is a **curated toolkit** around browser APIs.
|
|
39
|
-
|
|
40
|
-
It does less, because it **does the right thing**. And when that's not the right thing for you, we hand you the wrench.
|
|
36
|
+
## <div style="color:red">During v2.x.x, LIKE's API will change.</div>
|
|
41
37
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
- **Fire-and-forget Assets:** Async asset loading directly on realtime web games is annoying. We let you pretend it's instant and synchronous.
|
|
45
|
-
|
|
46
|
-
- **Physical Joypad:** Our gamepad module auto-maps to physical buttons like "bottom" and "top". Because A isn't always in the same spot.
|
|
38
|
+
## What it is
|
|
47
39
|
|
|
48
|
-
|
|
40
|
+
LIKE is a cozy way to make 2d games for browser.
|
|
49
41
|
|
|
50
|
-
|
|
42
|
+
## What LIKE does
|
|
51
43
|
|
|
52
|
-
-
|
|
44
|
+
- **🔥 Fire-and-forget Assets:** Graphics and audio that pretend to be synchronous.
|
|
45
|
+
- **🎯 DWIM graphics:** Turns repetitive draw calls into one while removing state bleed for properties like `lineCap`.
|
|
46
|
+
- **↔️ Two Canvas Modes:**
|
|
47
|
+
- 🖊️ Audio-resize the canvas; sharp at any resolution.
|
|
48
|
+
- 👾 For retro-style developers, pixels stay crisp but smooth via prescaling.
|
|
49
|
+
- **⭕ Easier Geometry:** `Vector2` and `Rect` are just number tuples (arrays), but a pure-functional library makes them easy to work with and plays nice with `map` and `reduce`.
|
|
50
|
+
- **🚲 Easy Input:** Keyboard, Mouse, and Gamepad all are given both event-based and query-based options. Choose what fits your architecture. Most gamepads get auto-mapped perfectly, are easy to remap, and LIKE can load and save user mappings automatically.
|
|
51
|
+
- **👟Consistent APIs:** Colors 0-1, not 0-255. Seconds, not milliseconds. Physical gamepad buttons, not "A" or "B".
|
|
52
|
+
- **👉 Actions System:** An input layer maps inputs to actions, which fire usable events.
|
|
53
|
+
- **🌎 Global control:** Choose how to handle LIKE events, and manage resources with centralized trackers. LIKE is a great foundation for your own engine.
|
|
54
|
+
- **🐦 Light and Elegant:** Zero dependencies and less than 5000 lines of code -- focused entirely on what matters.
|
|
53
55
|
|
|
54
56
|
## Installation
|
|
55
57
|
|
|
58
|
+
Most package managers will work.
|
|
59
|
+
|
|
56
60
|
```bash
|
|
57
61
|
npm install like2d
|
|
58
|
-
# or
|
|
59
|
-
|
|
62
|
+
# or ...
|
|
63
|
+
deno add jsr:@like2d/like
|
|
64
|
+
# or...
|
|
60
65
|
```
|
|
61
66
|
|
|
62
67
|
## Quick Start
|
|
63
68
|
|
|
64
|
-
|
|
69
|
+
To try Like2D quickly, use this starter with
|
|
70
|
+
hot reloading and a basic webpage.
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
npx degit 44100hertz/Like2D/examples/starter my-game
|
|
74
|
+
```
|
|
65
75
|
|
|
66
76
|
## Usage Example
|
|
67
77
|
|
|
68
78
|
```typescript
|
|
69
|
-
import { createLike } from
|
|
79
|
+
import { createLike } from "like2d";
|
|
70
80
|
|
|
71
81
|
const like = createLike(document.body);
|
|
72
82
|
|
|
73
83
|
like.load = () => {
|
|
74
|
-
like.setMode(
|
|
75
|
-
like.input.
|
|
84
|
+
like.setMode([800, 600]);
|
|
85
|
+
like.input.setAction("jump", ["Space", "BBottom"]);
|
|
76
86
|
};
|
|
77
87
|
|
|
78
88
|
like.update = (dt) => {
|
|
79
|
-
if (like.input.justPressed(
|
|
80
|
-
console.log(
|
|
89
|
+
if (like.input.justPressed("jump")) {
|
|
90
|
+
console.log("Jump!");
|
|
81
91
|
}
|
|
82
92
|
};
|
|
83
93
|
|
|
84
94
|
like.draw = () => {
|
|
85
95
|
like.gfx.clear([0.1, 0.1, 0.1, 1]);
|
|
86
|
-
like.gfx.circle(
|
|
87
|
-
like.gfx.print(
|
|
96
|
+
like.gfx.circle("fill", "dodgerblue", [400, 300], 50);
|
|
97
|
+
like.gfx.print("white", "Hello Like2D!", [20, 20]);
|
|
88
98
|
};
|
|
89
99
|
|
|
90
100
|
await like.start();
|
|
@@ -93,27 +103,20 @@ await like.start();
|
|
|
93
103
|
## For Love2D Developers
|
|
94
104
|
|
|
95
105
|
LIKE's API is not the same as LOVE, but similar in spirit. Notable differences:
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
106
|
+
|
|
107
|
+
- Draw your graphics in one call, that's all. No setup or state bleed.
|
|
108
|
+
- You manage your own instance of like in a big friendly object. This allows us to have multiple games on one page.
|
|
109
|
+
- We use Vector2 and Rect tuples (like `[x, y]`) instead of loose coordinates.
|
|
110
|
+
- Theres an actions system -- `input.setAction` / `actionpressed` and `actionreleased` callbacks.
|
|
111
|
+
- Some things are missing either due to browser limitations or smaller scope.
|
|
102
112
|
|
|
103
113
|
## Feedback welcome
|
|
104
114
|
|
|
105
|
-
|
|
106
|
-
1. Make sure you're on the latest release.
|
|
107
|
-
2. If the issue exists already, just comment on that one.
|
|
108
|
-
3. See if it happens in other web browsers.
|
|
115
|
+
[LIKE is on GitHub.](https://github.com/44100hertz/Like2D)
|
|
109
116
|
|
|
110
|
-
|
|
111
|
-
1. ask: Would it make sense as a core feature, or should it be an external library?
|
|
112
|
-
2. See if the feature exists already.
|
|
113
|
-
3. Think about the demand for it overall. Make your case why game developers want it.
|
|
114
|
-
4. Consider just making a PR yourself, or sending a prompt/spec that an AI can hack on.
|
|
117
|
+
[Check out the docs for our long-term vision.](https://github.com/44100hertz/Like2D/tree/master/docs)
|
|
115
118
|
|
|
116
|
-
[
|
|
119
|
+
[Feature requests welcome. PRs discouraged for now.](https://github.com/44100hertz/Like2D/issues/)
|
|
117
120
|
|
|
118
121
|
## License
|
|
119
122
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vector2.bench.d.ts","sourceRoot":"","sources":["../../src/__benchmarks__/vector2.bench.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { bench, describe } from 'vitest';
|
|
2
|
+
import { Vec2 } from '../math/vector2';
|
|
3
|
+
const VEC2_COUNT = 10000;
|
|
4
|
+
function makeVec2s(count) {
|
|
5
|
+
const vec2s = [];
|
|
6
|
+
for (let i = 0; i < count; i++) {
|
|
7
|
+
vec2s.push([Math.random() * 1000, Math.random() * 1000]);
|
|
8
|
+
}
|
|
9
|
+
return vec2s;
|
|
10
|
+
}
|
|
11
|
+
describe('Vector2', () => {
|
|
12
|
+
const a = makeVec2s(VEC2_COUNT);
|
|
13
|
+
const b = makeVec2s(VEC2_COUNT);
|
|
14
|
+
describe('binary operations', () => {
|
|
15
|
+
bench('add', () => {
|
|
16
|
+
let sum = 0;
|
|
17
|
+
for (let i = 0; i < VEC2_COUNT; i++) {
|
|
18
|
+
const result = Vec2.add(a[i], b[i]);
|
|
19
|
+
sum += result[0];
|
|
20
|
+
}
|
|
21
|
+
if (sum === -1)
|
|
22
|
+
console.log(sum);
|
|
23
|
+
});
|
|
24
|
+
bench('sub', () => {
|
|
25
|
+
let sum = 0;
|
|
26
|
+
for (let i = 0; i < VEC2_COUNT; i++) {
|
|
27
|
+
const result = Vec2.sub(a[i], b[i]);
|
|
28
|
+
sum += result[0];
|
|
29
|
+
}
|
|
30
|
+
if (sum === -1)
|
|
31
|
+
console.log(sum);
|
|
32
|
+
});
|
|
33
|
+
bench('mul', () => {
|
|
34
|
+
let sum = 0;
|
|
35
|
+
for (let i = 0; i < VEC2_COUNT; i++) {
|
|
36
|
+
const result = Vec2.mul(a[i], b[i]);
|
|
37
|
+
sum += result[0];
|
|
38
|
+
}
|
|
39
|
+
if (sum === -1)
|
|
40
|
+
console.log(sum);
|
|
41
|
+
});
|
|
42
|
+
bench('div', () => {
|
|
43
|
+
let sum = 0;
|
|
44
|
+
for (let i = 0; i < VEC2_COUNT; i++) {
|
|
45
|
+
const result = Vec2.div(a[i], b[i]);
|
|
46
|
+
sum += result[0];
|
|
47
|
+
}
|
|
48
|
+
if (sum === -1)
|
|
49
|
+
console.log(sum);
|
|
50
|
+
});
|
|
51
|
+
bench('dot', () => {
|
|
52
|
+
let sum = 0;
|
|
53
|
+
for (let i = 0; i < VEC2_COUNT; i++) {
|
|
54
|
+
const result = Vec2.dot(a[i], b[i]);
|
|
55
|
+
sum += result;
|
|
56
|
+
}
|
|
57
|
+
if (sum === -1)
|
|
58
|
+
console.log(sum);
|
|
59
|
+
});
|
|
60
|
+
bench('chained ops (add, sub, mul, div, dot)', () => {
|
|
61
|
+
let sum = 0;
|
|
62
|
+
for (let i = 0; i < VEC2_COUNT; i++) {
|
|
63
|
+
const r1 = Vec2.add(a[i], b[i]);
|
|
64
|
+
const r2 = Vec2.sub(r1, a[i]);
|
|
65
|
+
const r3 = Vec2.mul(r2, 2);
|
|
66
|
+
const r4 = Vec2.div(r3, b[i]);
|
|
67
|
+
const result = Vec2.dot(r4, a[i]);
|
|
68
|
+
sum += result;
|
|
69
|
+
}
|
|
70
|
+
if (sum === -1)
|
|
71
|
+
console.log(sum);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
});
|
|
@@ -5,28 +5,29 @@
|
|
|
5
5
|
*
|
|
6
6
|
* ## Track and give global control to all audio objects
|
|
7
7
|
* Start, stop, or set global volume for every currently playing sound.
|
|
8
|
-
*
|
|
9
8
|
*/
|
|
10
|
-
|
|
9
|
+
/** Pass this into like.audio.newSource as config. */
|
|
10
|
+
export type AudioSourceOptions = {
|
|
11
11
|
volume?: number;
|
|
12
12
|
};
|
|
13
13
|
/**
|
|
14
|
-
* Handle to a loaded audio resource.
|
|
14
|
+
* Handle to a loaded audio resource, which pretends to be synchronous.
|
|
15
15
|
* Use `play()`, `stop()`, `pause()`, `resume()` for playback control.
|
|
16
16
|
* Access the underlying HTMLAudioElement via `source.audio` for looping,
|
|
17
17
|
* pitch, etc. Note: Use `source.setVolume()` instead of setting
|
|
18
18
|
* `source.audio.volume` directly to ensure global volume scaling works correctly.
|
|
19
19
|
*/
|
|
20
|
-
export declare class
|
|
20
|
+
export declare class AudioSource {
|
|
21
21
|
readonly path: string;
|
|
22
22
|
/** Underlying HTMLAudioElement. Modify directly for looping, pitch, etc. Use methods for playback control. Avoid setting volume directly. */
|
|
23
23
|
readonly audio: HTMLAudioElement;
|
|
24
|
-
|
|
24
|
+
/** Avoid setting these directly. */
|
|
25
|
+
readonly options: Required<AudioSourceOptions>;
|
|
25
26
|
/** Resolves when the audio is loaded and ready to play. */
|
|
26
27
|
readonly ready: Promise<void>;
|
|
27
28
|
private loadState;
|
|
28
29
|
private audioRef;
|
|
29
|
-
constructor(path: string, audioRef: Audio, options?:
|
|
30
|
+
constructor(path: string, audioRef: Audio, options?: AudioSourceOptions);
|
|
30
31
|
isReady(): boolean;
|
|
31
32
|
play(): void;
|
|
32
33
|
stop(): void;
|
|
@@ -42,20 +43,31 @@ export declare class Source {
|
|
|
42
43
|
getVolume(): number;
|
|
43
44
|
getDuration(): number;
|
|
44
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* The audio subsystem.
|
|
48
|
+
*
|
|
49
|
+
* Manages a handful of AudioSource objects, for things like global volume,
|
|
50
|
+
* global play/pause, etc..
|
|
51
|
+
*
|
|
52
|
+
* To make a new source, use `like.audio.newSource`.
|
|
53
|
+
*/
|
|
45
54
|
export declare class Audio {
|
|
46
55
|
private sources;
|
|
47
56
|
private globalVolume;
|
|
48
|
-
|
|
57
|
+
/**
|
|
58
|
+
* Get a {@link AudioSource}
|
|
59
|
+
*/
|
|
60
|
+
newSource(path: string, options?: AudioSourceOptions): AudioSource;
|
|
49
61
|
/** Get all audio sources -- note that sources are tracked
|
|
50
62
|
* using weak references, and storing this list can cause
|
|
51
63
|
* a memory leak.
|
|
52
64
|
*/
|
|
53
|
-
|
|
65
|
+
getAllSources(): AudioSource[];
|
|
54
66
|
stopAll(): void;
|
|
55
67
|
pauseAll(): void;
|
|
56
68
|
resumeAll(): void;
|
|
57
69
|
setVolume(volume: number): void;
|
|
58
70
|
getVolume(): number;
|
|
59
|
-
clone(source:
|
|
71
|
+
clone(source: AudioSource): AudioSource;
|
|
60
72
|
}
|
|
61
73
|
//# sourceMappingURL=audio.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audio.d.ts","sourceRoot":"","sources":["../../src/audio/audio.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,qDAAqD;AACrD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAA;AAMD;;;;;;GAMG;AACH,qBAAa,WAAW;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,6IAA6I;IAC7I,QAAQ,CAAC,KAAK,EAAE,gBAAgB,CAAC;IACjC,oCAAoC;IACpC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,kBAAkB,CAAC,CAAC;IAC/C,2DAA2D;IAC3D,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9B,OAAO,CAAC,SAAS,CAAoE;IACrF,OAAO,CAAC,QAAQ,CAAQ;gBAEZ,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,GAAE,kBAAuB;IAmC3E,OAAO,IAAI,OAAO;IAIlB,IAAI,IAAI,IAAI;IAUZ,IAAI,IAAI,IAAI;IAUZ,KAAK,IAAI,IAAI;IAQb,MAAM,IAAI,IAAI;IAYd,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAQ5B,IAAI,IAAI,MAAM;IAKd,SAAS,IAAI,OAAO;IAKpB,QAAQ,IAAI,OAAO;IAKnB,SAAS,IAAI,OAAO;IAKpB,+FAA+F;IAC/F,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAK/B,SAAS,IAAI,MAAM;IAInB,WAAW,IAAI,MAAM;CAItB;AAED;;;;;;;GAOG;AACH,qBAAa,KAAK;IAChB,OAAO,CAAC,OAAO,CAA8B;IAC7C,OAAO,CAAC,YAAY,CAAK;IAEzB;;OAEG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,WAAW;IAMlE;;;QAGI;IACJ,aAAa,IAAI,WAAW,EAAE;IAS9B,OAAO,IAAI,IAAI;IAIf,QAAQ,IAAI,IAAI;IAIhB,SAAS,IAAI,IAAI;IAIjB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAO/B,SAAS,IAAI,MAAM;IAInB,KAAK,CAAC,MAAM,EAAE,WAAW,GAAG,WAAW;CAGxC"}
|
|
@@ -5,16 +5,15 @@
|
|
|
5
5
|
*
|
|
6
6
|
* ## Track and give global control to all audio objects
|
|
7
7
|
* Start, stop, or set global volume for every currently playing sound.
|
|
8
|
-
*
|
|
9
8
|
*/
|
|
10
9
|
/**
|
|
11
|
-
* Handle to a loaded audio resource.
|
|
10
|
+
* Handle to a loaded audio resource, which pretends to be synchronous.
|
|
12
11
|
* Use `play()`, `stop()`, `pause()`, `resume()` for playback control.
|
|
13
12
|
* Access the underlying HTMLAudioElement via `source.audio` for looping,
|
|
14
13
|
* pitch, etc. Note: Use `source.setVolume()` instead of setting
|
|
15
14
|
* `source.audio.volume` directly to ensure global volume scaling works correctly.
|
|
16
15
|
*/
|
|
17
|
-
export class
|
|
16
|
+
export class AudioSource {
|
|
18
17
|
constructor(path, audioRef, options = {}) {
|
|
19
18
|
Object.defineProperty(this, "path", {
|
|
20
19
|
enumerable: true,
|
|
@@ -29,6 +28,7 @@ export class Source {
|
|
|
29
28
|
writable: true,
|
|
30
29
|
value: void 0
|
|
31
30
|
});
|
|
31
|
+
/** Avoid setting these directly. */
|
|
32
32
|
Object.defineProperty(this, "options", {
|
|
33
33
|
enumerable: true,
|
|
34
34
|
configurable: true,
|
|
@@ -169,6 +169,14 @@ export class Source {
|
|
|
169
169
|
return 0;
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* The audio subsystem.
|
|
174
|
+
*
|
|
175
|
+
* Manages a handful of AudioSource objects, for things like global volume,
|
|
176
|
+
* global play/pause, etc..
|
|
177
|
+
*
|
|
178
|
+
* To make a new source, use `like.audio.newSource`.
|
|
179
|
+
*/
|
|
172
180
|
export class Audio {
|
|
173
181
|
constructor() {
|
|
174
182
|
Object.defineProperty(this, "sources", {
|
|
@@ -184,8 +192,11 @@ export class Audio {
|
|
|
184
192
|
value: 1
|
|
185
193
|
});
|
|
186
194
|
}
|
|
195
|
+
/**
|
|
196
|
+
* Get a {@link AudioSource}
|
|
197
|
+
*/
|
|
187
198
|
newSource(path, options) {
|
|
188
|
-
const source = new
|
|
199
|
+
const source = new AudioSource(path, this, options);
|
|
189
200
|
this.sources.push(new WeakRef(source));
|
|
190
201
|
return source;
|
|
191
202
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/audio/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,WAAW,EAAE,KAAK,EAAE,kBAAkB,EAAC,MAAM,SAAS,CAAA"}
|
package/dist/engine.d.ts
CHANGED
|
@@ -1,25 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @module engine
|
|
3
|
+
* @description Core game engine - lifecycle management and event dispatch.
|
|
4
|
+
*/
|
|
5
|
+
import type { EventType, EventMap, Dispatcher } from './events';
|
|
6
|
+
import type { Like } from './like';
|
|
7
|
+
export type EngineDispatcher = Dispatcher<EventType>;
|
|
8
|
+
export type EngineProps<T extends keyof EventMap> = {
|
|
9
|
+
canvas: HTMLCanvasElement;
|
|
10
|
+
abort: AbortSignal;
|
|
11
|
+
dispatch: Dispatcher<T>;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* @private
|
|
15
|
+
* Core game engine managing the event loop and subsystems.
|
|
16
|
+
*/
|
|
4
17
|
export declare class Engine {
|
|
18
|
+
private container;
|
|
19
|
+
/** The canvas on which we bind all events. Not always the same canvas
|
|
20
|
+
* that we render to. */
|
|
5
21
|
private canvas;
|
|
6
22
|
private isRunning;
|
|
7
23
|
private lastTime;
|
|
8
|
-
private
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
private gfxState;
|
|
13
|
-
private windowFocusHandler;
|
|
14
|
-
private windowBlurHandler;
|
|
15
|
-
private canvasFocusHandler;
|
|
16
|
-
private canvasBlurHandler;
|
|
17
|
-
private fullscreenChangeHandler;
|
|
24
|
+
private abort;
|
|
25
|
+
/**
|
|
26
|
+
* The Like interface providing access to all engine subsystems.
|
|
27
|
+
*/
|
|
18
28
|
readonly like: Like;
|
|
19
29
|
constructor(container: HTMLElement);
|
|
20
30
|
private dispatch;
|
|
21
|
-
|
|
22
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Start the game loop.
|
|
33
|
+
*/
|
|
34
|
+
start(): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Clean up all resources and stop the engine.
|
|
37
|
+
*/
|
|
23
38
|
dispose(): void;
|
|
24
39
|
}
|
|
25
40
|
//# sourceMappingURL=engine.d.ts.map
|
package/dist/engine.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH,OAAO,KAAK,EAAa,SAAS,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC3E,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAInC,MAAM,MAAM,gBAAgB,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC;AACrD,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,MAAM,QAAQ,IAAI;IAClD,MAAM,EAAE,iBAAiB,CAAC;IAC1B,KAAK,EAAE,WAAW,CAAC;IACnB,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;CACzB,CAAA;AAED;;;GAGG;AACH,qBAAa,MAAM;IAaL,OAAO,CAAC,SAAS;IAZ7B;4BACwB;IACxB,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,QAAQ,CAAK;IACrB,OAAO,CAAC,KAAK,CAAyB;IAEtC;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;gBAEA,SAAS,EAAE,WAAW;IAuD1C,OAAO,CAAC,QAAQ;IAShB;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IA4B5B;;OAEG;IACH,OAAO,IAAI,IAAI;CAIhB"}
|