@vpmedia/phaser 1.46.0 → 1.49.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +7 -7
- package/src/index.js +0 -1
- package/src/phaser/core/animation_parser.js +1 -1
- package/src/phaser/core/game.js +9 -2
- package/src/phaser/core/input.js +2 -2
- package/src/phaser/core/loader.js +11 -11
- package/src/phaser/core/scale_manager.js +5 -5
- package/src/phaser/core/signal.js +4 -6
- package/src/phaser/core/signal_binding.js +1 -1
- package/src/phaser/core/sound.js +1 -1
- package/src/phaser/core/sound_manager.js +1 -1
- package/src/phaser/core/sound_sprite.js +1 -1
- package/src/phaser/display/bitmap_text.js +1 -1
- package/src/phaser/display/button.js +2 -2
- package/src/phaser/display/canvas/buffer.js +5 -0
- package/src/phaser/display/canvas/graphics.js +10 -10
- package/src/phaser/display/canvas/pool.js +3 -2
- package/src/phaser/display/canvas/renderer.js +3 -2
- package/src/phaser/display/canvas/tinter.js +48 -18
- package/src/phaser/display/canvas/util.js +1 -1
- package/src/phaser/display/display_object.js +4 -4
- package/src/phaser/display/text.js +9 -9
- package/src/phaser/display/webgl/graphics.js +3 -3
- package/src/phaser/display/webgl/renderer.js +3 -2
- package/src/phaser/display/webgl/shader/normal.js +3 -3
- package/src/phaser/display/webgl/texture.js +1 -1
- package/src/phaser/display/webgl/util.js +8 -8
- package/src/phaser/geom/circle.js +1 -1
- package/src/phaser/geom/ellipse.js +1 -1
- package/src/phaser/geom/point.js +1 -1
- package/src/phaser/geom/rectangle.js +1 -13
- package/src/phaser/util/math.js +1 -2
- package/types/index.d.ts +33 -34
- package/types/index.d.ts.map +1 -1
- package/types/phaser/core/animation.d.ts +7 -7
- package/types/phaser/core/animation.d.ts.map +1 -1
- package/types/phaser/core/animation_manager.d.ts +6 -6
- package/types/phaser/core/animation_manager.d.ts.map +1 -1
- package/types/phaser/core/animation_parser.d.ts +2 -2
- package/types/phaser/core/array_set.d.ts.map +1 -1
- package/types/phaser/core/cache.d.ts +2 -2
- package/types/phaser/core/cache.d.ts.map +1 -1
- package/types/phaser/core/dom.d.ts +1 -1
- package/types/phaser/core/event_manager.d.ts +1 -1
- package/types/phaser/core/event_manager.d.ts.map +1 -1
- package/types/phaser/core/factory.d.ts +1 -1
- package/types/phaser/core/frame_data.d.ts +5 -5
- package/types/phaser/core/game.d.ts +8 -2
- package/types/phaser/core/game.d.ts.map +1 -1
- package/types/phaser/core/input.d.ts +5 -5
- package/types/phaser/core/input.d.ts.map +1 -1
- package/types/phaser/core/input_handler.d.ts +15 -15
- package/types/phaser/core/input_mouse.d.ts +2 -2
- package/types/phaser/core/input_mspointer.d.ts +1 -1
- package/types/phaser/core/input_pointer.d.ts +2 -2
- package/types/phaser/core/input_pointer.d.ts.map +1 -1
- package/types/phaser/core/input_touch.d.ts +1 -1
- package/types/phaser/core/loader.d.ts +2 -2
- package/types/phaser/core/loader_parser.d.ts +4 -4
- package/types/phaser/core/raf.d.ts +1 -1
- package/types/phaser/core/scale_manager.d.ts +3 -3
- package/types/phaser/core/scale_manager.d.ts.map +1 -1
- package/types/phaser/core/scene_manager.d.ts +1 -1
- package/types/phaser/core/scene_manager.d.ts.map +1 -1
- package/types/phaser/core/signal.d.ts.map +1 -1
- package/types/phaser/core/signal_binding.d.ts +2 -2
- package/types/phaser/core/signal_binding.d.ts.map +1 -1
- package/types/phaser/core/sound.d.ts +3 -3
- package/types/phaser/core/sound.d.ts.map +1 -1
- package/types/phaser/core/sound_manager.d.ts +3 -3
- package/types/phaser/core/sound_manager.d.ts.map +1 -1
- package/types/phaser/core/sound_sprite.d.ts +3 -3
- package/types/phaser/core/stage.d.ts +3 -3
- package/types/phaser/core/stage.d.ts.map +1 -1
- package/types/phaser/core/time.d.ts +2 -2
- package/types/phaser/core/time.d.ts.map +1 -1
- package/types/phaser/core/timer.d.ts +1 -1
- package/types/phaser/core/timer.d.ts.map +1 -1
- package/types/phaser/core/timer_event.d.ts +1 -1
- package/types/phaser/core/timer_event.d.ts.map +1 -1
- package/types/phaser/core/tween.d.ts +1 -1
- package/types/phaser/core/tween.d.ts.map +1 -1
- package/types/phaser/core/tween_data.d.ts +1 -1
- package/types/phaser/core/tween_manager.d.ts +1 -1
- package/types/phaser/core/world.d.ts +1 -1
- package/types/phaser/display/bitmap_text.d.ts +9 -9
- package/types/phaser/display/bitmap_text.d.ts.map +1 -1
- package/types/phaser/display/button.d.ts +2 -2
- package/types/phaser/display/button.d.ts.map +1 -1
- package/types/phaser/display/canvas/buffer.d.ts.map +1 -1
- package/types/phaser/display/canvas/pool.d.ts +2 -1
- package/types/phaser/display/canvas/pool.d.ts.map +1 -1
- package/types/phaser/display/canvas/renderer.d.ts +7 -6
- package/types/phaser/display/canvas/renderer.d.ts.map +1 -1
- package/types/phaser/display/canvas/tinter.d.ts.map +1 -1
- package/types/phaser/display/canvas/util.d.ts +2 -2
- package/types/phaser/display/canvas/util.d.ts.map +1 -1
- package/types/phaser/display/display_object.d.ts +11 -11
- package/types/phaser/display/display_object.d.ts.map +1 -1
- package/types/phaser/display/graphics.d.ts +2 -2
- package/types/phaser/display/group.d.ts +1 -1
- package/types/phaser/display/image.d.ts +7 -7
- package/types/phaser/display/image.d.ts.map +1 -1
- package/types/phaser/display/sprite_batch.d.ts +1 -1
- package/types/phaser/display/sprite_util.d.ts +5 -5
- package/types/phaser/display/text.d.ts +25 -25
- package/types/phaser/display/text.d.ts.map +1 -1
- package/types/phaser/display/webgl/fast_sprite_batch.d.ts +1 -1
- package/types/phaser/display/webgl/graphics.d.ts +4 -2
- package/types/phaser/display/webgl/graphics.d.ts.map +1 -1
- package/types/phaser/display/webgl/render_texture.d.ts +1 -1
- package/types/phaser/display/webgl/renderer.d.ts +8 -6
- package/types/phaser/display/webgl/renderer.d.ts.map +1 -1
- package/types/phaser/display/webgl/shader/complex.d.ts +1 -1
- package/types/phaser/display/webgl/shader/complex.d.ts.map +1 -1
- package/types/phaser/display/webgl/shader/fast.d.ts +1 -1
- package/types/phaser/display/webgl/shader/fast.d.ts.map +1 -1
- package/types/phaser/display/webgl/shader/normal.d.ts +1 -1
- package/types/phaser/display/webgl/shader/normal.d.ts.map +1 -1
- package/types/phaser/display/webgl/shader/primitive.d.ts +1 -1
- package/types/phaser/display/webgl/shader/primitive.d.ts.map +1 -1
- package/types/phaser/display/webgl/shader/strip.d.ts +1 -1
- package/types/phaser/display/webgl/shader/strip.d.ts.map +1 -1
- package/types/phaser/display/webgl/sprite_batch.d.ts +2 -2
- package/types/phaser/display/webgl/stencil_manager.d.ts +3 -3
- package/types/phaser/display/webgl/texture.d.ts +1 -1
- package/types/phaser/display/webgl/util.d.ts +20 -12
- package/types/phaser/display/webgl/util.d.ts.map +1 -1
- package/types/phaser/geom/circle.d.ts +7 -7
- package/types/phaser/geom/circle.d.ts.map +1 -1
- package/types/phaser/geom/polygon.d.ts +1 -1
- package/types/phaser/geom/polygon.d.ts.map +1 -1
- package/types/phaser/geom/rectangle.d.ts +11 -11
- package/types/phaser/geom/rectangle.d.ts.map +1 -1
- package/types/phaser/util/math.d.ts.map +1 -1
- package/CHANGES.md +0 -21
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @vpmedia/phaser
|
|
2
2
|
|
|
3
|
-
[](https://badge.fury.io/js/@vpmedia%2Fphaser)
|
|
4
4
|
[](https://github.com/vpmedia/phaser/actions/workflows/ci.yml)
|
|
5
5
|
|
|
6
6
|
@vpmedia/phaser is the modern ECMAScript port of the popular Phaser game engine v2.6.2.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vpmedia/phaser",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.49.0",
|
|
4
4
|
"description": "@vpmedia/phaser is the modern ECMAScript port of the popular Phaser game engine v2.6.2",
|
|
5
5
|
"author": "Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,16 +23,16 @@
|
|
|
23
23
|
"types": "./types/index.d.ts",
|
|
24
24
|
"type": "module",
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@eslint/js": "^9.
|
|
26
|
+
"@eslint/js": "^9.14.0",
|
|
27
27
|
"@jest/globals": "^29.7.0",
|
|
28
|
-
"@types/jest": "^29.5.
|
|
29
|
-
"eslint": "^9.
|
|
30
|
-
"eslint-plugin-jsdoc": "^50.3
|
|
28
|
+
"@types/jest": "^29.5.14",
|
|
29
|
+
"eslint": "^9.14.0",
|
|
30
|
+
"eslint-plugin-jsdoc": "^50.4.3",
|
|
31
31
|
"eslint-plugin-unicorn": "^56.0.0",
|
|
32
|
-
"globals": "^15.
|
|
32
|
+
"globals": "^15.12.0",
|
|
33
33
|
"jest": "^29.7.0",
|
|
34
34
|
"jest-environment-jsdom": "^29.7.0",
|
|
35
|
-
"lefthook": "^1.
|
|
35
|
+
"lefthook": "^1.8.2",
|
|
36
36
|
"prettier": "^3.3.3",
|
|
37
37
|
"typescript": "^5.6.3"
|
|
38
38
|
},
|
package/src/index.js
CHANGED
|
@@ -37,7 +37,7 @@ export function spriteSheet(game, key, frameWidth, frameHeight, frameMax, margin
|
|
|
37
37
|
// Zero or smaller than frame sizes?
|
|
38
38
|
if (width === 0 || height === 0 || width < frameWidth || height < frameHeight || total === 0) {
|
|
39
39
|
console.warn(
|
|
40
|
-
`AnimationParser.spriteSheet: '${
|
|
40
|
+
`AnimationParser.spriteSheet: '${key}'s width/height zero or width/height < given frameWidth/frameHeight`
|
|
41
41
|
);
|
|
42
42
|
return null;
|
|
43
43
|
}
|
package/src/phaser/core/game.js
CHANGED
|
@@ -146,11 +146,18 @@ export class Game {
|
|
|
146
146
|
} catch (e) {
|
|
147
147
|
isWebGlReady = false;
|
|
148
148
|
const tags = {};
|
|
149
|
+
/** @type {WebGLRenderer} */
|
|
150
|
+
// @ts-ignore
|
|
151
|
+
const renderer = this.renderer;
|
|
152
|
+
if (renderer.gl) {
|
|
153
|
+
tags['webgl.error'] = renderer.gl.getError();
|
|
154
|
+
tags['webgl.context_lost'] = renderer.gl.isContextLost();
|
|
155
|
+
}
|
|
149
156
|
if (window.PhaserRegistry?.GL_PROGRAM_INFO_LOG) {
|
|
150
|
-
tags.
|
|
157
|
+
tags['webgl.program_log'] = window.PhaserRegistry.GL_PROGRAM_INFO_LOG;
|
|
151
158
|
}
|
|
152
159
|
if (window.PhaserRegistry?.GL_SHADER_INFO_LOG) {
|
|
153
|
-
tags.
|
|
160
|
+
tags['webgl.shader_log'] = window.PhaserRegistry.GL_SHADER_INFO_LOG;
|
|
154
161
|
}
|
|
155
162
|
this.exceptionHandler(e, tags);
|
|
156
163
|
}
|
package/src/phaser/core/input.js
CHANGED
|
@@ -162,13 +162,13 @@ export class Input {
|
|
|
162
162
|
*/
|
|
163
163
|
addPointer() {
|
|
164
164
|
if (this.pointers.length >= MAX_POINTERS) {
|
|
165
|
-
console.warn(`Input.addPointer: Maximum limit of ${
|
|
165
|
+
console.warn(`Input.addPointer: Maximum limit of ${MAX_POINTERS} pointers reached.`);
|
|
166
166
|
return null;
|
|
167
167
|
}
|
|
168
168
|
const id = this.pointers.length + 1;
|
|
169
169
|
const pointer = new Pointer(this.game, id, POINTER_CONTACT);
|
|
170
170
|
this.pointers.push(pointer);
|
|
171
|
-
this[`pointer${
|
|
171
|
+
this[`pointer${id}`] = pointer;
|
|
172
172
|
return pointer;
|
|
173
173
|
}
|
|
174
174
|
|
|
@@ -163,14 +163,14 @@ export class Loader {
|
|
|
163
163
|
*/
|
|
164
164
|
addToFileList(type, key = '', url = null, properties = null, overwrite = false, extension = null) {
|
|
165
165
|
if (key === undefined || key === '') {
|
|
166
|
-
console.warn(`Loader: Invalid or no key given of type ${
|
|
166
|
+
console.warn(`Loader: Invalid or no key given of type ${type}`);
|
|
167
167
|
return this;
|
|
168
168
|
}
|
|
169
169
|
if (url === undefined || url === null) {
|
|
170
170
|
if (extension) {
|
|
171
171
|
url = key + extension;
|
|
172
172
|
} else {
|
|
173
|
-
console.warn(`Loader: No URL given for file type: ${
|
|
173
|
+
console.warn(`Loader: No URL given for file type: ${type} key: ${key}`);
|
|
174
174
|
return this;
|
|
175
175
|
}
|
|
176
176
|
}
|
|
@@ -376,12 +376,12 @@ export class Loader {
|
|
|
376
376
|
}
|
|
377
377
|
this.audio(key, urls, autoDecode);
|
|
378
378
|
if (jsonURL) {
|
|
379
|
-
this.json(`${key
|
|
379
|
+
this.json(`${key}-audioatlas`, jsonURL);
|
|
380
380
|
} else if (jsonData) {
|
|
381
381
|
if (typeof jsonData === 'string') {
|
|
382
382
|
jsonData = JSON.parse(jsonData);
|
|
383
383
|
}
|
|
384
|
-
this.cache.addJSON(`${key
|
|
384
|
+
this.cache.addJSON(`${key}-audioatlas`, '', jsonData);
|
|
385
385
|
}
|
|
386
386
|
return this;
|
|
387
387
|
}
|
|
@@ -399,10 +399,10 @@ export class Loader {
|
|
|
399
399
|
*/
|
|
400
400
|
bitmapFont(key, textureURL = null, atlasURL = null, atlasData = null, xSpacing = 0, ySpacing = 0) {
|
|
401
401
|
if (textureURL === undefined || textureURL === null) {
|
|
402
|
-
textureURL = `${key
|
|
402
|
+
textureURL = `${key}.png`;
|
|
403
403
|
}
|
|
404
404
|
if (atlasURL === null && atlasData === null) {
|
|
405
|
-
atlasURL = `${key
|
|
405
|
+
atlasURL = `${key}.xml`;
|
|
406
406
|
}
|
|
407
407
|
// A URL to a json/xml atlas has been given
|
|
408
408
|
if (atlasURL) {
|
|
@@ -441,10 +441,10 @@ export class Loader {
|
|
|
441
441
|
*/
|
|
442
442
|
atlas(key, textureURL, atlasURL = null, atlasData = null, format = TEXTURE_ATLAS_JSON_HASH) {
|
|
443
443
|
if (textureURL === undefined || textureURL === null) {
|
|
444
|
-
textureURL = `${key
|
|
444
|
+
textureURL = `${key}.png`;
|
|
445
445
|
}
|
|
446
446
|
if (!atlasURL && !atlasData) {
|
|
447
|
-
atlasURL = `${key
|
|
447
|
+
atlasURL = `${key}.json`;
|
|
448
448
|
}
|
|
449
449
|
// A URL to a json/xml file has been given
|
|
450
450
|
if (atlasURL) {
|
|
@@ -936,7 +936,7 @@ export class Loader {
|
|
|
936
936
|
if (!reason && xhr) {
|
|
937
937
|
reason = xhr.status;
|
|
938
938
|
}
|
|
939
|
-
const message = `Error loading asset (${
|
|
939
|
+
const message = `Error loading asset (${reason})`;
|
|
940
940
|
this.asyncComplete(file, message);
|
|
941
941
|
}
|
|
942
942
|
|
|
@@ -976,7 +976,7 @@ export class Loader {
|
|
|
976
976
|
if (file.format === TEXTURE_ATLAS_JSON_HASH) {
|
|
977
977
|
this.xhrLoad(file, this.transformUrl(file.atlasURL, file), 'text', this.jsonLoadComplete);
|
|
978
978
|
} else {
|
|
979
|
-
throw new Error(`Invalid Texture Atlas format: ${
|
|
979
|
+
throw new Error(`Invalid Texture Atlas format: ${file.format}`);
|
|
980
980
|
}
|
|
981
981
|
}
|
|
982
982
|
break;
|
|
@@ -1068,7 +1068,7 @@ export class Loader {
|
|
|
1068
1068
|
const xml = this.parseXml(data);
|
|
1069
1069
|
if (!xml) {
|
|
1070
1070
|
const responseType = xhr.responseType || xhr.contentType; // contentType for MS-XDomainRequest
|
|
1071
|
-
console.warn(`Loader - ${
|
|
1071
|
+
console.warn(`Loader - ${file.key}: invalid XML (${responseType})`);
|
|
1072
1072
|
this.asyncComplete(file, 'invalid XML');
|
|
1073
1073
|
return;
|
|
1074
1074
|
}
|
|
@@ -552,10 +552,10 @@ export class ScaleManager {
|
|
|
552
552
|
const offset = targetEdge - currentEdge;
|
|
553
553
|
margin.left = Math.round(offset);
|
|
554
554
|
}
|
|
555
|
-
canvas.style.marginLeft = `${margin.left
|
|
555
|
+
canvas.style.marginLeft = `${margin.left}px`;
|
|
556
556
|
if (margin.left !== 0) {
|
|
557
557
|
margin.right = -(parentBounds.width - canvasBounds.width - margin.left);
|
|
558
|
-
canvas.style.marginRight = `${margin.right
|
|
558
|
+
canvas.style.marginRight = `${margin.right}px`;
|
|
559
559
|
}
|
|
560
560
|
}
|
|
561
561
|
if (vertical) {
|
|
@@ -569,10 +569,10 @@ export class ScaleManager {
|
|
|
569
569
|
const offset = targetEdge - currentEdge;
|
|
570
570
|
margin.top = Math.round(offset);
|
|
571
571
|
}
|
|
572
|
-
canvas.style.marginTop = `${margin.top
|
|
572
|
+
canvas.style.marginTop = `${margin.top}px`;
|
|
573
573
|
if (margin.top !== 0) {
|
|
574
574
|
margin.bottom = -(parentBounds.height - canvasBounds.height - margin.top);
|
|
575
|
-
canvas.style.marginBottom = `${margin.bottom
|
|
575
|
+
canvas.style.marginBottom = `${margin.bottom}px`;
|
|
576
576
|
}
|
|
577
577
|
}
|
|
578
578
|
// Silly backwards compatibility..
|
|
@@ -613,7 +613,7 @@ export class ScaleManager {
|
|
|
613
613
|
* @param {string} cssWidth - TBD.
|
|
614
614
|
* @param {string} cssHeight - TBD.
|
|
615
615
|
*/
|
|
616
|
-
resetCanvas(cssWidth = `${this.width
|
|
616
|
+
resetCanvas(cssWidth = `${this.width}px`, cssHeight = `${this.height}px`) {
|
|
617
617
|
const canvas = this.game.canvas;
|
|
618
618
|
if (!this.compatibility.noMargins) {
|
|
619
619
|
canvas.style.marginLeft = '';
|
|
@@ -44,11 +44,9 @@ export class Signal {
|
|
|
44
44
|
binding = this._bindings[prevIndex];
|
|
45
45
|
if (binding.isOnce() !== isOnce) {
|
|
46
46
|
throw new Error(
|
|
47
|
-
`You cannot add${
|
|
48
|
-
isOnce ? '' : 'Once'
|
|
49
|
-
|
|
50
|
-
!isOnce ? '' : 'Once'
|
|
51
|
-
}() the same listener without removing the relationship first.`
|
|
47
|
+
`You cannot add${isOnce ? '' : 'Once'}() then add${
|
|
48
|
+
!isOnce ? '' : 'Once'
|
|
49
|
+
}() the same listener without removing the relationship first.`
|
|
52
50
|
);
|
|
53
51
|
}
|
|
54
52
|
} else {
|
|
@@ -243,7 +241,7 @@ export class Signal {
|
|
|
243
241
|
* @returns {string} TBD.
|
|
244
242
|
*/
|
|
245
243
|
toString() {
|
|
246
|
-
return `[Signal active:${
|
|
244
|
+
return `[Signal active:${this.active} numListeners:${this.getNumListeners()}]`;
|
|
247
245
|
}
|
|
248
246
|
|
|
249
247
|
/**
|
|
@@ -96,6 +96,6 @@ export class SignalBinding {
|
|
|
96
96
|
* @returns {string} TBD.
|
|
97
97
|
*/
|
|
98
98
|
toString() {
|
|
99
|
-
return `[SignalBinding isOnce:${
|
|
99
|
+
return `[SignalBinding isOnce:${this._isOnce}, isBound:${this.isBound()}, active:${this.active}]`;
|
|
100
100
|
}
|
|
101
101
|
}
|
package/src/phaser/core/sound.js
CHANGED
|
@@ -268,7 +268,7 @@ export class Sound {
|
|
|
268
268
|
this._tempVolume = this.volume;
|
|
269
269
|
this._tempLoop = this.loop;
|
|
270
270
|
} else {
|
|
271
|
-
console.warn(`Sound.play: audio marker ${
|
|
271
|
+
console.warn(`Sound.play: audio marker ${marker} does not exist`);
|
|
272
272
|
return this;
|
|
273
273
|
}
|
|
274
274
|
} else {
|
|
@@ -160,7 +160,7 @@ export class SoundManager {
|
|
|
160
160
|
error: e,
|
|
161
161
|
});
|
|
162
162
|
this.removeUnlockHandlers();
|
|
163
|
-
this.game.exceptionHandler(e, { initialState, state: this.context.state });
|
|
163
|
+
this.game.exceptionHandler(e, { 'audio.initialState': initialState, 'audio.state': this.context.state });
|
|
164
164
|
});
|
|
165
165
|
}
|
|
166
166
|
|
|
@@ -7,7 +7,7 @@ export class SoundSprite {
|
|
|
7
7
|
constructor(game, key) {
|
|
8
8
|
this.game = game;
|
|
9
9
|
this.key = key;
|
|
10
|
-
this.config = this.game.cache.getJSON(`${key
|
|
10
|
+
this.config = this.game.cache.getJSON(`${key}-audioatlas`);
|
|
11
11
|
this.autoplayKey = null;
|
|
12
12
|
this.autoplay = false;
|
|
13
13
|
this.sounds = {};
|
|
@@ -318,7 +318,7 @@ export class BitmapText extends DisplayObject {
|
|
|
318
318
|
if (typeof this.tint === 'number') {
|
|
319
319
|
let colorStr = this.tint.toString(16);
|
|
320
320
|
while (colorStr.length < 6) {
|
|
321
|
-
colorStr = `0${
|
|
321
|
+
colorStr = `0${colorStr}`;
|
|
322
322
|
}
|
|
323
323
|
return `#${colorStr.toUpperCase()}`;
|
|
324
324
|
}
|
|
@@ -127,7 +127,7 @@ export class Button extends Image {
|
|
|
127
127
|
* @param {boolean} switchImmediately - TBD.
|
|
128
128
|
*/
|
|
129
129
|
setStateFrame(state, frame, switchImmediately = false) {
|
|
130
|
-
const frameKey = `_on${
|
|
130
|
+
const frameKey = `_on${state}Frame`;
|
|
131
131
|
if (frame) {
|
|
132
132
|
this[frameKey] = frame;
|
|
133
133
|
if (switchImmediately) {
|
|
@@ -148,7 +148,7 @@ export class Button extends Image {
|
|
|
148
148
|
return false;
|
|
149
149
|
}
|
|
150
150
|
const state = this.input.enabled || !this._onDisabledFrame ? newState : STATE_DISABLED;
|
|
151
|
-
const frameKey = `_on${
|
|
151
|
+
const frameKey = `_on${state}Frame`;
|
|
152
152
|
const frame = this[frameKey];
|
|
153
153
|
if (typeof frame === 'string') {
|
|
154
154
|
this.frameName = frame;
|
|
@@ -59,23 +59,23 @@ export function renderGraphics(graphics, context) {
|
|
|
59
59
|
}
|
|
60
60
|
if (data.fill) {
|
|
61
61
|
context.globalAlpha = data.fillAlpha * worldAlpha;
|
|
62
|
-
context.fillStyle = `#${
|
|
62
|
+
context.fillStyle = `#${`00000${(fillColor | 0).toString(16)}`.substr(-6)}`;
|
|
63
63
|
context.fill();
|
|
64
64
|
}
|
|
65
65
|
if (data.lineWidth) {
|
|
66
66
|
context.globalAlpha = data.lineAlpha * worldAlpha;
|
|
67
|
-
context.strokeStyle = `#${
|
|
67
|
+
context.strokeStyle = `#${`00000${(lineColor | 0).toString(16)}`.substr(-6)}`;
|
|
68
68
|
context.stroke();
|
|
69
69
|
}
|
|
70
70
|
} else if (data.type === GEOM_RECTANGLE) {
|
|
71
71
|
if (data.fillColor || data.fillColor === 0) {
|
|
72
72
|
context.globalAlpha = data.fillAlpha * worldAlpha;
|
|
73
|
-
context.fillStyle = `#${
|
|
73
|
+
context.fillStyle = `#${`00000${(fillColor | 0).toString(16)}`.substr(-6)}`;
|
|
74
74
|
context.fillRect(shape.x, shape.y, shape.width, shape.height);
|
|
75
75
|
}
|
|
76
76
|
if (data.lineWidth) {
|
|
77
77
|
context.globalAlpha = data.lineAlpha * worldAlpha;
|
|
78
|
-
context.strokeStyle = `#${
|
|
78
|
+
context.strokeStyle = `#${`00000${(lineColor | 0).toString(16)}`.substr(-6)}`;
|
|
79
79
|
context.strokeRect(shape.x, shape.y, shape.width, shape.height);
|
|
80
80
|
}
|
|
81
81
|
} else if (data.type === GEOM_CIRCLE) {
|
|
@@ -84,12 +84,12 @@ export function renderGraphics(graphics, context) {
|
|
|
84
84
|
context.closePath();
|
|
85
85
|
if (data.fill) {
|
|
86
86
|
context.globalAlpha = data.fillAlpha * worldAlpha;
|
|
87
|
-
context.fillStyle = `#${
|
|
87
|
+
context.fillStyle = `#${`00000${(fillColor | 0).toString(16)}`.substr(-6)}`;
|
|
88
88
|
context.fill();
|
|
89
89
|
}
|
|
90
90
|
if (data.lineWidth) {
|
|
91
91
|
context.globalAlpha = data.lineAlpha * worldAlpha;
|
|
92
|
-
context.strokeStyle = `#${
|
|
92
|
+
context.strokeStyle = `#${`00000${(lineColor | 0).toString(16)}`.substr(-6)}`;
|
|
93
93
|
context.stroke();
|
|
94
94
|
}
|
|
95
95
|
} else if (data.type === GEOM_ELLIPSE) {
|
|
@@ -114,12 +114,12 @@ export function renderGraphics(graphics, context) {
|
|
|
114
114
|
context.closePath();
|
|
115
115
|
if (data.fill) {
|
|
116
116
|
context.globalAlpha = data.fillAlpha * worldAlpha;
|
|
117
|
-
context.fillStyle = `#${
|
|
117
|
+
context.fillStyle = `#${`00000${(fillColor | 0).toString(16)}`.substr(-6)}`;
|
|
118
118
|
context.fill();
|
|
119
119
|
}
|
|
120
120
|
if (data.lineWidth) {
|
|
121
121
|
context.globalAlpha = data.lineAlpha * worldAlpha;
|
|
122
|
-
context.strokeStyle = `#${
|
|
122
|
+
context.strokeStyle = `#${`00000${(lineColor | 0).toString(16)}`.substr(-6)}`;
|
|
123
123
|
context.stroke();
|
|
124
124
|
}
|
|
125
125
|
} else if (data.type === GEOM_ROUNDED_RECTANGLE) {
|
|
@@ -143,12 +143,12 @@ export function renderGraphics(graphics, context) {
|
|
|
143
143
|
context.closePath();
|
|
144
144
|
if (data.fillColor || data.fillColor === 0) {
|
|
145
145
|
context.globalAlpha = data.fillAlpha * worldAlpha;
|
|
146
|
-
context.fillStyle = `#${
|
|
146
|
+
context.fillStyle = `#${`00000${(fillColor | 0).toString(16)}`.substr(-6)}`;
|
|
147
147
|
context.fill();
|
|
148
148
|
}
|
|
149
149
|
if (data.lineWidth) {
|
|
150
150
|
context.globalAlpha = data.lineAlpha * worldAlpha;
|
|
151
|
-
context.strokeStyle = `#${
|
|
151
|
+
context.strokeStyle = `#${`00000${(lineColor | 0).toString(16)}`.substr(-6)}`;
|
|
152
152
|
context.stroke();
|
|
153
153
|
}
|
|
154
154
|
}
|
|
@@ -91,16 +91,17 @@ export function getFree() {
|
|
|
91
91
|
* @param {object} parent - TBD.
|
|
92
92
|
* @param {number} width - TBD.
|
|
93
93
|
* @param {number} height - TBD.
|
|
94
|
+
* @param {boolean} skipPool - TBD.
|
|
94
95
|
* @returns {HTMLCanvasElement} TBD.
|
|
95
96
|
*/
|
|
96
|
-
export function create(parent, width, height) {
|
|
97
|
+
export function create(parent, width, height, skipPool = false) {
|
|
97
98
|
if (parent === undefined) {
|
|
98
99
|
console.warn('Created CanvasPool element with undefined parent.');
|
|
99
100
|
}
|
|
100
101
|
const idx = getFirst();
|
|
101
102
|
const pool = getPool();
|
|
102
103
|
let canvas;
|
|
103
|
-
if (idx === -1) {
|
|
104
|
+
if (idx === -1 || skipPool === true) {
|
|
104
105
|
const container = {
|
|
105
106
|
parent,
|
|
106
107
|
canvas: document.createElement('canvas'),
|
|
@@ -40,6 +40,7 @@ export class CanvasRenderer {
|
|
|
40
40
|
this.width = game.width * this.resolution;
|
|
41
41
|
this.height = game.height * this.resolution;
|
|
42
42
|
this.view = game.canvas;
|
|
43
|
+
/** @type {CanvasRenderingContext2D} */
|
|
43
44
|
this.context = this.view.getContext('2d', { alpha: this.transparent });
|
|
44
45
|
if (!this.context) {
|
|
45
46
|
throw new Error('Error creating Canvas2D context');
|
|
@@ -106,8 +107,8 @@ export class CanvasRenderer {
|
|
|
106
107
|
this.view.width = this.width;
|
|
107
108
|
this.view.height = this.height;
|
|
108
109
|
if (this.autoResize) {
|
|
109
|
-
this.view.style.width = `${this.width / this.resolution
|
|
110
|
-
this.view.style.height = `${this.height / this.resolution
|
|
110
|
+
this.view.style.width = `${this.width / this.resolution}px`;
|
|
111
|
+
this.view.style.height = `${this.height / this.resolution}px`;
|
|
111
112
|
}
|
|
112
113
|
if (this.renderSession.smoothProperty) {
|
|
113
114
|
this.context[this.renderSession.smoothProperty] = this.renderSession.scaleMode === SCALE_LINEAR;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { CanvasBuffer } from './buffer.js';
|
|
2
|
-
import { create, removeByCanvas } from './pool.js';
|
|
3
1
|
import { hex2rgb } from '../../util/math.js';
|
|
2
|
+
import { create, removeByCanvas } from './pool.js';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* TBD.
|
|
@@ -9,7 +8,7 @@ import { hex2rgb } from '../../util/math.js';
|
|
|
9
8
|
* @returns {object} TBD.
|
|
10
9
|
*/
|
|
11
10
|
export function getTintedTexture(sprite, color) {
|
|
12
|
-
const canvas = sprite.tintedTexture || create('CanvasTinter');
|
|
11
|
+
const canvas = sprite.tintedTexture || create('CanvasTinter', 1, 1);
|
|
13
12
|
window.PhaserRegistry.CANVAS_TINT_METHOD(sprite.texture, color, canvas);
|
|
14
13
|
return canvas;
|
|
15
14
|
}
|
|
@@ -28,7 +27,7 @@ export function tintWithMultiply(texture, color, canvas) {
|
|
|
28
27
|
canvas.height = crop.height;
|
|
29
28
|
}
|
|
30
29
|
context.clearRect(0, 0, crop.width, crop.height);
|
|
31
|
-
context.fillStyle = `#${
|
|
30
|
+
context.fillStyle = `#${`00000${(color | 0).toString(16)}`.substr(-6)}`;
|
|
32
31
|
context.fillRect(0, 0, crop.width, crop.height);
|
|
33
32
|
context.globalCompositeOperation = 'multiply';
|
|
34
33
|
context.drawImage(texture.baseTexture.source, crop.x, crop.y, crop.width, crop.height, 0, 0, crop.width, crop.height);
|
|
@@ -75,20 +74,37 @@ export function tintWithPerPixel(texture, color, canvas) {
|
|
|
75
74
|
* @returns {boolean} TBD.
|
|
76
75
|
*/
|
|
77
76
|
export function checkInverseAlpha() {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
//
|
|
83
|
-
const
|
|
77
|
+
// Check for DOM
|
|
78
|
+
if (document === undefined) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
// Create canvas and context
|
|
82
|
+
const canvas = create('CanvasAlpha', 2, 1, true);
|
|
83
|
+
const context = canvas.getContext('2d');
|
|
84
|
+
if (!context) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
// Set canvas fill style
|
|
88
|
+
context.fillStyle = 'rgba(10, 20, 30, 0.5)';
|
|
89
|
+
// Draw a single pixel
|
|
90
|
+
context.fillRect(0, 0, 1, 1);
|
|
91
|
+
// Get the color values
|
|
92
|
+
const s1 = context.getImageData(0, 0, 1, 1);
|
|
84
93
|
if (s1 === null) {
|
|
85
94
|
return false;
|
|
86
95
|
}
|
|
87
|
-
//
|
|
88
|
-
|
|
89
|
-
//
|
|
90
|
-
const s2 =
|
|
91
|
-
//
|
|
96
|
+
// Plot them to x2
|
|
97
|
+
context.putImageData(s1, 1, 0);
|
|
98
|
+
// Get those values
|
|
99
|
+
const s2 = context.getImageData(1, 0, 1, 1);
|
|
100
|
+
// Dispose canvas
|
|
101
|
+
try {
|
|
102
|
+
context.reset();
|
|
103
|
+
} catch {
|
|
104
|
+
// pass
|
|
105
|
+
}
|
|
106
|
+
removeByCanvas(canvas);
|
|
107
|
+
// Compare and return
|
|
92
108
|
return (
|
|
93
109
|
s2.data[0] === s1.data[0] && s2.data[1] === s1.data[1] && s2.data[2] === s1.data[2] && s2.data[3] === s1.data[3]
|
|
94
110
|
);
|
|
@@ -99,17 +115,24 @@ export function checkInverseAlpha() {
|
|
|
99
115
|
* @returns {boolean} TBD.
|
|
100
116
|
*/
|
|
101
117
|
export function canUseNewCanvasBlendModes() {
|
|
118
|
+
// Check for DOM
|
|
102
119
|
if (document === undefined) {
|
|
103
120
|
return false;
|
|
104
121
|
}
|
|
122
|
+
// Create test images
|
|
105
123
|
const pngHead = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAABAQMAAADD8p2OAAAAA1BMVEX/';
|
|
106
124
|
const pngEnd = 'AAAACklEQVQI12NgAAAAAgAB4iG8MwAAAABJRU5ErkJggg==';
|
|
107
125
|
const magenta = new Image();
|
|
108
|
-
magenta.src = `${pngHead
|
|
126
|
+
magenta.src = `${pngHead}AP804Oa6${pngEnd}`;
|
|
109
127
|
const yellow = new Image();
|
|
110
|
-
yellow.src = `${pngHead
|
|
111
|
-
|
|
128
|
+
yellow.src = `${pngHead}/wCKxvRF${pngEnd}`;
|
|
129
|
+
// Create canvas and context
|
|
130
|
+
const canvas = create('CanvasTinter', 6, 1, true);
|
|
112
131
|
const context = canvas.getContext('2d');
|
|
132
|
+
if (!context) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
// Draw test images to canvas
|
|
113
136
|
context.globalCompositeOperation = 'multiply';
|
|
114
137
|
context.drawImage(magenta, 0, 0);
|
|
115
138
|
context.drawImage(yellow, 2, 0);
|
|
@@ -117,7 +140,14 @@ export function canUseNewCanvasBlendModes() {
|
|
|
117
140
|
return false;
|
|
118
141
|
}
|
|
119
142
|
const data = context.getImageData(2, 0, 1, 1).data;
|
|
143
|
+
// Dispose canvas
|
|
144
|
+
try {
|
|
145
|
+
context.reset();
|
|
146
|
+
} catch {
|
|
147
|
+
// pass
|
|
148
|
+
}
|
|
120
149
|
removeByCanvas(canvas);
|
|
150
|
+
// Compare and return
|
|
121
151
|
return data[0] === 255 && data[1] === 0 && data[2] === 0;
|
|
122
152
|
}
|
|
123
153
|
|
|
@@ -129,7 +129,7 @@ export function setTransform(context, translateX, translateY, scaleX, scaleY, sk
|
|
|
129
129
|
export function getSmoothingPrefix(context) {
|
|
130
130
|
const VENDORS = ['i', 'webkitI', 'msI', 'mozI', 'oI'];
|
|
131
131
|
for (let i = 0; i < VENDORS.length; i += 1) {
|
|
132
|
-
const s = `${VENDORS[i]
|
|
132
|
+
const s = `${VENDORS[i]}mageSmoothingEnabled`;
|
|
133
133
|
if (context && context[s]) {
|
|
134
134
|
return s;
|
|
135
135
|
}
|
|
@@ -95,7 +95,7 @@ export class DisplayObject {
|
|
|
95
95
|
this.children.splice(index, 0, child);
|
|
96
96
|
return child;
|
|
97
97
|
}
|
|
98
|
-
throw new Error(`${child
|
|
98
|
+
throw new Error(`${child}addChildAt: The index ${index} supplied is out of bounds ${this.children.length}`);
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
/**
|
|
@@ -155,9 +155,9 @@ export class DisplayObject {
|
|
|
155
155
|
getChildAt(index) {
|
|
156
156
|
if (index < 0 || index >= this.children.length) {
|
|
157
157
|
throw new Error(
|
|
158
|
-
`getChildAt: Supplied index ${
|
|
159
|
-
index
|
|
160
|
-
|
|
158
|
+
`getChildAt: Supplied index ${
|
|
159
|
+
index
|
|
160
|
+
} does not exist in the child list, or the supplied DisplayObject must be a child of the caller`
|
|
161
161
|
);
|
|
162
162
|
}
|
|
163
163
|
return this.children[index];
|
|
@@ -545,7 +545,7 @@ export class Text extends Image {
|
|
|
545
545
|
// append the entire line and exit early
|
|
546
546
|
const lineWidth = context.measureText(line).width;
|
|
547
547
|
if (lineWidth < wordWrapWidth) {
|
|
548
|
-
output += `${line
|
|
548
|
+
output += `${line}\n`;
|
|
549
549
|
} else {
|
|
550
550
|
// otherwise, calculate new lines
|
|
551
551
|
let currentLineWidth = wordWrapWidth;
|
|
@@ -553,7 +553,7 @@ export class Text extends Image {
|
|
|
553
553
|
const words = line.split(' ');
|
|
554
554
|
for (let j = 0; j < words.length; j += 1) {
|
|
555
555
|
const word = words[j];
|
|
556
|
-
const wordWithSpace = `${word
|
|
556
|
+
const wordWithSpace = `${word} `;
|
|
557
557
|
let wordWidth = context.measureText(wordWithSpace).width;
|
|
558
558
|
if (wordWidth > currentLineWidth) {
|
|
559
559
|
// break word
|
|
@@ -587,7 +587,7 @@ export class Text extends Image {
|
|
|
587
587
|
.join(' ')
|
|
588
588
|
.replace(/[ \n]*$/gi, '');
|
|
589
589
|
// prepend remainder to next line
|
|
590
|
-
lines[i + 1] = `${remainder
|
|
590
|
+
lines[i + 1] = `${remainder} ${lines[i + 1] || ''}`;
|
|
591
591
|
linesCount = lines.length;
|
|
592
592
|
break; // processing on this line
|
|
593
593
|
// append word with space to output
|
|
@@ -597,7 +597,7 @@ export class Text extends Image {
|
|
|
597
597
|
}
|
|
598
598
|
}
|
|
599
599
|
// append processed line to output
|
|
600
|
-
output += `${out.replace(/[ \n]*$/gi, '')
|
|
600
|
+
output += `${out.replace(/[ \n]*$/gi, '')}\n`;
|
|
601
601
|
}
|
|
602
602
|
}
|
|
603
603
|
// trim the end of the string
|
|
@@ -624,11 +624,11 @@ export class Text extends Image {
|
|
|
624
624
|
if (j > 0) {
|
|
625
625
|
result += '\n';
|
|
626
626
|
}
|
|
627
|
-
result += `${words[j]
|
|
627
|
+
result += `${words[j]} `;
|
|
628
628
|
spaceLeft = this.style.wordWrapWidth - wordWidth;
|
|
629
629
|
} else {
|
|
630
630
|
spaceLeft -= wordWidthWithSpace;
|
|
631
|
-
result += `${words[j]
|
|
631
|
+
result += `${words[j]} `;
|
|
632
632
|
}
|
|
633
633
|
}
|
|
634
634
|
if (i < lines.length - 1) {
|
|
@@ -674,7 +674,7 @@ export class Text extends Image {
|
|
|
674
674
|
let family = m[5].trim();
|
|
675
675
|
// If it looks like the value should be quoted, but isn't, then quote it.
|
|
676
676
|
if (!/^(?:inherit|serif|sans-serif|cursive|fantasy|monospace)$/.exec(family) && !/['",]/.exec(family)) {
|
|
677
|
-
family = `'${
|
|
677
|
+
family = `'${family}'`;
|
|
678
678
|
}
|
|
679
679
|
return {
|
|
680
680
|
font,
|
|
@@ -685,7 +685,7 @@ export class Text extends Image {
|
|
|
685
685
|
fontFamily: family,
|
|
686
686
|
};
|
|
687
687
|
}
|
|
688
|
-
console.warn(`[Text] Error parsing CSS font: ${
|
|
688
|
+
console.warn(`[Text] Error parsing CSS font: ${font}`);
|
|
689
689
|
return { font };
|
|
690
690
|
}
|
|
691
691
|
|
|
@@ -1039,7 +1039,7 @@ export class Text extends Image {
|
|
|
1039
1039
|
mutatedValue = mutatedValue.trim();
|
|
1040
1040
|
// If it looks like the value should be quoted, but isn't, then quote it.
|
|
1041
1041
|
if (!/^(?:inherit|serif|sans-serif|cursive|fantasy|monospace)$/.exec(mutatedValue) && !/['",]/.exec(mutatedValue)) {
|
|
1042
|
-
mutatedValue = `'${
|
|
1042
|
+
mutatedValue = `'${mutatedValue}'`;
|
|
1043
1043
|
}
|
|
1044
1044
|
|
|
1045
1045
|
this._fontComponents.fontFamily = mutatedValue;
|