diff --git a/static/rot/rot.js b/static/rot/rot.js index 3a4ace2b..728bd11a 100644 --- a/static/rot/rot.js +++ b/static/rot/rot.js @@ -50,8 +50,14 @@ localStorage.audiovolume = number; //Save updateVolumeLabel(); } - function volumeAdd(number) { - volumeSet(Math.min(1, Math.max(0, audio.volume + number))); + function volumeInc() { + //We would not need to multiply by 10 and truncate if + //not for javascript constantly spewing rounding errors. + //But we do not live in an ideal world. + volumeSet(Math.min(1, Math.floor((Math.trunc(audio.volume * 1000) / 100) + 1) * 0.1)); + } + function volumeDec() { + volumeSet(Math.max(0, Math.ceil((Math.trunc(audio.volume * 1000) / 100) - 1) * 0.1)); } function updateVolumeLabel() { const percentage = `${Math.round(audio.volume * 100)}%`; @@ -378,8 +384,8 @@ localStorage.audiomuted = audio.muted = musicmute.checked; playMusic(); }) - volumeStepDwn.addEventListener('click', () => volumeAdd(-0.05)); - volumeStepUp.addEventListener('click', () => volumeAdd(0.05)); + volumeStepDwn.addEventListener('click', volumeDec); + volumeStepUp.addEventListener('click', volumeInc); updateVolumeLabel(); }