@makefully/platypus 4.1.16 → 4.1.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": "@makefully/platypus",
3
- "version": "4.1.16",
3
+ "version": "4.1.19",
4
4
  "description": "2D tile-based HTML5 game engine with a component-based entity model",
5
5
  "license": "MIT",
6
6
  "contributors": [
@@ -82,7 +82,7 @@
82
82
  },
83
83
  "optionalDependencies": {
84
84
  "box2d3-wasm": "^4.2.0",
85
- "jsmediatags": "github:probityrules/jsmediatags",
85
+ "@probityrules/jsmediatags": "^4.0.4",
86
86
  "poly-decomp": "^0.3.0"
87
87
  },
88
88
  "engines": {
@@ -24,6 +24,26 @@ const
24
24
  speed: 1,
25
25
  playthrough: false
26
26
  },
27
+ createPanFilter = (pan = 0) => new filters.StereoFilter(pan),
28
+ setClipPan = (clip, pan) => {
29
+ if (!clip) {
30
+ return;
31
+ }
32
+
33
+ if (clip.panFilter) {
34
+ clip.panFilter.pan = pan;
35
+ return;
36
+ }
37
+
38
+ clip.panFilter = createPanFilter(pan);
39
+ clip.filters = [clip.panFilter];
40
+ },
41
+ releaseClipPan = (clip) => {
42
+ if (clip?.panFilter) {
43
+ clip.panFilter.destroy();
44
+ clip.panFilter = null;
45
+ }
46
+ },
27
47
  playSound = function (soundDefinition) {
28
48
  let sound = '',
29
49
  attributes = null;
@@ -61,26 +81,16 @@ const
61
81
  data.loop = data.loop > 1 || data.loop < 0;
62
82
  }
63
83
 
64
- if (data.pan) {
65
- if (soundInstance.panFilter) {
66
- soundInstance.panFilter.pan = data.pan;
67
- } else {
68
- soundInstance.panFilter = new filters.StereoFilter(data.pan);
69
- }
70
- }
71
- if (soundInstance.panFilter || this.autoPanFilter) {
72
- const
73
- appliedFilters = [];
74
-
75
- if (soundInstance.panFilter) {
76
- appliedFilters.push(soundInstance.panFilter);
77
- }
78
- if (this.autoPanFilter) {
79
- appliedFilters.push(this.autoPanFilter);
80
- }
81
- soundInstance.filters = appliedFilters;
84
+ const
85
+ pan = data.pan || (this.autoPan ? this.autoPanValue : 0);
86
+
87
+ if (this.autoPan || data.pan) {
88
+ data.filters = [createPanFilter(pan)];
82
89
  }
83
90
  data.audio = this.player.play(soundInstance, data);
91
+ if (data.filters) {
92
+ data.audio.panFilter = data.filters[0];
93
+ }
84
94
  //if (data.volume) {
85
95
  // data.audio.volume = data.volume;
86
96
  //}
@@ -273,6 +283,7 @@ export default createComponentClass(/** @lends platypus.components.AudioSFX.prot
273
283
  this.player = platypus.game.sfxPlayer;
274
284
 
275
285
  this.volume = 1;
286
+ this.autoPanValue = 0;
276
287
 
277
288
  if (audioMap) {
278
289
  const
@@ -287,13 +298,15 @@ export default createComponentClass(/** @lends platypus.components.AudioSFX.prot
287
298
  const
288
299
  key = keys[i],
289
300
  sound = audioMap[key],
301
+ // Must match the resolved id stored on clips in playSound / stopAudio.
302
+ soundId = platypus.assetCache.getFileId(sound.sound ?? sound),
290
303
  playClip = playSound(sound);
291
304
 
292
305
  if (this.eventBased) {
293
306
  this.addEventListener(key, playClip);
294
307
  }
295
308
  if (this.stateBased) {
296
- this.addStateCheck(key, sound.sound ?? sound, playClip);
309
+ this.addStateCheck(key, soundId, playClip);
297
310
  }
298
311
  }
299
312
  }
@@ -306,17 +319,13 @@ export default createComponentClass(/** @lends platypus.components.AudioSFX.prot
306
319
  "range": this.autoPan.range || -1,
307
320
  "buffer": this.autoPan.buffer || 0
308
321
  };
309
- let lastPan = 0;
310
-
311
322
  this.volume = autoPan.maximum;
312
-
313
- this.autoPanFilter = new filters.StereoFilter(lastPan);
314
323
 
315
324
  this.addEventListener("camera-update", function (camera) {
316
325
  const
317
326
  delta = this.owner.x - camera.viewport.x,
318
327
  distance = Math.abs(delta),
319
- direction = delta / distance,
328
+ direction = distance ? delta / distance : 0,
320
329
  range = autoPan.range === -1 ? camera.viewport.width : autoPan.range;
321
330
  let pan = 0,
322
331
  volume = 1;
@@ -332,9 +341,11 @@ export default createComponentClass(/** @lends platypus.components.AudioSFX.prot
332
341
  volume = autoPan.maximum;
333
342
  }
334
343
 
335
- if (pan !== lastPan) {
336
- this.autoPanFilter.pan = pan;
337
- lastPan = pan;
344
+ if (pan !== this.autoPanValue) {
345
+ this.autoPanValue = pan;
346
+ this.getAllClips((clip) => {
347
+ setClipPan(clip, pan);
348
+ });
338
349
  }
339
350
  if (volume !== this.volume) {
340
351
  /**
@@ -475,9 +486,7 @@ export default createComponentClass(/** @lends platypus.components.AudioSFX.prot
475
486
  "set-pan": function (pan, soundId = '') {
476
487
  const
477
488
  handler = (clip) => {
478
- if (clip) {
479
- clip.pan = pan;
480
- }
489
+ setClipPan(clip, pan);
481
490
  };
482
491
 
483
492
  if (soundId) {
@@ -573,6 +582,7 @@ export default createComponentClass(/** @lends platypus.components.AudioSFX.prot
573
582
  if (clips[i].playthrough ?? playthrough) {
574
583
  } else {
575
584
  this.player.stop(clips[i]);
585
+ releaseClipPan(clips[i]);
576
586
  greenSplice(clips, i);
577
587
  }
578
588
  }
@@ -582,6 +592,7 @@ export default createComponentClass(/** @lends platypus.components.AudioSFX.prot
582
592
  if (clips[i].playthrough ?? playthrough) {
583
593
  } else {
584
594
  this.player.stop(clips[i]);
595
+ releaseClipPan(clips[i]);
585
596
  }
586
597
  }
587
598
  clips.length = 0;
@@ -593,6 +604,7 @@ export default createComponentClass(/** @lends platypus.components.AudioSFX.prot
593
604
  i = this.activeAudioClips.indexOf(audioClip);
594
605
 
595
606
  if (i >= 0) {
607
+ releaseClipPan(audioClip);
596
608
  greenSplice(this.activeAudioClips, i);
597
609
  }
598
610
  },
@@ -613,7 +625,7 @@ export default createComponentClass(/** @lends platypus.components.AudioSFX.prot
613
625
  if (active) {
614
626
  play.call(this);
615
627
  } else {
616
- this.stopAudio(audioId, this.forcePlaythrough);
628
+ this.stopAudio(audioId, this.forcePlayThrough);
617
629
  }
618
630
  checkData.playing = active;
619
631
  }