diff --git a/src/bongocat.js b/src/bongocat.js index 5875649..dc63957 100644 --- a/src/bongocat.js +++ b/src/bongocat.js @@ -46,6 +46,7 @@ var stackMode = false; var defaultNotation = "bongo"; var currentSong = null; +var volume = 1.0; window.maxNotesPerBatch = 5; @@ -63,9 +64,13 @@ notations["bongo+"] = parseSongBongo; // ====================================================== // // =================== helper methods =================== // // ====================================================== // -function setBPM(targetBPM, username) +function setVolume(volumeParam) { + volume = Math.min(1.0, Math.max(0, Number(volumeParam))); +} +function setBPM(targetBPM, username) +{ targetBPM = Number(targetBPM); if (isNaN(targetBPM)) { @@ -116,6 +121,7 @@ function playSound(cmd, cBpm) setInstrument(audio.dataset.instrument); audio.currentTime = 0; + audio.volume = volume; audio.play(); } @@ -139,14 +145,17 @@ function introAnimation(song) }); document.getElementById("dedications").innerHTML = "This song is dedicated to " + song.dedications.join(", "); + document.getElementById("dedications").style.visibility = "visible"; } else { document.getElementById("dedications").innerHTML = ""; + document.getElementById("dedications").style.visibility = "hidden"; } document.getElementById("bongocat").style.left = "0px"; playing = true; } + function outroAnimation() { document.getElementById("bongocat").style.left = "-1920px"; @@ -157,6 +166,7 @@ function outroAnimation() currentSong = null; }, 1000); } + function setInstrument(instrument) { var c = document.getElementById("instruments").children; @@ -169,12 +179,14 @@ function setInstrument(instrument) newInstrument.style.visibility = "visible"; } + function setPaw(paw, cBpm) { var currentPaw = document.getElementById(paw); currentPaw.style.backgroundPosition = "top right"; window.setTimeout(releasePaw, cBpm / 2, paw); } + function releasePaw(paw) { @@ -364,7 +376,7 @@ function skipSong(args) return; } - console.log(`${args.tags.username} cleared the current song ${currentSong}`) + console.log(`${args.tags.username} cleared the current song ${currentSong}`); for (let id of currentSong.timeoutIDs) { @@ -376,6 +388,17 @@ function skipSong(args) commands["!bongoskip"] = skipSong; +function setVolumeCommand(args) +{ + if (!isSuperUser(args.tags)) + { + return; + } + setVolume(args.arg); +} + +commands["!bongovolume"] = setVolumeCommand; + // ====================================================== // // ==================== user commands =================== // // ====================================================== // @@ -507,6 +530,12 @@ if (params.get("stackMode")) stackMode = true; } +let volumeParam = params.get("volume"); +if (volumeParam && !isNaN(Number(volumeParam))) +{ + setVolume(volumeParam); +} + // ====================================================== // // ======================== tmijs ======================= // // ====================================================== //