Skip to content

Commit

Permalink
Merge pull request #20 from JvPeek/develop
Browse files Browse the repository at this point in the history
Volume Control
  • Loading branch information
awsdcrafting authored Aug 8, 2023
2 parents 1501be5 + 1e3df8e commit 3d094a0
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions src/bongocat.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ var stackMode = false;
var defaultNotation = "bongo";

var currentSong = null;
var volume = 1.0;

window.maxNotesPerBatch = 5;

Expand All @@ -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))
{
Expand Down Expand Up @@ -116,6 +121,7 @@ function playSound(cmd, cBpm)
setInstrument(audio.dataset.instrument);

audio.currentTime = 0;
audio.volume = volume;
audio.play();
}

Expand All @@ -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";
Expand All @@ -157,6 +166,7 @@ function outroAnimation()
currentSong = null;
}, 1000);
}

function setInstrument(instrument)
{
var c = document.getElementById("instruments").children;
Expand All @@ -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)
{

Expand Down Expand Up @@ -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)
{
Expand All @@ -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 =================== //
// ====================================================== //
Expand Down Expand Up @@ -507,6 +530,12 @@ if (params.get("stackMode"))
stackMode = true;
}

let volumeParam = params.get("volume");
if (volumeParam && !isNaN(Number(volumeParam)))
{
setVolume(volumeParam);
}

// ====================================================== //
// ======================== tmijs ======================= //
// ====================================================== //
Expand Down

0 comments on commit 3d094a0

Please sign in to comment.