like2d 2.7.4 → 2.9.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 +34 -35
- package/dist/core/audio.d.ts +12 -9
- package/dist/core/audio.d.ts.map +1 -1
- package/dist/core/audio.js +7 -4
- package/dist/core/canvas.d.ts +58 -0
- package/dist/core/canvas.d.ts.map +1 -0
- package/dist/core/canvas.js +209 -0
- package/dist/core/events.d.ts +92 -7
- package/dist/core/events.d.ts.map +1 -1
- package/dist/core/events.js +20 -0
- package/dist/core/gamepad-mapping.d.ts +57 -18
- package/dist/core/gamepad-mapping.d.ts.map +1 -1
- package/dist/core/gamepad-mapping.js +23 -223
- package/dist/core/gamepad.d.ts +34 -58
- package/dist/core/gamepad.d.ts.map +1 -1
- package/dist/core/gamepad.js +79 -213
- package/dist/core/graphics.d.ts +175 -64
- package/dist/core/graphics.d.ts.map +1 -1
- package/dist/core/graphics.js +294 -198
- package/dist/core/input-state.d.ts +2 -2
- package/dist/core/input-state.d.ts.map +1 -1
- package/dist/core/input.d.ts +22 -15
- package/dist/core/input.d.ts.map +1 -1
- package/dist/core/input.js +25 -37
- package/dist/core/keyboard.d.ts +7 -7
- package/dist/core/keyboard.d.ts.map +1 -1
- package/dist/core/keyboard.js +24 -31
- package/dist/core/like.d.ts +98 -44
- package/dist/core/like.d.ts.map +1 -1
- package/dist/core/like.js +8 -0
- package/dist/core/mouse.d.ts +45 -22
- package/dist/core/mouse.d.ts.map +1 -1
- package/dist/core/mouse.js +90 -78
- package/dist/core/timer.d.ts +2 -5
- package/dist/core/timer.d.ts.map +1 -1
- package/dist/core/timer.js +2 -14
- package/dist/engine.d.ts +61 -11
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +119 -102
- package/dist/index.d.ts +42 -21
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +35 -14
- package/dist/math/index.d.ts +2 -0
- package/dist/math/index.d.ts.map +1 -0
- package/dist/math/index.js +1 -0
- package/dist/math/rect.d.ts +71 -0
- package/dist/math/rect.d.ts.map +1 -0
- package/dist/{core → math}/rect.js +8 -0
- package/dist/math/vector2.d.ts +78 -0
- package/dist/math/vector2.d.ts.map +1 -0
- package/dist/{core → math}/vector2.js +24 -0
- package/dist/prefab-scenes/index.d.ts +7 -0
- package/dist/prefab-scenes/index.d.ts.map +1 -0
- package/dist/prefab-scenes/index.js +6 -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} +47 -7
- package/dist/scene.d.ts +103 -5
- package/dist/scene.d.ts.map +1 -1
- package/dist/scene.js +28 -1
- package/package.json +18 -2
- 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 -25
- package/dist/core/canvas-manager.d.ts.map +0 -1
- package/dist/core/canvas-manager.js +0 -178
- 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/rect.d.ts +0 -26
- package/dist/core/rect.d.ts.map +0 -1
- package/dist/core/vector2.d.ts +0 -26
- package/dist/core/vector2.d.ts.map +0 -1
- package/dist/gamecontrollerdb.txt +0 -2221
- package/dist/scenes/startup.d.ts +0 -18
- package/dist/scenes/startup.d.ts.map +0 -1
package/dist/scene.js
CHANGED
|
@@ -1 +1,28 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @module scene
|
|
3
|
+
* @description A helpful callback / state management layer, plus utility scenes.
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Used to call a scene's own handlers like `update` or `draw`,
|
|
8
|
+
* typically at the end of handleEvent
|
|
9
|
+
* after modifying the event stream or composing sub-scenes.
|
|
10
|
+
*/
|
|
11
|
+
export const callSceneHandlers = (scene, like, event) => {
|
|
12
|
+
if (event.type in scene) {
|
|
13
|
+
scene[event.type](like, ...event.args);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Used to call sub scenes while respecting potential `handleEvent` within them.
|
|
18
|
+
* The main scene is similar to a sub-scene of the root (like) object in this
|
|
19
|
+
* regard.
|
|
20
|
+
*/
|
|
21
|
+
export const sceneDispatch = (scene, like, event) => {
|
|
22
|
+
if (scene.handleEvent) {
|
|
23
|
+
scene.handleEvent(like, event);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
callSceneHandlers(scene, like, event);
|
|
27
|
+
}
|
|
28
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "like2d",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.0",
|
|
4
4
|
"description": "A web-native game framework inspired by Love2D",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -10,6 +10,22 @@
|
|
|
10
10
|
".": {
|
|
11
11
|
"import": "./dist/index.js",
|
|
12
12
|
"types": "./dist/index.d.ts"
|
|
13
|
+
},
|
|
14
|
+
"./scene": {
|
|
15
|
+
"import": "./dist/scene.js",
|
|
16
|
+
"types": "./dist/scene.d.ts"
|
|
17
|
+
},
|
|
18
|
+
"./math/*": {
|
|
19
|
+
"import": "./dist/math/*.js",
|
|
20
|
+
"types": "./dist/math/*.d.ts"
|
|
21
|
+
},
|
|
22
|
+
"./prefab-scenes": {
|
|
23
|
+
"import": "./dist/prefab-scenes/index.js",
|
|
24
|
+
"types": "./dist/prefab-scenes/index.d.ts"
|
|
25
|
+
},
|
|
26
|
+
"./internal/*": {
|
|
27
|
+
"import": "./dist/core/*.js",
|
|
28
|
+
"types": "./dist/core/*.d.ts"
|
|
13
29
|
}
|
|
14
30
|
},
|
|
15
31
|
"files": [
|
|
@@ -19,7 +35,7 @@
|
|
|
19
35
|
"LICENSE"
|
|
20
36
|
],
|
|
21
37
|
"scripts": {
|
|
22
|
-
"build": "tsc
|
|
38
|
+
"build": "tsc",
|
|
23
39
|
"typecheck": "tsc --noEmit",
|
|
24
40
|
"lint": "echo 'No linting configured'",
|
|
25
41
|
"clean": "rm -rf dist",
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { Vector2 } from './vector2';
|
|
2
|
-
export type CanvasMode = {
|
|
3
|
-
pixelResolution: Vector2 | null;
|
|
4
|
-
fullscreen: boolean;
|
|
5
|
-
};
|
|
6
|
-
export type PartialCanvasMode = {
|
|
7
|
-
pixelResolution?: Vector2 | null;
|
|
8
|
-
fullscreen?: boolean;
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* Calculate the scale and offset for rendering fixed-size content to a target canvas.
|
|
12
|
-
* This is useful when you want to render in "native" mode but maintain a fixed game resolution.
|
|
13
|
-
*
|
|
14
|
-
* @param canvasSize - The actual canvas size in pixels
|
|
15
|
-
* @param gameSize - The desired game resolution (fixed size)
|
|
16
|
-
* @returns Object containing the scale factor and offset for centering
|
|
17
|
-
*/
|
|
18
|
-
export declare function calcFixedScale(canvasSize: Vector2, gameSize: Vector2): {
|
|
19
|
-
scale: number;
|
|
20
|
-
offset: Vector2;
|
|
21
|
-
};
|
|
22
|
-
//# sourceMappingURL=canvas-config.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"canvas-config.d.ts","sourceRoot":"","sources":["../../src/core/canvas-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,MAAM,MAAM,UAAU,GAAG;IACvB,eAAe,EAAE,OAAO,GAAG,IAAI,CAAC;IAChC,UAAU,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,eAAe,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IACjC,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,CAKzG"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Calculate the scale and offset for rendering fixed-size content to a target canvas.
|
|
3
|
-
* This is useful when you want to render in "native" mode but maintain a fixed game resolution.
|
|
4
|
-
*
|
|
5
|
-
* @param canvasSize - The actual canvas size in pixels
|
|
6
|
-
* @param gameSize - The desired game resolution (fixed size)
|
|
7
|
-
* @returns Object containing the scale factor and offset for centering
|
|
8
|
-
*/
|
|
9
|
-
export function calcFixedScale(canvasSize, gameSize) {
|
|
10
|
-
const scale = Math.min(canvasSize[0] / gameSize[0], canvasSize[1] / gameSize[1]);
|
|
11
|
-
const scaledGame = [gameSize[0] * scale, gameSize[1] * scale];
|
|
12
|
-
const offset = [(canvasSize[0] - scaledGame[0]) * 0.5, (canvasSize[1] - scaledGame[1]) * 0.5];
|
|
13
|
-
return { scale, offset };
|
|
14
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { CanvasMode, PartialCanvasMode } from './canvas-config';
|
|
2
|
-
import { type Vector2 } from './vector2';
|
|
3
|
-
export declare class CanvasManager {
|
|
4
|
-
private canvas;
|
|
5
|
-
private container;
|
|
6
|
-
private ctx;
|
|
7
|
-
private config;
|
|
8
|
-
private resizeObserver;
|
|
9
|
-
private pixelCanvas;
|
|
10
|
-
private pixelCtx;
|
|
11
|
-
private onWindowResize;
|
|
12
|
-
onResize: ((size: Vector2, pixelSize: Vector2, fullscreen: boolean) => void) | null;
|
|
13
|
-
constructor(canvas: HTMLCanvasElement, container: HTMLElement, ctx: CanvasRenderingContext2D, config?: CanvasMode);
|
|
14
|
-
private listenForPixelRatioChanges;
|
|
15
|
-
setMode(mode: PartialCanvasMode): void;
|
|
16
|
-
getMode(): CanvasMode;
|
|
17
|
-
private applyConfig;
|
|
18
|
-
private applyPixelMode;
|
|
19
|
-
private applyNativeMode;
|
|
20
|
-
dispose(): void;
|
|
21
|
-
present(): void;
|
|
22
|
-
getDisplayCanvas(): HTMLCanvasElement;
|
|
23
|
-
transformMousePosition(cssX: number, cssY: number): Vector2;
|
|
24
|
-
}
|
|
25
|
-
//# sourceMappingURL=canvas-manager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"canvas-manager.d.ts","sourceRoot":"","sources":["../../src/core/canvas-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAQ,KAAK,OAAO,EAAE,MAAM,WAAW,CAAC;AAmB/C,qBAAa,aAAa;IAUtB,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,GAAG;IACX,OAAO,CAAC,MAAM;IAZhB,OAAO,CAAC,cAAc,CAA+B;IACrD,OAAO,CAAC,WAAW,CAAkC;IACrD,OAAO,CAAC,QAAQ,CAAyC;IAEzD,OAAO,CAAC,cAAc,CAA4B;IAE3C,QAAQ,EAAE,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,KAAK,IAAI,CAAC,GAAG,IAAI,CAAQ;gBAGxF,MAAM,EAAE,iBAAiB,EACzB,SAAS,EAAE,WAAW,EACtB,GAAG,EAAE,wBAAwB,EAC7B,MAAM,GAAE,UAAyD;IAW3E,OAAO,CAAC,0BAA0B;IAQlC,OAAO,CAAC,IAAI,EAAE,iBAAiB,GAAG,IAAI;IAKtC,OAAO,IAAI,UAAU;IAIrB,OAAO,CAAC,WAAW;IA2BnB,OAAO,CAAC,cAAc;IAwBtB,OAAO,CAAC,eAAe;IAkBvB,OAAO,IAAI,IAAI;IAQf,OAAO,IAAI,IAAI;IAaf,gBAAgB,IAAI,iBAAiB;IAIrC,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO;CAiB5D"}
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import { Vec2 } from './vector2';
|
|
2
|
-
function setCanvasSize(canvas, size) {
|
|
3
|
-
canvas.width = size[0];
|
|
4
|
-
canvas.height = size[1];
|
|
5
|
-
}
|
|
6
|
-
function setCanvasDisplaySize(canvas, size) {
|
|
7
|
-
canvas.style.width = `${size[0]}px`;
|
|
8
|
-
canvas.style.height = `${size[1]}px`;
|
|
9
|
-
}
|
|
10
|
-
function centerElement(el) {
|
|
11
|
-
el.style.position = 'absolute';
|
|
12
|
-
el.style.left = '50%';
|
|
13
|
-
el.style.top = '50%';
|
|
14
|
-
el.style.transform = 'translate(-50%, -50%)';
|
|
15
|
-
}
|
|
16
|
-
export class CanvasManager {
|
|
17
|
-
constructor(canvas, container, ctx, config = { pixelResolution: null, fullscreen: false }) {
|
|
18
|
-
Object.defineProperty(this, "canvas", {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
configurable: true,
|
|
21
|
-
writable: true,
|
|
22
|
-
value: canvas
|
|
23
|
-
});
|
|
24
|
-
Object.defineProperty(this, "container", {
|
|
25
|
-
enumerable: true,
|
|
26
|
-
configurable: true,
|
|
27
|
-
writable: true,
|
|
28
|
-
value: container
|
|
29
|
-
});
|
|
30
|
-
Object.defineProperty(this, "ctx", {
|
|
31
|
-
enumerable: true,
|
|
32
|
-
configurable: true,
|
|
33
|
-
writable: true,
|
|
34
|
-
value: ctx
|
|
35
|
-
});
|
|
36
|
-
Object.defineProperty(this, "config", {
|
|
37
|
-
enumerable: true,
|
|
38
|
-
configurable: true,
|
|
39
|
-
writable: true,
|
|
40
|
-
value: config
|
|
41
|
-
});
|
|
42
|
-
Object.defineProperty(this, "resizeObserver", {
|
|
43
|
-
enumerable: true,
|
|
44
|
-
configurable: true,
|
|
45
|
-
writable: true,
|
|
46
|
-
value: null
|
|
47
|
-
});
|
|
48
|
-
Object.defineProperty(this, "pixelCanvas", {
|
|
49
|
-
enumerable: true,
|
|
50
|
-
configurable: true,
|
|
51
|
-
writable: true,
|
|
52
|
-
value: null
|
|
53
|
-
});
|
|
54
|
-
Object.defineProperty(this, "pixelCtx", {
|
|
55
|
-
enumerable: true,
|
|
56
|
-
configurable: true,
|
|
57
|
-
writable: true,
|
|
58
|
-
value: null
|
|
59
|
-
});
|
|
60
|
-
Object.defineProperty(this, "onWindowResize", {
|
|
61
|
-
enumerable: true,
|
|
62
|
-
configurable: true,
|
|
63
|
-
writable: true,
|
|
64
|
-
value: () => this.applyConfig()
|
|
65
|
-
});
|
|
66
|
-
Object.defineProperty(this, "onResize", {
|
|
67
|
-
enumerable: true,
|
|
68
|
-
configurable: true,
|
|
69
|
-
writable: true,
|
|
70
|
-
value: null
|
|
71
|
-
});
|
|
72
|
-
this.resizeObserver = new ResizeObserver(() => this.applyConfig());
|
|
73
|
-
this.resizeObserver.observe(this.container);
|
|
74
|
-
window.addEventListener('resize', this.onWindowResize);
|
|
75
|
-
this.listenForPixelRatioChanges();
|
|
76
|
-
this.applyConfig();
|
|
77
|
-
}
|
|
78
|
-
listenForPixelRatioChanges() {
|
|
79
|
-
const media = window.matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`);
|
|
80
|
-
media.addEventListener('change', () => {
|
|
81
|
-
this.applyConfig();
|
|
82
|
-
this.listenForPixelRatioChanges();
|
|
83
|
-
}, { once: true });
|
|
84
|
-
}
|
|
85
|
-
setMode(mode) {
|
|
86
|
-
this.config = { ...this.config, ...mode };
|
|
87
|
-
this.applyConfig();
|
|
88
|
-
}
|
|
89
|
-
getMode() {
|
|
90
|
-
return { ...this.config };
|
|
91
|
-
}
|
|
92
|
-
applyConfig() {
|
|
93
|
-
const containerSize = document.fullscreenElement
|
|
94
|
-
? [document.fullscreenElement.clientWidth, document.fullscreenElement.clientHeight]
|
|
95
|
-
: [this.container.clientWidth, this.container.clientHeight];
|
|
96
|
-
// Always clean up pixel canvas first
|
|
97
|
-
if (this.pixelCanvas) {
|
|
98
|
-
this.pixelCanvas.remove();
|
|
99
|
-
this.pixelCanvas = null;
|
|
100
|
-
this.pixelCtx = null;
|
|
101
|
-
}
|
|
102
|
-
if (this.config.pixelResolution) {
|
|
103
|
-
this.applyPixelMode(containerSize);
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
this.applyNativeMode(containerSize);
|
|
107
|
-
}
|
|
108
|
-
const displayCanvas = this.pixelCanvas ?? this.canvas;
|
|
109
|
-
this.onResize?.(containerSize, [displayCanvas.width, displayCanvas.height], this.config.fullscreen);
|
|
110
|
-
}
|
|
111
|
-
applyPixelMode(csize) {
|
|
112
|
-
const gameSize = this.config.pixelResolution;
|
|
113
|
-
const pixelRatio = window.devicePixelRatio || 1;
|
|
114
|
-
const scale = Math.min(csize[0] / gameSize[0], csize[1] / gameSize[1]);
|
|
115
|
-
const physicalScale = scale * pixelRatio;
|
|
116
|
-
const intScale = Math.max(1, Math.floor(physicalScale));
|
|
117
|
-
this.pixelCanvas = document.createElement('canvas');
|
|
118
|
-
this.pixelCtx = this.pixelCanvas.getContext('2d');
|
|
119
|
-
setCanvasSize(this.pixelCanvas, Vec2.mul(gameSize, intScale));
|
|
120
|
-
setCanvasSize(this.canvas, gameSize);
|
|
121
|
-
this.canvas.style.display = 'none';
|
|
122
|
-
const pc = this.pixelCanvas;
|
|
123
|
-
setCanvasDisplaySize(pc, Vec2.mul(gameSize, scale));
|
|
124
|
-
pc.style.maxWidth = '100%';
|
|
125
|
-
pc.style.maxHeight = '100%';
|
|
126
|
-
pc.style.imageRendering = 'auto';
|
|
127
|
-
centerElement(pc);
|
|
128
|
-
this.container.appendChild(pc);
|
|
129
|
-
}
|
|
130
|
-
applyNativeMode(csize) {
|
|
131
|
-
const pixelRatio = window.devicePixelRatio || 1;
|
|
132
|
-
const canvasSize = Vec2.mul(csize, pixelRatio);
|
|
133
|
-
setCanvasSize(this.canvas, Vec2.floor(canvasSize));
|
|
134
|
-
setCanvasDisplaySize(this.canvas, csize);
|
|
135
|
-
this.canvas.style.position = 'absolute';
|
|
136
|
-
this.canvas.style.left = '0';
|
|
137
|
-
this.canvas.style.top = '0';
|
|
138
|
-
this.canvas.style.transform = 'none';
|
|
139
|
-
this.canvas.style.margin = '0';
|
|
140
|
-
this.canvas.style.display = 'block';
|
|
141
|
-
this.canvas.style.imageRendering = 'auto';
|
|
142
|
-
this.ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
143
|
-
}
|
|
144
|
-
dispose() {
|
|
145
|
-
this.resizeObserver?.disconnect();
|
|
146
|
-
window.removeEventListener('resize', this.onWindowResize);
|
|
147
|
-
this.pixelCanvas?.remove();
|
|
148
|
-
this.pixelCanvas = null;
|
|
149
|
-
this.pixelCtx = null;
|
|
150
|
-
}
|
|
151
|
-
present() {
|
|
152
|
-
if (!this.pixelCtx || !this.pixelCanvas) {
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
this.pixelCtx.imageSmoothingEnabled = false;
|
|
156
|
-
this.pixelCtx.drawImage(this.canvas, 0, 0, this.canvas.width, this.canvas.height, 0, 0, this.pixelCanvas.width, this.pixelCanvas.height);
|
|
157
|
-
}
|
|
158
|
-
getDisplayCanvas() {
|
|
159
|
-
return this.pixelCanvas ?? this.canvas;
|
|
160
|
-
}
|
|
161
|
-
transformMousePosition(cssX, cssY) {
|
|
162
|
-
const displayCanvas = this.getDisplayCanvas();
|
|
163
|
-
const rect = displayCanvas.getBoundingClientRect();
|
|
164
|
-
const relative = [cssX - rect.left, cssY - rect.top];
|
|
165
|
-
if (this.config.pixelResolution) {
|
|
166
|
-
// In pixel mode: CSS position (as fraction of CSS size) × game size = game position
|
|
167
|
-
const gameSize = this.config.pixelResolution;
|
|
168
|
-
return Vec2.mul(relative, [gameSize[0] / rect.width, gameSize[1] / rect.height]);
|
|
169
|
-
}
|
|
170
|
-
else {
|
|
171
|
-
// In native mode, canvas fills the container completely at position 0,0
|
|
172
|
-
// Mouse coordinates should be relative to the canvas, accounting for the fact
|
|
173
|
-
// that the canvas internal pixel size != CSS size
|
|
174
|
-
const pixelRatio = window.devicePixelRatio || 1;
|
|
175
|
-
return Vec2.mul(relative, pixelRatio);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export declare namespace GP {
|
|
2
|
-
const Bottom = 0;
|
|
3
|
-
const Right = 1;
|
|
4
|
-
const Left = 2;
|
|
5
|
-
const Top = 3;
|
|
6
|
-
const LB = 4;
|
|
7
|
-
const RB = 5;
|
|
8
|
-
const LT = 6;
|
|
9
|
-
const RT = 7;
|
|
10
|
-
const Back = 8;
|
|
11
|
-
const Start = 9;
|
|
12
|
-
const Guide = 10;
|
|
13
|
-
const LS = 11;
|
|
14
|
-
const RS = 12;
|
|
15
|
-
const DUp = 13;
|
|
16
|
-
const DDown = 14;
|
|
17
|
-
const DLeft = 15;
|
|
18
|
-
const DRight = 16;
|
|
19
|
-
}
|
|
20
|
-
export declare const GP_NAMES: Record<number, string>;
|
|
21
|
-
export declare const GP_NAME_MAP: Record<string, number>;
|
|
22
|
-
export declare function getGPName(buttonIndex: number): string;
|
|
23
|
-
//# sourceMappingURL=gamepad-buttons.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"gamepad-buttons.d.ts","sourceRoot":"","sources":["../../src/core/gamepad-buttons.ts"],"names":[],"mappings":"AAGA,yBAAiB,EAAE,CAAC;IAEX,MAAM,MAAM,IAAI,CAAC;IACjB,MAAM,KAAK,IAAI,CAAC;IAChB,MAAM,IAAI,IAAI,CAAC;IACf,MAAM,GAAG,IAAI,CAAC;IAGd,MAAM,EAAE,IAAI,CAAC;IACb,MAAM,EAAE,IAAI,CAAC;IACb,MAAM,EAAE,IAAI,CAAC;IACb,MAAM,EAAE,IAAI,CAAC;IAGb,MAAM,IAAI,IAAI,CAAC;IACf,MAAM,KAAK,IAAI,CAAC;IAChB,MAAM,KAAK,KAAK,CAAC;IAGjB,MAAM,EAAE,KAAK,CAAC;IACd,MAAM,EAAE,KAAK,CAAC;IAGd,MAAM,GAAG,KAAK,CAAC;IACf,MAAM,KAAK,KAAK,CAAC;IACjB,MAAM,KAAK,KAAK,CAAC;IACjB,MAAM,MAAM,KAAK,CAAC;CAC1B;AAMD,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAE3C,CAAC;AAGF,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAkC,CAAC;AAElF,wBAAgB,SAAS,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAErD"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
// Gamepad button constants
|
|
2
|
-
// Use these constants instead of magic numbers
|
|
3
|
-
export var GP;
|
|
4
|
-
(function (GP) {
|
|
5
|
-
// Face buttons (physical positions)
|
|
6
|
-
GP.Bottom = 0; // A on Xbox, X on PlayStation, B on Nintendo
|
|
7
|
-
GP.Right = 1; // B on Xbox, O on PlayStation, A on Nintendo
|
|
8
|
-
GP.Left = 2; // X on Xbox, □ on PlayStation, Y on Nintendo
|
|
9
|
-
GP.Top = 3; // Y on Xbox, △ on PlayStation, X on Nintendo
|
|
10
|
-
// Bumpers and triggers
|
|
11
|
-
GP.LB = 4; // Left bumper (L1)
|
|
12
|
-
GP.RB = 5; // Right bumper (R1)
|
|
13
|
-
GP.LT = 6; // Left trigger (L2)
|
|
14
|
-
GP.RT = 7; // Right trigger (R2)
|
|
15
|
-
// Menu buttons
|
|
16
|
-
GP.Back = 8; // Select/Back/Minus
|
|
17
|
-
GP.Start = 9; // Start/Plus
|
|
18
|
-
GP.Guide = 10; // Home/Guide button
|
|
19
|
-
// Stick presses
|
|
20
|
-
GP.LS = 11; // Left stick press (L3)
|
|
21
|
-
GP.RS = 12; // Right stick press (R3)
|
|
22
|
-
// D-Pad
|
|
23
|
-
GP.DUp = 13;
|
|
24
|
-
GP.DDown = 14;
|
|
25
|
-
GP.DLeft = 15;
|
|
26
|
-
GP.DRight = 16;
|
|
27
|
-
})(GP || (GP = {}));
|
|
28
|
-
// Build reverse mappings programmatically
|
|
29
|
-
const GP_ENTRIES = Object.entries(GP);
|
|
30
|
-
// Map button index to name (for debugging/display)
|
|
31
|
-
export const GP_NAMES = Object.fromEntries(GP_ENTRIES.map(([name, index]) => [index, name]));
|
|
32
|
-
// Map name to button index (for action system parsing)
|
|
33
|
-
export const GP_NAME_MAP = Object.fromEntries(GP_ENTRIES);
|
|
34
|
-
export function getGPName(buttonIndex) {
|
|
35
|
-
return GP_NAMES[buttonIndex] ?? `Button${buttonIndex}`;
|
|
36
|
-
}
|
package/dist/core/rect.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { Vector2 } from './vector2';
|
|
2
|
-
export type Rect = [number, number, number, number];
|
|
3
|
-
export declare namespace Rect {
|
|
4
|
-
function fromPoints(a: Vector2, b: Vector2): Rect;
|
|
5
|
-
function fromCenter(center: Vector2, size: Vector2): Rect;
|
|
6
|
-
function position(r: Rect): Vector2;
|
|
7
|
-
function size(r: Rect): Vector2;
|
|
8
|
-
function center(r: Rect): Vector2;
|
|
9
|
-
function topLeft(r: Rect): Vector2;
|
|
10
|
-
function topRight(r: Rect): Vector2;
|
|
11
|
-
function bottomLeft(r: Rect): Vector2;
|
|
12
|
-
function bottomRight(r: Rect): Vector2;
|
|
13
|
-
function area(r: Rect): number;
|
|
14
|
-
function isEmpty(r: Rect): boolean;
|
|
15
|
-
function containsPoint(r: Rect, point: Vector2): boolean;
|
|
16
|
-
function containsRect(r: Rect, other: Rect): boolean;
|
|
17
|
-
function intersects(r: Rect, other: Rect): boolean;
|
|
18
|
-
function intersection(r: Rect, other: Rect): Rect;
|
|
19
|
-
function union(r: Rect, other: Rect): Rect;
|
|
20
|
-
function inflate(r: Rect, amount: number): Rect;
|
|
21
|
-
function offset(r: Rect, delta: Vector2): Rect;
|
|
22
|
-
function setPosition(r: Rect, pos: Vector2): Rect;
|
|
23
|
-
function setSize(r: Rect, size: Vector2): Rect;
|
|
24
|
-
function setCenter(r: Rect, center: Vector2): Rect;
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=rect.d.ts.map
|
package/dist/core/rect.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rect.d.ts","sourceRoot":"","sources":["../../src/core/rect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,MAAM,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAEpD,yBAAiB,IAAI,CAAC;IACpB,SAAgB,UAAU,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,IAAI,CAMvD;IAED,SAAgB,UAAU,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,CAO/D;IAED,SAAgB,QAAQ,CAAC,CAAC,EAAE,IAAI,GAAG,OAAO,CAEzC;IAED,SAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,GAAG,OAAO,CAErC;IAED,SAAgB,MAAM,CAAC,CAAC,EAAE,IAAI,GAAG,OAAO,CAEvC;IAED,SAAgB,OAAO,CAAC,CAAC,EAAE,IAAI,GAAG,OAAO,CAExC;IAED,SAAgB,QAAQ,CAAC,CAAC,EAAE,IAAI,GAAG,OAAO,CAEzC;IAED,SAAgB,UAAU,CAAC,CAAC,EAAE,IAAI,GAAG,OAAO,CAE3C;IAED,SAAgB,WAAW,CAAC,CAAC,EAAE,IAAI,GAAG,OAAO,CAE5C;IAED,SAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,GAAG,MAAM,CAEpC;IAED,SAAgB,OAAO,CAAC,CAAC,EAAE,IAAI,GAAG,OAAO,CAExC;IAED,SAAgB,aAAa,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAO9D;IAED,SAAgB,YAAY,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,GAAG,OAAO,CAO1D;IAED,SAAgB,UAAU,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,GAAG,OAAO,CAOxD;IAED,SAAgB,YAAY,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,GAAG,IAAI,CAWvD;IAED,SAAgB,KAAK,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,GAAG,IAAI,CAMhD;IAED,SAAgB,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAOrD;IAED,SAAgB,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAEpD;IAED,SAAgB,WAAW,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,GAAG,IAAI,CAEvD;IAED,SAAgB,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,CAEpD;IAED,SAAgB,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI,CAOxD;CACF"}
|
package/dist/core/vector2.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export type Vector2 = [number, number];
|
|
2
|
-
export declare namespace Vec2 {
|
|
3
|
-
function add(a: Vector2, b: Vector2): Vector2;
|
|
4
|
-
function sub(a: Vector2, b: Vector2): Vector2;
|
|
5
|
-
function mul(v: Vector2, other: Vector2 | number): Vector2;
|
|
6
|
-
function div(v: Vector2, other: Vector2 | number): Vector2;
|
|
7
|
-
function dot(a: Vector2, b: Vector2): number;
|
|
8
|
-
function cross(a: Vector2, b: Vector2): number;
|
|
9
|
-
function lengthSq(v: Vector2): number;
|
|
10
|
-
function length(v: Vector2): number;
|
|
11
|
-
function normalize(v: Vector2): Vector2;
|
|
12
|
-
function distance(a: Vector2, b: Vector2): number;
|
|
13
|
-
function lerp(a: Vector2, b: Vector2, t: number): Vector2;
|
|
14
|
-
function angle(v: Vector2): number;
|
|
15
|
-
function rotate(v: Vector2, angle: number): Vector2;
|
|
16
|
-
function negate(v: Vector2): Vector2;
|
|
17
|
-
function floor(v: Vector2): Vector2;
|
|
18
|
-
function ceil(v: Vector2): Vector2;
|
|
19
|
-
function round(v: Vector2): Vector2;
|
|
20
|
-
function min(a: Vector2, b: Vector2): Vector2;
|
|
21
|
-
function max(a: Vector2, b: Vector2): Vector2;
|
|
22
|
-
function clamp(v: Vector2, min: Vector2, max: Vector2): Vector2;
|
|
23
|
-
function fromAngle(angle: number, len?: number): Vector2;
|
|
24
|
-
function zero(): Vector2;
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=vector2.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vector2.d.ts","sourceRoot":"","sources":["../../src/core/vector2.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,OAAO,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAEvC,yBAAiB,IAAI,CAAC;IACpB,SAAgB,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAEnD;IAED,SAAgB,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAEnD;IAED,SAAgB,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,CAKhE;IAED,SAAgB,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,CAKhE;IAED,SAAgB,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,MAAM,CAElD;IAED,SAAgB,KAAK,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,MAAM,CAEpD;IAED,SAAgB,QAAQ,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CAE3C;IAED,SAAgB,MAAM,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CAEzC;IAED,SAAgB,SAAS,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAI7C;IAED,SAAgB,QAAQ,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,MAAM,CAEvD;IAED,SAAgB,IAAI,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAE/D;IAED,SAAgB,KAAK,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CAExC;IAED,SAAgB,MAAM,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAIzD;IAED,SAAgB,MAAM,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAE1C;IAED,SAAgB,KAAK,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAEzC;IAED,SAAgB,IAAI,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAExC;IAED,SAAgB,KAAK,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAEzC;IAED,SAAgB,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAEnD;IAED,SAAgB,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAEnD;IAED,SAAgB,KAAK,CAAC,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,GAAG,OAAO,CAKrE;IAED,SAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,GAAE,MAAU,GAAG,OAAO,CAEjE;IAED,SAAgB,IAAI,IAAI,OAAO,CAE9B;CACF"}
|