@vpmedia/phaser 1.46.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/sound_manager.js +1 -1
- 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 +1 -0
- package/src/phaser/display/canvas/tinter.js +45 -15
- 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
|
},
|
|
@@ -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
|
|
|
@@ -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');
|
|
@@ -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
|
|
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
|