diff --git a/src/js/commandline-lists.js b/src/js/commandline-lists.js index c8b52bc4f..1fad589ef 100644 --- a/src/js/commandline-lists.js +++ b/src/js/commandline-lists.js @@ -642,6 +642,40 @@ let commandsSoundOnError = { ], }; +let commandsSoundVolume = { + title: "Sound volume...", + configKey: "soundVolume", + list: [ + { + id: "setSoundVolume0.1", + display: "quiet", + configValue: "0.1", + exec: () => { + UpdateConfig.setSoundVolume("0.1"); + Sound.playClick(); + }, + }, + { + id: "setSoundVolume0.5", + display: "medium", + configValue: "0.5", + exec: () => { + UpdateConfig.setSoundVolume("0.5"); + Sound.playClick(); + }, + }, + { + id: "setSoundVolume1.0", + display: "loud", + configValue: "1.0", + exec: () => { + UpdateConfig.setSoundVolume("1.0"); + Sound.playClick(); + }, + }, + ], +}; + let commandsFlipTestColors = { title: "Flip test colors...", configKey: "flipTestColors", @@ -2466,12 +2500,6 @@ export let defaultCommands = { icon: "fa-hand-paper", subgroup: commandsStopOnError, }, - { - id: "changeSoundOnClick", - display: "Sound on click...", - icon: "fa-volume-up", - subgroup: commandsSoundOnClick, - }, { id: "changeNumbers", display: "Numbers...", @@ -2606,12 +2634,24 @@ export let defaultCommands = { icon: "fa-exchange-alt", subgroup: commandsOppositeShiftMode, }, + { + id: "changeSoundOnClick", + display: "Sound on click...", + icon: "fa-volume-up", + subgroup: commandsSoundOnClick, + }, { id: "changeSoundOnError", display: "Sound on error...", icon: "fa-volume-mute", subgroup: commandsSoundOnError, }, + { + id: "changeSoundVolume", + display: "Sound volume...", + icon: "fa-volume-down", + subgroup: commandsSoundVolume, + }, { id: "changeFlipTestColors", display: "Flip test colors...", diff --git a/src/js/config.js b/src/js/config.js index c786b6635..891de277c 100644 --- a/src/js/config.js +++ b/src/js/config.js @@ -101,6 +101,7 @@ let defaultConfig = { capsLockWarning: true, playSoundOnError: false, playSoundOnClick: "off", + soundVolume: "0.5", startGraphsAtZero: true, swapEscAndTab: false, showOutOfFocusWarning: true, @@ -274,11 +275,13 @@ export function setPlaySoundOnClick(val, nosave) { if (!nosave) saveToLocalStorage(); } -export function togglePlaySoundOnError() { - config.playSoundOnError = !config.playSoundOnError; - if (config.playSoundOnError == undefined) { - config.playSoundOnError = false; +export function setSoundVolume(val, nosave) { + if (val == undefined) { + val = "1.0"; } + config.soundVolume = val; + Sound.setVolume(val); + if (!nosave) saveToLocalStorage(); } //difficulty @@ -1644,6 +1647,7 @@ export function apply(configObj) { setCapsLockWarning(configObj.capsLockWarning, true); setPlaySoundOnError(configObj.playSoundOnError, true); setPlaySoundOnClick(configObj.playSoundOnClick, true); + setSoundVolume(configObj.soundVolume, true); setStopOnError(configObj.stopOnError, true); setFavThemes(configObj.favThemes, true); setFunbox(configObj.funbox, true); diff --git a/src/js/settings.js b/src/js/settings.js index bf5ebc901..3f8247bae 100644 --- a/src/js/settings.js +++ b/src/js/settings.js @@ -174,6 +174,11 @@ async function initGroups() { groups.confidenceMode.updateButton(); } ); + groups.soundVolume = new SettingsGroup( + "soundVolume", + UpdateConfig.setSoundVolume, + () => {} + ); groups.playSoundOnError = new SettingsGroup( "playSoundOnError", UpdateConfig.setPlaySoundOnError, diff --git a/src/js/sound.js b/src/js/sound.js index 3397f1fd9..4558e9a33 100644 --- a/src/js/sound.js +++ b/src/js/sound.js @@ -1,5 +1,5 @@ import Config from "./config"; -import { Howl } from "howler"; +import Howler, { Howl } from "howler"; let errorSound = null; let clickSounds = null; @@ -244,3 +244,7 @@ export function playError() { errorSound.seek(0); errorSound.play(); } + +export function setVolume(val) { + Howler.Howler.volume(val); +} diff --git a/static/index.html b/static/index.html index 72d4e44ea..3f8ee83b7 100644 --- a/static/index.html +++ b/static/index.html @@ -2906,6 +2906,36 @@
+
+

sound volume

+
Change the volume of the sound effects.
+
+
+ quiet +
+
+ medium +
+
+ loud +
+
+

play sound on click