diff --git a/src/js/stendhal/Client.ts b/src/js/stendhal/Client.ts index fb79e4c737..cce9000332 100644 --- a/src/js/stendhal/Client.ts +++ b/src/js/stendhal/Client.ts @@ -132,6 +132,8 @@ export class Client { // alias for backward-compat until changed in all source stendhal.ui.gamewindow = stendhal.ui.viewport; stendhal.ui.soundMan = singletons.getSoundManager(); + // update sound levels from config at startup + stendhal.ui.soundMan.onConfigUpdate(); } /** diff --git a/src/js/stendhal/ui/SoundManager.ts b/src/js/stendhal/ui/SoundManager.ts index 746a471f80..34f31c3d99 100644 --- a/src/js/stendhal/ui/SoundManager.ts +++ b/src/js/stendhal/ui/SoundManager.ts @@ -743,6 +743,21 @@ export class SoundManager { ui.onSoundUpdate(); } + /** + * Can be called when configuration values change. + */ + onConfigUpdate() { + for (const layerName of ["master", ...this.layers]) { + let vol = stendhal.config.getFloat("sound." + layerName + ".volume"); + if (typeof(vol) !== "number") { + console.warn("Unrecognized volume value for layer \"" + layerName + "\":", vol); + // default to 100% + vol = 1.0; + } + this.setVolume(layerName, vol); + } + } + /** * Called at startup to pre-cache certain sounds. */