Update volume levels at client startup

Closes: https://github.com/arianne/stendhal/issues/722
This commit is contained in:
Jordan Irwin 2024-05-13 21:28:04 -07:00
parent 52d1569418
commit a899c8d0d4
No known key found for this signature in database
GPG key ID: E3E358C2F44C290A
2 changed files with 17 additions and 0 deletions

View file

@ -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();
}
/**

View file

@ -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.
*/