@makefully/platypus 4.1.14 → 4.1.16

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": "@makefully/platypus",
3
- "version": "4.1.14",
3
+ "version": "4.1.16",
4
4
  "description": "2D tile-based HTML5 game engine with a component-based entity model",
5
5
  "license": "MIT",
6
6
  "contributors": [
@@ -1,7 +1,7 @@
1
1
  /* global platypus */
2
2
  import {arrayCache, greenSplice} from '../utils/array.js';
3
3
  import Data from '../Data.js';
4
- import {Sound} from '@pixi/sound';
4
+ import {Sound, filters} from '@pixi/sound';
5
5
  import StateMap from '../StateMap.js';
6
6
  import createComponentClass from '../factory.js';
7
7
 
@@ -65,20 +65,20 @@ const
65
65
  if (soundInstance.panFilter) {
66
66
  soundInstance.panFilter.pan = data.pan;
67
67
  } else {
68
- soundInstance.panFilter = new Sound.filters.StereoFilter(data.pan);
68
+ soundInstance.panFilter = new filters.StereoFilter(data.pan);
69
69
  }
70
70
  }
71
71
  if (soundInstance.panFilter || this.autoPanFilter) {
72
72
  const
73
- filters = [];
73
+ appliedFilters = [];
74
74
 
75
75
  if (soundInstance.panFilter) {
76
- filters.push(soundInstance.panFilter);
76
+ appliedFilters.push(soundInstance.panFilter);
77
77
  }
78
78
  if (this.autoPanFilter) {
79
- filters.push(this.autoPanFilter);
79
+ appliedFilters.push(this.autoPanFilter);
80
80
  }
81
- soundInstance.filters = filters;
81
+ soundInstance.filters = appliedFilters;
82
82
  }
83
83
  data.audio = this.player.play(soundInstance, data);
84
84
  //if (data.volume) {
@@ -310,7 +310,7 @@ export default createComponentClass(/** @lends platypus.components.AudioSFX.prot
310
310
 
311
311
  this.volume = autoPan.maximum;
312
312
 
313
- this.autoPanFilter = new Sound.filters.StereoFilter(lastPan);
313
+ this.autoPanFilter = new filters.StereoFilter(lastPan);
314
314
 
315
315
  this.addEventListener("camera-update", function (camera) {
316
316
  const
@@ -187,6 +187,10 @@ const
187
187
  },
188
188
 
189
189
  addChildEventListeners (entity) {
190
+ if (this._destroyed) {
191
+ return;
192
+ }
193
+
190
194
  const
191
195
  {_listeners} = entity;
192
196
 
@@ -219,33 +223,55 @@ const
219
223
  },
220
224
 
221
225
  removeChildEventListeners: function (entity) {
222
- if (entity.containerListener?.events) {
226
+ const
227
+ listener = entity.containerListener;
228
+
229
+ if (!listener) {
230
+ return;
231
+ }
232
+
233
+ const
234
+ {events} = listener,
235
+ // Prefer current shape; fall back to legacy `messages`.
236
+ handlers = listener.handlers ?? listener.messages;
237
+
238
+ if (events && handlers) {
223
239
  const
224
- {events, handlers} = entity.containerListener,
225
240
  {length} = events;
226
241
 
227
242
  for (let i = 0; i < length; i++) {
228
- this.off(
229
- events[i],
230
- handlers[i].callback,
231
- handlers[i].context
232
- );
243
+ const
244
+ handler = handlers[i];
245
+
246
+ if (!handler) {
247
+ continue;
248
+ }
249
+
250
+ if (handler.callback) {
251
+ this.off(events[i], handler.callback, handler.context);
252
+ } else {
253
+ this.off(events[i], handler);
254
+ }
233
255
  }
256
+ }
234
257
 
258
+ if (events) {
235
259
  arrayCache.recycle(events);
236
- arrayCache.recycle(handlers);
237
-
238
- entity.containerListener.recycle();
239
- entity.containerListener = null;
240
260
  }
261
+ if (listener.handlers) {
262
+ arrayCache.recycle(listener.handlers);
263
+ }
264
+ if (listener.messages) {
265
+ arrayCache.recycle(listener.messages);
266
+ }
267
+
268
+ listener.recycle();
269
+ entity.containerListener = null;
241
270
  },
242
271
 
243
272
  addChildEventListener: function (entity, event, handler) {
244
- if (!entity.containerListener) {
245
- entity.containerListener = Data.setUp(
246
- "events", arrayCache.setUp(),
247
- "handlers", arrayCache.setUp()
248
- );
273
+ if (this._destroyed) {
274
+ return;
249
275
  }
250
276
 
251
277
  const
@@ -258,6 +284,13 @@ const
258
284
  );
259
285
 
260
286
  if (newHandler) {
287
+ if (!entity.containerListener) {
288
+ entity.containerListener = Data.setUp(
289
+ "events", arrayCache.setUp(),
290
+ "handlers", arrayCache.setUp()
291
+ );
292
+ }
293
+
261
294
  entity.containerListener.events.push(event);
262
295
  entity.containerListener.handlers.push(newHandler);
263
296
  }
@@ -265,7 +298,19 @@ const
265
298
 
266
299
  removeChildEventListener: function (entity, event, callback) {
267
300
  const
268
- {events, handlers} = entity.containerListener;
301
+ listener = entity.containerListener;
302
+
303
+ if (!listener) {
304
+ return;
305
+ }
306
+
307
+ const
308
+ {events, handlers} = listener;
309
+
310
+ if (!events || !handlers) {
311
+ return;
312
+ }
313
+
269
314
  let i = events.length;
270
315
 
271
316
  while (i--) {