like2d 2.11.0 → 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.
Files changed (59) hide show
  1. package/README.md +6 -4
  2. package/dist/audio/index.d.ts +1 -1
  3. package/dist/audio/index.d.ts.map +1 -1
  4. package/dist/engine.d.ts +3 -8
  5. package/dist/engine.d.ts.map +1 -1
  6. package/dist/engine.js +3 -10
  7. package/dist/events.d.ts +19 -4
  8. package/dist/events.d.ts.map +1 -1
  9. package/dist/graphics/canvas.d.ts +8 -0
  10. package/dist/graphics/canvas.d.ts.map +1 -1
  11. package/dist/graphics/canvas.js +5 -0
  12. package/dist/graphics/graphics.d.ts +45 -32
  13. package/dist/graphics/graphics.d.ts.map +1 -1
  14. package/dist/graphics/graphics.js +45 -74
  15. package/dist/graphics/image.d.ts +22 -0
  16. package/dist/graphics/image.d.ts.map +1 -0
  17. package/dist/graphics/image.js +62 -0
  18. package/dist/graphics/index.d.ts +6 -4
  19. package/dist/graphics/index.d.ts.map +1 -1
  20. package/dist/graphics/index.js +2 -2
  21. package/dist/index.d.ts +6 -4
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +9 -2
  24. package/dist/input/gamepad-mapping.d.ts +4 -4
  25. package/dist/input/gamepad-mapping.d.ts.map +1 -1
  26. package/dist/input/gamepad-mapping.js +4 -4
  27. package/dist/input/gamepad.d.ts +11 -1
  28. package/dist/input/gamepad.d.ts.map +1 -1
  29. package/dist/input/gamepad.js +11 -1
  30. package/dist/input/index.d.ts +13 -5
  31. package/dist/input/index.d.ts.map +1 -1
  32. package/dist/input/index.js +5 -1
  33. package/dist/input/input.d.ts +56 -5
  34. package/dist/input/input.d.ts.map +1 -1
  35. package/dist/input/input.js +61 -7
  36. package/dist/input/keyboard.d.ts +26 -3
  37. package/dist/input/keyboard.d.ts.map +1 -1
  38. package/dist/input/keyboard.js +24 -0
  39. package/dist/input/mouse.d.ts +34 -6
  40. package/dist/input/mouse.d.ts.map +1 -1
  41. package/dist/input/mouse.js +31 -3
  42. package/dist/like.d.ts +5 -7
  43. package/dist/like.d.ts.map +1 -1
  44. package/dist/like.js +0 -4
  45. package/dist/math/index.d.ts +8 -9
  46. package/dist/math/index.d.ts.map +1 -1
  47. package/dist/math/index.js +8 -9
  48. package/dist/math/vector2.d.ts +1 -0
  49. package/dist/math/vector2.d.ts.map +1 -1
  50. package/dist/prefab-scenes/index.d.ts +5 -3
  51. package/dist/prefab-scenes/index.d.ts.map +1 -1
  52. package/dist/prefab-scenes/index.js +4 -2
  53. package/dist/prefab-scenes/mapGamepad.d.ts +13 -0
  54. package/dist/prefab-scenes/mapGamepad.d.ts.map +1 -1
  55. package/dist/prefab-scenes/mapGamepad.js +13 -0
  56. package/dist/scene.d.ts +1 -6
  57. package/dist/scene.d.ts.map +1 -1
  58. package/dist/scene.js +0 -5
  59. package/package.json +1 -2
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
- ## Feedback welcome
113
+ ## Links
114
114
 
115
- [LIKE is on GitHub.](https://github.com/44100hertz/Like2D)
115
+ [NPM](https://www.npmjs.com/package/like2d)
116
116
 
117
- [Check out the docs for our long-term vision.](https://github.com/44100hertz/Like2D/tree/master/docs)
117
+ [JSR](https://jsr.io/@like2d/like)
118
118
 
119
- [Feature requests welcome. PRs discouraged for now.](https://github.com/44100hertz/Like2D/issues/)
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
 
@@ -1,2 +1,2 @@
1
- export type { AudioSource, Audio, AudioSourceOptions } from "./audio";
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,WAAW,EAAE,KAAK,EAAE,kBAAkB,EAAC,MAAM,SAAS,CAAA"}
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
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
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
@@ -1 +1 @@
1
- {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH,OAAO,KAAK,EAAa,SAAS,EAAE,QAAQ,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC9F,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAInC,MAAM,MAAM,gBAAgB,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC;AACrD,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;CACz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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 { Graphics } from './graphics/index';
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", {
@@ -75,7 +68,7 @@ export class Engine {
75
68
  const keyboard = new Keyboard(props);
76
69
  const mouse = new Mouse(props);
77
70
  const gamepad = new Gamepad(props);
78
- const input = new Input(props.dispatch, { keyboard, mouse, gamepad });
71
+ const input = new Input(props, { keyboard, mouse, gamepad });
79
72
  this.like = {
80
73
  audio,
81
74
  timer,
package/dist/events.d.ts CHANGED
@@ -4,7 +4,8 @@
4
4
  */
5
5
  import type { Vector2 } from './math/vector2';
6
6
  import type { LikeButton } from './input';
7
- export type MouseButton = 'left' | 'middle' | 'right';
7
+ import { MouseButton } from './input/mouse';
8
+ /** @private */
8
9
  export type LikeCanvasEventMap = HTMLElementEventMap & {
9
10
  'like:mousemoved': CustomEvent<{
10
11
  pos: Vector2;
@@ -22,12 +23,18 @@ export type LikeCanvasEventMap = HTMLElementEventMap & {
22
23
  dt: number;
23
24
  }>;
24
25
  };
25
- export type LikeCanvasEvent = LikeCanvasEventMap;
26
+ /** @private Custom canvas type that uses our event map as the single source of truth */
26
27
  export interface LikeCanvasElement extends HTMLCanvasElement {
27
28
  addEventListener<K extends keyof LikeCanvasEventMap>(type: K, listener: (this: LikeCanvasElement, ev: LikeCanvasEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
28
29
  }
29
30
  /**
30
- * The master type will all events on it.
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
+ *
31
38
  */
32
39
  export type EventMap = {
33
40
  /** Game initialization. Called once before the first frame. */
@@ -62,20 +69,28 @@ export type EventMap = {
62
69
  gamepadconnected: [index: number];
63
70
  /** Fires when a gamepad is disconnected. */
64
71
  gamepaddisconnected: [index: number];
65
- /** Mapped action triggered. See {@link Input} for action mapping. */
72
+ /** Mapped action triggered. See {@link input.Input} for action mapping. */
66
73
  actionpressed: [action: string];
67
74
  /** Mapped action released. */
68
75
  actionreleased: [action: string];
69
76
  };
77
+ /** @private */
70
78
  export type EventType = keyof EventMap;
79
+ /** @private */
71
80
  export type LikeMouseEvent = 'mousemoved' | 'mousepressed' | 'mousereleased';
81
+ /** @private */
72
82
  export type LikeKeyboardEvent = 'keypressed' | 'keyreleased';
83
+ /** @private */
73
84
  export type LikeGamepadEvent = 'gamepadpressed' | 'gamepadreleased' | 'gamepadconnected' | 'gamepaddisconnected';
85
+ /** @private */
86
+ export type LikeActionEvent = 'actionpressed' | 'actionreleased';
74
87
  /**
88
+ * @private
75
89
  * Generic dispatcher - each module defines its own event subset
76
90
  */
77
91
  export type Dispatcher<T extends EventType> = <K extends T>(type: K, args: EventMap[K]) => void;
78
92
  /**
93
+ * @private
79
94
  * Discriminated union of all event objects.
80
95
  */
81
96
  export type LikeEvent = {
@@ -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,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AAE,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
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;
@@ -1 +1 @@
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,MAAM,MAAM,iBAAiB,GAAG;IAAE,UAAU,EAAE,OAAO,CAAA;CAAE,CAAC;AACxD,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,QAAQ,CAAC;AAE5C,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,QAA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,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"}
@@ -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 */
@@ -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,28 +53,42 @@ 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
- * All of these methods exist on `like.gfx`, but with `ctx`
68
- * bound to the first arg.
57
+ * LIKE's way of drawing to the screen.
58
+ *
59
+ * More specifically: a system for wrapping canvas draw calls conveniently.
69
60
  *
70
- * Acts as the core of the graphics system, but can be used separately.
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
- * import { draw } from "like/graphics"
74
- * draw.clear(my2dContext, "red");
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
93
  export declare class Graphics {
79
94
  private ctx;
@@ -86,13 +101,11 @@ export declare class Graphics {
86
101
  setContext(ctx: CanvasRenderingContext2D): void;
87
102
  /**
88
103
  * Clears the canvas with a solid color.
89
- * @param this.ctx Canvas context.
90
104
  * @param color Fill color.
91
105
  */
92
106
  clear(color?: Color): void;
93
107
  /**
94
108
  * Draws a rectangle.
95
- * @param this.ctx Canvas context.
96
109
  * @param mode Fill or line.
97
110
  * @param color Fill or stroke color.
98
111
  * @param rect Rectangle [x, y, w, h].
@@ -101,7 +114,7 @@ export declare class Graphics {
101
114
  rectangle(mode: DrawMode, color: Color, rect: Rectangle, props?: ShapeProps): void;
102
115
  /**
103
116
  * Draws a circle or ellipse.
104
- * @param this.ctx Canvas context.
117
+
105
118
  * @param mode Fill or line.
106
119
  * @param color Fill or stroke color.
107
120
  * @param position Center position.
@@ -114,7 +127,7 @@ export declare class Graphics {
114
127
  }): void;
115
128
  /**
116
129
  * Draws connected line segments.
117
- * @param this.ctx Canvas context.
130
+
118
131
  * @param color Stroke color.
119
132
  * @param points Array of [x, y] positions.
120
133
  * @param props Optional stroke properties.
@@ -130,7 +143,7 @@ export declare class Graphics {
130
143
  * to the left and right of its position. If you align right, your position
131
144
  * becomes the upper-right corner of the text.
132
145
  *
133
- * @param this.ctx Canvas context.
146
+
134
147
  * @param color Fill color.
135
148
  * @param text Text string.
136
149
  * @param position Top-left position.
@@ -143,7 +156,7 @@ export declare class Graphics {
143
156
  * @remarks named "draw" because it draws anything _drawable_
144
157
  * in the long run.
145
158
  *
146
- * @param this.ctx Canvas context.
159
+
147
160
  * @param handle Image handle from newImage.
148
161
  * @param position Draw position.
149
162
  * @param props Optional rotation, scale, origin, or quad.
@@ -152,20 +165,20 @@ export declare class Graphics {
152
165
  /**
153
166
  * Loads an image from a path.
154
167
  * Unlike built-in loading, this pretends to be synchronous.
155
- * @param this.ctx Canvas context.
168
+
156
169
  * @param path Image file path.
157
170
  * @returns ImageHandle for use with draw.
158
171
  */
159
172
  newImage(path: string): ImageHandle;
160
173
  /**
161
174
  * Sets the clipping region.
162
- * @param this.ctx Canvas context.
175
+
163
176
  * @param rect Clipping rectangle, or full canvas if omitted.
164
177
  */
165
178
  clip(rect?: Rectangle): void;
166
179
  /**
167
180
  * Draws a polygon.
168
- * @param this.ctx Canvas context.
181
+
169
182
  * @param mode Fill or line.
170
183
  * @param color Fill or stroke color.
171
184
  * @param points Array of [x, y] vertices.
@@ -174,36 +187,36 @@ export declare class Graphics {
174
187
  polygon(mode: DrawMode, color: Color, points: Vector2[], props?: ShapeProps): void;
175
188
  /**
176
189
  * Draws individual pixels.
177
- * @param this.ctx Canvas context.
190
+
178
191
  * @param color Fill color.
179
192
  * @param pts Array of [x, y] positions.
180
193
  */
181
194
  points(color: Color, pts: Vector2[]): void;
182
195
  /**
183
196
  * Saves canvas state.
184
- * @param this.ctx Canvas context.
197
+
185
198
  */
186
199
  push(): void;
187
200
  /**
188
201
  * Restores canvas state.
189
- * @param this.ctx Canvas context.
202
+
190
203
  */
191
204
  pop(): void;
192
205
  /**
193
206
  * Applies a translation.
194
- * @param this.ctx Canvas context.
207
+
195
208
  * @param offset [x, y] offset.
196
209
  */
197
210
  translate(offset: Vector2): void;
198
211
  /**
199
212
  * Applies a rotation.
200
- * @param this.ctx Canvas context.
213
+
201
214
  * @param angle Rotation in radians.
202
215
  */
203
216
  rotate(angle: number): void;
204
217
  /**
205
218
  * Applies a scale.
206
- * @param this.ctx Canvas context.
219
+
207
220
  * @param factor Scale factor (number or [x, y]).
208
221
  */
209
222
  scale(factor: number | Vector2): void;
@@ -1 +1 @@
1
- {"version":3,"file":"graphics.d.ts","sourceRoot":"","sources":["../../src/graphics/graphics.ts"],"names":[],"mappings":"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IAoBP;;;;;;;;;;OAUG;IACH,IAAI,CACF,MAAM,EAAE,WAAW,EACnB,QAAQ,EAAE,OAAO,EACjB,KAAK,CAAC,EAAE,SAAS,GAChB,IAAI;IAuBP;;;;;;OAMG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW;IAInC;;;;OAIG;IACH,IAAI,CAAC,IAAI,CAAC,EAAE,SAAS,GAAG,IAAI;IAW5B;;;;;;;OAOG;IACH,OAAO,CACL,IAAI,EAAE,QAAQ,EACd,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,OAAO,EAAE,EACjB,KAAK,CAAC,EAAE,UAAU,GACjB,IAAI;IAkBP;;;;;OAKG;IACH,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,IAAI;IAK1C;;;OAGG;IACH,IAAI,IAAI,IAAI;IAIZ;;;OAGG;IACH,GAAG,IAAI,IAAI;IAIX;;;;OAIG;IACH,SAAS,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI;IAKhC;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAI3B;;;;OAIG;IACH,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI;CAItC"}
@@ -27,59 +27,7 @@
27
27
  * - Angles in radians, 0 is right, positive is clockwise
28
28
  */
29
29
  import { Vec2 } from "../math/vector2";
30
- export class ImageHandle {
31
- constructor(path) {
32
- Object.defineProperty(this, "path", {
33
- enumerable: true,
34
- configurable: true,
35
- writable: true,
36
- value: void 0
37
- });
38
- Object.defineProperty(this, "element", {
39
- enumerable: true,
40
- configurable: true,
41
- writable: true,
42
- value: null
43
- });
44
- Object.defineProperty(this, "loadPromise", {
45
- enumerable: true,
46
- configurable: true,
47
- writable: true,
48
- value: void 0
49
- });
50
- Object.defineProperty(this, "isLoaded", {
51
- enumerable: true,
52
- configurable: true,
53
- writable: true,
54
- value: false
55
- });
56
- this.path = path;
57
- this.loadPromise = new Promise((resolve, reject) => {
58
- const img = new Image();
59
- img.onload = () => {
60
- this.element = img;
61
- this.isLoaded = true;
62
- resolve();
63
- };
64
- img.onerror = () => {
65
- reject(new Error(`Failed to load image: ${path}`));
66
- };
67
- img.src = path;
68
- });
69
- }
70
- isReady() {
71
- return this.isLoaded;
72
- }
73
- ready() {
74
- return this.loadPromise;
75
- }
76
- get size() {
77
- return [this.element?.width ?? 0, this.element?.height ?? 0];
78
- }
79
- getElement() {
80
- return this.element;
81
- }
82
- }
30
+ import { ImageHandle } from "./image";
83
31
  function parseColor(color) {
84
32
  if (typeof color === "string")
85
33
  return color;
@@ -117,16 +65,41 @@ function getFontHeight(ctx) {
117
65
  return match ? parseInt(match[1]) : 16;
118
66
  }
119
67
  /**
120
- * All of these methods exist on `like.gfx`, but with `ctx`
121
- * bound to the first arg.
68
+ * LIKE's way of drawing to the screen.
69
+ *
70
+ * More specifically: a system for wrapping canvas draw calls conveniently.
122
71
  *
123
- * Acts as the core of the graphics system, but can be used separately.
72
+ * - Reduces state in calls -- no `setColor`, etc. Everything is passed in.
73
+ * - Abstracts away common drawing operations.
124
74
  *
75
+ * ### Examples
76
+ * Draw a spinning symbol in the center of the screen using transforms.
125
77
  * ```ts
126
- * import { draw } from "like/graphics"
127
- * draw.clear(my2dContext, "red");
128
- * ```
78
+ * function drawSpinningYinYang(like: Like) {
79
+ * const color1 = "black";
80
+ * const color2 = "white";
81
+ * const size = 50;
82
+ * const pos = Vec2.div(like.canvas.getSize(), 2); // calc center of screen
83
+ * const speed = 0.5; // rotations per second
84
+ *
85
+ * like.gfx.push();
86
+ * like.gfx.translate(pos);
87
+ * like.gfx.rotate(like.timer.getTime() * Math.PI * 2.0 * speed);
88
+ * like.gfx.scale(size);
89
+ * like.gfx.circle("fill", color1, [0, 0], 2);
90
+ * // use the arc parameter to fill in a semicircle. Note that it's clockwise from {x:1, y:0}.
91
+ * like.gfx.circle("fill", color2, [0, 0], 2, { arc: [Math.PI/2, Math.PI*3/2] });
92
+ * like.gfx.circle("fill", color2, [0, -1], 1);
93
+ * like.gfx.circle("fill", color1, [0, 1], 1);
94
+ * like.gfx.circle("fill", color2, [0, 1], 1/3);
95
+ * like.gfx.circle("fill", color1, [0, -1], 1/3);
96
+ * like.gfx.pop();
97
+ * }
129
98
  *
99
+ * like.draw = (like: Like) => {
100
+ * drawSpinningYinYang(like);
101
+ * }
102
+ * ```
130
103
  */
131
104
  export class Graphics {
132
105
  constructor(ctx) {
@@ -147,7 +120,6 @@ export class Graphics {
147
120
  }
148
121
  /**
149
122
  * Clears the canvas with a solid color.
150
- * @param this.ctx Canvas context.
151
123
  * @param color Fill color.
152
124
  */
153
125
  clear(color = [0, 0, 0, 1]) {
@@ -156,7 +128,6 @@ export class Graphics {
156
128
  }
157
129
  /**
158
130
  * Draws a rectangle.
159
- * @param this.ctx Canvas context.
160
131
  * @param mode Fill or line.
161
132
  * @param color Fill or stroke color.
162
133
  * @param rect Rectangle [x, y, w, h].
@@ -176,7 +147,7 @@ export class Graphics {
176
147
  }
177
148
  /**
178
149
  * Draws a circle or ellipse.
179
- * @param this.ctx Canvas context.
150
+
180
151
  * @param mode Fill or line.
181
152
  * @param color Fill or stroke color.
182
153
  * @param position Center position.
@@ -212,7 +183,7 @@ export class Graphics {
212
183
  }
213
184
  /**
214
185
  * Draws connected line segments.
215
- * @param this.ctx Canvas context.
186
+
216
187
  * @param color Stroke color.
217
188
  * @param points Array of [x, y] positions.
218
189
  * @param props Optional stroke properties.
@@ -238,7 +209,7 @@ export class Graphics {
238
209
  * to the left and right of its position. If you align right, your position
239
210
  * becomes the upper-right corner of the text.
240
211
  *
241
- * @param this.ctx Canvas context.
212
+
242
213
  * @param color Fill color.
243
214
  * @param text Text string.
244
215
  * @param position Top-left position.
@@ -270,7 +241,7 @@ export class Graphics {
270
241
  * @remarks named "draw" because it draws anything _drawable_
271
242
  * in the long run.
272
243
  *
273
- * @param this.ctx Canvas context.
244
+
274
245
  * @param handle Image handle from newImage.
275
246
  * @param position Draw position.
276
247
  * @param props Optional rotation, scale, origin, or quad.
@@ -301,7 +272,7 @@ export class Graphics {
301
272
  /**
302
273
  * Loads an image from a path.
303
274
  * Unlike built-in loading, this pretends to be synchronous.
304
- * @param this.ctx Canvas context.
275
+
305
276
  * @param path Image file path.
306
277
  * @returns ImageHandle for use with draw.
307
278
  */
@@ -310,7 +281,7 @@ export class Graphics {
310
281
  }
311
282
  /**
312
283
  * Sets the clipping region.
313
- * @param this.ctx Canvas context.
284
+
314
285
  * @param rect Clipping rectangle, or full canvas if omitted.
315
286
  */
316
287
  clip(rect) {
@@ -326,7 +297,7 @@ export class Graphics {
326
297
  }
327
298
  /**
328
299
  * Draws a polygon.
329
- * @param this.ctx Canvas context.
300
+
330
301
  * @param mode Fill or line.
331
302
  * @param color Fill or stroke color.
332
303
  * @param points Array of [x, y] vertices.
@@ -353,7 +324,7 @@ export class Graphics {
353
324
  }
354
325
  /**
355
326
  * Draws individual pixels.
356
- * @param this.ctx Canvas context.
327
+
357
328
  * @param color Fill color.
358
329
  * @param pts Array of [x, y] positions.
359
330
  */
@@ -363,21 +334,21 @@ export class Graphics {
363
334
  }
364
335
  /**
365
336
  * Saves canvas state.
366
- * @param this.ctx Canvas context.
337
+
367
338
  */
368
339
  push() {
369
340
  this.ctx.save();
370
341
  }
371
342
  /**
372
343
  * Restores canvas state.
373
- * @param this.ctx Canvas context.
344
+
374
345
  */
375
346
  pop() {
376
347
  this.ctx.restore();
377
348
  }
378
349
  /**
379
350
  * Applies a translation.
380
- * @param this.ctx Canvas context.
351
+
381
352
  * @param offset [x, y] offset.
382
353
  */
383
354
  translate(offset) {
@@ -386,7 +357,7 @@ export class Graphics {
386
357
  }
387
358
  /**
388
359
  * Applies a rotation.
389
- * @param this.ctx Canvas context.
360
+
390
361
  * @param angle Rotation in radians.
391
362
  */
392
363
  rotate(angle) {
@@ -394,7 +365,7 @@ export class Graphics {
394
365
  }
395
366
  /**
396
367
  * Applies a scale.
397
- * @param this.ctx Canvas context.
368
+
398
369
  * @param factor Scale factor (number or [x, y]).
399
370
  */
400
371
  scale(factor) {
@@ -0,0 +1,22 @@
1
+ import { Vector2 } from "../math";
2
+ /**
3
+ * An image that can be drawn using {@link Graphics.draw}
4
+ *
5
+ * Unlike raw HTMLImageElement, there is no need to wait for it to load.
6
+ * If the image isn't loaded, it simply won't draw it at all.
7
+ *
8
+ * If you're planning on loading many large images, simply preload
9
+ * these image handles beforehand so that they're ready.
10
+ */
11
+ export declare class ImageHandle {
12
+ readonly path: string;
13
+ private element;
14
+ private loadPromise;
15
+ private isLoaded;
16
+ constructor(path: string);
17
+ isReady(): boolean;
18
+ ready(): Promise<void>;
19
+ get size(): Vector2;
20
+ getElement(): HTMLImageElement | null;
21
+ }
22
+ //# sourceMappingURL=image.d.ts.map