@vpmedia/phaser 1.63.0 → 1.65.0

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @vpmedia/phaser
2
2
 
3
- [![npm version](https://badge.fury.io/js/@vpmedia%2Fphaser.svg?v=1.63.0)](https://badge.fury.io/js/@vpmedia%2Fphaser)
3
+ [![npm version](https://badge.fury.io/js/@vpmedia%2Fphaser.svg?v=1.65.0)](https://badge.fury.io/js/@vpmedia%2Fphaser)
4
4
  [![Node.js CI](https://github.com/vpmedia/phaser/actions/workflows/ci.yml/badge.svg)](https://github.com/vpmedia/phaser/actions/workflows/ci.yml)
5
5
 
6
6
  @vpmedia/phaser is the modern ECMAScript port of the popular Phaser game engine v2.6.2.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vpmedia/phaser",
3
- "version": "1.63.0",
3
+ "version": "1.65.0",
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",
@@ -29,16 +29,6 @@ export class SoundManager {
29
29
  this._watchContext = null;
30
30
  }
31
31
 
32
- /**
33
- * TBD.
34
- * @param {string} eventName - TBD.
35
- * @param {object} eventData - TBD.
36
- */
37
- dispatchOnChangeEvent(eventName, eventData) {
38
- this.game.logger.debug(eventName, eventData);
39
- this.onChange.dispatch(eventName, eventData);
40
- }
41
-
42
32
  /**
43
33
  * TBD.
44
34
  */
@@ -86,59 +76,86 @@ export class SoundManager {
86
76
  this.masterGain.connect(this.context.destination);
87
77
  // handle audio state unlock
88
78
  // possible states: interrupted, suspended, running, closed
89
- this.onUnlockEventBinded = this.onUnlockEvent.bind(this);
90
79
  if (this.context.state === 'suspended' || this.context.state === 'interrupted') {
91
80
  this.addUnlockHandlers();
92
81
  }
93
- this.context.addEventListener('statechange', () => {
94
- this.dispatchOnChangeEvent('onContextStateChange', {
95
- state: this.context.state,
96
- isLocked: this.isLocked,
97
- });
98
- if (!this.isLocked && (this.context.state === 'suspended' || this.context.state === 'interrupted')) {
99
- this.addUnlockHandlers();
100
- } else if (this.isLocked && this.context.state === 'running') {
101
- this.removeUnlockHandlers();
102
- }
103
- });
82
+ this.context.addEventListener('statechange', this.onContextStateChange, false);
83
+ for (const eventType of ['pageshow', 'visibilitychange', 'resume']) {
84
+ window.addEventListener(eventType, this.onPageLifecycleChange, true);
85
+ }
104
86
  }
105
87
 
106
88
  /**
107
89
  * TBD.
108
90
  */
109
- addUnlockHandlers() {
91
+ onPageLifecycleChange = () => {
92
+ if (!document.hidden) {
93
+ this.checkUnlockHandlers();
94
+ }
95
+ };
96
+
97
+ /**
98
+ * TBD.
99
+ */
100
+ onContextStateChange = () => {
101
+ this.game.logger.info('onContextStateChange', {
102
+ state: this.context.state,
103
+ isLocked: this.isLocked,
104
+ });
105
+ this.checkUnlockHandlers();
106
+ };
107
+
108
+ /**
109
+ * TBD.
110
+ */
111
+ checkUnlockHandlers = () => {
112
+ this.game.logger.info('checkUnlockHandlers', {
113
+ state: this.context.state,
114
+ isLocked: this.isLocked,
115
+ });
116
+ if (!this.isLocked && (this.context.state === 'suspended' || this.context.state === 'interrupted')) {
117
+ this.addUnlockHandlers();
118
+ } else if (this.isLocked && this.context.state === 'running') {
119
+ this.removeUnlockHandlers();
120
+ }
121
+ };
122
+
123
+ /**
124
+ * TBD.
125
+ */
126
+ addUnlockHandlers = () => {
110
127
  this.isLocked = true;
111
- this.dispatchOnChangeEvent('addUnlockHandlers', {
128
+ this.game.logger.info('addUnlockHandlers', {
112
129
  state: this.context.state,
113
130
  isLocked: this.isLocked,
114
131
  });
115
- document.body.addEventListener('touchend', this.onUnlockEventBinded, false);
116
- document.body.addEventListener('click', this.onUnlockEventBinded, false);
117
- document.body.addEventListener('keydown', this.onUnlockEventBinded, false);
118
- }
132
+ document.body.addEventListener('touchend', this.onUnlockEvent, false);
133
+ document.body.addEventListener('click', this.onUnlockEvent, false);
134
+ document.body.addEventListener('keydown', this.onUnlockEvent, false);
135
+ };
119
136
 
120
137
  /**
121
138
  * TBD.
122
139
  */
123
- removeUnlockHandlers() {
140
+ removeUnlockHandlers = () => {
124
141
  this.isLocked = false;
125
- this.dispatchOnChangeEvent('removeUnlockHandlers', {
142
+ this.game.logger.info('removeUnlockHandlers', {
126
143
  state: this.context.state,
127
144
  isLocked: this.isLocked,
128
145
  });
129
- document.body.removeEventListener('touchend', this.onUnlockEventBinded);
130
- document.body.removeEventListener('click', this.onUnlockEventBinded);
131
- document.body.removeEventListener('keydown', this.onUnlockEventBinded);
132
- }
146
+ document.body.removeEventListener('touchend', this.onUnlockEvent, false);
147
+ document.body.removeEventListener('click', this.onUnlockEvent, false);
148
+ document.body.removeEventListener('keydown', this.onUnlockEvent, false);
149
+ };
133
150
 
134
151
  /**
135
152
  * TBD.
136
153
  * @param {Event} event - TBD.
137
154
  */
138
- onUnlockEvent(event) {
155
+ onUnlockEvent = (event) => {
139
156
  const initialState = this.context.state;
140
157
  if (initialState !== 'suspended' && initialState !== 'interrupted') {
141
- this.dispatchOnChangeEvent('onUnlockResumeDenied', {
158
+ this.game.logger.info('onUnlockResumeDenied', {
142
159
  state: initialState,
143
160
  isLocked: this.isLocked,
144
161
  event,
@@ -146,7 +163,7 @@ export class SoundManager {
146
163
  this.removeUnlockHandlers();
147
164
  return;
148
165
  }
149
- this.dispatchOnChangeEvent('onContextResumeStart', {
166
+ this.game.logger.info('onContextResumeStart', {
150
167
  state: initialState,
151
168
  isLocked: this.isLocked,
152
169
  event,
@@ -154,7 +171,7 @@ export class SoundManager {
154
171
  this.context
155
172
  .resume()
156
173
  .then(() => {
157
- this.dispatchOnChangeEvent('onContextResumeResult', {
174
+ this.game.logger.info('onContextResumeResult', {
158
175
  initialState,
159
176
  state: this.context.state,
160
177
  isLocked: this.isLocked,
@@ -162,7 +179,7 @@ export class SoundManager {
162
179
  this.removeUnlockHandlers();
163
180
  })
164
181
  .catch((error) => {
165
- this.dispatchOnChangeEvent('onContextResumeReject', {
182
+ this.game.logger.info('onContextResumeReject', {
166
183
  initialState,
167
184
  state: this.context.state,
168
185
  isLocked: this.isLocked,
@@ -171,7 +188,7 @@ export class SoundManager {
171
188
  this.removeUnlockHandlers();
172
189
  this.game.exceptionHandler(error, { 'audio.initialState': initialState, 'audio.state': this.context.state });
173
190
  });
174
- }
191
+ };
175
192
 
176
193
  /**
177
194
  * TBD.
@@ -258,6 +275,7 @@ export class SoundManager {
258
275
  }
259
276
  // All decoded already?
260
277
  if (this._watchList.total === 0) {
278
+ this.game.logger.info('All sounds decoded');
261
279
  this._watching = false;
262
280
  callback.call(callbackContext);
263
281
  } else {
@@ -286,6 +304,7 @@ export class SoundManager {
286
304
  key = this._watchList.next;
287
305
  }
288
306
  if (this._watchList.total === 0) {
307
+ this.game.logger.info('All sounds decoded');
289
308
  this._watching = false;
290
309
  this._watchCallback.call(this._watchContext);
291
310
  }
@@ -24,29 +24,34 @@ export class SoundManager {
24
24
  _watchContext: any;
25
25
  /**
26
26
  * TBD.
27
- * @param {string} eventName - TBD.
28
- * @param {object} eventData - TBD.
29
27
  */
30
- dispatchOnChangeEvent(eventName: string, eventData: object): void;
28
+ boot(): void;
29
+ masterGain: any;
31
30
  /**
32
31
  * TBD.
33
32
  */
34
- boot(): void;
35
- masterGain: any;
36
- onUnlockEventBinded: (event: Event) => void;
33
+ onPageLifecycleChange: () => void;
34
+ /**
35
+ * TBD.
36
+ */
37
+ onContextStateChange: () => void;
38
+ /**
39
+ * TBD.
40
+ */
41
+ checkUnlockHandlers: () => void;
37
42
  /**
38
43
  * TBD.
39
44
  */
40
- addUnlockHandlers(): void;
45
+ addUnlockHandlers: () => void;
41
46
  /**
42
47
  * TBD.
43
48
  */
44
- removeUnlockHandlers(): void;
49
+ removeUnlockHandlers: () => void;
45
50
  /**
46
51
  * TBD.
47
52
  * @param {Event} event - TBD.
48
53
  */
49
- onUnlockEvent(event: Event): void;
54
+ onUnlockEvent: (event: Event) => void;
50
55
  /**
51
56
  * TBD.
52
57
  */
@@ -1 +1 @@
1
- {"version":3,"file":"sound_manager.d.ts","sourceRoot":"","sources":["../../../src/phaser/core/sound_manager.js"],"names":[],"mappings":"AAKA;IACE;;;OAGG;IACH,kBAFW,OAAO,WAAW,EAAE,IAAI,EAqBlC;IAlBC,+BAAgB;IAChB,iBAA4B;IAC5B,2BAA2B;IAC3B,SADW,YAAY,CACJ;IACnB,oBAAoB;IACpB,iBAAoB;IACpB,yBAA2B;IAC3B,kBAAqB;IACrB,qBAAuB;IACvB,oBAAuB;IACvB,gBAAmB;IACnB,mBAAyB;IACzB,gBAAgB;IAChB,eAAiB;IACjB,qBAAgC;IAChC,mBAAsB;IACtB,yBAA0B;IAC1B,mBAAyB;IAG3B;;;;OAIG;IACH,iCAHW,MAAM,aACN,MAAM,QAKhB;IAED;;OAEG;IACH,aA2DC;IAvBG,gBAA+C;IAQjD,6BA+CS,KAAK,UA/C0C;IAiB1D;;OAEG;IACH,0BASC;IAED;;OAEG;IACH,6BASC;IAED;;;OAGG;IACH,qBAFW,KAAK,QAsCf;IAED;;OAEG;IACH,gBASC;IAED;;OAEG;IACH,iBASC;IAED;;OAEG;IACH,kBASC;IAED;;;OAGG;IACH,YAFW,MAAM,QAiBhB;IAED;;;;;OAKG;IACH,0BAJW,KAAK,EAAE,GAAC,MAAM,EAAE,uCAEhB,MAAM,QAyBhB;IAED;;OAEG;IACH,eAoBC;IAED;;;;;;;OAOG;IACH,SANW,MAAM,WACN,MAAM,SACN,OAAO,YACP,OAAO,GACL,KAAK,CAMjB;IAED;;;;OAIG;IACH,eAHW,MAAM,GACJ,WAAW,CAIvB;IAED;;;;OAIG;IACH,cAHW,KAAK,GACH,OAAO,CAanB;IAED;;;;OAIG;IACH,iBAHW,MAAM,GACJ,MAAM,CAclB;IAED;;;;;;OAMG;IACH,UALW,MAAM,WACN,MAAM,SACN,OAAO,GACL,KAAK,CASjB;IAED;;OAEG;IACH,gBAUC;IAJG,iBAA6C;IAMjD;;OAEG;IACH,kBASC;IAED;;OAEG;IACH,gBAgBC;IAUD;;OAEG;IACH,yBAcC;IAzBD;;;OAGG;IACH,oBAEC;IA6BD;;OAEG;IACH,0BAYC;IAvBD;;;OAGG;IACH,qBAEC;CAkBF;uBAtdsB,aAAa;yBADX,gBAAgB;sBAEnB,YAAY;4BACN,mBAAmB"}
1
+ {"version":3,"file":"sound_manager.d.ts","sourceRoot":"","sources":["../../../src/phaser/core/sound_manager.js"],"names":[],"mappings":"AAKA;IACE;;;OAGG;IACH,kBAFW,OAAO,WAAW,EAAE,IAAI,EAqBlC;IAlBC,+BAAgB;IAChB,iBAA4B;IAC5B,2BAA2B;IAC3B,SADW,YAAY,CACJ;IACnB,oBAAoB;IACpB,iBAAoB;IACpB,yBAA2B;IAC3B,kBAAqB;IACrB,qBAAuB;IACvB,oBAAuB;IACvB,gBAAmB;IACnB,mBAAyB;IACzB,gBAAgB;IAChB,eAAiB;IACjB,qBAAgC;IAChC,mBAAsB;IACtB,yBAA0B;IAC1B,mBAAyB;IAG3B;;OAEG;IACH,aAmDC;IAfG,gBAA+C;IAiBnD;;OAEG;IACH,kCAIE;IAEF;;OAEG;IACH,iCAME;IAEF;;OAEG;IACH,gCAUE;IAEF;;OAEG;IACH,8BASE;IAEF;;OAEG;IACH,iCASE;IAEF;;;OAGG;IACH,uBAFW,KAAK,UAsCd;IAEF;;OAEG;IACH,gBASC;IAED;;OAEG;IACH,iBASC;IAED;;OAEG;IACH,kBASC;IAED;;;OAGG;IACH,YAFW,MAAM,QAiBhB;IAED;;;;;OAKG;IACH,0BAJW,KAAK,EAAE,GAAC,MAAM,EAAE,uCAEhB,MAAM,QA0BhB;IAED;;OAEG;IACH,eAqBC;IAED;;;;;;;OAOG;IACH,SANW,MAAM,WACN,MAAM,SACN,OAAO,YACP,OAAO,GACL,KAAK,CAMjB;IAED;;;;OAIG;IACH,eAHW,MAAM,GACJ,WAAW,CAIvB;IAED;;;;OAIG;IACH,cAHW,KAAK,GACH,OAAO,CAanB;IAED;;;;OAIG;IACH,iBAHW,MAAM,GACJ,MAAM,CAclB;IAED;;;;;;OAMG;IACH,UALW,MAAM,WACN,MAAM,SACN,OAAO,GACL,KAAK,CASjB;IAED;;OAEG;IACH,gBAUC;IAJG,iBAA6C;IAMjD;;OAEG;IACH,kBASC;IAED;;OAEG;IACH,gBAgBC;IAUD;;OAEG;IACH,yBAcC;IAzBD;;;OAGG;IACH,oBAEC;IA6BD;;OAEG;IACH,0BAYC;IAvBD;;;OAGG;IACH,qBAEC;CAkBF;uBAzesB,aAAa;yBADX,gBAAgB;sBAEnB,YAAY;4BACN,mBAAmB"}