like2d 2.3.0 → 2.5.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 +27 -18
- package/dist/adapters/callback/index.d.ts +20 -40
- package/dist/adapters/callback/index.d.ts.map +1 -1
- package/dist/adapters/callback/index.js +29 -79
- package/dist/adapters/scene/index.d.ts +6 -30
- package/dist/adapters/scene/index.d.ts.map +1 -1
- package/dist/adapters/scene/index.js +22 -77
- package/dist/adapters/scene/scene.d.ts +14 -13
- package/dist/adapters/scene/scene.d.ts.map +1 -1
- package/dist/adapters/scene/startup-scene.d.ts +9 -8
- package/dist/adapters/scene/startup-scene.d.ts.map +1 -1
- package/dist/adapters/scene/startup-scene.js +37 -17
- package/dist/core/canvas-config.d.ts +7 -7
- package/dist/core/canvas-config.d.ts.map +1 -1
- package/dist/core/canvas-manager.d.ts +7 -8
- package/dist/core/canvas-manager.d.ts.map +1 -1
- package/dist/core/canvas-manager.js +52 -71
- package/dist/core/events.d.ts +21 -49
- package/dist/core/events.d.ts.map +1 -1
- package/dist/core/graphics.d.ts +38 -32
- package/dist/core/graphics.d.ts.map +1 -1
- package/dist/core/graphics.js +192 -275
- package/dist/core/like.d.ts +54 -0
- package/dist/core/like.d.ts.map +1 -0
- package/dist/core/like.js +1 -0
- package/dist/core/player-movement.d.ts +16 -0
- package/dist/core/player-movement.d.ts.map +1 -0
- package/dist/core/player-movement.js +20 -0
- package/dist/engine.d.ts +9 -28
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +89 -63
- package/dist/index.d.ts +8 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/package.json +9 -9
|
@@ -1 +1 @@
|
|
|
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,OAAO,GAAG,
|
|
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,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CanvasMode, PartialCanvasMode } from './canvas-config';
|
|
2
2
|
import { type Vector2 } from './vector2';
|
|
3
3
|
export declare class CanvasManager {
|
|
4
4
|
private canvas;
|
|
@@ -6,17 +6,16 @@ export declare class CanvasManager {
|
|
|
6
6
|
private ctx;
|
|
7
7
|
private config;
|
|
8
8
|
private resizeObserver;
|
|
9
|
-
private
|
|
10
|
-
private
|
|
9
|
+
private pixelCanvas;
|
|
10
|
+
private pixelCtx;
|
|
11
11
|
private onWindowResize;
|
|
12
|
-
private onFullscreenChange;
|
|
13
12
|
onResize: ((size: Vector2, pixelSize: Vector2, fullscreen: boolean) => void) | null;
|
|
14
|
-
constructor(canvas: HTMLCanvasElement, container: HTMLElement, ctx: CanvasRenderingContext2D, config?:
|
|
13
|
+
constructor(canvas: HTMLCanvasElement, container: HTMLElement, ctx: CanvasRenderingContext2D, config?: CanvasMode);
|
|
15
14
|
private listenForPixelRatioChanges;
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
setMode(mode: PartialCanvasMode): void;
|
|
16
|
+
getMode(): CanvasMode;
|
|
18
17
|
private applyConfig;
|
|
19
|
-
private
|
|
18
|
+
private applyPixelMode;
|
|
20
19
|
private applyNativeMode;
|
|
21
20
|
dispose(): void;
|
|
22
21
|
present(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canvas-manager.d.ts","sourceRoot":"","sources":["../../src/core/canvas-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
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"}
|
|
@@ -14,7 +14,7 @@ function centerElement(el) {
|
|
|
14
14
|
el.style.transform = 'translate(-50%, -50%)';
|
|
15
15
|
}
|
|
16
16
|
export class CanvasManager {
|
|
17
|
-
constructor(canvas, container, ctx, config = {
|
|
17
|
+
constructor(canvas, container, ctx, config = { pixelResolution: null, fullscreen: false }) {
|
|
18
18
|
Object.defineProperty(this, "canvas", {
|
|
19
19
|
enumerable: true,
|
|
20
20
|
configurable: true,
|
|
@@ -45,13 +45,13 @@ export class CanvasManager {
|
|
|
45
45
|
writable: true,
|
|
46
46
|
value: null
|
|
47
47
|
});
|
|
48
|
-
Object.defineProperty(this, "
|
|
48
|
+
Object.defineProperty(this, "pixelCanvas", {
|
|
49
49
|
enumerable: true,
|
|
50
50
|
configurable: true,
|
|
51
51
|
writable: true,
|
|
52
52
|
value: null
|
|
53
53
|
});
|
|
54
|
-
Object.defineProperty(this, "
|
|
54
|
+
Object.defineProperty(this, "pixelCtx", {
|
|
55
55
|
enumerable: true,
|
|
56
56
|
configurable: true,
|
|
57
57
|
writable: true,
|
|
@@ -63,12 +63,6 @@ export class CanvasManager {
|
|
|
63
63
|
writable: true,
|
|
64
64
|
value: () => this.applyConfig()
|
|
65
65
|
});
|
|
66
|
-
Object.defineProperty(this, "onFullscreenChange", {
|
|
67
|
-
enumerable: true,
|
|
68
|
-
configurable: true,
|
|
69
|
-
writable: true,
|
|
70
|
-
value: () => this.applyConfig()
|
|
71
|
-
});
|
|
72
66
|
Object.defineProperty(this, "onResize", {
|
|
73
67
|
enumerable: true,
|
|
74
68
|
configurable: true,
|
|
@@ -78,7 +72,6 @@ export class CanvasManager {
|
|
|
78
72
|
this.resizeObserver = new ResizeObserver(() => this.applyConfig());
|
|
79
73
|
this.resizeObserver.observe(this.container);
|
|
80
74
|
window.addEventListener('resize', this.onWindowResize);
|
|
81
|
-
document.addEventListener('fullscreenchange', this.onFullscreenChange);
|
|
82
75
|
this.listenForPixelRatioChanges();
|
|
83
76
|
this.applyConfig();
|
|
84
77
|
}
|
|
@@ -89,63 +82,50 @@ export class CanvasManager {
|
|
|
89
82
|
this.listenForPixelRatioChanges();
|
|
90
83
|
}, { once: true });
|
|
91
84
|
}
|
|
92
|
-
|
|
93
|
-
this.config = config;
|
|
85
|
+
setMode(mode) {
|
|
86
|
+
this.config = { ...this.config, ...mode };
|
|
94
87
|
this.applyConfig();
|
|
95
88
|
}
|
|
96
|
-
|
|
89
|
+
getMode() {
|
|
97
90
|
return { ...this.config };
|
|
98
91
|
}
|
|
99
92
|
applyConfig() {
|
|
100
93
|
const containerSize = document.fullscreenElement
|
|
101
94
|
? [document.fullscreenElement.clientWidth, document.fullscreenElement.clientHeight]
|
|
102
95
|
: [this.container.clientWidth, this.container.clientHeight];
|
|
103
|
-
// Always clean up pixel
|
|
104
|
-
if (this.
|
|
105
|
-
this.
|
|
106
|
-
this.
|
|
107
|
-
this.
|
|
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);
|
|
108
104
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
this.applyFixedMode(containerSize);
|
|
112
|
-
break;
|
|
113
|
-
case 'native':
|
|
114
|
-
this.applyNativeMode(containerSize);
|
|
115
|
-
break;
|
|
105
|
+
else {
|
|
106
|
+
this.applyNativeMode(containerSize);
|
|
116
107
|
}
|
|
117
|
-
const displayCanvas = this.
|
|
118
|
-
|
|
119
|
-
this.onResize?.(containerSize, [displayCanvas.width, displayCanvas.height], isFullscreen);
|
|
108
|
+
const displayCanvas = this.pixelCanvas ?? this.canvas;
|
|
109
|
+
this.onResize?.(containerSize, [displayCanvas.width, displayCanvas.height], this.config.fullscreen);
|
|
120
110
|
}
|
|
121
|
-
|
|
122
|
-
const
|
|
111
|
+
applyPixelMode(csize) {
|
|
112
|
+
const gameSize = this.config.pixelResolution;
|
|
123
113
|
const pixelRatio = window.devicePixelRatio || 1;
|
|
124
114
|
const scale = Math.min(csize[0] / gameSize[0], csize[1] / gameSize[1]);
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
this.container.appendChild(pac);
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
setCanvasSize(this.canvas, gameSize);
|
|
143
|
-
this.canvas.style.display = 'block';
|
|
144
|
-
setCanvasDisplaySize(this.canvas, Vec2.mul(gameSize, scale));
|
|
145
|
-
this.canvas.style.imageRendering = pixelArt ? 'pixelated' : 'auto';
|
|
146
|
-
this.ctx.imageSmoothingEnabled = !pixelArt;
|
|
147
|
-
centerElement(this.canvas);
|
|
148
|
-
}
|
|
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);
|
|
149
129
|
}
|
|
150
130
|
applyNativeMode(csize) {
|
|
151
131
|
const pixelRatio = window.devicePixelRatio || 1;
|
|
@@ -164,34 +144,35 @@ export class CanvasManager {
|
|
|
164
144
|
dispose() {
|
|
165
145
|
this.resizeObserver?.disconnect();
|
|
166
146
|
window.removeEventListener('resize', this.onWindowResize);
|
|
167
|
-
|
|
168
|
-
this.
|
|
169
|
-
this.
|
|
170
|
-
this.pixelArtCtx = null;
|
|
147
|
+
this.pixelCanvas?.remove();
|
|
148
|
+
this.pixelCanvas = null;
|
|
149
|
+
this.pixelCtx = null;
|
|
171
150
|
}
|
|
172
151
|
present() {
|
|
173
|
-
if (!this.
|
|
152
|
+
if (!this.pixelCtx || !this.pixelCanvas) {
|
|
174
153
|
return;
|
|
175
154
|
}
|
|
176
|
-
this.
|
|
177
|
-
this.
|
|
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);
|
|
178
157
|
}
|
|
179
158
|
getDisplayCanvas() {
|
|
180
|
-
return this.
|
|
159
|
+
return this.pixelCanvas ?? this.canvas;
|
|
181
160
|
}
|
|
182
161
|
transformMousePosition(cssX, cssY) {
|
|
183
162
|
const displayCanvas = this.getDisplayCanvas();
|
|
184
163
|
const rect = displayCanvas.getBoundingClientRect();
|
|
185
164
|
const relative = [cssX - rect.left, cssY - rect.top];
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
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);
|
|
195
176
|
}
|
|
196
177
|
}
|
|
197
178
|
}
|
package/dist/core/events.d.ts
CHANGED
|
@@ -1,52 +1,24 @@
|
|
|
1
1
|
import type { Vector2 } from './vector2';
|
|
2
|
-
export type
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
type: 'resize';
|
|
16
|
-
args: [size: Vector2, pixelSize: Vector2, fullscreen: boolean];
|
|
17
|
-
timestamp: number;
|
|
18
|
-
} | {
|
|
19
|
-
type: 'keypressed';
|
|
20
|
-
args: [scancode: string, keycode: string];
|
|
21
|
-
timestamp: number;
|
|
22
|
-
} | {
|
|
23
|
-
type: 'keyreleased';
|
|
24
|
-
args: [scancode: string, keycode: string];
|
|
25
|
-
timestamp: number;
|
|
26
|
-
} | {
|
|
27
|
-
type: 'mousepressed';
|
|
28
|
-
args: [x: number, y: number, button: number];
|
|
29
|
-
timestamp: number;
|
|
30
|
-
} | {
|
|
31
|
-
type: 'mousereleased';
|
|
32
|
-
args: [x: number, y: number, button: number];
|
|
33
|
-
timestamp: number;
|
|
34
|
-
} | {
|
|
35
|
-
type: 'gamepadpressed';
|
|
36
|
-
args: [gamepadIndex: number, buttonIndex: number, buttonName: string];
|
|
37
|
-
timestamp: number;
|
|
38
|
-
} | {
|
|
39
|
-
type: 'gamepadreleased';
|
|
40
|
-
args: [gamepadIndex: number, buttonIndex: number, buttonName: string];
|
|
41
|
-
timestamp: number;
|
|
42
|
-
} | {
|
|
43
|
-
type: 'actionpressed';
|
|
44
|
-
args: [action: string];
|
|
45
|
-
timestamp: number;
|
|
46
|
-
} | {
|
|
47
|
-
type: 'actionreleased';
|
|
48
|
-
args: [action: string];
|
|
49
|
-
timestamp: number;
|
|
2
|
+
export type EventMap = {
|
|
3
|
+
load: [];
|
|
4
|
+
update: [dt: number];
|
|
5
|
+
draw: [];
|
|
6
|
+
resize: [size: Vector2, pixelSize: Vector2, fullscreen: boolean];
|
|
7
|
+
keypressed: [scancode: string, keycode: string];
|
|
8
|
+
keyreleased: [scancode: string, keycode: string];
|
|
9
|
+
mousepressed: [x: number, y: number, button: number];
|
|
10
|
+
mousereleased: [x: number, y: number, button: number];
|
|
11
|
+
gamepadpressed: [gamepadIndex: number, buttonIndex: number, buttonName: string];
|
|
12
|
+
gamepadreleased: [gamepadIndex: number, buttonIndex: number, buttonName: string];
|
|
13
|
+
actionpressed: [action: string];
|
|
14
|
+
actionreleased: [action: string];
|
|
50
15
|
};
|
|
51
|
-
export type EventType =
|
|
16
|
+
export type EventType = keyof EventMap;
|
|
17
|
+
export type Like2DEvent = {
|
|
18
|
+
[K in EventType]: {
|
|
19
|
+
type: K;
|
|
20
|
+
args: EventMap[K];
|
|
21
|
+
timestamp: number;
|
|
22
|
+
};
|
|
23
|
+
}[EventType];
|
|
52
24
|
//# sourceMappingURL=events.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/core/events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/core/events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGzC,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,EAAE,EAAE,CAAC;IACT,MAAM,EAAE,CAAC,EAAE,EAAE,M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|
|
13
|
-
color?: Color;
|
|
14
13
|
lineWidth?: number;
|
|
15
14
|
lineCap?: 'butt' | 'round' | 'square';
|
|
16
15
|
lineJoin?: 'bevel' | 'miter' | 'round';
|
|
@@ -27,6 +26,11 @@ export type PrintProps = {
|
|
|
27
26
|
limit?: number;
|
|
28
27
|
align?: 'left' | 'center' | 'right';
|
|
29
28
|
};
|
|
29
|
+
export type GraphicsState = {
|
|
30
|
+
screenCtx: CanvasRenderingContext2D;
|
|
31
|
+
currentCtx: CanvasRenderingContext2D;
|
|
32
|
+
canvases: Map<Canvas, true>;
|
|
33
|
+
};
|
|
30
34
|
export declare class ImageHandle {
|
|
31
35
|
readonly path: string;
|
|
32
36
|
private element;
|
|
@@ -38,37 +42,39 @@ export declare class ImageHandle {
|
|
|
38
42
|
get size(): Vector2;
|
|
39
43
|
getElement(): HTMLImageElement | null;
|
|
40
44
|
}
|
|
41
|
-
export declare
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
45
|
+
export declare function newState(ctx: CanvasRenderingContext2D): GraphicsState;
|
|
46
|
+
export declare function clear(s: GraphicsState, color?: Color): void;
|
|
47
|
+
export declare function rectangle(s: GraphicsState, mode: DrawMode, color: Color, rect: Rect, props?: ShapeProps): void;
|
|
48
|
+
export declare function circle(s: GraphicsState, mode: DrawMode, color: Color, position: Vector2, radii: number | Vector2, props?: ShapeProps & {
|
|
49
|
+
angle?: number;
|
|
50
|
+
arc?: [number, number];
|
|
51
|
+
}): void;
|
|
52
|
+
export declare function line(s: GraphicsState, color: Color, points: Vector2[], props?: ShapeProps): void;
|
|
53
|
+
export declare function print(s: GraphicsState, color: Color, text: string, position: Vector2, props?: PrintProps): void;
|
|
54
|
+
export declare function drawImage(s: GraphicsState, handle: ImageHandle, position: Vector2, props?: DrawProps): void;
|
|
55
|
+
export declare function getCanvasSize(s: GraphicsState): Vector2;
|
|
56
|
+
export declare function newCanvas(s: GraphicsState, size: Vector2): Canvas;
|
|
57
|
+
export declare function setCanvas(s: GraphicsState, canvas?: Canvas | null): void;
|
|
58
|
+
export declare function clip(s: GraphicsState, rect?: Rect): void;
|
|
59
|
+
export declare function polygon(s: GraphicsState, mode: DrawMode, color: Color, points: Vector2[], props?: ShapeProps): void;
|
|
60
|
+
export declare function points(s: GraphicsState, color: Color, pts: Vector2[]): void;
|
|
61
|
+
export declare function newImage(path: string): ImageHandle;
|
|
62
|
+
export type BoundGraphics = {
|
|
63
|
+
clear: (color?: Color) => void;
|
|
64
|
+
rectangle: (mode: DrawMode, color: Color, rect: Rect, props?: ShapeProps) => void;
|
|
65
|
+
circle: (mode: DrawMode, color: Color, position: Vector2, radii: number | Vector2, props?: ShapeProps & {
|
|
55
66
|
angle?: number;
|
|
56
67
|
arc?: [number, number];
|
|
57
|
-
})
|
|
58
|
-
line(color: Color, points: Vector2[], props?: ShapeProps)
|
|
59
|
-
print(color: Color, text: string, position: Vector2, props?: PrintProps)
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
clip(rect?: Rect): void;
|
|
70
|
-
polygon(mode: DrawMode, color: Color, points: Vector2[], props?: ShapeProps): void;
|
|
71
|
-
arc(mode: DrawMode, x: number, y: number, radius: number, angle1: number, angle2: number, props?: ShapeProps): void;
|
|
72
|
-
points(color: Color, points: Vector2[]): void;
|
|
73
|
-
}
|
|
68
|
+
}) => void;
|
|
69
|
+
line: (color: Color, points: Vector2[], props?: ShapeProps) => void;
|
|
70
|
+
print: (color: Color, text: string, position: Vector2, props?: PrintProps) => void;
|
|
71
|
+
draw: (handle: ImageHandle, position: Vector2, props?: DrawProps) => void;
|
|
72
|
+
getCanvasSize: () => Vector2;
|
|
73
|
+
newCanvas: (size: Vector2) => Canvas;
|
|
74
|
+
setCanvas: (canvas?: Canvas | null) => void;
|
|
75
|
+
clip: (rect?: Rect) => void;
|
|
76
|
+
polygon: (mode: DrawMode, color: Color, points: Vector2[], props?: ShapeProps) => void;
|
|
77
|
+
points: (color: Color, pts: Vector2[]) => void;
|
|
78
|
+
};
|
|
79
|
+
export declare function bindGraphics(s: GraphicsState): BoundGraphics;
|
|
74
80
|
//# 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,GAAG,MAAM,GAAG,MAAM,CAAC;AAEhC,MAAM,MAAM,KAAK,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC;AAC/D,MAAM,MAAM,IAAI,GAAG,IAAI,CAAC;AAExB,YAAY,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAE9B,MAAM,MAAM,MAAM,GAAG;IACnB,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,iBAAiB,CAAC;IAC3B,GAAG,EAAE,wBAAwB,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,
|
|
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,GAAG,MAAM,GAAG,MAAM,CAAC;AAEhC,MAAM,MAAM,KAAK,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,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