@vpmedia/phaser 1.0.17 → 1.0.19

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.17",
3
+ "version": "1.0.19",
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",
@@ -137,33 +137,6 @@ export default class {
137
137
  }
138
138
  }
139
139
 
140
- addTouchLockCallback(callback, context, onEnd = false) {
141
- this.lockCallbacks.push({ callback, context, onEnd });
142
- }
143
-
144
- removeTouchLockCallback(callback, context) {
145
- let i = this.lockCallbacks.length;
146
- while (i) {
147
- i -= 1;
148
- if (this.lockCallbacks[i].callback === callback && this.lockCallbacks[i].context === context) {
149
- this.lockCallbacks.splice(i, 1);
150
- return true;
151
- }
152
- }
153
- return false;
154
- }
155
-
156
- executeTouchLockCallbacks(onEnd, event) {
157
- let i = this.lockCallbacks.length;
158
- while (i) {
159
- i -= 1;
160
- const cb = this.lockCallbacks[i];
161
- if (cb.onEnd === onEnd && cb.callback.call(cb.context, this, event)) {
162
- this.lockCallbacks.splice(i, 1);
163
- }
164
- }
165
- }
166
-
167
140
  addPointer() {
168
141
  if (this.pointers.length >= MAX_POINTERS) {
169
142
  console.warn('Input.addPointer: Maximum limit of ' + MAX_POINTERS + ' pointers reached.');
@@ -77,7 +77,6 @@ export default class {
77
77
  }
78
78
 
79
79
  onPointerDown(event) {
80
- this.game.input.executeTouchLockCallbacks(false, event);
81
80
  this.event = event;
82
81
  this.eventPreventDefault(event);
83
82
  if (this.pointerDownCallback) {
@@ -112,7 +111,6 @@ export default class {
112
111
  }
113
112
 
114
113
  onPointerUp(event) {
115
- this.game.input.executeTouchLockCallbacks(true, event);
116
114
  this.event = event;
117
115
  this.eventPreventDefault(event);
118
116
  if (this.pointerUpCallback) {
@@ -66,7 +66,6 @@ export default class {
66
66
  }
67
67
 
68
68
  onTouchStart(event) {
69
- this.game.input.executeTouchLockCallbacks(false, event);
70
69
  this.event = event;
71
70
  if (!this.game.input.enabled || !this.enabled) {
72
71
  return;
@@ -130,7 +129,6 @@ export default class {
130
129
  }
131
130
 
132
131
  onTouchEnd(event) {
133
- this.game.input.executeTouchLockCallbacks(true, event);
134
132
  this.event = event;
135
133
  if (this.touchEndCallback) {
136
134
  this.touchEndCallback.call(this.callbackContext, event);
@@ -70,15 +70,20 @@ export default class {
70
70
  }
71
71
  this.masterGain.gain.value = 1;
72
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);
73
+ // handle audio state unlock
74
+ this.onUnlockEventBinded = this.onUnlockEvent.bind(this);
75
+ if (this.isUnlockNeeded()) {
80
76
  this.addUnlockHandlers();
81
77
  }
78
+ this.context.addEventListener('statechange', () => {
79
+ if (this.isUnlockNeeded()) {
80
+ this.addUnlockHandlers();
81
+ }
82
+ });
83
+ }
84
+
85
+ isUnlockNeeded() {
86
+ return !this.isLocked && !this.noAudio && (this.context.state === 'suspended' || this.context.state === 'interrupted');
82
87
  }
83
88
 
84
89
  addUnlockHandlers() {
@@ -86,6 +91,7 @@ export default class {
86
91
  document.body.addEventListener('touchend', this.onUnlockEventBinded, false);
87
92
  document.body.addEventListener('click', this.onUnlockEventBinded, false);
88
93
  document.body.addEventListener('keydown', this.onUnlockEventBinded, false);
94
+ this.isLocked = true;
89
95
  }
90
96
 
91
97
  removeUnlockHandlers() {
@@ -93,24 +99,23 @@ export default class {
93
99
  document.body.removeEventListener('touchend', this.onUnlockEventBinded);
94
100
  document.body.removeEventListener('click', this.onUnlockEventBinded);
95
101
  document.body.removeEventListener('keydown', this.onUnlockEventBinded);
102
+ this.isLocked = false;
96
103
  }
97
104
 
98
- onUnlockEvent(event) {
99
- if (this.context.state !== 'suspended') {
105
+ onUnlockEvent() {
106
+ if (!this.isUnlockNeeded()) {
107
+ this.removeUnlockHandlers();
100
108
  return;
101
109
  }
102
- console.log('onUnlockEvent', event);
110
+ const initialState = this.context.state;
103
111
  this.context.resume().then(() => {
104
112
  this.removeUnlockHandlers();
105
113
  }).catch((e) => {
106
114
  this.removeUnlockHandlers();
107
- this.game.exceptionHandler(e, { state: this.context.state });
115
+ this.game.exceptionHandler(e, { initialState, state: this.context.state });
108
116
  });
109
117
  }
110
118
 
111
- checkContextState() {
112
- }
113
-
114
119
  stopAll() {
115
120
  if (this.noAudio) {
116
121
  return;