like2d 1.0.0 → 2.0.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/LICENSE +22 -0
- package/README.md +67 -43
- package/dist/adapters/callback/index.d.ts +43 -0
- package/dist/adapters/callback/index.d.ts.map +1 -0
- package/dist/adapters/callback/index.js +80 -0
- package/dist/adapters/scene/index.d.ts +42 -0
- package/dist/adapters/scene/index.d.ts.map +1 -0
- package/dist/adapters/scene/index.js +112 -0
- package/dist/adapters/scene/scene.d.ts +18 -0
- package/dist/adapters/scene/scene.d.ts.map +1 -0
- package/dist/adapters/scene/startup-scene.d.ts +17 -0
- package/dist/adapters/scene/startup-scene.d.ts.map +1 -0
- package/dist/adapters/scene/startup-scene.js +41 -0
- package/dist/core/audio.d.ts +61 -0
- package/dist/core/audio.d.ts.map +1 -0
- package/dist/core/audio.js +226 -0
- package/dist/core/canvas-config.d.ts +22 -0
- package/dist/core/canvas-config.d.ts.map +1 -0
- package/dist/core/canvas-config.js +14 -0
- package/dist/core/canvas-manager.d.ts +26 -0
- package/dist/core/canvas-manager.d.ts.map +1 -0
- package/dist/core/canvas-manager.js +197 -0
- package/dist/core/events.d.ts +52 -0
- package/dist/core/events.d.ts.map +1 -0
- package/dist/core/gamepad-button-map.d.ts.map +1 -0
- package/dist/core/gamepad-buttons.d.ts +23 -0
- package/dist/core/gamepad-buttons.d.ts.map +1 -0
- package/dist/core/gamepad-buttons.js +36 -0
- package/dist/core/gamepad-db.d.ts.map +1 -0
- package/dist/{gamepad-mapping.d.ts → core/gamepad-mapping.d.ts} +3 -15
- package/dist/core/gamepad-mapping.d.ts.map +1 -0
- package/dist/core/gamepad-mapping.js +223 -0
- package/dist/{gamepad.d.ts → core/gamepad.d.ts} +22 -17
- package/dist/core/gamepad.d.ts.map +1 -0
- package/dist/{gamepad.js → core/gamepad.js} +91 -70
- package/dist/{graphics.d.ts → core/graphics.d.ts} +2 -8
- package/dist/core/graphics.d.ts.map +1 -0
- package/dist/{graphics.js → core/graphics.js} +4 -41
- package/dist/core/input-state.d.ts.map +1 -0
- package/dist/{input.d.ts → core/input.d.ts} +11 -14
- package/dist/core/input.d.ts.map +1 -0
- package/dist/{input.js → core/input.js} +31 -41
- package/dist/core/keyboard.d.ts +15 -0
- package/dist/core/keyboard.d.ts.map +1 -0
- package/dist/core/keyboard.js +70 -0
- package/dist/core/mouse.d.ts +29 -0
- package/dist/core/mouse.d.ts.map +1 -0
- package/dist/core/mouse.js +130 -0
- package/dist/{rect.d.ts → core/rect.d.ts} +1 -2
- package/dist/core/rect.d.ts.map +1 -0
- package/dist/{rect.js → core/rect.js} +24 -28
- package/dist/{timer.d.ts → core/timer.d.ts} +0 -1
- package/dist/core/timer.d.ts.map +1 -0
- package/dist/{timer.js → core/timer.js} +0 -1
- package/dist/{vector2.d.ts → core/vector2.d.ts} +4 -10
- package/dist/core/vector2.d.ts.map +1 -0
- package/dist/{vector2.js → core/vector2.js} +40 -40
- package/dist/engine.d.ts +42 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +154 -0
- package/dist/index.d.ts +38 -44
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +24 -250
- package/package.json +8 -23
- package/dist/audio.d.ts +0 -52
- package/dist/audio.d.ts.map +0 -1
- package/dist/audio.js +0 -250
- package/dist/events.d.ts +0 -36
- package/dist/events.d.ts.map +0 -1
- package/dist/gamepad-button-map.d.ts.map +0 -1
- package/dist/gamepad-db.d.ts.map +0 -1
- package/dist/gamepad-mapping.d.ts.map +0 -1
- package/dist/gamepad-mapping.js +0 -191
- package/dist/gamepad.d.ts.map +0 -1
- package/dist/graphics.d.ts.map +0 -1
- package/dist/input-state.d.ts.map +0 -1
- package/dist/input.d.ts.map +0 -1
- package/dist/keyboard.d.ts +0 -9
- package/dist/keyboard.d.ts.map +0 -1
- package/dist/keyboard.js +0 -33
- package/dist/mouse.d.ts +0 -20
- package/dist/mouse.d.ts.map +0 -1
- package/dist/mouse.js +0 -84
- package/dist/rect.d.ts.map +0 -1
- package/dist/scene.d.ts +0 -10
- package/dist/scene.d.ts.map +0 -1
- package/dist/timer.d.ts.map +0 -1
- package/dist/vector2.d.ts.map +0 -1
- /package/dist/{scene.js → adapters/scene/scene.js} +0 -0
- /package/dist/{events.js → core/events.js} +0 -0
- /package/dist/{gamepad-button-map.d.ts → core/gamepad-button-map.d.ts} +0 -0
- /package/dist/{gamepad-button-map.js → core/gamepad-button-map.js} +0 -0
- /package/dist/{gamepad-db.d.ts → core/gamepad-db.d.ts} +0 -0
- /package/dist/{gamepad-db.js → core/gamepad-db.js} +0 -0
- /package/dist/{input-state.d.ts → core/input-state.d.ts} +0 -0
- /package/dist/{input-state.js → core/input-state.js} +0 -0
|
@@ -1,105 +1,105 @@
|
|
|
1
|
-
export var
|
|
2
|
-
(function (
|
|
1
|
+
export var Vec2;
|
|
2
|
+
(function (Vec2) {
|
|
3
3
|
function add(a, b) {
|
|
4
4
|
return [a[0] + b[0], a[1] + b[1]];
|
|
5
5
|
}
|
|
6
|
-
|
|
6
|
+
Vec2.add = add;
|
|
7
7
|
function sub(a, b) {
|
|
8
8
|
return [a[0] - b[0], a[1] - b[1]];
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
function mul(v,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
Vec2.sub = sub;
|
|
11
|
+
function mul(v, other) {
|
|
12
|
+
if (typeof other === 'number') {
|
|
13
|
+
return [v[0] * other, v[1] * other];
|
|
14
|
+
}
|
|
15
|
+
return [v[0] * other[0], v[1] * other[1]];
|
|
16
|
+
}
|
|
17
|
+
Vec2.mul = mul;
|
|
18
|
+
function div(v, other) {
|
|
19
|
+
if (typeof other === 'number') {
|
|
20
|
+
return [v[0] / other, v[1] / other];
|
|
21
|
+
}
|
|
22
|
+
return [v[0] / other[0], v[1] / other[1]];
|
|
23
|
+
}
|
|
24
|
+
Vec2.div = div;
|
|
19
25
|
function dot(a, b) {
|
|
20
26
|
return a[0] * b[0] + a[1] * b[1];
|
|
21
27
|
}
|
|
22
|
-
|
|
28
|
+
Vec2.dot = dot;
|
|
23
29
|
function cross(a, b) {
|
|
24
30
|
return a[0] * b[1] - a[1] * b[0];
|
|
25
31
|
}
|
|
26
|
-
|
|
32
|
+
Vec2.cross = cross;
|
|
27
33
|
function lengthSq(v) {
|
|
28
34
|
return v[0] * v[0] + v[1] * v[1];
|
|
29
35
|
}
|
|
30
|
-
|
|
36
|
+
Vec2.lengthSq = lengthSq;
|
|
31
37
|
function length(v) {
|
|
32
38
|
return Math.sqrt(lengthSq(v));
|
|
33
39
|
}
|
|
34
|
-
|
|
40
|
+
Vec2.length = length;
|
|
35
41
|
function normalize(v) {
|
|
36
42
|
const len = length(v);
|
|
37
43
|
if (len === 0)
|
|
38
44
|
return [0, 0];
|
|
39
45
|
return div(v, len);
|
|
40
46
|
}
|
|
41
|
-
|
|
47
|
+
Vec2.normalize = normalize;
|
|
42
48
|
function distance(a, b) {
|
|
43
49
|
return length(sub(a, b));
|
|
44
50
|
}
|
|
45
|
-
|
|
51
|
+
Vec2.distance = distance;
|
|
46
52
|
function lerp(a, b, t) {
|
|
47
53
|
return [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t];
|
|
48
54
|
}
|
|
49
|
-
|
|
55
|
+
Vec2.lerp = lerp;
|
|
50
56
|
function angle(v) {
|
|
51
57
|
return Math.atan2(v[1], v[0]);
|
|
52
58
|
}
|
|
53
|
-
|
|
59
|
+
Vec2.angle = angle;
|
|
54
60
|
function rotate(v, angle) {
|
|
55
61
|
const cos = Math.cos(angle);
|
|
56
62
|
const sin = Math.sin(angle);
|
|
57
63
|
return [v[0] * cos - v[1] * sin, v[0] * sin + v[1] * cos];
|
|
58
64
|
}
|
|
59
|
-
|
|
60
|
-
function perpendicular(v) {
|
|
61
|
-
return [-v[1], v[0]];
|
|
62
|
-
}
|
|
63
|
-
V2.perpendicular = perpendicular;
|
|
65
|
+
Vec2.rotate = rotate;
|
|
64
66
|
function negate(v) {
|
|
65
67
|
return [-v[0], -v[1]];
|
|
66
68
|
}
|
|
67
|
-
|
|
69
|
+
Vec2.negate = negate;
|
|
68
70
|
function floor(v) {
|
|
69
71
|
return [Math.floor(v[0]), Math.floor(v[1])];
|
|
70
72
|
}
|
|
71
|
-
|
|
73
|
+
Vec2.floor = floor;
|
|
72
74
|
function ceil(v) {
|
|
73
75
|
return [Math.ceil(v[0]), Math.ceil(v[1])];
|
|
74
76
|
}
|
|
75
|
-
|
|
77
|
+
Vec2.ceil = ceil;
|
|
76
78
|
function round(v) {
|
|
77
79
|
return [Math.round(v[0]), Math.round(v[1])];
|
|
78
80
|
}
|
|
79
|
-
|
|
81
|
+
Vec2.round = round;
|
|
80
82
|
function min(a, b) {
|
|
81
83
|
return [Math.min(a[0], b[0]), Math.min(a[1], b[1])];
|
|
82
84
|
}
|
|
83
|
-
|
|
85
|
+
Vec2.min = min;
|
|
84
86
|
function max(a, b) {
|
|
85
87
|
return [Math.max(a[0], b[0]), Math.max(a[1], b[1])];
|
|
86
88
|
}
|
|
87
|
-
|
|
89
|
+
Vec2.max = max;
|
|
88
90
|
function clamp(v, min, max) {
|
|
89
91
|
return [
|
|
90
92
|
Math.max(min[0], Math.min(v[0], max[0])),
|
|
91
93
|
Math.max(min[1], Math.min(v[1], max[1])),
|
|
92
94
|
];
|
|
93
95
|
}
|
|
94
|
-
|
|
96
|
+
Vec2.clamp = clamp;
|
|
95
97
|
function fromAngle(angle, len = 1) {
|
|
96
98
|
return [Math.cos(angle) * len, Math.sin(angle) * len];
|
|
97
99
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
V2.right = [1, 0];
|
|
105
|
-
})(V2 || (V2 = {}));
|
|
100
|
+
Vec2.fromAngle = fromAngle;
|
|
101
|
+
function zero() {
|
|
102
|
+
return [0, 0];
|
|
103
|
+
}
|
|
104
|
+
Vec2.zero = zero;
|
|
105
|
+
})(Vec2 || (Vec2 = {}));
|
package/dist/engine.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Graphics } from './core/graphics';
|
|
2
|
+
import type { Audio } from './core/audio';
|
|
3
|
+
import type { Input } from './core/input';
|
|
4
|
+
import type { Timer } from './core/timer';
|
|
5
|
+
import type { Keyboard } from './core/keyboard';
|
|
6
|
+
import type { Mouse } from './core/mouse';
|
|
7
|
+
import type { Gamepad } from './core/gamepad';
|
|
8
|
+
import type { Like2DEvent } from './core/events';
|
|
9
|
+
import type { CanvasConfig } from './core/canvas-config';
|
|
10
|
+
export type EngineDeps = {
|
|
11
|
+
graphics: Graphics;
|
|
12
|
+
input: Input;
|
|
13
|
+
timer: Timer;
|
|
14
|
+
audio: Audio;
|
|
15
|
+
keyboard: Keyboard;
|
|
16
|
+
mouse: Mouse;
|
|
17
|
+
gamepad: Gamepad;
|
|
18
|
+
};
|
|
19
|
+
export declare class Engine {
|
|
20
|
+
private canvas;
|
|
21
|
+
private ctx;
|
|
22
|
+
private deps;
|
|
23
|
+
private isRunning;
|
|
24
|
+
private lastTime;
|
|
25
|
+
private container;
|
|
26
|
+
private canvasManager;
|
|
27
|
+
private onEvent;
|
|
28
|
+
constructor(container: HTMLElement);
|
|
29
|
+
setScaling(config: CanvasConfig): void;
|
|
30
|
+
setDeps(deps: EngineDeps): void;
|
|
31
|
+
dispose(): void;
|
|
32
|
+
private dispatchEvent;
|
|
33
|
+
start(onEvent: (event: Like2DEvent) => void): void;
|
|
34
|
+
stop(): void;
|
|
35
|
+
setSize(width: number, height: number): void;
|
|
36
|
+
getTime(): number;
|
|
37
|
+
getCanvas(): HTMLCanvasElement;
|
|
38
|
+
getContext(): CanvasRenderingContext2D;
|
|
39
|
+
transformMousePosition(cssX: number, cssY: number): [number, number];
|
|
40
|
+
toggleFullscreen(): void;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAa,MAAM,eAAe,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGzD,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,EAAE,QAAQ,CAAC;IACnB,KAAK,EAAE,KAAK,CAAC;IACb,KAAK,EAAE,KAAK,CAAC;IACb,KAAK,EAAE,KAAK,CAAC;IACb,QAAQ,EAAE,QAAQ,CAAC;IACnB,KAAK,EAAE,KAAK,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,qBAAa,MAAM;IACjB,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,GAAG,CAA2B;IACtC,OAAO,CAAC,IAAI,CAA2B;IACvC,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,QAAQ,CAAK;IACrB,OAAO,CAAC,SAAS,CAAc;IAC/B,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,OAAO,CAA+C;gBAElD,SAAS,EAAE,WAAW;IAmBlC,UAAU,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI;IAItC,OAAO,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI;IAI/B,OAAO,IAAI,IAAI;IAWf,OAAO,CAAC,aAAa;IAMrB,KAAK,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI;IA+C3C,IAAI;IAIJ,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAKrC,OAAO,IAAI,MAAM;IAIjB,SAAS,IAAI,iBAAiB;IAI9B,UAAU,IAAI,wBAAwB;IAItC,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;IAIpE,gBAAgB,IAAI,IAAI;CAOzB"}
|
package/dist/engine.js
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { CanvasManager } from './core/canvas-manager';
|
|
2
|
+
export class Engine {
|
|
3
|
+
constructor(container) {
|
|
4
|
+
Object.defineProperty(this, "canvas", {
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true,
|
|
8
|
+
value: void 0
|
|
9
|
+
});
|
|
10
|
+
Object.defineProperty(this, "ctx", {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
writable: true,
|
|
14
|
+
value: void 0
|
|
15
|
+
});
|
|
16
|
+
Object.defineProperty(this, "deps", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
configurable: true,
|
|
19
|
+
writable: true,
|
|
20
|
+
value: null
|
|
21
|
+
});
|
|
22
|
+
Object.defineProperty(this, "isRunning", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
writable: true,
|
|
26
|
+
value: false
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(this, "lastTime", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
configurable: true,
|
|
31
|
+
writable: true,
|
|
32
|
+
value: 0
|
|
33
|
+
});
|
|
34
|
+
Object.defineProperty(this, "container", {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
configurable: true,
|
|
37
|
+
writable: true,
|
|
38
|
+
value: void 0
|
|
39
|
+
});
|
|
40
|
+
Object.defineProperty(this, "canvasManager", {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
configurable: true,
|
|
43
|
+
writable: true,
|
|
44
|
+
value: void 0
|
|
45
|
+
});
|
|
46
|
+
Object.defineProperty(this, "onEvent", {
|
|
47
|
+
enumerable: true,
|
|
48
|
+
configurable: true,
|
|
49
|
+
writable: true,
|
|
50
|
+
value: null
|
|
51
|
+
});
|
|
52
|
+
this.canvas = document.createElement('canvas');
|
|
53
|
+
this.canvas.style.border = '1px solid #ccc';
|
|
54
|
+
this.canvas.style.display = 'block';
|
|
55
|
+
const ctx = this.canvas.getContext('2d');
|
|
56
|
+
if (!ctx)
|
|
57
|
+
throw new Error('Failed to get 2D context');
|
|
58
|
+
this.ctx = ctx;
|
|
59
|
+
this.container = container;
|
|
60
|
+
this.container.appendChild(this.canvas);
|
|
61
|
+
this.canvasManager = new CanvasManager(this.canvas, this.container, this.ctx, { mode: 'native' });
|
|
62
|
+
// Internal listener to forward to onEvent
|
|
63
|
+
this.canvasManager.onResize = (size, pixelSize, fullscreen) => {
|
|
64
|
+
this.dispatchEvent('resize', [size, pixelSize, fullscreen]);
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
setScaling(config) {
|
|
68
|
+
this.canvasManager.setConfig(config);
|
|
69
|
+
}
|
|
70
|
+
setDeps(deps) {
|
|
71
|
+
this.deps = deps;
|
|
72
|
+
}
|
|
73
|
+
dispose() {
|
|
74
|
+
this.isRunning = false;
|
|
75
|
+
this.deps?.keyboard.dispose();
|
|
76
|
+
this.deps?.mouse.dispose();
|
|
77
|
+
this.deps?.gamepad.dispose();
|
|
78
|
+
this.canvasManager.dispose();
|
|
79
|
+
if (this.canvas.parentNode === this.container) {
|
|
80
|
+
this.container.removeChild(this.canvas);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
dispatchEvent(type, args) {
|
|
84
|
+
if (this.onEvent) {
|
|
85
|
+
this.onEvent({ type, args, timestamp: performance.now() });
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
start(onEvent) {
|
|
89
|
+
if (!this.deps)
|
|
90
|
+
throw new Error('Engine dependencies not set. Call setDeps() before start().');
|
|
91
|
+
this.onEvent = onEvent;
|
|
92
|
+
this.isRunning = true;
|
|
93
|
+
this.lastTime = performance.now();
|
|
94
|
+
// Listeners for raw input
|
|
95
|
+
this.deps.keyboard.onKeyEvent = (scancode, keycode, type) => {
|
|
96
|
+
this.dispatchEvent(type === 'keydown' ? 'keypressed' : 'keyreleased', [scancode, keycode]);
|
|
97
|
+
};
|
|
98
|
+
this.deps.mouse.onMouseEvent = (clientX, clientY, button, type) => {
|
|
99
|
+
const [x, y] = this.transformMousePosition(clientX, clientY);
|
|
100
|
+
const b = (button ?? 0) + 1;
|
|
101
|
+
this.dispatchEvent(type === 'mousedown' ? 'mousepressed' : 'mousereleased', [x, y, b]);
|
|
102
|
+
};
|
|
103
|
+
this.deps.gamepad.onButtonEvent = (gpIndex, buttonIndex, buttonName, pressed) => {
|
|
104
|
+
this.dispatchEvent(pressed ? 'gamepadpressed' : 'gamepadreleased', [gpIndex, buttonIndex, buttonName]);
|
|
105
|
+
};
|
|
106
|
+
const loop = () => {
|
|
107
|
+
if (!this.isRunning)
|
|
108
|
+
return;
|
|
109
|
+
const currentTime = performance.now();
|
|
110
|
+
const dt = (currentTime - this.lastTime) / 1000;
|
|
111
|
+
this.lastTime = currentTime;
|
|
112
|
+
if (!this.deps.timer.isSleeping()) {
|
|
113
|
+
this.deps.timer.update(dt);
|
|
114
|
+
const inputEvents = this.deps.input.update();
|
|
115
|
+
inputEvents.pressed.forEach(action => this.dispatchEvent('actionpressed', [action]));
|
|
116
|
+
inputEvents.released.forEach(action => this.dispatchEvent('actionreleased', [action]));
|
|
117
|
+
this.dispatchEvent('update', [dt]);
|
|
118
|
+
}
|
|
119
|
+
this.deps.graphics.clear();
|
|
120
|
+
this.dispatchEvent('draw', [this.canvas]);
|
|
121
|
+
this.canvasManager.present();
|
|
122
|
+
requestAnimationFrame(loop);
|
|
123
|
+
};
|
|
124
|
+
this.dispatchEvent('load', []);
|
|
125
|
+
requestAnimationFrame(loop);
|
|
126
|
+
}
|
|
127
|
+
stop() {
|
|
128
|
+
this.isRunning = false;
|
|
129
|
+
}
|
|
130
|
+
setSize(width, height) {
|
|
131
|
+
this.canvas.width = width;
|
|
132
|
+
this.canvas.height = height;
|
|
133
|
+
}
|
|
134
|
+
getTime() {
|
|
135
|
+
return this.deps?.timer.getTime() ?? 0;
|
|
136
|
+
}
|
|
137
|
+
getCanvas() {
|
|
138
|
+
return this.canvas;
|
|
139
|
+
}
|
|
140
|
+
getContext() {
|
|
141
|
+
return this.ctx;
|
|
142
|
+
}
|
|
143
|
+
transformMousePosition(cssX, cssY) {
|
|
144
|
+
return this.canvasManager.transformMousePosition(cssX, cssY);
|
|
145
|
+
}
|
|
146
|
+
toggleFullscreen() {
|
|
147
|
+
if (!document.fullscreenElement) {
|
|
148
|
+
this.container.requestFullscreen().catch(console.error);
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
document.exitFullscreen();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,45 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
export
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
export {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
export {
|
|
38
|
-
export {
|
|
39
|
-
export type { StickPosition } from './gamepad';
|
|
40
|
-
export type { Vector2 } from './vector2';
|
|
41
|
-
export { V2 } from './vector2';
|
|
42
|
-
export type { Rect } from './rect';
|
|
43
|
-
export { R } from './rect';
|
|
44
|
-
export type { Event } from './events';
|
|
1
|
+
/**
|
|
2
|
+
* 2D vector as a tuple: [x, y]
|
|
3
|
+
*/
|
|
4
|
+
export type { Vector2 } from './core/vector2';
|
|
5
|
+
/**
|
|
6
|
+
* 2D vector math and utility functions
|
|
7
|
+
*/
|
|
8
|
+
export { Vec2 } from './core/vector2';
|
|
9
|
+
/**
|
|
10
|
+
* Rectangle math and utility functions.
|
|
11
|
+
* Rects are represented as [x, y, width, height] tuples.
|
|
12
|
+
*/
|
|
13
|
+
export { Rect } from './core/rect';
|
|
14
|
+
/**
|
|
15
|
+
* Common event structure for all engine events.
|
|
16
|
+
*/
|
|
17
|
+
export type { Like2DEvent, EventType } from './core/events';
|
|
18
|
+
/**
|
|
19
|
+
* Graphics types for drawing operations.
|
|
20
|
+
*/
|
|
21
|
+
export type { Color, Quad, ShapeProps, DrawProps, PrintProps } from './core/graphics';
|
|
22
|
+
/**
|
|
23
|
+
* Handle to an image asset that may be loading in the background.
|
|
24
|
+
*/
|
|
25
|
+
export { ImageHandle } from './core/graphics';
|
|
26
|
+
/**
|
|
27
|
+
* Audio source types for sound playback.
|
|
28
|
+
*/
|
|
29
|
+
export type { Source, SourceOptions } from './core/audio';
|
|
30
|
+
/**
|
|
31
|
+
* Core Scene interface for class-based game architecture.
|
|
32
|
+
*/
|
|
33
|
+
export type { Scene } from './adapters/scene/scene';
|
|
34
|
+
/**
|
|
35
|
+
* Gamepad utility functions and types.
|
|
36
|
+
*/
|
|
37
|
+
export { getGPName, GP } from './core/gamepad';
|
|
38
|
+
export type { StickPosition } from './core/gamepad';
|
|
45
39
|
//# 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":"AAKA;;GAEG;AACH,YAAY,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;GAEG;AACH,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEtC;;;GAGG;AACH,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAEnC;;GAEG;AACH,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE5D;;GAEG;AACH,YAAY,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAEtF;;GAEG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C;;GAEG;AACH,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE1D;;GAEG;AACH,YAAY,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAEpD;;GAEG;AACH,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAC/C,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC"}
|