like2d 2.10.2 → 2.11.1
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 +6 -4
- package/dist/audio/index.d.ts +1 -1
- package/dist/audio/index.d.ts.map +1 -1
- package/dist/engine.d.ts +5 -10
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +5 -14
- package/dist/events.d.ts +38 -21
- package/dist/events.d.ts.map +1 -1
- package/dist/graphics/canvas.d.ts +12 -4
- package/dist/graphics/canvas.d.ts.map +1 -1
- package/dist/graphics/canvas.js +13 -5
- package/dist/graphics/{drawing.d.ts → graphics.d.ts} +71 -50
- package/dist/graphics/graphics.d.ts.map +1 -0
- package/dist/graphics/{drawing.js → graphics.js} +156 -168
- package/dist/graphics/image.d.ts +22 -0
- package/dist/graphics/image.d.ts.map +1 -0
- package/dist/graphics/image.js +62 -0
- package/dist/graphics/index.d.ts +6 -15
- package/dist/graphics/index.d.ts.map +1 -1
- package/dist/graphics/index.js +2 -10
- package/dist/index.d.ts +6 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -2
- package/dist/input/gamepad-mapping.d.ts +4 -4
- package/dist/input/gamepad-mapping.d.ts.map +1 -1
- package/dist/input/gamepad-mapping.js +4 -4
- package/dist/input/gamepad.d.ts +11 -1
- package/dist/input/gamepad.d.ts.map +1 -1
- package/dist/input/gamepad.js +11 -1
- package/dist/input/index.d.ts +13 -5
- package/dist/input/index.d.ts.map +1 -1
- package/dist/input/index.js +5 -1
- package/dist/input/input.d.ts +56 -5
- package/dist/input/input.d.ts.map +1 -1
- package/dist/input/input.js +61 -7
- package/dist/input/keyboard.d.ts +26 -3
- package/dist/input/keyboard.d.ts.map +1 -1
- package/dist/input/keyboard.js +24 -0
- package/dist/input/mouse.d.ts +34 -6
- package/dist/input/mouse.d.ts.map +1 -1
- package/dist/input/mouse.js +33 -4
- package/dist/like.d.ts +9 -9
- package/dist/like.d.ts.map +1 -1
- package/dist/like.js +0 -4
- package/dist/math/index.d.ts +8 -9
- package/dist/math/index.d.ts.map +1 -1
- package/dist/math/index.js +8 -9
- package/dist/math/vector2.d.ts +1 -0
- package/dist/math/vector2.d.ts.map +1 -1
- package/dist/prefab-scenes/index.d.ts +5 -3
- package/dist/prefab-scenes/index.d.ts.map +1 -1
- package/dist/prefab-scenes/index.js +4 -2
- package/dist/prefab-scenes/mapGamepad.d.ts +13 -0
- package/dist/prefab-scenes/mapGamepad.d.ts.map +1 -1
- package/dist/prefab-scenes/mapGamepad.js +13 -0
- package/dist/scene.d.ts +1 -6
- package/dist/scene.d.ts.map +1 -1
- package/dist/scene.js +0 -5
- package/dist/timer/timer.d.ts.map +1 -1
- package/dist/timer/timer.js +1 -2
- package/package.json +1 -2
- package/dist/graphics/drawing.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -110,13 +110,15 @@ LIKE's API is not the same as LOVE, but similar in spirit. Notable differences:
|
|
|
110
110
|
- Theres an actions system -- `input.setAction` / `actionpressed` and `actionreleased` callbacks.
|
|
111
111
|
- Some things are missing either due to browser limitations or smaller scope.
|
|
112
112
|
|
|
113
|
-
##
|
|
113
|
+
## Links
|
|
114
114
|
|
|
115
|
-
[
|
|
115
|
+
[NPM](https://www.npmjs.com/package/like2d)
|
|
116
116
|
|
|
117
|
-
[
|
|
117
|
+
[JSR](https://jsr.io/@like2d/like)
|
|
118
118
|
|
|
119
|
-
[
|
|
119
|
+
[GitHub](https://github.com/44100hertz/Like2D)
|
|
120
|
+
|
|
121
|
+
[Full Documentation](https://44100hertz.github.io/Like2D/api/documents/README.html)
|
|
120
122
|
|
|
121
123
|
## License
|
|
122
124
|
|
package/dist/audio/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export type {
|
|
1
|
+
export type { Audio, AudioSource, AudioSourceOptions } from "./audio";
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/audio/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/audio/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAC,MAAM,SAAS,CAAA"}
|
package/dist/engine.d.ts
CHANGED
|
@@ -1,19 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
* @module engine
|
|
3
|
-
* @description Core game engine - lifecycle management and event dispatch.
|
|
4
|
-
*/
|
|
5
|
-
import type { EventType, EventMap, Dispatcher } from './events';
|
|
1
|
+
import type { EventType, EventMap, Dispatcher, LikeCanvasElement } from './events';
|
|
6
2
|
import type { Like } from './like';
|
|
3
|
+
/** @private */
|
|
7
4
|
export type EngineDispatcher = Dispatcher<EventType>;
|
|
5
|
+
/** @private */
|
|
8
6
|
export type EngineProps<T extends keyof EventMap> = {
|
|
9
|
-
canvas:
|
|
7
|
+
canvas: LikeCanvasElement;
|
|
10
8
|
abort: AbortSignal;
|
|
11
9
|
dispatch: Dispatcher<T>;
|
|
12
10
|
};
|
|
13
|
-
/**
|
|
14
|
-
* @private
|
|
15
|
-
* Core game engine managing the event loop and subsystems.
|
|
16
|
-
*/
|
|
11
|
+
/** @private */
|
|
17
12
|
export declare class Engine {
|
|
18
13
|
private container;
|
|
19
14
|
/** The canvas on which we bind all events. Not always the same canvas
|
package/dist/engine.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAa,SAAS,EAAE,QAAQ,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC9F,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAInC,eAAe;AACf,MAAM,MAAM,gBAAgB,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC;AACrD,eAAe;AACf,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,MAAM,QAAQ,IAAI;IAClD,MAAM,EAAE,iBAAiB,CAAC;IAC1B,KAAK,EAAE,WAAW,CAAC;IACnB,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;CACzB,CAAA;AAED,eAAe;AACf,qBAAa,MAAM;IAaL,OAAO,CAAC,SAAS;IAZ7B;4BACwB;IACxB,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,QAAQ,CAAK;IACrB,OAAO,CAAC,KAAK,CAAyB;IAEtC;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;gBAEA,SAAS,EAAE,WAAW;IAqD1C,OAAO,CAAC,QAAQ;IAShB;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IA4B5B;;OAEG;IACH,OAAO,IAAI,IAAI;CAIhB"}
|
package/dist/engine.js
CHANGED
|
@@ -1,20 +1,13 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module engine
|
|
3
|
-
* @description Core game engine - lifecycle management and event dispatch.
|
|
4
|
-
*/
|
|
5
1
|
import { Audio } from './audio/audio';
|
|
6
2
|
import { Input } from './input/input';
|
|
7
3
|
import { Timer } from './timer/timer';
|
|
8
4
|
import { Keyboard } from './input/keyboard';
|
|
9
5
|
import { Mouse } from './input/mouse';
|
|
10
6
|
import { Gamepad } from './input/gamepad';
|
|
11
|
-
import {
|
|
7
|
+
import { Graphics } from './graphics/graphics';
|
|
12
8
|
import { Canvas } from './graphics/canvas';
|
|
13
9
|
import { sceneDispatch } from './scene';
|
|
14
|
-
/**
|
|
15
|
-
* @private
|
|
16
|
-
* Core game engine managing the event loop and subsystems.
|
|
17
|
-
*/
|
|
10
|
+
/** @private */
|
|
18
11
|
export class Engine {
|
|
19
12
|
constructor(container) {
|
|
20
13
|
Object.defineProperty(this, "container", {
|
|
@@ -61,23 +54,21 @@ export class Engine {
|
|
|
61
54
|
this.canvas = document.createElement('canvas');
|
|
62
55
|
const canvas = new Canvas(this.canvas, this.dispatch.bind(this), this.abort.signal);
|
|
63
56
|
this.canvas.addEventListener("like:updateRenderTarget", (event) => {
|
|
64
|
-
|
|
65
|
-
return;
|
|
66
|
-
this.like.gfx = bindGraphics(event.detail.target.getContext('2d'));
|
|
57
|
+
this.like.gfx.setContext(event.detail.target.getContext("2d"));
|
|
67
58
|
});
|
|
68
59
|
this.container.appendChild(this.canvas);
|
|
69
|
-
let gfx = bindGraphics(this.canvas.getContext('2d'));
|
|
70
60
|
const props = {
|
|
71
61
|
canvas: this.canvas,
|
|
72
62
|
dispatch: this.dispatch.bind(this),
|
|
73
63
|
abort: this.abort.signal,
|
|
74
64
|
};
|
|
65
|
+
const gfx = new Graphics(this.canvas.getContext('2d'));
|
|
75
66
|
const audio = new Audio();
|
|
76
67
|
const timer = new Timer(props);
|
|
77
68
|
const keyboard = new Keyboard(props);
|
|
78
69
|
const mouse = new Mouse(props);
|
|
79
70
|
const gamepad = new Gamepad(props);
|
|
80
|
-
const input = new Input(props
|
|
71
|
+
const input = new Input(props, { keyboard, mouse, gamepad });
|
|
81
72
|
this.like = {
|
|
82
73
|
audio,
|
|
83
74
|
timer,
|
package/dist/events.d.ts
CHANGED
|
@@ -4,28 +4,37 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { Vector2 } from './math/vector2';
|
|
6
6
|
import type { LikeButton } from './input';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
7
|
+
import { MouseButton } from './input/mouse';
|
|
8
|
+
/** @private */
|
|
9
|
+
export type LikeCanvasEventMap = HTMLElementEventMap & {
|
|
10
|
+
'like:mousemoved': CustomEvent<{
|
|
11
|
+
pos: Vector2;
|
|
12
|
+
delta: Vector2;
|
|
13
|
+
}>;
|
|
14
|
+
'like:updateRenderTarget': CustomEvent<{
|
|
15
|
+
target: HTMLCanvasElement;
|
|
16
|
+
}>;
|
|
17
|
+
'like:resizeCanvas': CustomEvent<{
|
|
18
|
+
size: Vector2;
|
|
19
|
+
}>;
|
|
20
|
+
'like:preDraw': CustomEvent<{}>;
|
|
21
|
+
'like:postDraw': CustomEvent<{}>;
|
|
22
|
+
'like:update': CustomEvent<{
|
|
23
|
+
dt: number;
|
|
24
|
+
}>;
|
|
25
|
+
};
|
|
26
|
+
/** @private Custom canvas type that uses our event map as the single source of truth */
|
|
27
|
+
export interface LikeCanvasElement extends HTMLCanvasElement {
|
|
28
|
+
addEventListener<K extends keyof LikeCanvasEventMap>(type: K, listener: (this: LikeCanvasElement, ev: LikeCanvasEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
|
|
26
29
|
}
|
|
27
30
|
/**
|
|
28
|
-
*
|
|
31
|
+
* It's a list of every possible event in like2d!
|
|
32
|
+
*
|
|
33
|
+
* Not just that, but these events translate directly into `like` callbacks.
|
|
34
|
+
*
|
|
35
|
+
* For example: `keypressed: [scancode: string, keycode: string]` translates to
|
|
36
|
+
* setting `like.keypressed = (scancode, keycode) => { ... }`!
|
|
37
|
+
*
|
|
29
38
|
*/
|
|
30
39
|
export type EventMap = {
|
|
31
40
|
/** Game initialization. Called once before the first frame. */
|
|
@@ -60,20 +69,28 @@ export type EventMap = {
|
|
|
60
69
|
gamepadconnected: [index: number];
|
|
61
70
|
/** Fires when a gamepad is disconnected. */
|
|
62
71
|
gamepaddisconnected: [index: number];
|
|
63
|
-
/** Mapped action triggered. See {@link Input} for action mapping. */
|
|
72
|
+
/** Mapped action triggered. See {@link input.Input} for action mapping. */
|
|
64
73
|
actionpressed: [action: string];
|
|
65
74
|
/** Mapped action released. */
|
|
66
75
|
actionreleased: [action: string];
|
|
67
76
|
};
|
|
77
|
+
/** @private */
|
|
68
78
|
export type EventType = keyof EventMap;
|
|
79
|
+
/** @private */
|
|
69
80
|
export type LikeMouseEvent = 'mousemoved' | 'mousepressed' | 'mousereleased';
|
|
81
|
+
/** @private */
|
|
70
82
|
export type LikeKeyboardEvent = 'keypressed' | 'keyreleased';
|
|
83
|
+
/** @private */
|
|
71
84
|
export type LikeGamepadEvent = 'gamepadpressed' | 'gamepadreleased' | 'gamepadconnected' | 'gamepaddisconnected';
|
|
85
|
+
/** @private */
|
|
86
|
+
export type LikeActionEvent = 'actionpressed' | 'actionreleased';
|
|
72
87
|
/**
|
|
88
|
+
* @private
|
|
73
89
|
* Generic dispatcher - each module defines its own event subset
|
|
74
90
|
*/
|
|
75
91
|
export type Dispatcher<T extends EventType> = <K extends T>(type: K, args: EventMap[K]) => void;
|
|
76
92
|
/**
|
|
93
|
+
* @private
|
|
77
94
|
* Discriminated union of all event objects.
|
|
78
95
|
*/
|
|
79
96
|
export type LikeEvent = {
|
package/dist/events.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,eAAe;AACf,MAA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;AACf,MAAM,MAAM,gBAAgB,GAAG,gBAAgB,GAAG,iBAAiB,GAAG,kBAAkB,GAAG,qBAAqB,CAAC;AACjH,eAAe;AACf,MAAM,MAAM,eAAe,GAAG,eAAe,GAAG,gBAAgB,CAAC;AAEjE;;;GAGG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,SAAS,IAAI,CAAC,CAAC,SAAS,CAAC,EACxD,IAAI,EAAE,CAAC,EACP,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,KACd,IAAI,CAAC;AAEV;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG;KACrB,CAAC,IAAI,SAAS,GAAG;QAAE,IAAI,EAAE,CAAC,CAAC;QAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE;CACpE,CAAC,SAAS,CAAC,CAAC"}
|
|
@@ -1,10 +1,18 @@
|
|
|
1
|
-
import { type Dispatcher } from "../events";
|
|
1
|
+
import { type Dispatcher, type LikeCanvasElement } from "../events";
|
|
2
2
|
import { Rectangle } from "../math/rect";
|
|
3
3
|
import { type Vector2 } from "../math/vector2";
|
|
4
|
+
/**
|
|
5
|
+
* A set of options passed into {@link Canvas.setMode}
|
|
6
|
+
*/
|
|
4
7
|
export type CanvasModeOptions = {
|
|
5
8
|
fullscreen: boolean;
|
|
6
9
|
};
|
|
7
10
|
export type CanvasSize = Vector2 | 'native';
|
|
11
|
+
/**
|
|
12
|
+
* A manager for the HTML canvas element, similar to `love.window`.
|
|
13
|
+
*
|
|
14
|
+
* Controls game size / scaling -- both native and pixelart mode via {@link Canvas.setMode}, as well as fullscreen functions.
|
|
15
|
+
*/
|
|
8
16
|
export declare class Canvas {
|
|
9
17
|
/** The ultimately visible canvas in the browser */
|
|
10
18
|
private displayCanvas;
|
|
@@ -18,7 +26,7 @@ export declare class Canvas {
|
|
|
18
26
|
private resizeTimeoutId;
|
|
19
27
|
constructor(
|
|
20
28
|
/** The ultimately visible canvas in the browser */
|
|
21
|
-
displayCanvas:
|
|
29
|
+
displayCanvas: LikeCanvasElement, dispatch: Dispatcher<'resize'>, abort: AbortSignal);
|
|
22
30
|
/** Get a unified canvas info object. */
|
|
23
31
|
getMode(): {
|
|
24
32
|
size: Vector2;
|
|
@@ -59,7 +67,7 @@ export declare class Canvas {
|
|
|
59
67
|
/** Called every frame by the engine after drawing */
|
|
60
68
|
private postDraw;
|
|
61
69
|
/** @returns if size was changed. */
|
|
62
|
-
static setCanvasElemSize(canvas:
|
|
63
|
-
static getCanvasElemSize(canvas:
|
|
70
|
+
static setCanvasElemSize(canvas: LikeCanvasElement, newSize: Vector2): boolean;
|
|
71
|
+
static getCanvasElemSize(canvas: LikeCanvasElement): Vector2;
|
|
64
72
|
}
|
|
65
73
|
//# sourceMappingURL=canvas.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canvas.d.ts","sourceRoot":"","sources":["../../src/graphics/canvas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"canvas.d.ts","sourceRoot":"","sources":["../../src/graphics/canvas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,iBAAiB,EAAE,MAAM,WAAW,CAAC;AACpE,OAAO,EAAQ,SAAS,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAQ,KAAK,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAErD;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAAE,UAAU,EAAE,OAAO,CAAA;CAAE,CAAC;AACxD,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,QAAQ,CAAC;AAE5C;;;;GAIG;AACH,qBAAa,MAAM;IAUX,mDAAmD;IACnD,OAAO,CAAC,aAAa;IACrB,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,KAAK;IAZjB;;;MAGE;IACF,OAAO,CAAC,YAAY,CAAoB;IAExC,OAAO,CAAC,eAAe,CAAU;;IAG7B,mDAAmD;IAC3C,aAAa,EAAE,iBAAiB,EAChC,QAAQ,EAAE,UAAU,CAAC,QAAQ,CAAC,EAC9B,KAAK,EAAE,WAAW;IAoE9B,wCAAwC;IACxC,OAAO,IAAI;QAAE,IAAI,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,iBAAiB,CAAA;KAAE;IAStD;;;;;;;;;;;;;;OAcG;IACH,OAAO,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,GAAE,OAAO,CAAC,iBAAiB,CAAM;IA6BhE,8CAA8C;IAC9C,OAAO,IAAI,OAAO;IAIlB,OAAO,CAAC,cAAc;IAWtB,wCAAwC;IACxC,OAAO,IAAI,SAAS;IAIpB,uDAAuD;IACvD,OAAO,CAAC,mBAAmB;IAO3B,yBAAyB;IACzB,aAAa,IAAI,OAAO;IAIxB,sBAAsB;IACtB,aAAa,CAAC,UAAU,EAAE,OAAO;IAWjC;;;OAGG;IACH,OAAO,CAAC,OAAO;IAmBf,qDAAqD;IACrD,OAAO,CAAC,QAAQ;IA2BhB,qCAAqC;IACzC,MAAM,CAAC,iBAAiB,CAAC,MAAM,EAAE,iBAAiB,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO;IAU1E,MAAM,CAAC,iBAAiB,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO;CAG/D"}
|
package/dist/graphics/canvas.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { Rect } from "../math/rect";
|
|
2
2
|
import { Vec2 } from "../math/vector2";
|
|
3
|
+
/**
|
|
4
|
+
* A manager for the HTML canvas element, similar to `love.window`.
|
|
5
|
+
*
|
|
6
|
+
* Controls game size / scaling -- both native and pixelart mode via {@link Canvas.setMode}, as well as fullscreen functions.
|
|
7
|
+
*/
|
|
3
8
|
export class Canvas {
|
|
4
9
|
constructor(
|
|
5
10
|
/** The ultimately visible canvas in the browser */
|
|
@@ -208,11 +213,14 @@ export class Canvas {
|
|
|
208
213
|
}
|
|
209
214
|
/** @returns if size was changed. */
|
|
210
215
|
static setCanvasElemSize(canvas, newSize) {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
return
|
|
214
|
-
|
|
215
|
-
|
|
216
|
+
const ctx = canvas.getContext('2d');
|
|
217
|
+
if (!ctx)
|
|
218
|
+
return false;
|
|
219
|
+
if (canvas.width === newSize[0] && canvas.height === newSize[1])
|
|
220
|
+
return false;
|
|
221
|
+
canvas.width = newSize[0];
|
|
222
|
+
canvas.height = newSize[1];
|
|
223
|
+
return true;
|
|
216
224
|
}
|
|
217
225
|
static getCanvasElemSize(canvas) {
|
|
218
226
|
return [canvas.width, canvas.height];
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
*/
|
|
29
29
|
import { type Vector2 } from "../math/vector2";
|
|
30
30
|
import type { Rectangle } from "../math/rect";
|
|
31
|
+
import { ImageHandle } from "./image";
|
|
31
32
|
export type DrawMode = "fill" | "line";
|
|
32
33
|
/**
|
|
33
34
|
* - RGBA array with values 0-1: `[r, g, b, a]`
|
|
@@ -52,66 +53,86 @@ export type PrintProps = {
|
|
|
52
53
|
width?: number;
|
|
53
54
|
align?: CanvasTextAlign;
|
|
54
55
|
};
|
|
55
|
-
export declare class ImageHandle {
|
|
56
|
-
readonly path: string;
|
|
57
|
-
private element;
|
|
58
|
-
private loadPromise;
|
|
59
|
-
private isLoaded;
|
|
60
|
-
constructor(path: string);
|
|
61
|
-
isReady(): boolean;
|
|
62
|
-
ready(): Promise<void>;
|
|
63
|
-
get size(): Vector2;
|
|
64
|
-
getElement(): HTMLImageElement | null;
|
|
65
|
-
}
|
|
66
56
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
57
|
+
* LIKE's way of drawing to the screen.
|
|
58
|
+
*
|
|
59
|
+
* More specifically: a system for wrapping canvas draw calls conveniently.
|
|
69
60
|
*
|
|
70
|
-
*
|
|
61
|
+
* - Reduces state in calls -- no `setColor`, etc. Everything is passed in.
|
|
62
|
+
* - Abstracts away common drawing operations.
|
|
71
63
|
*
|
|
64
|
+
* ### Examples
|
|
65
|
+
* Draw a spinning symbol in the center of the screen using transforms.
|
|
72
66
|
* ```ts
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
67
|
+
* function drawSpinningYinYang(like: Like) {
|
|
68
|
+
* const color1 = "black";
|
|
69
|
+
* const color2 = "white";
|
|
70
|
+
* const size = 50;
|
|
71
|
+
* const pos = Vec2.div(like.canvas.getSize(), 2); // calc center of screen
|
|
72
|
+
* const speed = 0.5; // rotations per second
|
|
76
73
|
*
|
|
74
|
+
* like.gfx.push();
|
|
75
|
+
* like.gfx.translate(pos);
|
|
76
|
+
* like.gfx.rotate(like.timer.getTime() * Math.PI * 2.0 * speed);
|
|
77
|
+
* like.gfx.scale(size);
|
|
78
|
+
* like.gfx.circle("fill", color1, [0, 0], 2);
|
|
79
|
+
* // use the arc parameter to fill in a semicircle. Note that it's clockwise from {x:1, y:0}.
|
|
80
|
+
* like.gfx.circle("fill", color2, [0, 0], 2, { arc: [Math.PI/2, Math.PI*3/2] });
|
|
81
|
+
* like.gfx.circle("fill", color2, [0, -1], 1);
|
|
82
|
+
* like.gfx.circle("fill", color1, [0, 1], 1);
|
|
83
|
+
* like.gfx.circle("fill", color2, [0, 1], 1/3);
|
|
84
|
+
* like.gfx.circle("fill", color1, [0, -1], 1/3);
|
|
85
|
+
* like.gfx.pop();
|
|
86
|
+
* }
|
|
87
|
+
*
|
|
88
|
+
* like.draw = (like: Like) => {
|
|
89
|
+
* drawSpinningYinYang(like);
|
|
90
|
+
* }
|
|
91
|
+
* ```
|
|
77
92
|
*/
|
|
78
|
-
export declare
|
|
93
|
+
export declare class Graphics {
|
|
94
|
+
private ctx;
|
|
95
|
+
constructor(ctx: CanvasRenderingContext2D);
|
|
96
|
+
/**
|
|
97
|
+
* Set the 2d drawing context for graphics.
|
|
98
|
+
*
|
|
99
|
+
* Be aware that that `like` can set this value at any time.
|
|
100
|
+
*/
|
|
101
|
+
setContext(ctx: CanvasRenderingContext2D): void;
|
|
79
102
|
/**
|
|
80
103
|
* Clears the canvas with a solid color.
|
|
81
|
-
* @param ctx Canvas context.
|
|
82
104
|
* @param color Fill color.
|
|
83
105
|
*/
|
|
84
|
-
clear(
|
|
106
|
+
clear(color?: Color): void;
|
|
85
107
|
/**
|
|
86
108
|
* Draws a rectangle.
|
|
87
|
-
* @param ctx Canvas context.
|
|
88
109
|
* @param mode Fill or line.
|
|
89
110
|
* @param color Fill or stroke color.
|
|
90
111
|
* @param rect Rectangle [x, y, w, h].
|
|
91
112
|
* @param props Optional stroke properties.
|
|
92
113
|
*/
|
|
93
|
-
rectangle(
|
|
114
|
+
rectangle(mode: DrawMode, color: Color, rect: Rectangle, props?: ShapeProps): void;
|
|
94
115
|
/**
|
|
95
116
|
* Draws a circle or ellipse.
|
|
96
|
-
|
|
117
|
+
|
|
97
118
|
* @param mode Fill or line.
|
|
98
119
|
* @param color Fill or stroke color.
|
|
99
120
|
* @param position Center position.
|
|
100
121
|
* @param radii Radius (number) or [rx, ry] for ellipse.
|
|
101
122
|
* @param props Optional arc, center, and stroke properties. Center is true by default.
|
|
102
123
|
*/
|
|
103
|
-
circle(
|
|
124
|
+
circle(mode: DrawMode, color: Color, position: Vector2, radii: number | Vector2, props?: ShapeProps & {
|
|
104
125
|
arc?: [number, number];
|
|
105
126
|
center?: boolean;
|
|
106
127
|
}): void;
|
|
107
128
|
/**
|
|
108
129
|
* Draws connected line segments.
|
|
109
|
-
|
|
130
|
+
|
|
110
131
|
* @param color Stroke color.
|
|
111
132
|
* @param points Array of [x, y] positions.
|
|
112
133
|
* @param props Optional stroke properties.
|
|
113
134
|
*/
|
|
114
|
-
line(
|
|
135
|
+
line(color: Color, points: Vector2[], props?: ShapeProps): void;
|
|
115
136
|
/**
|
|
116
137
|
* Draws text at a position.
|
|
117
138
|
*
|
|
@@ -122,82 +143,82 @@ export declare const draw: {
|
|
|
122
143
|
* to the left and right of its position. If you align right, your position
|
|
123
144
|
* becomes the upper-right corner of the text.
|
|
124
145
|
*
|
|
125
|
-
|
|
146
|
+
|
|
126
147
|
* @param color Fill color.
|
|
127
148
|
* @param text Text string.
|
|
128
149
|
* @param position Top-left position.
|
|
129
150
|
* @param props {@link PrintProps} Optional font, text limit, or alignment.
|
|
130
151
|
*/
|
|
131
|
-
print(
|
|
152
|
+
print(color: Color, text: string, position: Vector2, props?: PrintProps): void;
|
|
132
153
|
/**
|
|
133
154
|
* Draws an image.
|
|
134
155
|
*
|
|
135
156
|
* @remarks named "draw" because it draws anything _drawable_
|
|
136
157
|
* in the long run.
|
|
137
158
|
*
|
|
138
|
-
|
|
159
|
+
|
|
139
160
|
* @param handle Image handle from newImage.
|
|
140
161
|
* @param position Draw position.
|
|
141
162
|
* @param props Optional rotation, scale, origin, or quad.
|
|
142
163
|
*/
|
|
143
|
-
draw(
|
|
164
|
+
draw(handle: ImageHandle, position: Vector2, props?: DrawProps): void;
|
|
144
165
|
/**
|
|
145
166
|
* Loads an image from a path.
|
|
146
167
|
* Unlike built-in loading, this pretends to be synchronous.
|
|
147
|
-
|
|
168
|
+
|
|
148
169
|
* @param path Image file path.
|
|
149
170
|
* @returns ImageHandle for use with draw.
|
|
150
171
|
*/
|
|
151
|
-
newImage(
|
|
172
|
+
newImage(path: string): ImageHandle;
|
|
152
173
|
/**
|
|
153
174
|
* Sets the clipping region.
|
|
154
|
-
|
|
175
|
+
|
|
155
176
|
* @param rect Clipping rectangle, or full canvas if omitted.
|
|
156
177
|
*/
|
|
157
|
-
clip(
|
|
178
|
+
clip(rect?: Rectangle): void;
|
|
158
179
|
/**
|
|
159
180
|
* Draws a polygon.
|
|
160
|
-
|
|
181
|
+
|
|
161
182
|
* @param mode Fill or line.
|
|
162
183
|
* @param color Fill or stroke color.
|
|
163
184
|
* @param points Array of [x, y] vertices.
|
|
164
185
|
* @param props Optional stroke properties.
|
|
165
186
|
*/
|
|
166
|
-
polygon(
|
|
187
|
+
polygon(mode: DrawMode, color: Color, points: Vector2[], props?: ShapeProps): void;
|
|
167
188
|
/**
|
|
168
189
|
* Draws individual pixels.
|
|
169
|
-
|
|
190
|
+
|
|
170
191
|
* @param color Fill color.
|
|
171
192
|
* @param pts Array of [x, y] positions.
|
|
172
193
|
*/
|
|
173
|
-
points(
|
|
194
|
+
points(color: Color, pts: Vector2[]): void;
|
|
174
195
|
/**
|
|
175
196
|
* Saves canvas state.
|
|
176
|
-
|
|
197
|
+
|
|
177
198
|
*/
|
|
178
|
-
push(
|
|
199
|
+
push(): void;
|
|
179
200
|
/**
|
|
180
201
|
* Restores canvas state.
|
|
181
|
-
|
|
202
|
+
|
|
182
203
|
*/
|
|
183
|
-
pop(
|
|
204
|
+
pop(): void;
|
|
184
205
|
/**
|
|
185
206
|
* Applies a translation.
|
|
186
|
-
|
|
207
|
+
|
|
187
208
|
* @param offset [x, y] offset.
|
|
188
209
|
*/
|
|
189
|
-
translate(
|
|
210
|
+
translate(offset: Vector2): void;
|
|
190
211
|
/**
|
|
191
212
|
* Applies a rotation.
|
|
192
|
-
|
|
213
|
+
|
|
193
214
|
* @param angle Rotation in radians.
|
|
194
215
|
*/
|
|
195
|
-
rotate(
|
|
216
|
+
rotate(angle: number): void;
|
|
196
217
|
/**
|
|
197
218
|
* Applies a scale.
|
|
198
|
-
|
|
219
|
+
|
|
199
220
|
* @param factor Scale factor (number or [x, y]).
|
|
200
221
|
*/
|
|
201
|
-
scale(
|
|
202
|
-
}
|
|
203
|
-
//# sourceMappingURL=
|
|
222
|
+
scale(factor: number | Vector2): void;
|
|
223
|
+
}
|
|
224
|
+
//# sourceMappingURL=graphics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphics.d.ts","sourceRoot":"","sources":["../../src/graphics/graphics.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAQ,KAAK,OAAO,EAA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