@vpmedia/phaser 1.0.20 → 1.0.22

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.20",
3
+ "version": "1.0.22",
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",
@@ -73,46 +73,45 @@ export default class {
73
73
  this.masterGain.connect(this.context.destination);
74
74
  // handle audio state unlock
75
75
  this.onUnlockEventBinded = this.onUnlockEvent.bind(this);
76
- if (this.isUnlockNeeded()) {
76
+ if (this.context.state === 'suspended' || this.context.state === 'interrupted') {
77
77
  this.addUnlockHandlers();
78
78
  }
79
79
  this.context.addEventListener('statechange', () => {
80
80
  this.onLockChange.dispatch('onContextStateChange', { state: this.context.state, isLocked: this.isLocked });
81
- if (this.isUnlockNeeded()) {
81
+ if (!this.isLocked && (this.context.state === 'suspended' || this.context.state === 'interrupted')) {
82
82
  this.addUnlockHandlers();
83
+ } else if (this.isLocked) {
84
+ this.removeUnlockHandlers();
83
85
  }
84
86
  });
85
87
  }
86
88
 
87
- isUnlockNeeded() {
88
- return !this.isLocked && !this.noAudio && (this.context.state === 'suspended' || this.context.state === 'interrupted');
89
- }
90
-
91
89
  addUnlockHandlers() {
90
+ this.isLocked = true;
92
91
  this.onLockChange.dispatch('addUnlockHandlers', { state: this.context.state, isLocked: this.isLocked });
93
92
  document.body.addEventListener('touchstart', this.onUnlockEventBinded, false);
94
93
  document.body.addEventListener('touchend', this.onUnlockEventBinded, false);
95
94
  document.body.addEventListener('click', this.onUnlockEventBinded, false);
96
95
  document.body.addEventListener('keydown', this.onUnlockEventBinded, false);
97
- this.isLocked = true;
98
96
  }
99
97
 
100
98
  removeUnlockHandlers() {
99
+ this.isLocked = false;
101
100
  this.onLockChange.dispatch('removeUnlockHandlers', { state: this.context.state, isLocked: this.isLocked });
102
101
  document.body.removeEventListener('touchstart', this.onUnlockEventBinded);
103
102
  document.body.removeEventListener('touchend', this.onUnlockEventBinded);
104
103
  document.body.removeEventListener('click', this.onUnlockEventBinded);
105
104
  document.body.removeEventListener('keydown', this.onUnlockEventBinded);
106
- this.isLocked = false;
107
105
  }
108
106
 
109
107
  onUnlockEvent(event) {
110
- this.onLockChange.dispatch('onUnlockEvent', { state: this.context.state, isLocked: this.isLocked, event });
111
- if (!this.isUnlockNeeded()) {
108
+ const initialState = this.context.state;
109
+ if (this.context.state !== 'suspended' && this.context.state !== 'interrupted') {
110
+ this.onLockChange.dispatch('onUnlockResumeDenied', { state: this.context.state, isLocked: this.isLocked, event });
112
111
  this.removeUnlockHandlers();
113
112
  return;
114
113
  }
115
- const initialState = this.context.state;
114
+ this.onLockChange.dispatch('onContextResumeStart', { state: this.context.state, isLocked: this.isLocked, event });
116
115
  this.context.resume().then(() => {
117
116
  this.onLockChange.dispatch('onContextResumeResult', { state: this.context.state, isLocked: this.isLocked });
118
117
  this.removeUnlockHandlers();