@vpmedia/phaser 1.63.0 → 1.64.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.64.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.64.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,82 @@ 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
+ if (!this.isLocked && (this.context.state === 'suspended' || this.context.state === 'interrupted')) {
113
+ this.addUnlockHandlers();
114
+ } else if (this.isLocked && this.context.state === 'running') {
115
+ this.removeUnlockHandlers();
116
+ }
117
+ };
118
+
119
+ /**
120
+ * TBD.
121
+ */
122
+ addUnlockHandlers = () => {
110
123
  this.isLocked = true;
111
- this.dispatchOnChangeEvent('addUnlockHandlers', {
124
+ this.game.logger.info('addUnlockHandlers', {
112
125
  state: this.context.state,
113
126
  isLocked: this.isLocked,
114
127
  });
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
- }
128
+ document.body.addEventListener('touchend', this.onUnlockEvent, false);
129
+ document.body.addEventListener('click', this.onUnlockEvent, false);
130
+ document.body.addEventListener('keydown', this.onUnlockEvent, false);
131
+ };
119
132
 
120
133
  /**
121
134
  * TBD.
122
135
  */
123
- removeUnlockHandlers() {
136
+ removeUnlockHandlers = () => {
124
137
  this.isLocked = false;
125
- this.dispatchOnChangeEvent('removeUnlockHandlers', {
138
+ this.game.logger.info('removeUnlockHandlers', {
126
139
  state: this.context.state,
127
140
  isLocked: this.isLocked,
128
141
  });
129
- document.body.removeEventListener('touchend', this.onUnlockEventBinded);
130
- document.body.removeEventListener('click', this.onUnlockEventBinded);
131
- document.body.removeEventListener('keydown', this.onUnlockEventBinded);
132
- }
142
+ document.body.removeEventListener('touchend', this.onUnlockEvent, false);
143
+ document.body.removeEventListener('click', this.onUnlockEvent, false);
144
+ document.body.removeEventListener('keydown', this.onUnlockEvent, false);
145
+ };
133
146
 
134
147
  /**
135
148
  * TBD.
136
149
  * @param {Event} event - TBD.
137
150
  */
138
- onUnlockEvent(event) {
151
+ onUnlockEvent = (event) => {
139
152
  const initialState = this.context.state;
140
153
  if (initialState !== 'suspended' && initialState !== 'interrupted') {
141
- this.dispatchOnChangeEvent('onUnlockResumeDenied', {
154
+ this.game.logger.info('onUnlockResumeDenied', {
142
155
  state: initialState,
143
156
  isLocked: this.isLocked,
144
157
  event,
@@ -146,7 +159,7 @@ export class SoundManager {
146
159
  this.removeUnlockHandlers();
147
160
  return;
148
161
  }
149
- this.dispatchOnChangeEvent('onContextResumeStart', {
162
+ this.game.logger.info('onContextResumeStart', {
150
163
  state: initialState,
151
164
  isLocked: this.isLocked,
152
165
  event,
@@ -154,7 +167,7 @@ export class SoundManager {
154
167
  this.context
155
168
  .resume()
156
169
  .then(() => {
157
- this.dispatchOnChangeEvent('onContextResumeResult', {
170
+ this.game.logger.info('onContextResumeResult', {
158
171
  initialState,
159
172
  state: this.context.state,
160
173
  isLocked: this.isLocked,
@@ -162,7 +175,7 @@ export class SoundManager {
162
175
  this.removeUnlockHandlers();
163
176
  })
164
177
  .catch((error) => {
165
- this.dispatchOnChangeEvent('onContextResumeReject', {
178
+ this.game.logger.info('onContextResumeReject', {
166
179
  initialState,
167
180
  state: this.context.state,
168
181
  isLocked: this.isLocked,
@@ -171,7 +184,7 @@ export class SoundManager {
171
184
  this.removeUnlockHandlers();
172
185
  this.game.exceptionHandler(error, { 'audio.initialState': initialState, 'audio.state': this.context.state });
173
186
  });
174
- }
187
+ };
175
188
 
176
189
  /**
177
190
  * TBD.
@@ -258,6 +271,7 @@ export class SoundManager {
258
271
  }
259
272
  // All decoded already?
260
273
  if (this._watchList.total === 0) {
274
+ this.game.logger.info('All sounds decoded');
261
275
  this._watching = false;
262
276
  callback.call(callbackContext);
263
277
  } else {
@@ -286,6 +300,7 @@ export class SoundManager {
286
300
  key = this._watchList.next;
287
301
  }
288
302
  if (this._watchList.total === 0) {
303
+ this.game.logger.info('All sounds decoded');
289
304
  this._watching = false;
290
305
  this._watchCallback.call(this._watchContext);
291
306
  }
@@ -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,gCAME;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;uBAresB,aAAa;yBADX,gBAAgB;sBAEnB,YAAY;4BACN,mBAAmB"}