@vpmedia/phaser 1.45.0 → 1.48.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/phaser/core/animation_manager.js +2 -2
- package/src/phaser/core/game.js +1 -7
- package/src/phaser/core/sound_manager.js +3 -2
- package/src/phaser/display/canvas/buffer.js +5 -0
- package/src/phaser/display/canvas/pool.js +3 -2
- package/src/phaser/display/canvas/renderer.js +2 -1
- package/src/phaser/display/canvas/tinter.js +45 -15
- package/src/phaser/display/display_object.js +1 -1
- package/src/phaser/display/webgl/renderer.js +1 -1
- package/src/phaser/display/webgl/util.js +6 -4
- package/src/phaser/geom/util/point.js +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.48.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
|
},
|
|
@@ -306,7 +306,7 @@ export class AnimationManager {
|
|
|
306
306
|
this.sprite.setFrame(this.currentFrame);
|
|
307
307
|
}
|
|
308
308
|
} else {
|
|
309
|
-
this.game.exceptionHandler(new Error('Cannot set frame'), { key: value });
|
|
309
|
+
this.game.exceptionHandler(new Error('Cannot set frame'), { 'asset.key': value });
|
|
310
310
|
}
|
|
311
311
|
}
|
|
312
312
|
|
|
@@ -332,7 +332,7 @@ export class AnimationManager {
|
|
|
332
332
|
this.sprite.setFrame(this.currentFrame);
|
|
333
333
|
}
|
|
334
334
|
} else {
|
|
335
|
-
this.game.exceptionHandler(new Error('Cannot set frameName'), { key: value });
|
|
335
|
+
this.game.exceptionHandler(new Error('Cannot set frameName'), { 'asset.key': value });
|
|
336
336
|
}
|
|
337
337
|
}
|
|
338
338
|
}
|
package/src/phaser/core/game.js
CHANGED
|
@@ -145,13 +145,7 @@ export class Game {
|
|
|
145
145
|
isWebGlReady = true;
|
|
146
146
|
} catch (e) {
|
|
147
147
|
isWebGlReady = false;
|
|
148
|
-
const tags = {
|
|
149
|
-
'document.readyState': document.readyState,
|
|
150
|
-
'document.hidden': document.hidden,
|
|
151
|
-
'document.visibilityState': document.visibilityState,
|
|
152
|
-
'canvas.width': this.canvas.width,
|
|
153
|
-
'canvas.height': this.canvas.height,
|
|
154
|
-
};
|
|
148
|
+
const tags = {};
|
|
155
149
|
if (window.PhaserRegistry?.GL_PROGRAM_INFO_LOG) {
|
|
156
150
|
tags.gl_program_log = window.PhaserRegistry.GL_PROGRAM_INFO_LOG;
|
|
157
151
|
}
|
|
@@ -61,6 +61,7 @@ export class SoundManager {
|
|
|
61
61
|
this.context === null ||
|
|
62
62
|
(this.context && this.context.createGain === undefined && this.context.createGainNode === undefined)
|
|
63
63
|
) {
|
|
64
|
+
this.game.exceptionHandler(new Error('Error creating AudioContext'));
|
|
64
65
|
this.noAudio = true;
|
|
65
66
|
return;
|
|
66
67
|
}
|
|
@@ -159,7 +160,7 @@ export class SoundManager {
|
|
|
159
160
|
error: e,
|
|
160
161
|
});
|
|
161
162
|
this.removeUnlockHandlers();
|
|
162
|
-
this.game.exceptionHandler(e, { initialState, state: this.context.state });
|
|
163
|
+
this.game.exceptionHandler(e, { 'audio.initialState': initialState, 'audio.state': this.context.state });
|
|
163
164
|
});
|
|
164
165
|
}
|
|
165
166
|
|
|
@@ -220,7 +221,7 @@ export class SoundManager {
|
|
|
220
221
|
this.game.cache.decodedSound(key, buffer);
|
|
221
222
|
})
|
|
222
223
|
.catch((e) => {
|
|
223
|
-
this.game.exceptionHandler(e, { key });
|
|
224
|
+
this.game.exceptionHandler(e, { 'asset.key': key });
|
|
224
225
|
});
|
|
225
226
|
}
|
|
226
227
|
}
|
|
@@ -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,9 +40,10 @@ 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
|
-
throw new Error('Error creating
|
|
46
|
+
throw new Error('Error creating Canvas2D context');
|
|
46
47
|
}
|
|
47
48
|
this.refresh = true;
|
|
48
49
|
this.count = 0;
|
|
@@ -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
|
}
|
|
@@ -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
126
|
magenta.src = `${pngHead }AP804Oa6${ pngEnd}`;
|
|
109
127
|
const yellow = new Image();
|
|
110
128
|
yellow.src = `${pngHead }/wCKxvRF${ pngEnd}`;
|
|
111
|
-
|
|
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
|
|
|
@@ -111,7 +111,7 @@ export class DisplayObject {
|
|
|
111
111
|
const index1 = this.getChildIndex(child);
|
|
112
112
|
const index2 = this.getChildIndex(child2);
|
|
113
113
|
if (index1 < 0 || index2 < 0) {
|
|
114
|
-
throw new Error('swapChildren: Both the supplied DisplayObjects must be a child of the caller
|
|
114
|
+
throw new Error('swapChildren: Both the supplied DisplayObjects must be a child of the caller');
|
|
115
115
|
}
|
|
116
116
|
this.children[index1] = child2;
|
|
117
117
|
this.children[index2] = child;
|
|
@@ -128,7 +128,7 @@ export class WebGLRenderer {
|
|
|
128
128
|
this.gl = gl;
|
|
129
129
|
if (!gl) {
|
|
130
130
|
// fail, not able to get a context
|
|
131
|
-
throw new Error('
|
|
131
|
+
throw new Error('Error creating WebGL context');
|
|
132
132
|
}
|
|
133
133
|
this.initRegistry();
|
|
134
134
|
this.glContextId = window.PhaserRegistry.GL_CONTEXT_ID;
|
|
@@ -19,9 +19,10 @@ export function compileShader(gl, shaderSrc, shaderType) {
|
|
|
19
19
|
gl.shaderSource(shader, src);
|
|
20
20
|
gl.compileShader(shader);
|
|
21
21
|
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
|
|
22
|
-
if (window.PhaserRegistry) {
|
|
23
|
-
window.PhaserRegistry
|
|
22
|
+
if (!window.PhaserRegistry) {
|
|
23
|
+
window.PhaserRegistry = {};
|
|
24
24
|
}
|
|
25
|
+
window.PhaserRegistry.GL_SHADER_INFO_LOG = gl.getShaderInfoLog(shader);
|
|
25
26
|
return null;
|
|
26
27
|
}
|
|
27
28
|
return shader;
|
|
@@ -65,9 +66,10 @@ export function compileProgram(gl, vertexSrc, fragmentSrc) {
|
|
|
65
66
|
gl.linkProgram(shaderProgram);
|
|
66
67
|
|
|
67
68
|
if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS)) {
|
|
68
|
-
if (window.PhaserRegistry) {
|
|
69
|
-
window.PhaserRegistry
|
|
69
|
+
if (!window.PhaserRegistry) {
|
|
70
|
+
window.PhaserRegistry = {};
|
|
70
71
|
}
|
|
72
|
+
window.PhaserRegistry.GL_PROGRAM_INFO_LOG = gl.getProgramInfoLog(shaderProgram);
|
|
71
73
|
}
|
|
72
74
|
return shaderProgram;
|
|
73
75
|
}
|
|
@@ -248,7 +248,7 @@ export function centroid(points, output = null) {
|
|
|
248
248
|
const result = output || new Point();
|
|
249
249
|
const pointsLen = points.length;
|
|
250
250
|
if (pointsLen < 1) {
|
|
251
|
-
throw new Error('Point(points) array must not be empty
|
|
251
|
+
throw new Error('Point(points) array must not be empty');
|
|
252
252
|
}
|
|
253
253
|
if (pointsLen === 1) {
|
|
254
254
|
result.copyFrom(points[0]);
|
package/CHANGES.md
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# Release notes
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
This project adheres to [Semantic Versioning](http://semver.org/).
|
|
5
|
-
|
|
6
|
-
## 1.44.0
|
|
7
|
-
|
|
8
|
-
- Improved Canvas2D fallback handling
|
|
9
|
-
|
|
10
|
-
## 1.43.0
|
|
11
|
-
|
|
12
|
-
- Updated dependencies
|
|
13
|
-
|
|
14
|
-
## 1.42.0
|
|
15
|
-
|
|
16
|
-
- Added error notification for invalid texture frames
|
|
17
|
-
|
|
18
|
-
## 1.41.0
|
|
19
|
-
|
|
20
|
-
- Updated dependencies
|
|
21
|
-
- Changed package to ES6 module
|