@vpmedia/phaser 1.0.16 → 1.0.18
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/dist/phaser.cjs +1 -1
- package/dist/phaser.cjs.LICENSE.txt +1 -1
- package/dist/phaser.cjs.map +1 -1
- package/dist/phaser.js +1 -1
- package/dist/phaser.js.LICENSE.txt +1 -1
- package/dist/phaser.js.map +1 -1
- package/package.json +4 -4
- package/src/phaser/core/cache.js +2 -2
- package/src/phaser/core/sound_manager.js +45 -68
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vpmedia/phaser",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.18",
|
|
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",
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
"eslint": "^8.28.0",
|
|
27
27
|
"eslint-config-prettier": "^8.5.0",
|
|
28
28
|
"eslint-plugin-import": "^2.26.0",
|
|
29
|
-
"eslint-plugin-jest": "^27.1.
|
|
30
|
-
"eslint-plugin-jsdoc": "^39.6.
|
|
29
|
+
"eslint-plugin-jest": "^27.1.6",
|
|
30
|
+
"eslint-plugin-jsdoc": "^39.6.4",
|
|
31
31
|
"eslint-plugin-prettier": "^4.2.1",
|
|
32
32
|
"husky": "^8.0.2",
|
|
33
33
|
"jest": "^29.3.1",
|
|
34
|
-
"lint-staged": "^13.0.
|
|
34
|
+
"lint-staged": "^13.0.4",
|
|
35
35
|
"prettier": "^2.8.0",
|
|
36
36
|
"webpack": "^5.75.0",
|
|
37
37
|
"webpack-cli": "^4.10.0"
|
package/src/phaser/core/cache.js
CHANGED
|
@@ -137,7 +137,7 @@ export default class {
|
|
|
137
137
|
data,
|
|
138
138
|
isDecoding: false,
|
|
139
139
|
decoded: false,
|
|
140
|
-
locked: this.game.sound.
|
|
140
|
+
locked: this.game.sound.isLocked,
|
|
141
141
|
};
|
|
142
142
|
this._resolveURL(url, this._cache.sound[key]);
|
|
143
143
|
}
|
|
@@ -222,7 +222,7 @@ export default class {
|
|
|
222
222
|
isSoundReady(key) {
|
|
223
223
|
const sound = this.getItem(key, SOUND, 'isSoundDecoded');
|
|
224
224
|
if (sound) {
|
|
225
|
-
return (sound.decoded && !this.game.sound.
|
|
225
|
+
return (sound.decoded && !this.game.sound.isLocked);
|
|
226
226
|
}
|
|
227
227
|
return false;
|
|
228
228
|
}
|
|
@@ -19,7 +19,7 @@ export default class {
|
|
|
19
19
|
this.baseLatency = 0; // https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/baseLatency
|
|
20
20
|
this.noAudio = false;
|
|
21
21
|
this.connectToMaster = true;
|
|
22
|
-
this.
|
|
22
|
+
this.isLocked = false;
|
|
23
23
|
this.muteOnPause = true;
|
|
24
24
|
this._codeMuted = false;
|
|
25
25
|
this._muted = false;
|
|
@@ -45,7 +45,7 @@ export default class {
|
|
|
45
45
|
} catch (e) {
|
|
46
46
|
this.context = null;
|
|
47
47
|
this.noAudio = true;
|
|
48
|
-
this.
|
|
48
|
+
this.isLocked = false;
|
|
49
49
|
this.game.exceptionHandler(e);
|
|
50
50
|
}
|
|
51
51
|
} else if (window.webkitAudioContext) {
|
|
@@ -54,72 +54,62 @@ export default class {
|
|
|
54
54
|
} catch (e) {
|
|
55
55
|
this.context = null;
|
|
56
56
|
this.noAudio = true;
|
|
57
|
-
this.
|
|
57
|
+
this.isLocked = false;
|
|
58
58
|
this.game.exceptionHandler(e);
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
if (this.context === null || (this.context && this.context.createGain === undefined && this.context.createGainNode === undefined)) {
|
|
62
62
|
this.noAudio = true;
|
|
63
|
-
} else {
|
|
64
|
-
this.baseLatency = this.context.baseLatency || (256 / (this.context.sampleRate || 44100));
|
|
65
|
-
if (this.context.createGain === undefined) {
|
|
66
|
-
this.masterGain = this.context.createGainNode();
|
|
67
|
-
} else {
|
|
68
|
-
this.masterGain = this.context.createGain();
|
|
69
|
-
}
|
|
70
|
-
this.masterGain.gain.value = 1;
|
|
71
|
-
this.masterGain.connect(this.context.destination);
|
|
72
|
-
}
|
|
73
|
-
if (this.noAudio) {
|
|
74
63
|
return;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
this.
|
|
64
|
+
}
|
|
65
|
+
this.baseLatency = this.context.baseLatency || (256 / (this.context.sampleRate || 44100));
|
|
66
|
+
if (this.context.createGain === undefined) {
|
|
67
|
+
this.masterGain = this.context.createGainNode();
|
|
68
|
+
} else {
|
|
69
|
+
this.masterGain = this.context.createGain();
|
|
70
|
+
}
|
|
71
|
+
this.masterGain.gain.value = 1;
|
|
72
|
+
this.masterGain.connect(this.context.destination);
|
|
73
|
+
// handle audio context state
|
|
74
|
+
console.log("AudioContext initial state", this.context.state);
|
|
75
|
+
this.context.onstatechange = () => {
|
|
76
|
+
console.log("AudioContext change state", this.context.state);
|
|
77
|
+
};
|
|
78
|
+
if (this.context.state === 'suspended') {
|
|
79
|
+
this.isLocked = true;
|
|
80
|
+
this.onUnlockEventBinded = this.onUnlockEvent.bind(this);
|
|
81
|
+
this.addUnlockHandlers();
|
|
79
82
|
}
|
|
80
83
|
}
|
|
81
84
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
85
|
+
addUnlockHandlers() {
|
|
86
|
+
document.body.addEventListener('touchstart', this.onUnlockEventBinded, false);
|
|
87
|
+
document.body.addEventListener('touchend', this.onUnlockEventBinded, false);
|
|
88
|
+
document.body.addEventListener('click', this.onUnlockEventBinded, false);
|
|
89
|
+
document.body.addEventListener('keydown', this.onUnlockEventBinded, false);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
removeUnlockHandlers() {
|
|
93
|
+
document.body.removeEventListener('touchstart', this.onUnlockEventBinded);
|
|
94
|
+
document.body.removeEventListener('touchend', this.onUnlockEventBinded);
|
|
95
|
+
document.body.removeEventListener('click', this.onUnlockEventBinded);
|
|
96
|
+
document.body.removeEventListener('keydown', this.onUnlockEventBinded);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
onUnlockEvent(event) {
|
|
100
|
+
if (this.context.state !== 'suspended') {
|
|
89
101
|
return;
|
|
90
102
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}, this);
|
|
99
|
-
}
|
|
103
|
+
console.log('onUnlockEvent', event);
|
|
104
|
+
this.context.resume().then(() => {
|
|
105
|
+
this.removeUnlockHandlers();
|
|
106
|
+
}).catch((e) => {
|
|
107
|
+
this.removeUnlockHandlers();
|
|
108
|
+
this.game.exceptionHandler(e, { state: this.context.state });
|
|
109
|
+
});
|
|
100
110
|
}
|
|
101
111
|
|
|
102
|
-
|
|
103
|
-
if (!this.touchLocked || this._unlockSource !== null) {
|
|
104
|
-
return true;
|
|
105
|
-
}
|
|
106
|
-
// Create empty buffer and play it
|
|
107
|
-
// The SoundManager.update loop captures the state of it and then resets touchLocked to false
|
|
108
|
-
const buffer = this.context.createBuffer(1, 1, 22050);
|
|
109
|
-
this._unlockSource = this.context.createBufferSource();
|
|
110
|
-
this._unlockSource.buffer = buffer;
|
|
111
|
-
this._unlockSource.connect(this.context.destination);
|
|
112
|
-
if (this._unlockSource.start === undefined) {
|
|
113
|
-
this._unlockSource.noteOn(0);
|
|
114
|
-
} else {
|
|
115
|
-
this._unlockSource.start(0);
|
|
116
|
-
}
|
|
117
|
-
if (this.context.state === 'suspended') {
|
|
118
|
-
this.context.resume().catch((e) => {
|
|
119
|
-
this.game.exceptionHandler(e, { state: this.context.state, reason: 'unlock' });
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
return true;
|
|
112
|
+
checkContextState() {
|
|
123
113
|
}
|
|
124
114
|
|
|
125
115
|
stopAll() {
|
|
@@ -201,19 +191,6 @@ export default class {
|
|
|
201
191
|
if (this.noAudio) {
|
|
202
192
|
return;
|
|
203
193
|
}
|
|
204
|
-
if (this.touchLocked && this._unlockSource !== null && (this._unlockSource.playbackState === this._unlockSource.PLAYING_STATE || this._unlockSource.playbackState === this._unlockSource.FINISHED_STATE)) {
|
|
205
|
-
this.touchLocked = false;
|
|
206
|
-
this._unlockSource = null;
|
|
207
|
-
if (this.context.state === 'suspended') {
|
|
208
|
-
this.context.resume().catch((e) => {
|
|
209
|
-
this.game.exceptionHandler(e, { state: this.context.state, reason: 'update_suspended' });
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
} else if (this.context.state === 'interrupted') {
|
|
213
|
-
this.context.resume().catch((e) => {
|
|
214
|
-
this.game.exceptionHandler(e, { state: this.context.state, reason: 'update_interrupted' });
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
194
|
for (let i = 0; i < this._sounds.length; i += 1) {
|
|
218
195
|
this._sounds[i].update();
|
|
219
196
|
}
|