@vpmedia/phaser 1.0.15 → 1.0.17

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vpmedia/phaser",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
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.5",
30
- "eslint-plugin-jsdoc": "^39.6.2",
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.3",
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"
@@ -137,7 +137,7 @@ export default class {
137
137
  data,
138
138
  isDecoding: false,
139
139
  decoded: false,
140
- locked: this.game.sound.touchLocked,
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.touchLocked);
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.touchLocked = false;
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.touchLocked = false;
48
+ this.isLocked = false;
49
49
  this.game.exceptionHandler(e);
50
50
  }
51
51
  } else if (window.webkitAudioContext) {
@@ -54,72 +54,61 @@ export default class {
54
54
  } catch (e) {
55
55
  this.context = null;
56
56
  this.noAudio = true;
57
- this.touchLocked = false;
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
- if (this.game.device.iOS || this.game.device.android) {
77
- this.game.input.addTouchLockCallback(this.unlock, this, true);
78
- this.touchLocked = true;
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
+ this.context.onstatechange = () => {
75
+ console.log("AudioContext", this.context.state);
76
+ };
77
+ if (this.context.state === 'suspended') {
78
+ this.isLocked = true;
79
+ this.onUnlockEventBinded = this.onUnlockEvent.bind(this);
80
+ this.addUnlockHandlers();
79
81
  }
80
82
  }
81
83
 
82
- checkContextState() {
83
- // this must be called from the final game state since input.onUp handlers are reset by state manager
84
- if (this.noAudio) {
85
- return;
86
- }
87
- if (this.game.device.iOS || this.game.device.android) {
88
- // touch lock callback already handles context resume
84
+ addUnlockHandlers() {
85
+ document.body.addEventListener('touchstart', this.onUnlockEventBinded, false);
86
+ document.body.addEventListener('touchend', this.onUnlockEventBinded, false);
87
+ document.body.addEventListener('click', this.onUnlockEventBinded, false);
88
+ document.body.addEventListener('keydown', this.onUnlockEventBinded, false);
89
+ }
90
+
91
+ removeUnlockHandlers() {
92
+ document.body.removeEventListener('touchstart', this.onUnlockEventBinded);
93
+ document.body.removeEventListener('touchend', this.onUnlockEventBinded);
94
+ document.body.removeEventListener('click', this.onUnlockEventBinded);
95
+ document.body.removeEventListener('keydown', this.onUnlockEventBinded);
96
+ }
97
+
98
+ onUnlockEvent(event) {
99
+ if (this.context.state !== 'suspended') {
89
100
  return;
90
101
  }
91
- if (this.context.state === 'suspended') {
92
- this.game.input.onUp.addOnce(() => {
93
- if (this.context.state === 'suspended') {
94
- this.context.resume().catch((e) => {
95
- this.game.exceptionHandler(e, { state: this.context.state, trigger: 'check' });
96
- });
97
- }
98
- }, this);
99
- }
102
+ console.log('onUnlockEvent', event);
103
+ this.context.resume().then(() => {
104
+ this.removeUnlockHandlers();
105
+ }).catch((e) => {
106
+ this.removeUnlockHandlers();
107
+ this.game.exceptionHandler(e, { state: this.context.state });
108
+ });
100
109
  }
101
110
 
102
- unlock() {
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, trigger: 'unlock' });
120
- });
121
- }
122
- return true;
111
+ checkContextState() {
123
112
  }
124
113
 
125
114
  stopAll() {
@@ -201,19 +190,6 @@ export default class {
201
190
  if (this.noAudio) {
202
191
  return;
203
192
  }
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, trigger: 'update' });
210
- });
211
- }
212
- } else if (this.context.state === 'interrupted') {
213
- this.context.resume().catch((e) => {
214
- this.game.exceptionHandler(e, { state: this.context.state });
215
- });
216
- }
217
193
  for (let i = 0; i < this._sounds.length; i += 1) {
218
194
  this._sounds[i].update();
219
195
  }