@vpmedia/phaser 1.0.23 → 1.0.25

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.23",
3
+ "version": "1.0.25",
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",
@@ -53,7 +53,6 @@ export default class {
53
53
  this.gainNode.connect(this.masterGainNode);
54
54
  }
55
55
  }
56
- this.onDecoded = new Signal();
57
56
  this.onPlay = new Signal();
58
57
  this.onPause = new Signal();
59
58
  this.onResume = new Signal();
@@ -72,7 +71,6 @@ export default class {
72
71
  this._muteVolume = 0;
73
72
  this._tempLoop = 0;
74
73
  this._paused = false;
75
- this._onDecodedEventDispatched = false;
76
74
  }
77
75
 
78
76
  soundHasUnlocked(key) {
@@ -116,7 +114,6 @@ export default class {
116
114
  this.context = null;
117
115
  this._buffer = null;
118
116
  this.externalNode = null;
119
- this.onDecoded.dispose();
120
117
  this.onPlay.dispose();
121
118
  this.onPause.dispose();
122
119
  this.onResume.dispose();
@@ -133,10 +130,6 @@ export default class {
133
130
  this.destroy();
134
131
  return;
135
132
  }
136
- if (this.isDecoded && !this._onDecodedEventDispatched) {
137
- this.onDecoded.dispatch(this);
138
- this._onDecodedEventDispatched = true;
139
- }
140
133
  if (this.pendingPlayback && this.game.cache.isSoundReady(this.key)) {
141
134
  this.pendingPlayback = false;
142
135
  this.play(this._tempMarker, this._tempPosition, this._tempVolume, this._tempLoop);
@@ -435,7 +428,6 @@ export default class {
435
428
  this.context = null;
436
429
  this._buffer = null;
437
430
  this.externalNode = null;
438
- this.onDecoded.dispose();
439
431
  this.onPlay.dispose();
440
432
  this.onPause.dispose();
441
433
  this.onResume.dispose();
@@ -11,11 +11,7 @@ export default class {
11
11
 
12
12
  constructor(game) {
13
13
  this.game = game;
14
- this.onSoundDecode = new Signal();
15
- this.onVolumeChange = new Signal();
16
- this.onLockChange = new Signal();
17
- this.onMute = new Signal();
18
- this.onUnMute = new Signal();
14
+ this.onChange = new Signal();
19
15
  this.context = null;
20
16
  this.baseLatency = 0; // https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/baseLatency
21
17
  this.noAudio = false;
@@ -72,15 +68,16 @@ export default class {
72
68
  this.masterGain.gain.value = 1;
73
69
  this.masterGain.connect(this.context.destination);
74
70
  // handle audio state unlock
71
+ // possible states: interrupted, suspended, running, closed
75
72
  this.onUnlockEventBinded = this.onUnlockEvent.bind(this);
76
73
  if (this.context.state === 'suspended' || this.context.state === 'interrupted') {
77
74
  this.addUnlockHandlers();
78
75
  }
79
76
  this.context.addEventListener('statechange', () => {
80
- this.onLockChange.dispatch('onContextStateChange', { state: this.context.state, isLocked: this.isLocked });
77
+ this.onChange.dispatch('onContextStateChange', { state: this.context.state, isLocked: this.isLocked });
81
78
  if (!this.isLocked && (this.context.state === 'suspended' || this.context.state === 'interrupted')) {
82
79
  this.addUnlockHandlers();
83
- } else if (this.isLocked) {
80
+ } else if (this.isLocked && this.context.state === 'running') {
84
81
  this.removeUnlockHandlers();
85
82
  }
86
83
  });
@@ -88,7 +85,7 @@ export default class {
88
85
 
89
86
  addUnlockHandlers() {
90
87
  this.isLocked = true;
91
- this.onLockChange.dispatch('addUnlockHandlers', { state: this.context.state, isLocked: this.isLocked });
88
+ this.onChange.dispatch('addUnlockHandlers', { state: this.context.state, isLocked: this.isLocked });
92
89
  document.body.addEventListener('touchstart', this.onUnlockEventBinded, false);
93
90
  document.body.addEventListener('touchend', this.onUnlockEventBinded, false);
94
91
  document.body.addEventListener('click', this.onUnlockEventBinded, false);
@@ -97,7 +94,7 @@ export default class {
97
94
 
98
95
  removeUnlockHandlers() {
99
96
  this.isLocked = false;
100
- this.onLockChange.dispatch('removeUnlockHandlers', { state: this.context.state, isLocked: this.isLocked });
97
+ this.onChange.dispatch('removeUnlockHandlers', { state: this.context.state, isLocked: this.isLocked });
101
98
  document.body.removeEventListener('touchstart', this.onUnlockEventBinded);
102
99
  document.body.removeEventListener('touchend', this.onUnlockEventBinded);
103
100
  document.body.removeEventListener('click', this.onUnlockEventBinded);
@@ -107,16 +104,16 @@ export default class {
107
104
  onUnlockEvent(event) {
108
105
  const initialState = this.context.state;
109
106
  if (initialState !== 'suspended' && initialState !== 'interrupted') {
110
- this.onLockChange.dispatch('onUnlockResumeDenied', { state: initialState, isLocked: this.isLocked, event });
107
+ this.onChange.dispatch('onUnlockResumeDenied', { state: initialState, isLocked: this.isLocked, event });
111
108
  this.removeUnlockHandlers();
112
109
  return;
113
110
  }
114
- this.onLockChange.dispatch('onContextResumeStart', { state: initialState, isLocked: this.isLocked, event });
111
+ this.onChange.dispatch('onContextResumeStart', { state: initialState, isLocked: this.isLocked, event });
115
112
  this.context.resume().then(() => {
116
- this.onLockChange.dispatch('onContextResumeResult', { initialState, state: this.context.state, isLocked: this.isLocked });
113
+ this.onChange.dispatch('onContextResumeResult', { initialState, state: this.context.state, isLocked: this.isLocked });
117
114
  this.removeUnlockHandlers();
118
115
  }).catch((e) => {
119
- this.onLockChange.dispatch('onContextResumeReject', { initialState, state: this.context.state, isLocked: this.isLocked, error: e });
116
+ this.onChange.dispatch('onContextResumeReject', { initialState, state: this.context.state, isLocked: this.isLocked, error: e });
120
117
  this.removeUnlockHandlers();
121
118
  this.game.exceptionHandler(e, { initialState, state: this.context.state });
122
119
  });
@@ -155,7 +152,7 @@ export default class {
155
152
  }
156
153
  }
157
154
 
158
- decode(key, sound = null) {
155
+ decode(key) {
159
156
  const soundData = this.game.cache.getSoundData(key);
160
157
  if (soundData) {
161
158
  if (this.game.cache.isSoundDecoded(key) === false) {
@@ -163,7 +160,6 @@ export default class {
163
160
  this.context.decodeAudioData(soundData)
164
161
  .then((buffer) => {
165
162
  this.game.cache.decodedSound(key, buffer);
166
- this.onSoundDecode.dispatch(key, sound);
167
163
  })
168
164
  .catch((e) => {
169
165
  this.game.exceptionHandler(e, { key });
@@ -270,7 +266,7 @@ export default class {
270
266
  this._muteVolume = this.masterGain.gain.value;
271
267
  this.masterGain.gain.value = 0;
272
268
  }
273
- this.onMute.dispatch();
269
+ this.onChange.dispatch('muted');
274
270
  }
275
271
 
276
272
  unsetMute() {
@@ -281,7 +277,7 @@ export default class {
281
277
  if (!this.noAudio) {
282
278
  this.masterGain.gain.value = this._muteVolume;
283
279
  }
284
- this.onUnMute.dispatch();
280
+ this.onChange.dispatch('unmuted');
285
281
  }
286
282
 
287
283
  destroy() {
@@ -292,7 +288,7 @@ export default class {
292
288
  }
293
289
  }
294
290
  this._sounds = [];
295
- this.onSoundDecode.dispose();
291
+ this.onChange.dispose();
296
292
  if (this.context) {
297
293
  if (window.PhaserRegistry) {
298
294
  window.PhaserRegistry.audioContext = this.context;
@@ -337,7 +333,6 @@ export default class {
337
333
  if (!this.noAudio) {
338
334
  this.masterGain.gain.value = value;
339
335
  }
340
- this.onVolumeChange.dispatch(value);
341
336
  }
342
337
  }
343
338