Skip to content

Commit

Permalink
support to v12 (it pottentially breaks compatibility to old versions
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcomac committed Jul 22, 2024
1 parent a43b9ea commit 8cc5102
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 50 deletions.
4 changes: 4 additions & 0 deletions apps/soundboardapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ class SoundBoardApplication extends Application {
}, 50);
}

activateListeners(html) {
super.bringToTop();
}

// noinspection JSUnusedGlobalSymbols
getData() {
var sounds = [];
Expand Down
4 changes: 4 additions & 0 deletions apps/soundboardhelpapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class SoundBoardHelp extends Application {

}

activateListeners(html) {
super.bringToTop();
}

// TODO Localization
// noinspection JSUnusedGlobalSymbols
getData() {
Expand Down
4 changes: 4 additions & 0 deletions apps/soundboardpackagemanagerapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class SoundBoardPackageManagerApplication extends Application {
return options;
}

activateListeners(html) {
super.bringToTop();
}

// noinspection JSUnusedGlobalSymbols
getData() {
this.packageManager.alphabetizePacks();
Expand Down
37 changes: 20 additions & 17 deletions helpers/soundboardaudiohelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,16 @@ class SBAudioHelper {
}
volume *= game.settings.get('core', 'globalInterfaceVolume');

var soundNode = new Sound(src);
soundNode.container._onEnd = () => {
var soundNode = new foundry.audio.Sound(src);
soundNode.loop = sound.loop;
soundNode.addEventListener('end', () => {
this.removeActiveSound(soundNode);
try {
soundNode.stop();
} catch (e) {
// Do nothing
}
if (sound?.isLoop) {
if (sound?.loop) {
if (!sound?.loopDelay || sound?.loopDelay === 0) {
SoundBoard.playSound(sound.identifyingPath, true);
} else {
Expand All @@ -91,20 +92,22 @@ class SBAudioHelper {
}, sound.loopDelay * 1000);
}
}
};
soundNode.on('stop', () => {
if (sound?.isLoop) {
sound.isLoop = false;
});

soundNode.addEventListener('stop', () => {
if (sound?.loop) {
sound.loop = false;
}
});
soundNode.on('start', () => {
this.detuneNode(soundNode, detune);

soundNode.addEventListener("play", () => {
this.detuneNode(soundNode, detune);

let individualGainNode = game.audio.context.createGain();
individualGainNode.gain.value = soundNode.individualVolume;
soundNode.node.disconnect();
soundNode.sourceNode.disconnect();
individualGainNode.connect(game.audio.soundboardGain);
soundNode.node.connect(individualGainNode);
soundNode.sourceNode.connect(individualGainNode);
soundNode.individualGainNode = individualGainNode;
// soundNode.node.connect(iirfilter).connect(AudioHelper.soundboardGain);
this.activeSounds.push(soundNode);
Expand All @@ -127,7 +130,7 @@ class SBAudioHelper {
}

async cache({src, volume}) {
var soundNode = new Sound(src);
var soundNode = new foundry.audio.Sound(src);
await soundNode.load();
let player = game.user.name;
SoundBoard.socketHelper.sendData({
Expand All @@ -143,11 +146,11 @@ class SBAudioHelper {
}

_callStop(sound) {
if (!sound.container.isBuffer) {
sound.container.element.onended = undefined;
sound.container.element.pause();
sound.container.element.src = '';
sound.container.element.remove();
if (!sound.isBuffer) {
sound.element.onended = undefined;
sound.element.pause();
sound.element.src = '';
sound.element.remove();
}

sound.stop();
Expand Down
8 changes: 4 additions & 4 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@
}
],
"socket": true,
"minimumCoreVersion": 9,
"compatibleCoreVersion": "10.291",
"minimumCoreVersion": 12,
"compatibleCoreVersion": "12",
"compatibility": {
"minimum": 9,
"verified": "10.291"
"minimum": 12,
"verified": "12"
},
"url": "https://github.com/BlitzKraig/fvtt-SoundBoard",
"manifest": "https://raw.githubusercontent.com/BlitzKraig/fvtt-SoundBoard/master/module.json",
Expand Down
40 changes: 11 additions & 29 deletions soundboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ class SoundBoard {
}
SoundBoard.openedBoard = new SoundBoardApplication();
SoundBoard.openedBoard.render(true);
try {
SoundBoard.openedBoard.bringToTop();
} catch (e) {
console.error(e);
}
}

static openSoundBoardFav() {
Expand All @@ -93,11 +88,6 @@ class SoundBoard {
}
SoundBoard.openedBoard = new SoundBoardFavApplication();
SoundBoard.openedBoard.render(true);
try {
SoundBoard.openedBoard.bringToTop();
} catch (e) {
console.error(e);
}
}

static openSoundBoardBundled() {
Expand All @@ -107,24 +97,15 @@ class SoundBoard {
}
SoundBoard.openedBoard = new SoundBoardBundledApplication();
SoundBoard.openedBoard.render(true);
try {
SoundBoard.openedBoard.bringToTop();
} catch (e) {
console.error(e);
}
}

static openSoundBoardHelp() {
try {
new SoundBoardHelp().render(true).bringToTop();
} catch (e) {
console.error(e);
}
new SoundBoardHelp().render(true);
}

static openSoundBoardPackageManager() {
try {
new SoundBoardPackageManagerApplication(SoundBoard.packageManager).render(true).bringToTop();
new SoundBoardPackageManagerApplication(SoundBoard.packageManager).render(true); //.bringToTop();
} catch (e) {
console.error(e);
}
Expand Down Expand Up @@ -181,7 +162,7 @@ class SoundBoard {
} else {
this.favoriteSound(identifyingPath);
}
} else if (sound.isLoop) {
} else if (sound.loop) {
SoundBoard.stopLoop(identifyingPath);
} else if (SBCompatLayer.getKeyDown('Control', 'ControlLeft')) {
this.stopSound(identifyingPath);
Expand Down Expand Up @@ -209,16 +190,18 @@ class SoundBoard {

let detune = game.settings.get('SoundBoard', 'detuneAmount');

let loop = sound.loop;

if (detune > 0) {
detune *= 10;
let normalizedAmount = Math.random() * detune;
detune = 0 - detune / 2 + normalizedAmount;
}

let payload = {
src,
volume,
detune
detune,
loop
};
if (SoundBoard.cacheMode) {
SoundBoard.audioHelper.cache(payload);
Expand Down Expand Up @@ -311,7 +294,6 @@ class SoundBoard {
}

static async targetPlayer(html, id) {
// console.log(html);
$(html).addClass('active');
$(html).siblings().removeClass('active');
if (!id) {
Expand Down Expand Up @@ -445,17 +427,17 @@ class SoundBoard {

static startLoop(identifyingPath) {
let sound = SoundBoard.getSoundFromIdentifyingPath(identifyingPath);
if (sound.isLoop) {
if (sound.loop) {
return;
}
sound.isLoop = true;
sound.loop = true;
SoundBoard.playSound(identifyingPath);

$('#soundboard-app .btn').filter(`[uuid=${$.escapeSelector(identifyingPath)}]`).addClass('loop-active');
}

static stopLoop(identifyingPath) {
SoundBoard.getSoundFromIdentifyingPath(identifyingPath).isLoop = false;
SoundBoard.getSoundFromIdentifyingPath(identifyingPath).loop = false;
$('#soundboard-app .btn').filter(`[uuid=${$.escapeSelector(identifyingPath)}]`).removeClass('loop-active');
}

Expand All @@ -466,7 +448,7 @@ class SoundBoard {
delayInSeconds = 600;
}
SoundBoard.getSoundFromIdentifyingPath(identifyingPath).loopDelay = delayInSeconds;
if (!SoundBoard.getSoundFromIdentifyingPath(identifyingPath).isLoop) {
if (!SoundBoard.getSoundFromIdentifyingPath(identifyingPath).loop) {
SoundBoard.startLoop(identifyingPath);
}
$(button).siblings('.dropdown-item').removeClass('active');
Expand Down

0 comments on commit 8cc5102

Please sign in to comment.