@vpmedia/phaser 1.0.18 → 1.0.20

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.18",
3
+ "version": "1.0.20",
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) {
@@ -5,17 +5,8 @@
5
5
  */
6
6
  import Point from '../geom/point';
7
7
  import Circle from '../geom/circle';
8
- import DeviceButton from './input_button';
9
8
  import { POINTER, POINTER_CURSOR, POINTER_CONTACT, MOUSE_OVERRIDES_TOUCH, TOUCH_OVERRIDES_MOUSE, MOUSE_TOUCH_COMBINE } from './const';
10
9
 
11
- const NO_BUTTON = 0;
12
- const LEFT_BUTTON = 1;
13
- const RIGHT_BUTTON = 2;
14
- const MIDDLE_BUTTON = 4;
15
- const BACK_BUTTON = 8;
16
- const FORWARD_BUTTON = 16;
17
- const ERASER_BUTTON = 32;
18
-
19
10
  export default class {
20
11
 
21
12
  constructor(game, id, pointerMode) {
@@ -28,12 +19,6 @@ export default class {
28
19
  this.pointerMode = pointerMode || (POINTER_CURSOR | POINTER_CONTACT);
29
20
  this.target = null;
30
21
  this.button = null;
31
- this.leftButton = new DeviceButton(this, LEFT_BUTTON);
32
- this.rightButton = new DeviceButton(this, RIGHT_BUTTON);
33
- this.middleButton = new DeviceButton(this, MIDDLE_BUTTON);
34
- this.backButton = new DeviceButton(this, BACK_BUTTON);
35
- this.forwardButton = new DeviceButton(this, FORWARD_BUTTON);
36
- this.eraserButton = new DeviceButton(this, ERASER_BUTTON);
37
22
  this._holdSent = false;
38
23
  this._history = [];
39
24
  this._nextDrop = 0;
@@ -74,9 +59,6 @@ export default class {
74
59
  resetButtons() {
75
60
  this.isDown = false;
76
61
  this.isUp = true;
77
- if (this.isMouse) {
78
- this.leftButton.reset();
79
- }
80
62
  }
81
63
 
82
64
  updateButtons(event) {
@@ -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);
@@ -13,6 +13,7 @@ export default class {
13
13
  this.game = game;
14
14
  this.onSoundDecode = new Signal();
15
15
  this.onVolumeChange = new Signal();
16
+ this.onLockChange = new Signal();
16
17
  this.onMute = new Signal();
17
18
  this.onUnMute = new Signal();
18
19
  this.context = null;
@@ -70,48 +71,58 @@ export default class {
70
71
  }
71
72
  this.masterGain.gain.value = 1;
72
73
  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);
74
+ // handle audio state unlock
75
+ this.onUnlockEventBinded = this.onUnlockEvent.bind(this);
76
+ if (this.isUnlockNeeded()) {
81
77
  this.addUnlockHandlers();
82
78
  }
79
+ this.context.addEventListener('statechange', () => {
80
+ this.onLockChange.dispatch('onContextStateChange', { state: this.context.state, isLocked: this.isLocked });
81
+ if (this.isUnlockNeeded()) {
82
+ this.addUnlockHandlers();
83
+ }
84
+ });
85
+ }
86
+
87
+ isUnlockNeeded() {
88
+ return !this.isLocked && !this.noAudio && (this.context.state === 'suspended' || this.context.state === 'interrupted');
83
89
  }
84
90
 
85
91
  addUnlockHandlers() {
92
+ this.onLockChange.dispatch('addUnlockHandlers', { state: this.context.state, isLocked: this.isLocked });
86
93
  document.body.addEventListener('touchstart', this.onUnlockEventBinded, false);
87
94
  document.body.addEventListener('touchend', this.onUnlockEventBinded, false);
88
95
  document.body.addEventListener('click', this.onUnlockEventBinded, false);
89
96
  document.body.addEventListener('keydown', this.onUnlockEventBinded, false);
97
+ this.isLocked = true;
90
98
  }
91
99
 
92
100
  removeUnlockHandlers() {
101
+ this.onLockChange.dispatch('removeUnlockHandlers', { state: this.context.state, isLocked: this.isLocked });
93
102
  document.body.removeEventListener('touchstart', this.onUnlockEventBinded);
94
103
  document.body.removeEventListener('touchend', this.onUnlockEventBinded);
95
104
  document.body.removeEventListener('click', this.onUnlockEventBinded);
96
105
  document.body.removeEventListener('keydown', this.onUnlockEventBinded);
106
+ this.isLocked = false;
97
107
  }
98
108
 
99
109
  onUnlockEvent(event) {
100
- if (this.context.state !== 'suspended') {
110
+ this.onLockChange.dispatch('onUnlockEvent', { state: this.context.state, isLocked: this.isLocked, event });
111
+ if (!this.isUnlockNeeded()) {
112
+ this.removeUnlockHandlers();
101
113
  return;
102
114
  }
103
- console.log('onUnlockEvent', event);
115
+ const initialState = this.context.state;
104
116
  this.context.resume().then(() => {
117
+ this.onLockChange.dispatch('onContextResumeResult', { state: this.context.state, isLocked: this.isLocked });
105
118
  this.removeUnlockHandlers();
106
119
  }).catch((e) => {
120
+ this.onLockChange.dispatch('onContextResumeReject', { state: this.context.state, isLocked: this.isLocked, error: e });
107
121
  this.removeUnlockHandlers();
108
- this.game.exceptionHandler(e, { state: this.context.state });
122
+ this.game.exceptionHandler(e, { initialState, state: this.context.state });
109
123
  });
110
124
  }
111
125
 
112
- checkContextState() {
113
- }
114
-
115
126
  stopAll() {
116
127
  if (this.noAudio) {
117
128
  return;