diff --git a/apps/soundboardapp.js b/apps/soundboardapp.js index ebc0cc1..5844278 100644 --- a/apps/soundboardapp.js +++ b/apps/soundboardapp.js @@ -77,6 +77,10 @@ class SoundBoardApplication extends Application { }, 50); } + activateListeners(html) { + super.bringToTop(); + } + // noinspection JSUnusedGlobalSymbols getData() { var sounds = []; diff --git a/apps/soundboardhelpapp.js b/apps/soundboardhelpapp.js index b8a3403..24f4b64 100644 --- a/apps/soundboardhelpapp.js +++ b/apps/soundboardhelpapp.js @@ -22,6 +22,10 @@ class SoundBoardHelp extends Application { } + activateListeners(html) { + super.bringToTop(); + } + // TODO Localization // noinspection JSUnusedGlobalSymbols getData() { diff --git a/apps/soundboardpackagemanagerapp.js b/apps/soundboardpackagemanagerapp.js index 1c4a364..2001605 100644 --- a/apps/soundboardpackagemanagerapp.js +++ b/apps/soundboardpackagemanagerapp.js @@ -17,6 +17,10 @@ class SoundBoardPackageManagerApplication extends Application { return options; } + activateListeners(html) { + super.bringToTop(); + } + // noinspection JSUnusedGlobalSymbols getData() { this.packageManager.alphabetizePacks(); diff --git a/helpers/soundboardaudiohelper.js b/helpers/soundboardaudiohelper.js index 3edb68e..eaccf60 100644 --- a/helpers/soundboardaudiohelper.js +++ b/helpers/soundboardaudiohelper.js @@ -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 { @@ -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); @@ -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({ @@ -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(); diff --git a/module.json b/module.json index 99494d7..7a7d15b 100644 --- a/module.json +++ b/module.json @@ -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", diff --git a/soundboard.js b/soundboard.js index 19a74f6..f44e994 100755 --- a/soundboard.js +++ b/soundboard.js @@ -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() { @@ -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() { @@ -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); } @@ -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); @@ -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); @@ -311,7 +294,6 @@ class SoundBoard { } static async targetPlayer(html, id) { - // console.log(html); $(html).addClass('active'); $(html).siblings().removeClass('active'); if (!id) { @@ -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'); } @@ -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');