Skip to content

Commit e9f747e

Browse files
committed
Add comments
1 parent 6b537c7 commit e9f747e

File tree

5 files changed

+1268
-67
lines changed

5 files changed

+1268
-67
lines changed
Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,47 @@
11
import CanvasBase from '../canvasbase/Canvas';
22

3+
/**
4+
* Canvas game object with image loading helpers.
5+
*/
36
export default class Canvas extends CanvasBase {
7+
/**
8+
* Load an image from a URL.
9+
* @param url - Image URL.
10+
* @param callback - Callback fired on load.
11+
* @returns This instance.
12+
*/
413
loadFromURL(
514
url: string,
615
callback?: () => void
716
): this;
817

18+
/**
19+
* Load an image from a URL and return a promise.
20+
* @param url - Image URL.
21+
* @returns A promise that resolves when loaded.
22+
*/
923
loadFromURLPromise(
1024
url: string
1125
): Promise<any>;
1226

27+
/**
28+
* Load an image from a File object.
29+
* @param file - File object.
30+
* @param callback - Callback fired on load.
31+
* @returns This instance.
32+
*/
1333
loadFromFile(
1434
file: File,
1535
callback?: () => void
1636
): this;
1737

38+
/**
39+
* Load an image from a File object and return a promise.
40+
* @param file - File object.
41+
* @returns A promise that resolves when loaded.
42+
*/
1843
loadFromFilePromise(
1944
file: File
2045
): Promise<any>;
2146

22-
}
47+
}

plugins/gameobjects/canvas/canvasbase/Canvas.d.ts

Lines changed: 128 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,153 @@
11
// import * as Phaser from 'phaser';
22
import CanvasGameObjectBase from '../../../utils/types/CanvasGameObjectBase';
33

4+
/**
5+
* Canvas-backed game object with texture update helpers.
6+
*/
47
export default class Canvas extends CanvasGameObjectBase {
8+
/**
9+
* Create a canvas game object.
10+
* @param scene - The Scene to which this object belongs.
11+
* @param x - The x position.
12+
* @param y - The y position.
13+
* @param width - The canvas width.
14+
* @param height - The canvas height.
15+
* @param resolution - Canvas resolution.
16+
*/
517
constructor(
618
scene: Phaser.Scene,
719
x?: number, y?: number,
820
width?: number, height?: number,
921
resolution?: number,
1022
);
1123

24+
/**
25+
* Current resolution value.
26+
*/
1227
readonly resolution: number;
28+
/**
29+
* Set resolution.
30+
* @param resolution - Resolution value.
31+
* @returns This instance.
32+
*/
1333
setResolution(resolution: number): this;
1434

35+
/**
36+
* Canvas element.
37+
*/
1538
canvas: HTMLCanvasElement;
39+
/**
40+
* Canvas 2D context.
41+
*/
1642
context: CanvasRenderingContext2D;
43+
/**
44+
* Get the canvas element.
45+
* @param readOnly - True to return without marking dirty.
46+
* @returns The canvas element.
47+
*/
1748
getCanvas(readOnly?: boolean): HTMLCanvasElement;
49+
/**
50+
* Get the canvas 2D context.
51+
* @param readOnly - True to return without marking dirty.
52+
* @returns The 2D context.
53+
*/
1854
getContext(readOnly?: boolean): CanvasRenderingContext2D;
1955

56+
/**
57+
* Set size of the game object.
58+
* @param width - Width value.
59+
* @param height - Height value.
60+
* @returns This instance.
61+
*/
2062
setSize(width: number, height: number): this;
63+
/**
64+
* Resize the canvas.
65+
* @param width - Width value.
66+
* @param height - Height value.
67+
* @returns This instance.
68+
*/
2169
resize(width: number, height: number): this;
70+
/**
71+
* Set the canvas size.
72+
* @param width - Width value.
73+
* @param height - Height value.
74+
* @returns This instance.
75+
*/
2276
setCanvasSize(width: number, height: number): this;
2377

78+
/**
79+
* Mark the canvas as needing redraw.
80+
* @returns This instance.
81+
*/
2482
needRedraw(): this;
83+
/**
84+
* True if the canvas is dirty.
85+
*/
2586
dirty: boolean;
2687

88+
/**
89+
* Clear the canvas.
90+
* @returns This instance.
91+
*/
2792
clear(): this;
93+
/**
94+
* Fill the canvas with a color.
95+
* @param color - Fill color.
96+
* @returns This instance.
97+
*/
2898
fill(color: string): this;
2999

100+
/**
101+
* Update the texture from the canvas.
102+
* @param callback - Optional draw callback.
103+
* @param scope - Callback scope.
104+
* @returns This instance.
105+
*/
30106
updateTexture(
31107
callback?: (canvasElem: HTMLCanvasElement, context: CanvasRenderingContext2D) => void,
32108
scope?: object
33109
): this;
34110

111+
/**
112+
* Generate a texture from the canvas.
113+
* @param key - Texture key.
114+
* @param x - Source x.
115+
* @param y - Source y.
116+
* @param width - Source width.
117+
* @param height - Source height.
118+
* @returns This instance.
119+
*/
35120
generateTexture(
36121
key: string | number,
37122
x?: number, y?: number,
38123
width?: number, height?: number
39124
): this;
40125

126+
/**
127+
* Load a texture into the canvas.
128+
* @param key - Texture key.
129+
* @param frame - Frame name.
130+
* @returns This instance.
131+
*/
41132
loadTexture(
42133
key: string,
43134
frame?: string,
44135
): this;
45136

137+
/**
138+
* Draw a frame to the canvas.
139+
* @param key - Texture key.
140+
* @param frame - Frame name.
141+
* @param dx - Destination x.
142+
* @param dy - Destination y.
143+
* @param dWidth - Destination width.
144+
* @param dHeight - Destination height.
145+
* @param sxOffset - Source x offset.
146+
* @param syOffset - Source y offset.
147+
* @param sWidth - Source width.
148+
* @param sHeight - Source height.
149+
* @returns This instance.
150+
*/
46151
drawFrame(
47152
key: string,
48153
frame?: string,
@@ -56,15 +161,37 @@ export default class Canvas extends CanvasGameObjectBase {
56161
sHeight?: number,
57162
): this;
58163

164+
/**
165+
* Get canvas data URL.
166+
* @param type - Mime type.
167+
* @param encoderOptions - Encoder options.
168+
* @returns Data URL string.
169+
*/
59170
getDataURL(
60171
type?: string,
61172
encoderOptions?: number
62173
): string;
63174

175+
/**
176+
* Get pixel color at a position.
177+
* @param x - X position.
178+
* @param y - Y position.
179+
* @returns The color.
180+
*/
64181
getPixel(
65182
x: number, y: number
66183
): Phaser.Display.Color;
67184

185+
/**
186+
* Set pixel color at a position.
187+
* @param x - X position.
188+
* @param y - Y position.
189+
* @param r - Red value or color object.
190+
* @param g - Green value.
191+
* @param b - Blue value.
192+
* @param a - Alpha value.
193+
* @returns This instance.
194+
*/
68195
setPixel(
69196
x: number, y: number,
70197
r: number | Phaser.Display.Color,
@@ -73,4 +200,4 @@ export default class Canvas extends CanvasGameObjectBase {
73200
a?: number
74201
): this;
75202

76-
}
203+
}

plugins/gameobjects/dynamictext/dynamictext/DynamicText.d.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ declare namespace DynamicText {
1717
type PaddingTypes = number |
1818
{ left?: number, right?: number, top?: number, bottom?: number };
1919

20+
type RadiusType = number | { x?: number, y?: number };
21+
2022
interface IRadiusConfig {
21-
tl?: (number | { x?: number, y?: number }),
22-
tr?: (number | { x?: number, y?: number }),
23-
bl?: (number | { x?: number, y?: number }),
24-
br?: (number | { x?: number, y?: number })
23+
tl?: RadiusType,
24+
tr?: RadiusType,
25+
bl?: RadiusType,
26+
br?: RadiusType
2527
}
2628

2729
interface IConfigBackground {

0 commit comments

Comments
 (0)