@vpmedia/phaser 1.94.0 → 1.96.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/CHANGELOG.md +41 -0
- package/package.json +11 -11
- package/src/phaser/core/animation.js +79 -56
- package/src/phaser/core/animation_manager.js +55 -55
- package/src/phaser/core/animation_parser.js +2 -2
- package/src/phaser/core/cache.js +154 -154
- package/src/phaser/core/device.js +2 -1
- package/src/phaser/core/device_util.js +27 -27
- package/src/phaser/core/dom.js +43 -43
- package/src/phaser/core/event_manager.js +63 -63
- package/src/phaser/core/factory.js +47 -47
- package/src/phaser/core/frame.js +30 -30
- package/src/phaser/core/frame_data.js +30 -28
- package/src/phaser/core/frame_util.js +8 -8
- package/src/phaser/core/game.js +35 -19
- package/src/phaser/core/input_pointer.js +18 -0
- package/src/phaser/core/loader.js +171 -171
- package/src/phaser/core/loader_parser.js +22 -22
- package/src/phaser/core/raf.js +1 -1
- package/src/phaser/core/scale_manager.js +3 -2
- package/src/phaser/core/scene.js +16 -10
- package/src/phaser/core/scene_manager.js +51 -43
- package/src/phaser/core/signal.js +56 -52
- package/src/phaser/core/sound.js +54 -54
- package/src/phaser/core/sound_manager.js +49 -49
- package/src/phaser/core/stage.js +16 -16
- package/src/phaser/core/time.js +54 -30
- package/src/phaser/core/timer.js +82 -64
- package/src/phaser/core/timer_event.js +9 -9
- package/src/phaser/core/tween.js +106 -90
- package/src/phaser/core/tween_data.js +30 -30
- package/src/phaser/core/tween_manager.js +32 -24
- package/src/phaser/core/world.js +4 -3
- package/src/phaser/display/bitmap_text.js +72 -54
- package/src/phaser/display/button.js +48 -47
- package/src/phaser/display/canvas/buffer.js +8 -8
- package/src/phaser/display/canvas/graphics.js +8 -8
- package/src/phaser/display/canvas/masker.js +5 -5
- package/src/phaser/display/canvas/pool.js +18 -18
- package/src/phaser/display/canvas/renderer.js +17 -16
- package/src/phaser/display/canvas/tinter.js +22 -22
- package/src/phaser/display/canvas/util.js +42 -42
- package/src/phaser/display/display_object.js +119 -108
- package/src/phaser/display/graphics.js +129 -112
- package/src/phaser/display/graphics_data.js +10 -10
- package/src/phaser/display/graphics_data_util.js +3 -3
- package/src/phaser/display/group.js +63 -50
- package/src/phaser/display/image.js +68 -50
- package/src/phaser/display/sprite_batch.js +2 -2
- package/src/phaser/display/sprite_util.js +19 -19
- package/src/phaser/display/text.js +217 -187
- package/src/phaser/display/webgl/abstract_filter.js +4 -4
- package/src/phaser/display/webgl/base_texture.js +9 -9
- package/src/phaser/display/webgl/blend_manager.js +7 -7
- package/src/phaser/display/webgl/earcut.js +95 -95
- package/src/phaser/display/webgl/earcut_node.js +4 -4
- package/src/phaser/display/webgl/fast_sprite_batch.js +15 -15
- package/src/phaser/display/webgl/filter_manager.js +9 -9
- package/src/phaser/display/webgl/filter_texture.js +10 -10
- package/src/phaser/display/webgl/graphics.js +37 -37
- package/src/phaser/display/webgl/graphics_data.js +4 -4
- package/src/phaser/display/webgl/mask_manager.js +6 -6
- package/src/phaser/display/webgl/render_texture.js +16 -16
- package/src/phaser/display/webgl/renderer.js +21 -20
- package/src/phaser/display/webgl/shader/complex.js +4 -4
- package/src/phaser/display/webgl/shader/fast.js +4 -4
- package/src/phaser/display/webgl/shader/normal.js +8 -8
- package/src/phaser/display/webgl/shader/primitive.js +4 -4
- package/src/phaser/display/webgl/shader/strip.js +4 -4
- package/src/phaser/display/webgl/shader_manager.js +9 -9
- package/src/phaser/display/webgl/sprite_batch.js +18 -18
- package/src/phaser/display/webgl/stencil_manager.js +16 -16
- package/src/phaser/display/webgl/texture.js +13 -13
- package/src/phaser/display/webgl/texture_util.js +8 -8
- package/src/phaser/display/webgl/util.js +25 -25
- package/src/phaser/geom/circle.js +74 -69
- package/src/phaser/geom/ellipse.js +33 -28
- package/src/phaser/geom/line.js +96 -93
- package/src/phaser/geom/matrix.js +61 -54
- package/src/phaser/geom/point.js +99 -96
- package/src/phaser/geom/polygon.js +27 -22
- package/src/phaser/geom/rectangle.js +137 -132
- package/src/phaser/geom/rounded_rectangle.js +12 -12
- package/src/phaser/geom/util/circle.js +33 -33
- package/src/phaser/geom/util/ellipse.js +5 -5
- package/src/phaser/geom/util/line.js +26 -26
- package/src/phaser/geom/util/matrix.js +8 -8
- package/src/phaser/geom/util/point.js +97 -97
- package/src/phaser/geom/util/polygon.js +4 -4
- package/src/phaser/geom/util/rectangle.js +74 -74
- package/src/phaser/geom/util/rounded_rectangle.js +4 -4
- package/src/phaser/util/math.js +81 -81
- package/types/phaser/core/animation.d.ts +79 -56
- package/types/phaser/core/animation.d.ts.map +1 -1
- package/types/phaser/core/animation_manager.d.ts +55 -55
- package/types/phaser/core/animation_parser.d.ts +3 -2
- package/types/phaser/core/animation_parser.d.ts.map +1 -1
- package/types/phaser/core/cache.d.ts +154 -154
- package/types/phaser/core/device.d.ts.map +1 -1
- package/types/phaser/core/dom.d.ts +51 -44
- package/types/phaser/core/dom.d.ts.map +1 -1
- package/types/phaser/core/event_manager.d.ts +63 -63
- package/types/phaser/core/factory.d.ts +47 -47
- package/types/phaser/core/frame.d.ts +30 -30
- package/types/phaser/core/frame_data.d.ts +28 -27
- package/types/phaser/core/frame_data.d.ts.map +1 -1
- package/types/phaser/core/game.d.ts +54 -21
- package/types/phaser/core/game.d.ts.map +1 -1
- package/types/phaser/core/input_pointer.d.ts +18 -0
- package/types/phaser/core/input_pointer.d.ts.map +1 -1
- package/types/phaser/core/loader.d.ts +175 -172
- package/types/phaser/core/loader.d.ts.map +1 -1
- package/types/phaser/core/loader_parser.d.ts.map +1 -1
- package/types/phaser/core/raf.d.ts +1 -1
- package/types/phaser/core/scale_manager.d.ts +6 -5
- package/types/phaser/core/scale_manager.d.ts.map +1 -1
- package/types/phaser/core/scene.d.ts +15 -9
- package/types/phaser/core/scene.d.ts.map +1 -1
- package/types/phaser/core/scene_manager.d.ts +51 -43
- package/types/phaser/core/scene_manager.d.ts.map +1 -1
- package/types/phaser/core/signal.d.ts +54 -51
- package/types/phaser/core/signal.d.ts.map +1 -1
- package/types/phaser/core/sound.d.ts +54 -54
- package/types/phaser/core/sound_manager.d.ts +49 -49
- package/types/phaser/core/stage.d.ts +10 -10
- package/types/phaser/core/time.d.ts +54 -30
- package/types/phaser/core/time.d.ts.map +1 -1
- package/types/phaser/core/timer.d.ts +82 -64
- package/types/phaser/core/timer.d.ts.map +1 -1
- package/types/phaser/core/timer_event.d.ts +9 -9
- package/types/phaser/core/tween.d.ts +106 -90
- package/types/phaser/core/tween.d.ts.map +1 -1
- package/types/phaser/core/tween_data.d.ts +30 -30
- package/types/phaser/core/tween_manager.d.ts +35 -67
- package/types/phaser/core/tween_manager.d.ts.map +1 -1
- package/types/phaser/core/world.d.ts +4 -3
- package/types/phaser/core/world.d.ts.map +1 -1
- package/types/phaser/display/bitmap_text.d.ts +76 -53
- package/types/phaser/display/bitmap_text.d.ts.map +1 -1
- package/types/phaser/display/button.d.ts +47 -46
- package/types/phaser/display/button.d.ts.map +1 -1
- package/types/phaser/display/canvas/buffer.d.ts +8 -8
- package/types/phaser/display/canvas/graphics.d.ts +3 -3
- package/types/phaser/display/canvas/graphics.d.ts.map +1 -1
- package/types/phaser/display/canvas/pool.d.ts +6 -3
- package/types/phaser/display/canvas/pool.d.ts.map +1 -1
- package/types/phaser/display/canvas/renderer.d.ts +18 -17
- package/types/phaser/display/canvas/renderer.d.ts.map +1 -1
- package/types/phaser/display/canvas/util.d.ts +6 -6
- package/types/phaser/display/canvas/util.d.ts.map +1 -1
- package/types/phaser/display/display_object.d.ts +119 -108
- package/types/phaser/display/display_object.d.ts.map +1 -1
- package/types/phaser/display/graphics.d.ts +118 -102
- package/types/phaser/display/graphics.d.ts.map +1 -1
- package/types/phaser/display/graphics_data.d.ts +10 -10
- package/types/phaser/display/group.d.ts +59 -47
- package/types/phaser/display/group.d.ts.map +1 -1
- package/types/phaser/display/image.d.ts +58 -45
- package/types/phaser/display/image.d.ts.map +1 -1
- package/types/phaser/display/text.d.ts +237 -188
- package/types/phaser/display/text.d.ts.map +1 -1
- package/types/phaser/display/webgl/abstract_filter.d.ts +4 -4
- package/types/phaser/display/webgl/base_texture.d.ts +10 -10
- package/types/phaser/display/webgl/base_texture.d.ts.map +1 -1
- package/types/phaser/display/webgl/blend_manager.d.ts +6 -6
- package/types/phaser/display/webgl/earcut.d.ts +95 -95
- package/types/phaser/display/webgl/earcut_node.d.ts +4 -4
- package/types/phaser/display/webgl/fast_sprite_batch.d.ts +15 -15
- package/types/phaser/display/webgl/filter_manager.d.ts +8 -8
- package/types/phaser/display/webgl/filter_texture.d.ts +10 -10
- package/types/phaser/display/webgl/graphics.d.ts +2 -2
- package/types/phaser/display/webgl/graphics.d.ts.map +1 -1
- package/types/phaser/display/webgl/graphics_data.d.ts +4 -4
- package/types/phaser/display/webgl/render_texture.d.ts +16 -16
- package/types/phaser/display/webgl/renderer.d.ts +21 -20
- package/types/phaser/display/webgl/renderer.d.ts.map +1 -1
- package/types/phaser/display/webgl/shader/complex.d.ts +4 -4
- package/types/phaser/display/webgl/shader/fast.d.ts +4 -4
- package/types/phaser/display/webgl/shader/normal.d.ts +8 -8
- package/types/phaser/display/webgl/shader/primitive.d.ts +4 -4
- package/types/phaser/display/webgl/shader/strip.d.ts +4 -4
- package/types/phaser/display/webgl/shader_manager.d.ts +8 -8
- package/types/phaser/display/webgl/sprite_batch.d.ts +17 -17
- package/types/phaser/display/webgl/stencil_manager.d.ts +15 -15
- package/types/phaser/display/webgl/texture.d.ts +12 -12
- package/types/phaser/display/webgl/texture_util.d.ts +4 -2
- package/types/phaser/display/webgl/texture_util.d.ts.map +1 -1
- package/types/phaser/geom/circle.d.ts +74 -69
- package/types/phaser/geom/circle.d.ts.map +1 -1
- package/types/phaser/geom/ellipse.d.ts +33 -28
- package/types/phaser/geom/ellipse.d.ts.map +1 -1
- package/types/phaser/geom/line.d.ts +96 -93
- package/types/phaser/geom/line.d.ts.map +1 -1
- package/types/phaser/geom/matrix.d.ts +61 -54
- package/types/phaser/geom/matrix.d.ts.map +1 -1
- package/types/phaser/geom/point.d.ts +99 -96
- package/types/phaser/geom/point.d.ts.map +1 -1
- package/types/phaser/geom/polygon.d.ts +29 -23
- package/types/phaser/geom/polygon.d.ts.map +1 -1
- package/types/phaser/geom/rectangle.d.ts +137 -132
- package/types/phaser/geom/rectangle.d.ts.map +1 -1
- package/types/phaser/geom/rounded_rectangle.d.ts +12 -12
- package/types/phaser/geom/util/point.d.ts +1 -1
- package/types/phaser/geom/util/point.d.ts.map +1 -1
- package/pnpm-workspace.yaml +0 -4
|
@@ -5,36 +5,47 @@ import { Image } from './image.js';
|
|
|
5
5
|
|
|
6
6
|
export class BitmapText extends DisplayObject {
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
* @param {import('../core/game.js').Game} game -
|
|
10
|
-
* @param {number} x -
|
|
11
|
-
* @param {number} y -
|
|
12
|
-
* @param {string} font -
|
|
13
|
-
* @param {string} text -
|
|
14
|
-
* @param {number} size -
|
|
15
|
-
* @param {string} align -
|
|
8
|
+
* Creates a new BitmapText instance.
|
|
9
|
+
* @param {import('../core/game.js').Game} game - The game instance this bitmap text belongs to.
|
|
10
|
+
* @param {number} x - The x position of the bitmap text.
|
|
11
|
+
* @param {number} y - The y position of the bitmap text.
|
|
12
|
+
* @param {string} font - The key of the bitmap font to use.
|
|
13
|
+
* @param {string} text - The text to display.
|
|
14
|
+
* @param {number} size - The font size.
|
|
15
|
+
* @param {string} align - The text alignment (left, center, right).
|
|
16
16
|
*/
|
|
17
17
|
constructor(game, x = 0, y = 0, font = '', text = '', size = 32, align = 'left') {
|
|
18
18
|
super(game);
|
|
19
|
+
/** @type {number} */
|
|
19
20
|
this.type = BITMAP_TEXT;
|
|
20
21
|
this.position.setTo(x, y);
|
|
22
|
+
/** @type {number} */
|
|
21
23
|
this.textWidth = 0;
|
|
24
|
+
/** @type {number} */
|
|
22
25
|
this.textHeight = 0;
|
|
26
|
+
/** @type {Point} */
|
|
23
27
|
this._prevAnchor = new Point();
|
|
24
28
|
this._glyphs = [];
|
|
29
|
+
/** @type {number} */
|
|
25
30
|
this._maxWidth = 0;
|
|
31
|
+
/** @type {string} */
|
|
26
32
|
this._text = text.toString() || '';
|
|
27
33
|
this._data = game.cache.getBitmapFont(font);
|
|
34
|
+
/** @type {string} */
|
|
28
35
|
this._font = font;
|
|
36
|
+
/** @type {number} */
|
|
29
37
|
this._fontSize = size;
|
|
38
|
+
/** @type {string} */
|
|
30
39
|
this._align = align;
|
|
40
|
+
/** @type {number} */
|
|
31
41
|
this._tint = 0xffffff;
|
|
32
42
|
this.updateText();
|
|
43
|
+
/** @type {boolean} */
|
|
33
44
|
this.dirty = false;
|
|
34
45
|
}
|
|
35
46
|
|
|
36
47
|
/**
|
|
37
|
-
*
|
|
48
|
+
* Destroys this bitmap text and cleans up resources.
|
|
38
49
|
*/
|
|
39
50
|
destroy() {
|
|
40
51
|
this._prevAnchor = null;
|
|
@@ -45,7 +56,7 @@ export class BitmapText extends DisplayObject {
|
|
|
45
56
|
}
|
|
46
57
|
|
|
47
58
|
/**
|
|
48
|
-
*
|
|
59
|
+
* Called before the update cycle for this bitmap text.
|
|
49
60
|
*/
|
|
50
61
|
preUpdate() {
|
|
51
62
|
if (this.pendingDestroy) {
|
|
@@ -67,19 +78,19 @@ export class BitmapText extends DisplayObject {
|
|
|
67
78
|
}
|
|
68
79
|
|
|
69
80
|
/**
|
|
70
|
-
*
|
|
71
|
-
* @param {string} text -
|
|
81
|
+
* Sets the text to display.
|
|
82
|
+
* @param {string} text - The new text to display.
|
|
72
83
|
*/
|
|
73
84
|
setText(text) {
|
|
74
85
|
this.text = text;
|
|
75
86
|
}
|
|
76
87
|
|
|
77
88
|
/**
|
|
78
|
-
*
|
|
79
|
-
* @param {object} data -
|
|
80
|
-
* @param {number} scale -
|
|
81
|
-
* @param {string} text -
|
|
82
|
-
* @returns {
|
|
89
|
+
* Scans a line of text to calculate its width and other properties.
|
|
90
|
+
* @param {object} data - The font data for this bitmap text.
|
|
91
|
+
* @param {number} scale - The scaling factor to apply to the font size.
|
|
92
|
+
* @param {string} text - The text to scan.
|
|
93
|
+
* @returns {{width: number, text: string, end: boolean, chars: number[]}} An object containing the width, processed text, end status, and character positions.
|
|
83
94
|
*/
|
|
84
95
|
scanLine(data, scale, text) {
|
|
85
96
|
let x = 0;
|
|
@@ -143,10 +154,10 @@ export class BitmapText extends DisplayObject {
|
|
|
143
154
|
}
|
|
144
155
|
|
|
145
156
|
/**
|
|
146
|
-
*
|
|
147
|
-
* @param {string} text -
|
|
148
|
-
* @param {string} replace -
|
|
149
|
-
* @returns {string}
|
|
157
|
+
* Cleans the provided text by removing invalid characters and replacing them with a specified character.
|
|
158
|
+
* @param {string} text - The text to clean.
|
|
159
|
+
* @param {string} replace - The character to use for replacement of invalid characters (default: '').
|
|
160
|
+
* @returns {string} The cleaned text.
|
|
150
161
|
*/
|
|
151
162
|
cleanText(text, replace = '') {
|
|
152
163
|
const data = this._data.font;
|
|
@@ -171,7 +182,7 @@ export class BitmapText extends DisplayObject {
|
|
|
171
182
|
}
|
|
172
183
|
|
|
173
184
|
/**
|
|
174
|
-
*
|
|
185
|
+
* Updates the internal text rendering based on current properties and content.
|
|
175
186
|
*/
|
|
176
187
|
updateText() {
|
|
177
188
|
const data = this._data.font;
|
|
@@ -242,8 +253,8 @@ export class BitmapText extends DisplayObject {
|
|
|
242
253
|
}
|
|
243
254
|
|
|
244
255
|
/**
|
|
245
|
-
*
|
|
246
|
-
* @returns {number}
|
|
256
|
+
* Removes unused glyphs from the pool and returns the number removed.
|
|
257
|
+
* @returns {number} The number of glyphs that were removed from the pool.
|
|
247
258
|
*/
|
|
248
259
|
purgeGlyphs() {
|
|
249
260
|
const len = this._glyphs.length;
|
|
@@ -263,7 +274,7 @@ export class BitmapText extends DisplayObject {
|
|
|
263
274
|
}
|
|
264
275
|
|
|
265
276
|
/**
|
|
266
|
-
*
|
|
277
|
+
* Updates the transform of this bitmap text, updating its text if needed.
|
|
267
278
|
*/
|
|
268
279
|
updateTransform() {
|
|
269
280
|
if (this.dirty || !this.anchor.equals(this._prevAnchor)) {
|
|
@@ -275,10 +286,10 @@ export class BitmapText extends DisplayObject {
|
|
|
275
286
|
}
|
|
276
287
|
|
|
277
288
|
/**
|
|
278
|
-
*
|
|
279
|
-
* @param {string} value -
|
|
280
|
-
* @param {number} position -
|
|
281
|
-
* @returns {BitmapText}
|
|
289
|
+
* Adds a color to a specific position in the text.
|
|
290
|
+
* @param {string} value - The color to apply (in hex format or CSS color name).
|
|
291
|
+
* @param {number} position - The character position to apply the color to.
|
|
292
|
+
* @returns {BitmapText} This bitmap text instance for chaining.
|
|
282
293
|
*/
|
|
283
294
|
addColor(value, position) {
|
|
284
295
|
const color = typeof value === 'string' ? Number.parseInt(value.replace('#', ''), 16) : value;
|
|
@@ -290,15 +301,16 @@ export class BitmapText extends DisplayObject {
|
|
|
290
301
|
}
|
|
291
302
|
|
|
292
303
|
/**
|
|
293
|
-
*
|
|
294
|
-
* @returns {string}
|
|
304
|
+
* Gets the text alignment property.
|
|
305
|
+
* @returns {string} The current text alignment (left, center, right).
|
|
295
306
|
*/
|
|
296
307
|
get align() {
|
|
297
308
|
return this._align;
|
|
298
309
|
}
|
|
299
310
|
|
|
300
311
|
/**
|
|
301
|
-
*
|
|
312
|
+
* Sets the text alignment property.
|
|
313
|
+
* @param {string} value - The new text alignment (left, center, right).
|
|
302
314
|
*/
|
|
303
315
|
set align(value) {
|
|
304
316
|
if (value !== this._align && (value === 'left' || value === 'center' || value === 'right')) {
|
|
@@ -308,15 +320,16 @@ export class BitmapText extends DisplayObject {
|
|
|
308
320
|
}
|
|
309
321
|
|
|
310
322
|
/**
|
|
311
|
-
*
|
|
312
|
-
* @returns {number}
|
|
323
|
+
* Gets the tint color of this bitmap text.
|
|
324
|
+
* @returns {number} The current tint color in RGB format.
|
|
313
325
|
*/
|
|
314
326
|
get tint() {
|
|
315
327
|
return this._tint;
|
|
316
328
|
}
|
|
317
329
|
|
|
318
330
|
/**
|
|
319
|
-
*
|
|
331
|
+
* Sets the tint color of this bitmap text.
|
|
332
|
+
* @param {number} value - The new tint color in RGB format.
|
|
320
333
|
*/
|
|
321
334
|
set tint(value) {
|
|
322
335
|
if (value !== this._tint) {
|
|
@@ -326,8 +339,8 @@ export class BitmapText extends DisplayObject {
|
|
|
326
339
|
}
|
|
327
340
|
|
|
328
341
|
/**
|
|
329
|
-
*
|
|
330
|
-
* @returns {string}
|
|
342
|
+
* Gets the fill color of this bitmap text as a hex string.
|
|
343
|
+
* @returns {string} The current fill color in hex format.
|
|
331
344
|
*/
|
|
332
345
|
get fill() {
|
|
333
346
|
if (typeof this.tint === 'number') {
|
|
@@ -341,22 +354,24 @@ export class BitmapText extends DisplayObject {
|
|
|
341
354
|
}
|
|
342
355
|
|
|
343
356
|
/**
|
|
344
|
-
*
|
|
357
|
+
* Sets the fill color of this bitmap text.
|
|
358
|
+
* @param {string} value - The new fill color in hex format or CSS color name.
|
|
345
359
|
*/
|
|
346
360
|
set fill(value) {
|
|
347
361
|
this.tint = typeof value === 'string' ? Number.parseInt(value.replace('#', ''), 16) : value;
|
|
348
362
|
}
|
|
349
363
|
|
|
350
364
|
/**
|
|
351
|
-
*
|
|
352
|
-
* @returns {string}
|
|
365
|
+
* Gets the font key used by this bitmap text.
|
|
366
|
+
* @returns {string} The current font key.
|
|
353
367
|
*/
|
|
354
368
|
get font() {
|
|
355
369
|
return this._font;
|
|
356
370
|
}
|
|
357
371
|
|
|
358
372
|
/**
|
|
359
|
-
*
|
|
373
|
+
* Sets the font key used by this bitmap text.
|
|
374
|
+
* @param {string} value - The new font key to use.
|
|
360
375
|
*/
|
|
361
376
|
set font(value) {
|
|
362
377
|
const trimmedValue = value.trim();
|
|
@@ -368,15 +383,16 @@ export class BitmapText extends DisplayObject {
|
|
|
368
383
|
}
|
|
369
384
|
|
|
370
385
|
/**
|
|
371
|
-
*
|
|
372
|
-
* @returns {number}
|
|
386
|
+
* Gets the font size of this bitmap text.
|
|
387
|
+
* @returns {number} The current font size.
|
|
373
388
|
*/
|
|
374
389
|
get fontSize() {
|
|
375
390
|
return this._fontSize;
|
|
376
391
|
}
|
|
377
392
|
|
|
378
393
|
/**
|
|
379
|
-
*
|
|
394
|
+
* Sets the font size of this bitmap text.
|
|
395
|
+
* @param {number} value - The new font size to use.
|
|
380
396
|
*/
|
|
381
397
|
set fontSize(value) {
|
|
382
398
|
value = Number.parseInt(value, 10);
|
|
@@ -387,16 +403,16 @@ export class BitmapText extends DisplayObject {
|
|
|
387
403
|
}
|
|
388
404
|
|
|
389
405
|
/**
|
|
390
|
-
*
|
|
391
|
-
* @returns {string}
|
|
406
|
+
* Gets the text content of this bitmap text.
|
|
407
|
+
* @returns {string} The current text content.
|
|
392
408
|
*/
|
|
393
409
|
get text() {
|
|
394
410
|
return this._text;
|
|
395
411
|
}
|
|
396
412
|
|
|
397
413
|
/**
|
|
398
|
-
*
|
|
399
|
-
* @param {string | number | boolean | Date} value -
|
|
414
|
+
* Sets the text content of this bitmap text.
|
|
415
|
+
* @param {string | number | boolean | Date} value - The new text content to set.
|
|
400
416
|
*/
|
|
401
417
|
set text(value) {
|
|
402
418
|
const typedValue = value.toString();
|
|
@@ -407,15 +423,16 @@ export class BitmapText extends DisplayObject {
|
|
|
407
423
|
}
|
|
408
424
|
|
|
409
425
|
/**
|
|
410
|
-
*
|
|
411
|
-
* @returns {number}
|
|
426
|
+
* Gets the maximum width of this bitmap text.
|
|
427
|
+
* @returns {number} The current maximum width.
|
|
412
428
|
*/
|
|
413
429
|
get maxWidth() {
|
|
414
430
|
return this._maxWidth;
|
|
415
431
|
}
|
|
416
432
|
|
|
417
433
|
/**
|
|
418
|
-
*
|
|
434
|
+
* Sets the maximum width of this bitmap text.
|
|
435
|
+
* @param {number} value - The new maximum width to set.
|
|
419
436
|
*/
|
|
420
437
|
set maxWidth(value) {
|
|
421
438
|
if (value !== this._maxWidth) {
|
|
@@ -425,15 +442,16 @@ export class BitmapText extends DisplayObject {
|
|
|
425
442
|
}
|
|
426
443
|
|
|
427
444
|
/**
|
|
428
|
-
*
|
|
429
|
-
* @returns {boolean}
|
|
445
|
+
* Gets whether smoothing is enabled for this bitmap text's font.
|
|
446
|
+
* @returns {boolean} True if smoothing is enabled, false otherwise.
|
|
430
447
|
*/
|
|
431
448
|
get smoothed() {
|
|
432
449
|
return !this._data.base.scaleMode;
|
|
433
450
|
}
|
|
434
451
|
|
|
435
452
|
/**
|
|
436
|
-
*
|
|
453
|
+
* Sets whether smoothing is enabled for this bitmap text's font.
|
|
454
|
+
* @param {boolean} value - Whether to enable smoothing (true) or not (false).
|
|
437
455
|
*/
|
|
438
456
|
set smoothed(value) {
|
|
439
457
|
if (value) {
|
|
@@ -11,18 +11,18 @@ const STATE_DISABLED = 'Disabled';
|
|
|
11
11
|
|
|
12
12
|
export class Button extends Image {
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
15
|
-
* @param {import('../core/game.js').Game} game -
|
|
16
|
-
* @param {number} x -
|
|
17
|
-
* @param {number} y -
|
|
18
|
-
* @param {string} key -
|
|
19
|
-
* @param {Function} callback -
|
|
20
|
-
* @param {object} callbackContext -
|
|
21
|
-
* @param {string} overFrame -
|
|
22
|
-
* @param {string} outFrame -
|
|
23
|
-
* @param {string} downFrame -
|
|
24
|
-
* @param {string} upFrame -
|
|
25
|
-
* @param {string} disabledFrame -
|
|
14
|
+
* Creates a new Button instance.
|
|
15
|
+
* @param {import('../core/game.js').Game} game - The game instance this button belongs to.
|
|
16
|
+
* @param {number} x - The x position of the button.
|
|
17
|
+
* @param {number} y - The y position of the button.
|
|
18
|
+
* @param {string} key - The texture key to use for the button.
|
|
19
|
+
* @param {Function} callback - The function to call when the button is clicked.
|
|
20
|
+
* @param {object} callbackContext - The context in which to call the callback function.
|
|
21
|
+
* @param {string} overFrame - The frame identifier to use when the mouse is over the button.
|
|
22
|
+
* @param {string} outFrame - The frame identifier to use when the mouse is outside the button.
|
|
23
|
+
* @param {string} downFrame - The frame identifier to use when the button is pressed.
|
|
24
|
+
* @param {string} upFrame - The frame identifier to use when the button is released.
|
|
25
|
+
* @param {string} disabledFrame - The frame identifier to use when the button is disabled.
|
|
26
26
|
*/
|
|
27
27
|
constructor(
|
|
28
28
|
game,
|
|
@@ -67,7 +67,7 @@ export class Button extends Image {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
/**
|
|
70
|
-
*
|
|
70
|
+
* Destroys this button and cleans up resources.
|
|
71
71
|
*/
|
|
72
72
|
destroy() {
|
|
73
73
|
this._onOverFrame = null;
|
|
@@ -93,9 +93,9 @@ export class Button extends Image {
|
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
/**
|
|
96
|
-
*
|
|
97
|
-
* @param {boolean} isEnabled -
|
|
98
|
-
* @param {boolean} isImmediate -
|
|
96
|
+
* Sets whether this button is enabled or disabled.
|
|
97
|
+
* @param {boolean} isEnabled - Whether the button should be enabled (true) or disabled (false).
|
|
98
|
+
* @param {boolean} isImmediate - Whether to change the state immediately or with a delay (default: false).
|
|
99
99
|
*/
|
|
100
100
|
setEnabled(isEnabled, isImmediate = false) {
|
|
101
101
|
this.input.enabled = isEnabled;
|
|
@@ -109,24 +109,24 @@ export class Button extends Image {
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
/**
|
|
112
|
-
*
|
|
112
|
+
* Clears all the frame settings for this button.
|
|
113
113
|
*/
|
|
114
114
|
clearFrames() {
|
|
115
115
|
this.setFrames(null, null, null, null, null);
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
/**
|
|
119
|
-
*
|
|
119
|
+
* Called when this button is removed from the world.
|
|
120
120
|
*/
|
|
121
121
|
removedFromWorld() {
|
|
122
122
|
this.inputEnabled = false;
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
/**
|
|
126
|
-
*
|
|
127
|
-
* @param {string} state -
|
|
128
|
-
* @param {string} frame -
|
|
129
|
-
* @param {boolean} switchImmediately -
|
|
126
|
+
* Sets a specific frame for a particular state of this button.
|
|
127
|
+
* @param {string} state - The state name (Over, Out, Down, Up, Disabled).
|
|
128
|
+
* @param {string} frame - The frame identifier to set for this state.
|
|
129
|
+
* @param {boolean} switchImmediately - Whether to switch to the new frame immediately (default: false).
|
|
130
130
|
*/
|
|
131
131
|
setStateFrame(state, frame, switchImmediately = false) {
|
|
132
132
|
const frameKey = `_on${state}Frame`;
|
|
@@ -141,9 +141,9 @@ export class Button extends Image {
|
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
/**
|
|
144
|
-
*
|
|
145
|
-
* @param {string} newState -
|
|
146
|
-
* @returns {boolean}
|
|
144
|
+
* Changes the frame of this button to match the specified state.
|
|
145
|
+
* @param {string} newState - The new state to change to (Over, Out, Down, Up, Disabled).
|
|
146
|
+
* @returns {boolean} True if the frame was changed, false otherwise.
|
|
147
147
|
*/
|
|
148
148
|
changeStateFrame(newState) {
|
|
149
149
|
if (this.freezeFrames) {
|
|
@@ -163,12 +163,12 @@ export class Button extends Image {
|
|
|
163
163
|
}
|
|
164
164
|
|
|
165
165
|
/**
|
|
166
|
-
*
|
|
167
|
-
* @param {string} overFrame -
|
|
168
|
-
* @param {string} outFrame -
|
|
169
|
-
* @param {string} downFrame -
|
|
170
|
-
* @param {string} upFrame -
|
|
171
|
-
* @param {string} disabledFrame -
|
|
166
|
+
* Sets the frame identifiers for all states of this button.
|
|
167
|
+
* @param {string} overFrame - The frame identifier to use when the mouse is over the button.
|
|
168
|
+
* @param {string} outFrame - The frame identifier to use when the mouse is outside the button.
|
|
169
|
+
* @param {string} downFrame - The frame identifier to use when the button is pressed.
|
|
170
|
+
* @param {string} upFrame - The frame identifier to use when the button is released.
|
|
171
|
+
* @param {string} disabledFrame - The frame identifier to use when the button is disabled.
|
|
172
172
|
*/
|
|
173
173
|
setFrames(overFrame, outFrame, downFrame, upFrame, disabledFrame = null) {
|
|
174
174
|
this.setStateFrame(STATE_OVER, overFrame, this.input.pointerOver());
|
|
@@ -181,9 +181,9 @@ export class Button extends Image {
|
|
|
181
181
|
}
|
|
182
182
|
|
|
183
183
|
/**
|
|
184
|
-
*
|
|
185
|
-
* @param {object} sprite -
|
|
186
|
-
* @param {object} pointer -
|
|
184
|
+
* Handles the input over event for this button.
|
|
185
|
+
* @param {object} sprite - The sprite that triggered the event.
|
|
186
|
+
* @param {object} pointer - The pointer that triggered the event.
|
|
187
187
|
*/
|
|
188
188
|
onInputOverHandler(sprite, pointer) {
|
|
189
189
|
if (pointer.justReleased() && (this.justReleasedPreventsOver & pointer.pointerMode) === pointer.pointerMode) {
|
|
@@ -200,9 +200,9 @@ export class Button extends Image {
|
|
|
200
200
|
}
|
|
201
201
|
|
|
202
202
|
/**
|
|
203
|
-
*
|
|
204
|
-
* @param {object} sprite -
|
|
205
|
-
* @param {object} pointer -
|
|
203
|
+
* Handles the input out event for this button.
|
|
204
|
+
* @param {object} sprite - The sprite that triggered the event.
|
|
205
|
+
* @param {object} pointer - The pointer that triggered the event.
|
|
206
206
|
*/
|
|
207
207
|
onInputOutHandler(sprite, pointer) {
|
|
208
208
|
this.changeStateFrame(STATE_OUT);
|
|
@@ -212,9 +212,9 @@ export class Button extends Image {
|
|
|
212
212
|
}
|
|
213
213
|
|
|
214
214
|
/**
|
|
215
|
-
*
|
|
216
|
-
* @param {object} sprite -
|
|
217
|
-
* @param {object} pointer -
|
|
215
|
+
* Handles the input down event for this button.
|
|
216
|
+
* @param {object} sprite - The sprite that triggered the event.
|
|
217
|
+
* @param {object} pointer - The pointer that triggered the event.
|
|
218
218
|
*/
|
|
219
219
|
onInputDownHandler(sprite, pointer) {
|
|
220
220
|
this.changeStateFrame(STATE_DOWN);
|
|
@@ -224,10 +224,10 @@ export class Button extends Image {
|
|
|
224
224
|
}
|
|
225
225
|
|
|
226
226
|
/**
|
|
227
|
-
*
|
|
228
|
-
* @param {object} sprite -
|
|
229
|
-
* @param {object} pointer -
|
|
230
|
-
* @param {boolean} isOver -
|
|
227
|
+
* Handles the input up event for this button.
|
|
228
|
+
* @param {object} sprite - The sprite that triggered the event.
|
|
229
|
+
* @param {object} pointer - The pointer that triggered the event.
|
|
230
|
+
* @param {boolean} isOver - Whether the pointer is currently over the button (default: true).
|
|
231
231
|
*/
|
|
232
232
|
onInputUpHandler(sprite, pointer, isOver) {
|
|
233
233
|
if (this.onInputUp) {
|
|
@@ -252,15 +252,16 @@ export class Button extends Image {
|
|
|
252
252
|
}
|
|
253
253
|
|
|
254
254
|
/**
|
|
255
|
-
*
|
|
256
|
-
* @returns {boolean}
|
|
255
|
+
* Gets whether input is currently enabled for this button.
|
|
256
|
+
* @returns {boolean} True if input is enabled, false otherwise.
|
|
257
257
|
*/
|
|
258
258
|
get inputEnabled() {
|
|
259
259
|
return this.input && this.input.enabled;
|
|
260
260
|
}
|
|
261
261
|
|
|
262
262
|
/**
|
|
263
|
-
*
|
|
263
|
+
* Sets whether input is currently enabled for this button.
|
|
264
|
+
* @param {boolean} value - Whether to enable (true) or disable (false) input.
|
|
264
265
|
*/
|
|
265
266
|
set inputEnabled(value) {
|
|
266
267
|
if (value) {
|
|
@@ -2,9 +2,9 @@ import { create, removeByCanvas } from './pool.js';
|
|
|
2
2
|
|
|
3
3
|
export class CanvasBuffer {
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
* @param {number} width -
|
|
7
|
-
* @param {number} height -
|
|
5
|
+
* Creates a new CanvasBuffer instance.
|
|
6
|
+
* @param {number} width - The width of the canvas buffer.
|
|
7
|
+
* @param {number} height - The height of the canvas buffer.
|
|
8
8
|
*/
|
|
9
9
|
constructor(width, height) {
|
|
10
10
|
this.width = width;
|
|
@@ -16,7 +16,7 @@ export class CanvasBuffer {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
19
|
+
* Clears the canvas buffer.
|
|
20
20
|
*/
|
|
21
21
|
clear() {
|
|
22
22
|
this.context.setTransform(1, 0, 0, 1, 0, 0);
|
|
@@ -24,9 +24,9 @@ export class CanvasBuffer {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
|
-
*
|
|
28
|
-
* @param {number} width -
|
|
29
|
-
* @param {number} height -
|
|
27
|
+
* Resizes the canvas buffer.
|
|
28
|
+
* @param {number} width - The new width of the canvas buffer.
|
|
29
|
+
* @param {number} height - The new height of the canvas buffer.
|
|
30
30
|
*/
|
|
31
31
|
resize(width, height) {
|
|
32
32
|
this.width = width;
|
|
@@ -36,7 +36,7 @@ export class CanvasBuffer {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
|
-
*
|
|
39
|
+
* Destroys the canvas buffer and cleans up resources.
|
|
40
40
|
*/
|
|
41
41
|
destroy() {
|
|
42
42
|
try {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { GEOM_CIRCLE, GEOM_ELLIPSE, GEOM_POLYGON, GEOM_RECTANGLE, GEOM_ROUNDED_RECTANGLE } from '../../core/const.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
* @param {
|
|
4
|
+
* Renders a graphics object to canvas.
|
|
5
|
+
* @param {import('../graphics.js').Graphics} graphics - The graphics object to render.
|
|
6
6
|
*/
|
|
7
7
|
export const updateGraphicsTint = (graphics) => {
|
|
8
8
|
if (graphics.tint === 0xffffff) {
|
|
@@ -27,9 +27,9 @@ export const updateGraphicsTint = (graphics) => {
|
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
31
|
-
* @param {
|
|
32
|
-
* @param {object} context -
|
|
30
|
+
* Renders a graphics object to canvas.
|
|
31
|
+
* @param {import('../graphics.js').Graphics} graphics - The graphics object to render.
|
|
32
|
+
* @param {object} context - The canvas rendering context.
|
|
33
33
|
*/
|
|
34
34
|
export const renderGraphics = (graphics, context) => {
|
|
35
35
|
const worldAlpha = graphics.worldAlpha;
|
|
@@ -156,9 +156,9 @@ export const renderGraphics = (graphics, context) => {
|
|
|
156
156
|
};
|
|
157
157
|
|
|
158
158
|
/**
|
|
159
|
-
*
|
|
160
|
-
* @param {
|
|
161
|
-
* @param {object} context -
|
|
159
|
+
* Renders a graphics object to canvas.
|
|
160
|
+
* @param {import('../graphics.js').Graphics} graphics - The graphics object to render.
|
|
161
|
+
* @param {object} context - The canvas rendering context.
|
|
162
162
|
*/
|
|
163
163
|
export const renderGraphicsMask = (graphics, context) => {
|
|
164
164
|
const len = graphics.graphicsData.length;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { renderGraphicsMask } from './graphics.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
* @param {object} maskData -
|
|
6
|
-
* @param {object} renderSession -
|
|
4
|
+
* Pushes a mask onto the rendering stack.
|
|
5
|
+
* @param {object} maskData - The mask data to apply.
|
|
6
|
+
* @param {object} renderSession - The rendering session object.
|
|
7
7
|
*/
|
|
8
8
|
export const pushMask = (maskData, renderSession) => {
|
|
9
9
|
const context = renderSession.context;
|
|
@@ -25,8 +25,8 @@ export const pushMask = (maskData, renderSession) => {
|
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
29
|
-
* @param {object} renderSession -
|
|
28
|
+
* Pops a mask from the rendering stack.
|
|
29
|
+
* @param {object} renderSession - The rendering session object.
|
|
30
30
|
*/
|
|
31
31
|
export const popMask = (renderSession) => {
|
|
32
32
|
renderSession.context.restore();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* @returns {object[]}
|
|
2
|
+
* Gets the canvas pool array.
|
|
3
|
+
* @returns {{canvas: HTMLCanvasElement, parent: object}[]} The canvas pool array.
|
|
4
4
|
*/
|
|
5
5
|
export const getPool = () => {
|
|
6
6
|
if (!window.PhaserRegistry) {
|
|
@@ -13,8 +13,8 @@ export const getPool = () => {
|
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
17
|
-
* @returns {
|
|
16
|
+
* Gets the current size of the canvas pool.
|
|
17
|
+
* @returns {number} The current size of the canvas pool.
|
|
18
18
|
*/
|
|
19
19
|
export const getFirst = () => {
|
|
20
20
|
const pool = getPool();
|
|
@@ -27,8 +27,8 @@ export const getFirst = () => {
|
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
31
|
-
* @param {object} parent -
|
|
30
|
+
* Adds a canvas to the pool with the specified parent.
|
|
31
|
+
* @param {object} parent - The parent object for the canvas.
|
|
32
32
|
*/
|
|
33
33
|
export const remove = (parent) => {
|
|
34
34
|
const pool = getPool();
|
|
@@ -42,8 +42,8 @@ export const remove = (parent) => {
|
|
|
42
42
|
};
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
|
-
*
|
|
46
|
-
* @param {HTMLCanvasElement} canvas -
|
|
45
|
+
* Removes a canvas from the pool.
|
|
46
|
+
* @param {HTMLCanvasElement} canvas - The canvas to remove from the pool.
|
|
47
47
|
*/
|
|
48
48
|
export const removeByCanvas = (canvas) => {
|
|
49
49
|
const pool = getPool();
|
|
@@ -57,8 +57,8 @@ export const removeByCanvas = (canvas) => {
|
|
|
57
57
|
};
|
|
58
58
|
|
|
59
59
|
/**
|
|
60
|
-
*
|
|
61
|
-
* @returns {number}
|
|
60
|
+
* Gets the total count of canvases in the pool.
|
|
61
|
+
* @returns {number} The total count of canvases in the pool.
|
|
62
62
|
*/
|
|
63
63
|
export const getTotal = () => {
|
|
64
64
|
const pool = getPool();
|
|
@@ -72,8 +72,8 @@ export const getTotal = () => {
|
|
|
72
72
|
};
|
|
73
73
|
|
|
74
74
|
/**
|
|
75
|
-
*
|
|
76
|
-
* @returns {number}
|
|
75
|
+
* Gets the number of free canvases in the pool.
|
|
76
|
+
* @returns {number} The number of free canvases in the pool.
|
|
77
77
|
*/
|
|
78
78
|
export const getFree = () => {
|
|
79
79
|
const pool = getPool();
|
|
@@ -87,12 +87,12 @@ export const getFree = () => {
|
|
|
87
87
|
};
|
|
88
88
|
|
|
89
89
|
/**
|
|
90
|
-
*
|
|
91
|
-
* @param {object} parent -
|
|
92
|
-
* @param {number} width -
|
|
93
|
-
* @param {number} height -
|
|
94
|
-
* @param {boolean} skipPool -
|
|
95
|
-
* @returns {HTMLCanvasElement}
|
|
90
|
+
* Gets a canvas from the pool or creates a new one.
|
|
91
|
+
* @param {object} parent - The parent object for the canvas.
|
|
92
|
+
* @param {number} [width] - Optional width of the canvas.
|
|
93
|
+
* @param {number} [height] - Optional height of the canvas.
|
|
94
|
+
* @param {boolean} skipPool - True to skip using the pool and create a new canvas.
|
|
95
|
+
* @returns {HTMLCanvasElement} The canvas from the pool or a newly created one.
|
|
96
96
|
*/
|
|
97
97
|
export const create = (parent, width, height, skipPool = false) => {
|
|
98
98
|
if (parent === undefined) {
|