@vpmedia/phaser 1.48.0 → 1.50.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 +2 -2
- 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_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/graphics.js +10 -10
- package/src/phaser/display/canvas/renderer.js +2 -2
- package/src/phaser/display/canvas/tinter.js +3 -3
- 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/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.50.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",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"@jest/globals": "^29.7.0",
|
|
28
28
|
"@types/jest": "^29.5.14",
|
|
29
29
|
"eslint": "^9.14.0",
|
|
30
|
-
"eslint-plugin-jsdoc": "^50.
|
|
30
|
+
"eslint-plugin-jsdoc": "^50.5.0",
|
|
31
31
|
"eslint-plugin-unicorn": "^56.0.0",
|
|
32
32
|
"globals": "^15.12.0",
|
|
33
33
|
"jest": "^29.7.0",
|
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 {
|
|
@@ -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
|
}
|
|
@@ -107,8 +107,8 @@ export class CanvasRenderer {
|
|
|
107
107
|
this.view.width = this.width;
|
|
108
108
|
this.view.height = this.height;
|
|
109
109
|
if (this.autoResize) {
|
|
110
|
-
this.view.style.width = `${this.width / this.resolution
|
|
111
|
-
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`;
|
|
112
112
|
}
|
|
113
113
|
if (this.renderSession.smoothProperty) {
|
|
114
114
|
this.context[this.renderSession.smoothProperty] = this.renderSession.scaleMode === SCALE_LINEAR;
|
|
@@ -27,7 +27,7 @@ export function tintWithMultiply(texture, color, canvas) {
|
|
|
27
27
|
canvas.height = crop.height;
|
|
28
28
|
}
|
|
29
29
|
context.clearRect(0, 0, crop.width, crop.height);
|
|
30
|
-
context.fillStyle = `#${
|
|
30
|
+
context.fillStyle = `#${`00000${(color | 0).toString(16)}`.substr(-6)}`;
|
|
31
31
|
context.fillRect(0, 0, crop.width, crop.height);
|
|
32
32
|
context.globalCompositeOperation = 'multiply';
|
|
33
33
|
context.drawImage(texture.baseTexture.source, crop.x, crop.y, crop.width, crop.height, 0, 0, crop.width, crop.height);
|
|
@@ -123,9 +123,9 @@ export function canUseNewCanvasBlendModes() {
|
|
|
123
123
|
const pngHead = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAABAQMAAADD8p2OAAAAA1BMVEX/';
|
|
124
124
|
const pngEnd = 'AAAACklEQVQI12NgAAAAAgAB4iG8MwAAAABJRU5ErkJggg==';
|
|
125
125
|
const magenta = new Image();
|
|
126
|
-
magenta.src = `${pngHead
|
|
126
|
+
magenta.src = `${pngHead}AP804Oa6${pngEnd}`;
|
|
127
127
|
const yellow = new Image();
|
|
128
|
-
yellow.src = `${pngHead
|
|
128
|
+
yellow.src = `${pngHead}/wCKxvRF${pngEnd}`;
|
|
129
129
|
// Create canvas and context
|
|
130
130
|
const canvas = create('CanvasTinter', 6, 1, true);
|
|
131
131
|
const context = canvas.getContext('2d');
|
|
@@ -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;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { GraphicsData } from './graphics_data.js';
|
|
2
|
-
import { Point } from '../../geom/point.js';
|
|
3
1
|
import { GEOM_CIRCLE, GEOM_ELLIPSE, GEOM_POLYGON, GEOM_RECTANGLE, GEOM_ROUNDED_RECTANGLE } from '../../core/const.js';
|
|
2
|
+
import { Point } from '../../geom/point.js';
|
|
4
3
|
import { hex2rgb } from '../../util/math.js';
|
|
5
4
|
import { triangulate } from './earcut.js';
|
|
5
|
+
import { GraphicsData } from './graphics_data.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* TBD.
|
|
@@ -485,7 +485,7 @@ export function buildPoly(graphicsData, webGLData) {
|
|
|
485
485
|
/**
|
|
486
486
|
* TBD.
|
|
487
487
|
* @param {object} graphics - TBD.
|
|
488
|
-
* @param {
|
|
488
|
+
* @param {WebGLRenderingContext & { id: number }} gl - TBD.
|
|
489
489
|
*/
|
|
490
490
|
export function updateGraphics(graphics, gl) {
|
|
491
491
|
const stencilBufferLimit = getStencilBufferLimit();
|
|
@@ -122,6 +122,7 @@ export class WebGLRenderer {
|
|
|
122
122
|
* @throws Error.
|
|
123
123
|
*/
|
|
124
124
|
initContext() {
|
|
125
|
+
/** @type {WebGLRenderingContext & { id: number }} */
|
|
125
126
|
const gl =
|
|
126
127
|
this.view.getContext('webgl', this._contextOptions) ||
|
|
127
128
|
this.view.getContext('experimental-webgl', this._contextOptions);
|
|
@@ -211,8 +212,8 @@ export class WebGLRenderer {
|
|
|
211
212
|
this.view.width = this.width;
|
|
212
213
|
this.view.height = this.height;
|
|
213
214
|
if (this.autoResize) {
|
|
214
|
-
this.view.style.width = `${this.width / this.resolution
|
|
215
|
-
this.view.style.height = `${this.height / this.resolution
|
|
215
|
+
this.view.style.width = `${this.width / this.resolution}px`;
|
|
216
|
+
this.view.style.height = `${this.height / this.resolution}px`;
|
|
216
217
|
}
|
|
217
218
|
this.gl.viewport(0, 0, this.width, this.height);
|
|
218
219
|
this.projection.x = this.width / 2 / this.resolution;
|
|
@@ -115,7 +115,7 @@ export class NormalShader {
|
|
|
115
115
|
}
|
|
116
116
|
} else {
|
|
117
117
|
// GL function reference
|
|
118
|
-
uniform.glFunc = gl[`uniform${
|
|
118
|
+
uniform.glFunc = gl[`uniform${type}`];
|
|
119
119
|
if (type === '2f' || type === '2i') {
|
|
120
120
|
uniform.glValueLength = 2;
|
|
121
121
|
} else if (type === '3f' || type === '3i') {
|
|
@@ -138,7 +138,7 @@ export class NormalShader {
|
|
|
138
138
|
return;
|
|
139
139
|
}
|
|
140
140
|
const gl = this.gl;
|
|
141
|
-
gl.activeTexture(gl[`TEXTURE${
|
|
141
|
+
gl.activeTexture(gl[`TEXTURE${this.textureCount}`]);
|
|
142
142
|
gl.bindTexture(gl.TEXTURE_2D, uniform.value.baseTexture._glTextures[gl.id]);
|
|
143
143
|
// Extended texture data
|
|
144
144
|
if (uniform.textureData) {
|
|
@@ -215,7 +215,7 @@ export class NormalShader {
|
|
|
215
215
|
);
|
|
216
216
|
} else if (uniform.type === 'sampler2D') {
|
|
217
217
|
if (uniform._init) {
|
|
218
|
-
gl.activeTexture(gl[`TEXTURE${
|
|
218
|
+
gl.activeTexture(gl[`TEXTURE${this.textureCount}`]);
|
|
219
219
|
if (uniform.value.baseTexture._dirty[gl.id]) {
|
|
220
220
|
window.PhaserRegistry.INSTANCES[gl.id].updateTexture(uniform.value.baseTexture);
|
|
221
221
|
} else {
|
|
@@ -96,7 +96,7 @@ export class Texture {
|
|
|
96
96
|
// TODO: make this configurable
|
|
97
97
|
const isTextureSilentFail = true;
|
|
98
98
|
if (!isTextureSilentFail) {
|
|
99
|
-
throw new Error(`Texture Error: frame does not fit inside the base Texture dimensions ${
|
|
99
|
+
throw new Error(`Texture Error: frame does not fit inside the base Texture dimensions ${this}`);
|
|
100
100
|
}
|
|
101
101
|
this.valid = false;
|
|
102
102
|
return;
|
|
@@ -5,10 +5,10 @@ export function initDefaultShaders() {}
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* TBD.
|
|
8
|
-
* @param {
|
|
8
|
+
* @param {WebGLRenderingContext & { id: number }} gl - TBD.
|
|
9
9
|
* @param {string[]|string} shaderSrc - TBD.
|
|
10
10
|
* @param {object} shaderType - TBD.
|
|
11
|
-
* @returns {
|
|
11
|
+
* @returns {WebGLShader} TBD.
|
|
12
12
|
*/
|
|
13
13
|
export function compileShader(gl, shaderSrc, shaderType) {
|
|
14
14
|
let src = shaderSrc;
|
|
@@ -30,9 +30,9 @@ export function compileShader(gl, shaderSrc, shaderType) {
|
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
32
|
* TBD.
|
|
33
|
-
* @param {
|
|
33
|
+
* @param {WebGLRenderingContext & { id: number }} gl - TBD.
|
|
34
34
|
* @param {string[]|string} shaderSrc - TBD.
|
|
35
|
-
* @returns {
|
|
35
|
+
* @returns {WebGLShader} TBD.
|
|
36
36
|
*/
|
|
37
37
|
export function compileVertexShader(gl, shaderSrc) {
|
|
38
38
|
return compileShader(gl, shaderSrc, gl.VERTEX_SHADER);
|
|
@@ -40,9 +40,9 @@ export function compileVertexShader(gl, shaderSrc) {
|
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
42
|
* TBD.
|
|
43
|
-
* @param {
|
|
43
|
+
* @param {WebGLRenderingContext & { id: number }} gl - TBD.
|
|
44
44
|
* @param {string[]|string} shaderSrc - TBD.
|
|
45
|
-
* @returns {
|
|
45
|
+
* @returns {WebGLShader} TBD.
|
|
46
46
|
*/
|
|
47
47
|
export function compileFragmentShader(gl, shaderSrc) {
|
|
48
48
|
return compileShader(gl, shaderSrc, gl.FRAGMENT_SHADER);
|
|
@@ -50,10 +50,10 @@ export function compileFragmentShader(gl, shaderSrc) {
|
|
|
50
50
|
|
|
51
51
|
/**
|
|
52
52
|
* TBD.
|
|
53
|
-
* @param {
|
|
53
|
+
* @param {WebGLRenderingContext & { id: number }} gl - TBD.
|
|
54
54
|
* @param {string[]|string} vertexSrc - TBD.
|
|
55
55
|
* @param {string[]|string} fragmentSrc - TBD.
|
|
56
|
-
* @returns {
|
|
56
|
+
* @returns {WebGLProgram} TBD.
|
|
57
57
|
*/
|
|
58
58
|
export function compileProgram(gl, vertexSrc, fragmentSrc) {
|
|
59
59
|
const fragmentShader = compileFragmentShader(gl, fragmentSrc);
|
|
@@ -157,7 +157,7 @@ export class Circle {
|
|
|
157
157
|
* @returns {string} TBD.
|
|
158
158
|
*/
|
|
159
159
|
toString() {
|
|
160
|
-
return `[{Circle (x=${
|
|
160
|
+
return `[{Circle (x=${this.x} y=${this.y} diameter=${this.diameter} radius=${this.radius})}]`;
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
/**
|
|
@@ -96,6 +96,6 @@ export class Ellipse {
|
|
|
96
96
|
* @returns {string} TBD.
|
|
97
97
|
*/
|
|
98
98
|
toString() {
|
|
99
|
-
return `[{Ellipse (x=${
|
|
99
|
+
return `[{Ellipse (x=${this.x} y=${this.y} width=${this.width} height=${this.height})}]`;
|
|
100
100
|
}
|
|
101
101
|
}
|