@makefully/platypus 4.1.16 → 4.1.17
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/CHANGELOG.md +6 -0
- package/lib/platypus.js +1 -1
- package/package.json +1 -1
- package/src/components/AudioSFX.js +39 -29
package/package.json
CHANGED
|
@@ -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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
|
@@ -306,17 +317,13 @@ export default createComponentClass(/** @lends platypus.components.AudioSFX.prot
|
|
|
306
317
|
"range": this.autoPan.range || -1,
|
|
307
318
|
"buffer": this.autoPan.buffer || 0
|
|
308
319
|
};
|
|
309
|
-
let lastPan = 0;
|
|
310
|
-
|
|
311
320
|
this.volume = autoPan.maximum;
|
|
312
|
-
|
|
313
|
-
this.autoPanFilter = new filters.StereoFilter(lastPan);
|
|
314
321
|
|
|
315
322
|
this.addEventListener("camera-update", function (camera) {
|
|
316
323
|
const
|
|
317
324
|
delta = this.owner.x - camera.viewport.x,
|
|
318
325
|
distance = Math.abs(delta),
|
|
319
|
-
direction = delta / distance,
|
|
326
|
+
direction = distance ? delta / distance : 0,
|
|
320
327
|
range = autoPan.range === -1 ? camera.viewport.width : autoPan.range;
|
|
321
328
|
let pan = 0,
|
|
322
329
|
volume = 1;
|
|
@@ -332,9 +339,11 @@ export default createComponentClass(/** @lends platypus.components.AudioSFX.prot
|
|
|
332
339
|
volume = autoPan.maximum;
|
|
333
340
|
}
|
|
334
341
|
|
|
335
|
-
if (pan !==
|
|
336
|
-
this.
|
|
337
|
-
|
|
342
|
+
if (pan !== this.autoPanValue) {
|
|
343
|
+
this.autoPanValue = pan;
|
|
344
|
+
this.getAllClips((clip) => {
|
|
345
|
+
setClipPan(clip, pan);
|
|
346
|
+
});
|
|
338
347
|
}
|
|
339
348
|
if (volume !== this.volume) {
|
|
340
349
|
/**
|
|
@@ -475,9 +484,7 @@ export default createComponentClass(/** @lends platypus.components.AudioSFX.prot
|
|
|
475
484
|
"set-pan": function (pan, soundId = '') {
|
|
476
485
|
const
|
|
477
486
|
handler = (clip) => {
|
|
478
|
-
|
|
479
|
-
clip.pan = pan;
|
|
480
|
-
}
|
|
487
|
+
setClipPan(clip, pan);
|
|
481
488
|
};
|
|
482
489
|
|
|
483
490
|
if (soundId) {
|
|
@@ -573,6 +580,7 @@ export default createComponentClass(/** @lends platypus.components.AudioSFX.prot
|
|
|
573
580
|
if (clips[i].playthrough ?? playthrough) {
|
|
574
581
|
} else {
|
|
575
582
|
this.player.stop(clips[i]);
|
|
583
|
+
releaseClipPan(clips[i]);
|
|
576
584
|
greenSplice(clips, i);
|
|
577
585
|
}
|
|
578
586
|
}
|
|
@@ -582,6 +590,7 @@ export default createComponentClass(/** @lends platypus.components.AudioSFX.prot
|
|
|
582
590
|
if (clips[i].playthrough ?? playthrough) {
|
|
583
591
|
} else {
|
|
584
592
|
this.player.stop(clips[i]);
|
|
593
|
+
releaseClipPan(clips[i]);
|
|
585
594
|
}
|
|
586
595
|
}
|
|
587
596
|
clips.length = 0;
|
|
@@ -593,6 +602,7 @@ export default createComponentClass(/** @lends platypus.components.AudioSFX.prot
|
|
|
593
602
|
i = this.activeAudioClips.indexOf(audioClip);
|
|
594
603
|
|
|
595
604
|
if (i >= 0) {
|
|
605
|
+
releaseClipPan(audioClip);
|
|
596
606
|
greenSplice(this.activeAudioClips, i);
|
|
597
607
|
}
|
|
598
608
|
},
|