like2d 2.6.0 → 2.7.2
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 +51 -42
- package/dist/core/graphics.d.ts +10 -0
- package/dist/core/graphics.d.ts.map +1 -1
- package/dist/core/graphics.js +18 -0
- package/dist/core/like.d.ts +5 -0
- package/dist/core/like.d.ts.map +1 -1
- package/dist/engine.d.ts +4 -7
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +46 -50
- package/dist/gamecontrollerdb.txt +2 -0
- package/dist/index.d.ts +13 -33
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -20
- package/dist/scene.d.ts +10 -0
- package/dist/scene.d.ts.map +1 -0
- package/dist/scenes/startup.d.ts +18 -0
- package/dist/scenes/startup.d.ts.map +1 -0
- package/dist/scenes/startup.js +48 -0
- package/package.json +13 -17
- package/dist/adapters/callback/index.d.ts +0 -23
- package/dist/adapters/callback/index.d.ts.map +0 -1
- package/dist/adapters/callback/index.js +0 -30
- package/dist/adapters/scene/index.d.ts +0 -18
- package/dist/adapters/scene/index.d.ts.map +0 -1
- package/dist/adapters/scene/index.js +0 -57
- package/dist/adapters/scene/scene.d.ts +0 -19
- package/dist/adapters/scene/scene.d.ts.map +0 -1
- package/dist/adapters/scene/startup-scene.d.ts +0 -18
- package/dist/adapters/scene/startup-scene.d.ts.map +0 -1
- package/dist/adapters/scene/startup-scene.js +0 -61
- package/dist/core/gamepad-button-map.d.ts +0 -5
- package/dist/core/gamepad-button-map.d.ts.map +0 -1
- package/dist/core/gamepad-button-map.js +0 -56
- package/dist/core/gamepad-db.d.ts +0 -49
- package/dist/core/gamepad-db.d.ts.map +0 -1
- package/dist/core/gamepad-db.js +0 -192
- package/dist/core/player-movement.d.ts +0 -16
- package/dist/core/player-movement.d.ts.map +0 -1
- package/dist/core/player-movement.js +0 -20
- /package/dist/{adapters/scene/scene.js → scene.js} +0 -0
package/README.md
CHANGED
|
@@ -1,8 +1,35 @@
|
|
|
1
1
|
# LÏKE2D
|
|
2
2
|
|
|
3
|
-
<
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
<svg width="300mm" height="105mm" version="1.1" viewBox="0 0 300 105" xmlns="http://www.w3.org/2000/svg">
|
|
4
|
+
<rect x="10" y="11.23" width="280" height="83.544" fill="#e48080" stroke="#000" stroke-linejoin="round" stroke-width="2"/>
|
|
5
|
+
<g fill="none" stroke="#000" stroke-linejoin="round">
|
|
6
|
+
<rect x="97.484" y="11.23" width="52.516" height="46.237"/>
|
|
7
|
+
<rect x="150" y="11.23" width="35.011" height="46.237"/>
|
|
8
|
+
<rect x="185.01" y="11.23" width="52.516" height="46.237"/>
|
|
9
|
+
<rect x="237.53" y="11.23" width="52.516" height="46.237"/>
|
|
10
|
+
</g>
|
|
11
|
+
<g>
|
|
12
|
+
<rect x="132.49" y="11.23" width="17.505" height="27.461"/>
|
|
13
|
+
<rect x="150" y="29.302" width="8.7527" height="18.776"/>
|
|
14
|
+
<rect x="176.26" y="29.302" width="8.7527" height="18.776"/>
|
|
15
|
+
</g>
|
|
16
|
+
<rect x="150" y="11.23" width="17.505" height="8.6845" fill="none" stroke="#000" stroke-linejoin="round"/>
|
|
17
|
+
<rect x="167.51" y="11.23" width="17.505" height="8.6845" fill="none" stroke="#000" stroke-linejoin="round"/>
|
|
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"/>
|
|
31
|
+
</g>
|
|
32
|
+
</svg>
|
|
6
33
|
|
|
7
34
|
A web-native 2D game framework inspired by [LÖVE](https://love2d.org/), built for simplicity and the modern web.
|
|
8
35
|
|
|
@@ -36,14 +63,10 @@ pnpm add like2d
|
|
|
36
63
|
|
|
37
64
|
[Like2D Starter Template](https://github.com/44100hertz/Like2D-starter)
|
|
38
65
|
|
|
39
|
-
## Usage
|
|
40
|
-
|
|
41
|
-
### Callback Pattern (Love2D-style)
|
|
42
|
-
|
|
43
|
-
Ideal for small games, jams, or prototyping.
|
|
66
|
+
## Usage Example
|
|
44
67
|
|
|
45
68
|
```typescript
|
|
46
|
-
import { createLike } from 'like2d
|
|
69
|
+
import { createLike } from 'like2d';
|
|
47
70
|
|
|
48
71
|
const like = createLike(document.body);
|
|
49
72
|
|
|
@@ -67,44 +90,30 @@ like.draw = () => {
|
|
|
67
90
|
await like.start();
|
|
68
91
|
```
|
|
69
92
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
Ideal for larger projects with menus, levels, and explicit state management.
|
|
73
|
-
|
|
74
|
-
```typescript
|
|
75
|
-
import { SceneRunner, type Scene } from 'like2d/scene';
|
|
76
|
-
import type { Like } from 'like2d';
|
|
77
|
-
|
|
78
|
-
class MyScene implements Scene {
|
|
79
|
-
load(like: Like) {
|
|
80
|
-
console.log('Scene loaded!');
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
update(like: Like, dt: number) {
|
|
84
|
-
// update logic
|
|
85
|
-
}
|
|
93
|
+
## For Love2D Developers
|
|
86
94
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
95
|
+
LIKE's API is not the same as LOVE, but similar in spirit. Notable differences:
|
|
96
|
+
- Graphics have less state, there is no setColor getColor etc.
|
|
97
|
+
- Our APIs are, in general, a bit different. You'll have to learn some.
|
|
98
|
+
- You manage your own state; like is not global, but you can share it around for similar results. This allows multiple LIKE instances per webpage.
|
|
99
|
+
- We use Vector2 and Rect tuples (as in `[number, number]`) instead of loose coordinates.
|
|
100
|
+
- Theres an actions system -- `input.map` / `actionpressed` and `actionreleased` callbacks.
|
|
101
|
+
- Some things are missing either due to browser limitations or smaller scope.
|
|
92
102
|
|
|
93
|
-
|
|
94
|
-
await runner.start(new MyScene());
|
|
95
|
-
```
|
|
103
|
+
## Feedback welcome
|
|
96
104
|
|
|
97
|
-
|
|
105
|
+
Before you report a bug:
|
|
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.
|
|
98
109
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
import { Vec2, Rect, type Like } from 'like2d'; // Core types and math
|
|
105
|
-
```
|
|
110
|
+
Before you request a feature:
|
|
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.
|
|
106
115
|
|
|
107
|
-
|
|
116
|
+
[Then, put your feedback on GitHub.](https://github.com/44100hertz/Like2D/issues)
|
|
108
117
|
|
|
109
118
|
## License
|
|
110
119
|
|
package/dist/core/graphics.d.ts
CHANGED
|
@@ -59,6 +59,11 @@ export declare function setCanvas(s: GraphicsState, canvas?: Canvas | null): voi
|
|
|
59
59
|
export declare function clip(s: GraphicsState, rect?: Rect): void;
|
|
60
60
|
export declare function polygon(s: GraphicsState, mode: DrawMode, color: Color, points: Vector2[], props?: ShapeProps): void;
|
|
61
61
|
export declare function points(s: GraphicsState, color: Color, pts: Vector2[]): void;
|
|
62
|
+
export declare function push(s: GraphicsState): void;
|
|
63
|
+
export declare function pop(s: GraphicsState): void;
|
|
64
|
+
export declare function translate(s: GraphicsState, offset: Vector2): void;
|
|
65
|
+
export declare function rotate(s: GraphicsState, angle: number): void;
|
|
66
|
+
export declare function scale(s: GraphicsState, factor: number | Vector2): void;
|
|
62
67
|
type Bind<F> = F extends (s: GraphicsState, ...args: infer A) => infer R ? (...args: A) => R : never;
|
|
63
68
|
export type BoundGraphics = {
|
|
64
69
|
[K in keyof typeof graphicsFns]: Bind<(typeof graphicsFns)[K]>;
|
|
@@ -77,6 +82,11 @@ declare const graphicsFns: {
|
|
|
77
82
|
readonly polygon: typeof polygon;
|
|
78
83
|
readonly points: typeof points;
|
|
79
84
|
readonly newImage: typeof newImage;
|
|
85
|
+
readonly push: typeof push;
|
|
86
|
+
readonly pop: typeof pop;
|
|
87
|
+
readonly translate: typeof translate;
|
|
88
|
+
readonly rotate: typeof rotate;
|
|
89
|
+
readonly scale: typeof scale;
|
|
80
90
|
};
|
|
81
91
|
export declare function bindGraphics(s: GraphicsState): BoundGraphics;
|
|
82
92
|
//# sourceMappingURL=graphics.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphics.d.ts","sourceRoot":"","sources":["../../src/core/graphics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEnC,KAAK,QAAQ,GA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,EAAE,OAAO,GAAG,IAAI,CAGjE;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAE5D;AAED,wBAAgB,KAAK,CAAC,CAAC,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI,CAGtE;AAID,KAAK,IAAI,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,aAAa,EAAE,GAAG,IAAI,EAAE,MAAM,CAAC,KAAK,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC;AAErG,MAAM,MAAM,aAAa,GAAG;KACzB,CAAC,IAAI,MAAM,OAAO,WAAW,GAAG,IAAI,CAAC,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;CAC/D,CAAC;AAEF,QAAA,MAAM,WAAW;;;;;;;;;;;;;;;;;;;CAKP,CAAC;AAEX,wBAAgB,YAAY,CAAC,CAAC,EAAE,aAAa,GAAG,aAAa,CAM5D"}
|
package/dist/core/graphics.js
CHANGED
|
@@ -253,10 +253,28 @@ export function points(s, color, pts) {
|
|
|
253
253
|
ctx.fillStyle = applyColor(color);
|
|
254
254
|
pts.forEach(([x, y]) => ctx.fillRect(x, y, 1, 1));
|
|
255
255
|
}
|
|
256
|
+
export function push(s) {
|
|
257
|
+
s.currentCtx.save();
|
|
258
|
+
}
|
|
259
|
+
export function pop(s) {
|
|
260
|
+
s.currentCtx.restore();
|
|
261
|
+
}
|
|
262
|
+
export function translate(s, offset) {
|
|
263
|
+
const [x, y] = offset;
|
|
264
|
+
s.currentCtx.translate(x, y);
|
|
265
|
+
}
|
|
266
|
+
export function rotate(s, angle) {
|
|
267
|
+
s.currentCtx.rotate(angle);
|
|
268
|
+
}
|
|
269
|
+
export function scale(s, factor) {
|
|
270
|
+
const [sx, sy] = typeof factor === 'number' ? [factor, factor] : factor;
|
|
271
|
+
s.currentCtx.scale(sx, sy);
|
|
272
|
+
}
|
|
256
273
|
const graphicsFns = {
|
|
257
274
|
clear, rectangle, circle, line, print,
|
|
258
275
|
draw: drawImage, getCanvasSize, newCanvas, setCanvas,
|
|
259
276
|
clip, polygon, points, newImage,
|
|
277
|
+
push, pop, translate, rotate, scale,
|
|
260
278
|
};
|
|
261
279
|
export function bindGraphics(s) {
|
|
262
280
|
const bound = {};
|
package/dist/core/like.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import type { Gamepad } from './gamepad';
|
|
|
7
7
|
import type { Vector2 } from './vector2';
|
|
8
8
|
import type { CanvasMode, PartialCanvasMode } from './canvas-config';
|
|
9
9
|
import type { BoundGraphics } from './graphics';
|
|
10
|
+
import type { Scene } from '../scene';
|
|
10
11
|
/**
|
|
11
12
|
* The Like interface provides access to all core systems and APIs
|
|
12
13
|
* that are passed to game callbacks (load, update, draw, etc.).
|
|
@@ -43,6 +44,10 @@ export interface Like {
|
|
|
43
44
|
* @returns The canvas size as a Vector2 [width, height]
|
|
44
45
|
*/
|
|
45
46
|
getCanvasSize(): Vector2;
|
|
47
|
+
/**
|
|
48
|
+
* Set the active scene. Pass null to revert to global callbacks.
|
|
49
|
+
*/
|
|
50
|
+
setScene(scene: Scene | null): void;
|
|
46
51
|
}
|
|
47
52
|
export type { Audio, Source, SourceOptions } from './audio';
|
|
48
53
|
export type { Timer } from './timer';
|
package/dist/core/like.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"like.d.ts","sourceRoot":"","sources":["../../src/core/like.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,EAAE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AK,CAAC;IAEtB,6BAA6B;IAC7B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAE1B,gDAAgD;IAChD,QAAQ,CAAC,GAAG,EAAE,aAAa,CAAC;IAE5B;;;OAGG;IACH,OAAO,CAAC,IAAI,EAAE,iBAAiB,GAAG,IAAI,CAAC;IAEvC;;;OAGG;IACH,OAAO,IAAI,UAAU,GAAG,SAAS,CAAC;IAElC;;;OAGG;IACH,aAAa,IAAI,OAAO,CAAC;IAEzB;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,GAAG,IAAI,CAAC;CACrC;AAGD,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC5D,YAAY,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,YAAY,EAAE,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAC9D,YAAY,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,YAAY,EAAE,KAAK,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAC7D,YAAY,EAAE,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACxE,YAAY,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/engine.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { Like2DEvent } from './core/events';
|
|
2
2
|
import type { PartialCanvasMode } from './core/canvas-config';
|
|
3
3
|
import type { Like } from './core/like';
|
|
4
|
-
export type { CanvasMode, PartialCanvasMode } from './core/canvas-config';
|
|
5
4
|
export declare class Engine {
|
|
6
5
|
private canvas;
|
|
7
6
|
private ctx;
|
|
@@ -9,15 +8,13 @@ export declare class Engine {
|
|
|
9
8
|
private lastTime;
|
|
10
9
|
private container;
|
|
11
10
|
private canvasManager;
|
|
12
|
-
private
|
|
11
|
+
private handleEvent;
|
|
12
|
+
private currentScene;
|
|
13
13
|
readonly like: Like;
|
|
14
14
|
constructor(container: HTMLElement);
|
|
15
|
-
private
|
|
15
|
+
private dispatch;
|
|
16
16
|
setMode(mode: PartialCanvasMode): void;
|
|
17
|
-
|
|
18
|
-
start(onEvent: (event: Like2DEvent) => void): Promise<void>;
|
|
19
|
-
stop(): void;
|
|
17
|
+
start(handleEvent: (event: Like2DEvent) => void): Promise<void>;
|
|
20
18
|
dispose(): void;
|
|
21
|
-
getCanvasSize(): [number, number];
|
|
22
19
|
}
|
|
23
20
|
//# 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":"AAOA,OAAO,KAAK,EAAE,WAAW,EAAa,MAAM,eAAe,CAAC;AAC5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,WAAW,EAAa,MAAM,eAAe,CAAC;AAC5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAIxC,qBAAa,MAAM;IACjB,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,GAAG,CAA2B;IACtC,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,QAAQ,CAAK;IACrB,OAAO,CAAC,SAAS,CAAc;IAC/B,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,WAAW,CAA+C;IAClE,OAAO,CAAC,YAAY,CAAsB;IAE1C,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;gBAER,SAAS,EAAE,WAAW;IAkElC,OAAO,CAAC,QAAQ;IAchB,OAAO,CAAC,IAAI,EAAE,iBAAiB,GAAG,IAAI;IAWhC,KAAK,CAAC,WAAW,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IA+BrE,OAAO,IAAI,IAAI;CAUhB"}
|
package/dist/engine.js
CHANGED
|
@@ -44,13 +44,18 @@ export class Engine {
|
|
|
44
44
|
writable: true,
|
|
45
45
|
value: void 0
|
|
46
46
|
});
|
|
47
|
-
Object.defineProperty(this, "
|
|
47
|
+
Object.defineProperty(this, "handleEvent", {
|
|
48
|
+
enumerable: true,
|
|
49
|
+
configurable: true,
|
|
50
|
+
writable: true,
|
|
51
|
+
value: null
|
|
52
|
+
});
|
|
53
|
+
Object.defineProperty(this, "currentScene", {
|
|
48
54
|
enumerable: true,
|
|
49
55
|
configurable: true,
|
|
50
56
|
writable: true,
|
|
51
57
|
value: null
|
|
52
58
|
});
|
|
53
|
-
// Public Like object with all systems - initialized in constructor
|
|
54
59
|
Object.defineProperty(this, "like", {
|
|
55
60
|
enumerable: true,
|
|
56
61
|
configurable: true,
|
|
@@ -67,17 +72,14 @@ export class Engine {
|
|
|
67
72
|
this.container = container;
|
|
68
73
|
this.container.appendChild(this.canvas);
|
|
69
74
|
this.canvasManager = new CanvasManager(this.canvas, this.container, this.ctx, { pixelResolution: null, fullscreen: false });
|
|
70
|
-
// Create graphics state and bind it
|
|
71
75
|
const gfxState = newState(this.ctx);
|
|
72
76
|
const gfx = bindGraphics(gfxState);
|
|
73
|
-
// Create all subsystems
|
|
74
77
|
const audio = new Audio();
|
|
75
78
|
const timer = new Timer();
|
|
76
79
|
const keyboard = new Keyboard();
|
|
77
80
|
const mouse = new Mouse((cssX, cssY) => this.canvasManager.transformMousePosition(cssX, cssY));
|
|
78
81
|
const gamepad = new Gamepad();
|
|
79
82
|
const input = new Input({ keyboard, mouse, gamepad });
|
|
80
|
-
// Create the Like object with all systems
|
|
81
83
|
this.like = {
|
|
82
84
|
audio,
|
|
83
85
|
timer,
|
|
@@ -89,81 +91,78 @@ export class Engine {
|
|
|
89
91
|
setMode: (m) => this.setMode(m),
|
|
90
92
|
getMode: () => this.canvasManager.getMode(),
|
|
91
93
|
getCanvasSize: () => [this.canvas.width, this.canvas.height],
|
|
94
|
+
setScene: (scene) => {
|
|
95
|
+
this.currentScene = scene;
|
|
96
|
+
scene?.load?.(this.like);
|
|
97
|
+
},
|
|
92
98
|
};
|
|
93
|
-
// Set up input event handlers
|
|
94
99
|
keyboard.onKeyEvent = (scancode, keycode, type) => {
|
|
95
|
-
this.
|
|
100
|
+
this.dispatch(type === 'keydown' ? 'keypressed' : 'keyreleased', [scancode, keycode]);
|
|
96
101
|
};
|
|
97
102
|
mouse.onMouseEvent = (clientX, clientY, button, type) => {
|
|
98
103
|
const [x, y] = this.canvasManager.transformMousePosition(clientX, clientY);
|
|
99
|
-
|
|
100
|
-
this.dispatchEvent(type === 'mousedown' ? 'mousepressed' : 'mousereleased', [x, y, b]);
|
|
104
|
+
this.dispatch(type === 'mousedown' ? 'mousepressed' : 'mousereleased', [x, y, (button ?? 0) + 1]);
|
|
101
105
|
};
|
|
102
106
|
gamepad.onButtonEvent = (gpIndex, buttonIndex, buttonName, pressed) => {
|
|
103
|
-
this.
|
|
107
|
+
this.dispatch(pressed ? 'gamepadpressed' : 'gamepadreleased', [gpIndex, buttonIndex, buttonName]);
|
|
104
108
|
};
|
|
105
|
-
// Internal listener to forward resize events
|
|
106
109
|
this.canvasManager.onResize = (size, pixelSize, fullscreen) => {
|
|
107
|
-
this.
|
|
110
|
+
this.dispatch('resize', [size, pixelSize, fullscreen]);
|
|
108
111
|
};
|
|
109
|
-
|
|
110
|
-
|
|
112
|
+
document.addEventListener('fullscreenchange', () => {
|
|
113
|
+
const mode = this.canvasManager.getMode();
|
|
114
|
+
const isFullscreen = !!document.fullscreenElement;
|
|
115
|
+
if (mode.fullscreen !== isFullscreen) {
|
|
116
|
+
this.canvasManager.setMode({ ...mode, fullscreen: isFullscreen });
|
|
117
|
+
}
|
|
118
|
+
});
|
|
111
119
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
120
|
+
dispatch(type, args) {
|
|
121
|
+
if (!this.handleEvent)
|
|
122
|
+
return;
|
|
123
|
+
const event = { type, args, timestamp: performance.now() };
|
|
124
|
+
if (this.currentScene) {
|
|
125
|
+
this.currentScene.handleEvent?.(this.like, event);
|
|
126
|
+
const method = this.currentScene[event.type];
|
|
127
|
+
method?.call(this.currentScene, this.like, ...args);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
this.handleEvent(event);
|
|
117
131
|
}
|
|
118
132
|
}
|
|
119
133
|
setMode(mode) {
|
|
120
134
|
const currentMode = this.canvasManager.getMode();
|
|
121
135
|
const mergedMode = { ...currentMode, ...mode };
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if (mergedMode.fullscreen) {
|
|
125
|
-
this.container.requestFullscreen().catch(console.error);
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
document.exitFullscreen();
|
|
129
|
-
}
|
|
136
|
+
if (mode.fullscreen !== undefined && mode.fullscreen !== currentMode.fullscreen) {
|
|
137
|
+
mergedMode.fullscreen ? this.container.requestFullscreen().catch(console.error) : document.exitFullscreen();
|
|
130
138
|
}
|
|
131
139
|
this.canvasManager.setMode(mode);
|
|
132
140
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
this.onEvent({ type, args, timestamp: performance.now() });
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
async start(onEvent) {
|
|
139
|
-
this.onEvent = onEvent;
|
|
141
|
+
async start(handleEvent) {
|
|
142
|
+
this.handleEvent = handleEvent;
|
|
140
143
|
this.isRunning = true;
|
|
141
144
|
this.lastTime = performance.now();
|
|
142
|
-
// Initialize gamepad
|
|
143
145
|
await this.like.gamepad.init();
|
|
144
146
|
const loop = () => {
|
|
145
147
|
if (!this.isRunning)
|
|
146
148
|
return;
|
|
147
|
-
const
|
|
148
|
-
const dt = (
|
|
149
|
-
this.lastTime =
|
|
149
|
+
const now = performance.now();
|
|
150
|
+
const dt = (now - this.lastTime) / 1000;
|
|
151
|
+
this.lastTime = now;
|
|
150
152
|
if (!this.like.timer.isSleeping()) {
|
|
151
153
|
this.like.timer.update(dt);
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
this.
|
|
154
|
+
const { pressed, released } = this.like.input.update();
|
|
155
|
+
pressed.forEach(action => this.dispatch('actionpressed', [action]));
|
|
156
|
+
released.forEach(action => this.dispatch('actionreleased', [action]));
|
|
157
|
+
this.dispatch('update', [dt]);
|
|
156
158
|
}
|
|
157
|
-
this.
|
|
159
|
+
this.dispatch('draw', []);
|
|
158
160
|
this.canvasManager.present();
|
|
159
161
|
requestAnimationFrame(loop);
|
|
160
162
|
};
|
|
161
|
-
this.
|
|
163
|
+
this.dispatch('load', []);
|
|
162
164
|
requestAnimationFrame(loop);
|
|
163
165
|
}
|
|
164
|
-
stop() {
|
|
165
|
-
this.isRunning = false;
|
|
166
|
-
}
|
|
167
166
|
dispose() {
|
|
168
167
|
this.isRunning = false;
|
|
169
168
|
this.like.keyboard.dispose();
|
|
@@ -174,7 +173,4 @@ export class Engine {
|
|
|
174
173
|
this.container.removeChild(this.canvas);
|
|
175
174
|
}
|
|
176
175
|
}
|
|
177
|
-
getCanvasSize() {
|
|
178
|
-
return [this.canvas.width, this.canvas.height];
|
|
179
|
-
}
|
|
180
176
|
}
|
|
@@ -927,6 +927,7 @@ xinput,XInput Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,
|
|
|
927
927
|
03000000050b00000045000031000000,ASUS Gamepad,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b7,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b8,righttrigger:a4,rightx:a2,righty:a3,start:b9,x:b2,y:b3,platform:Mac OS X,
|
|
928
928
|
03000000050b00000579000000010000,ASUS ROG Kunai 3,a:b0,b:b1,back:b12,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b14,leftshoulder:b6,leftstick:b15,lefttrigger:a5,leftx:a0,lefty:a1,misc1:b42,paddle1:b9,paddle2:b11,rightshoulder:b7,rightstick:b16,righttrigger:a4,rightx:a2,righty:a3,start:b13,x:b3,y:b4,platform:Mac OS X,
|
|
929
929
|
03000000050b00000679000000010000,ASUS ROG Kunai 3,a:b0,b:b1,back:b12,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b14,leftshoulder:b6,leftstick:b15,lefttrigger:a5,leftx:a0,lefty:a1,misc1:b23,rightshoulder:b7,rightstick:b16,righttrigger:a4,rightx:a2,righty:a3,start:b13,x:b3,y:b4,platform:Mac OS X,
|
|
930
|
+
030000006a0e00001140000001000000,Atari CX Wireless Controller,a:b0,leftx:a0,lefty:a1,platform:Mac OS X,
|
|
930
931
|
03000000503200000110000045010000,Atari VCS Classic,a:b0,b:b1,back:b4,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b3,start:b2,platform:Mac OS X,
|
|
931
932
|
03000000503200000110000047010000,Atari VCS Classic Controller,a:b0,b:b1,back:b4,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b3,start:b2,platform:Mac OS X,
|
|
932
933
|
03000000503200000210000047010000,Atari VCS Modern Controller,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b9,leftshoulder:b4,leftstick:b6,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a4,rightx:a2,righty:a3,start:b8,x:b2,y:b3,platform:Mac OS X,
|
|
@@ -1273,6 +1274,7 @@ xinput,XInput Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,
|
|
|
1273
1274
|
05000000050b00000045000040000000,ASUS Gamepad,a:b0,b:b1,back:b9,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b6,leftshoulder:b4,leftstick:b7,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b8,righttrigger:a4,rightx:a2,righty:a3,start:b10,x:b2,y:b3,platform:Linux,
|
|
1274
1275
|
03000000050b00000579000011010000,ASUS ROG Kunai 3,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,misc1:b36,paddle1:b52,paddle2:b53,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b3,y:b4,platform:Linux,
|
|
1275
1276
|
05000000050b00000679000000010000,ASUS ROG Kunai 3,a:b0,b:b1,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,misc1:b21,paddle1:b22,paddle2:b23,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b3,y:b4,platform:Linux,
|
|
1277
|
+
030000006a0e00001140000010010000,Atari CX Wireless Controller,a:b0,leftx:a0,lefty:a1,platform:Linux,
|
|
1276
1278
|
03000000503200000110000000000000,Atari VCS Classic Controller,a:b0,b:b1,back:b2,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b4,start:b3,platform:Linux,
|
|
1277
1279
|
03000000503200000110000011010000,Atari VCS Classic Controller,a:b0,b:b1,back:b2,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b4,start:b3,platform:Linux,
|
|
1278
1280
|
05000000503200000110000000000000,Atari VCS Classic Controller,a:b0,b:b1,back:b2,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b4,start:b3,platform:Linux,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,45 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* Passed as first argument to all callbacks.
|
|
4
|
-
*/
|
|
1
|
+
import type { EventMap, EventType } from './core/events';
|
|
2
|
+
import type { Like } from './core/like';
|
|
5
3
|
export type { Like } from './core/like';
|
|
6
|
-
/**
|
|
7
|
-
* 2D vector as a tuple: [x, y]
|
|
8
|
-
*/
|
|
9
4
|
export type { Vector2 } from './core/vector2';
|
|
10
|
-
/**
|
|
11
|
-
* 2D vector math and utility functions
|
|
12
|
-
*/
|
|
13
5
|
export { Vec2 } from './core/vector2';
|
|
14
|
-
/**
|
|
15
|
-
* Rectangle math and utility functions.
|
|
16
|
-
* Rects are represented as [x, y, width, height] tuples.
|
|
17
|
-
*/
|
|
18
6
|
export { Rect } from './core/rect';
|
|
19
|
-
/**
|
|
20
|
-
* Common event structure for all engine events.
|
|
21
|
-
*/
|
|
22
7
|
export type { Like2DEvent, EventType, EventMap } from './core/events';
|
|
23
8
|
export type { CanvasMode, PartialCanvasMode } from './core/canvas-config';
|
|
24
|
-
/**
|
|
25
|
-
* Graphics types for drawing operations.
|
|
26
|
-
*/
|
|
27
9
|
export type { Color, Quad, ShapeProps, DrawProps, PrintProps } from './core/graphics';
|
|
28
|
-
/**
|
|
29
|
-
* Handle to an image asset that may be loading in the background.
|
|
30
|
-
*/
|
|
31
10
|
export { ImageHandle } from './core/graphics';
|
|
32
|
-
/**
|
|
33
|
-
* Audio source types for sound playback.
|
|
34
|
-
*/
|
|
35
11
|
export type { Source, SourceOptions } from './core/audio';
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
*/
|
|
39
|
-
export type { Scene } from './adapters/scene/scene';
|
|
40
|
-
/**
|
|
41
|
-
* Gamepad utility functions and types.
|
|
42
|
-
*/
|
|
12
|
+
export type { Scene } from './scene';
|
|
13
|
+
export { StartupScene } from './scenes/startup';
|
|
43
14
|
export { getGPName, GP } from './core/gamepad';
|
|
44
15
|
export type { StickPosition } from './core/gamepad';
|
|
16
|
+
type Callback<K extends EventType> = (...args: EventMap[K]) => void;
|
|
17
|
+
type Callbacks = {
|
|
18
|
+
[K in EventType]?: Callback<K>;
|
|
19
|
+
};
|
|
20
|
+
export type LikeWithCallbacks = Like & Callbacks & {
|
|
21
|
+
start(): Promise<void>;
|
|
22
|
+
dispose(): void;
|
|
23
|
+
};
|
|
24
|
+
export declare function createLike(container: HTMLElement): LikeWithCallbacks;
|
|
45
25
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAe,QAAQ,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACtE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAExC,YAAY,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACxC,YAAY,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACtE,YAAY,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC1E,YAAY,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACtF,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC1D,YAAY,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAC/C,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAEpD,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,MAAM,MAAM,iBAAiB,GAAG,IAAI,GAAG,SAAS,GAAG;IACjD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,OAAO,IAAI,IAAI,CAAC;CACjB,CAAC;AAEF,wBAAgB,UAAU,CAAC,SAAS,EAAE,WAAW,GAAG,iBAAiB,CAapE"}
|
package/dist/index.js
CHANGED
|
@@ -1,24 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
// Use specific adapters for different patterns:
|
|
3
|
-
// - import { createLike, graphics } from 'like2d/callback' (Love2D-style callbacks)
|
|
4
|
-
// - import { SceneRunner, Scene } from 'like2d/scene' (Class-based scenes)
|
|
5
|
-
/**
|
|
6
|
-
* 2D vector math and utility functions
|
|
7
|
-
*/
|
|
1
|
+
import { Engine } from './engine';
|
|
8
2
|
export { Vec2 } from './core/vector2';
|
|
9
|
-
/**
|
|
10
|
-
* Rectangle math and utility functions.
|
|
11
|
-
* Rects are represented as [x, y, width, height] tuples.
|
|
12
|
-
*/
|
|
13
3
|
export { Rect } from './core/rect';
|
|
14
|
-
/**
|
|
15
|
-
* Handle to an image asset that may be loading in the background.
|
|
16
|
-
*/
|
|
17
4
|
export { ImageHandle } from './core/graphics';
|
|
18
|
-
|
|
19
|
-
* Gamepad utility functions and types.
|
|
20
|
-
*/
|
|
5
|
+
export { StartupScene } from './scenes/startup';
|
|
21
6
|
export { getGPName, GP } from './core/gamepad';
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
7
|
+
export function createLike(container) {
|
|
8
|
+
const engine = new Engine(container);
|
|
9
|
+
const callbacks = {};
|
|
10
|
+
const handleEvent = (event) => {
|
|
11
|
+
const cb = callbacks[event.type];
|
|
12
|
+
if (cb)
|
|
13
|
+
cb(...event.args);
|
|
14
|
+
};
|
|
15
|
+
return Object.assign(engine.like, callbacks, {
|
|
16
|
+
start: () => engine.start(handleEvent),
|
|
17
|
+
dispose: () => engine.dispose(),
|
|
18
|
+
});
|
|
19
|
+
}
|
package/dist/scene.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Like2DEvent, EventMap, EventType } from './core/events';
|
|
2
|
+
import type { Like } from './core/like';
|
|
3
|
+
type EventHandler<K extends EventType> = (like: Like, ...args: EventMap[K]) => void;
|
|
4
|
+
export type Scene = {
|
|
5
|
+
[K in EventType]?: EventHandler<K>;
|
|
6
|
+
} & {
|
|
7
|
+
handleEvent?(like: Like, event: Like2DEvent): void;
|
|
8
|
+
};
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=scene.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scene.d.ts","sourceRoot":"","sources":["../src/scene.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACtE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAExC,KAAK,YAAY,CAAC,CAAC,SAAS,SAAS,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;AAEpF,MAAM,MAAM,KAAK,GAAG;KACjB,CAAC,IAAI,SAAS,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC;CACnC,GAAG;IACF,WAAW,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,GAAG,IAAI,CAAC;CACpD,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Scene, Like } from '../index';
|
|
2
|
+
/**
|
|
3
|
+
* A simple startup scene that waits for a mouse click before advancing.
|
|
4
|
+
*
|
|
5
|
+
* This exists to work around browser autoplay restrictions - browsers require
|
|
6
|
+
* user interaction (like a click) before allowing audio playback. Show this
|
|
7
|
+
* scene first, then transition to your game scene on click.
|
|
8
|
+
*/
|
|
9
|
+
export declare class StartupScene implements Scene {
|
|
10
|
+
private next;
|
|
11
|
+
private onDraw?;
|
|
12
|
+
private logo;
|
|
13
|
+
constructor(next: Scene, onDraw?: ((like: Like) => void) | undefined);
|
|
14
|
+
load(like: Like): void;
|
|
15
|
+
draw(like: Like): void;
|
|
16
|
+
mousepressed(like: Like): void;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=startup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"startup.d.ts","sourceRoot":"","sources":["../../src/scenes/startup.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAM5C;;;;;;GAMG;AACH,qBAAa,YAAa,YAAW,KAAK;IAItC,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,MAAM,CAAC;IAJjB,OAAO,CAAC,IAAI,CAAe;gBAGjB,IAAI,EAAE,KAAK,EACX,MAAM,CAAC,GAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,aAAA;IAGvC,IAAI,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAItB,IAAI,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAWtB,YAAY,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;CAG/B"}
|