1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2026-03-02 03:39:21 +00:00

Properly implement sound and music volumes, debounce writes

This commit is contained in:
tobspr
2020-09-13 08:40:56 +02:00
parent 50e40888fd
commit 6042fcba62
13 changed files with 9695 additions and 9712 deletions

View File

@@ -185,6 +185,9 @@ export class SoundImplBrowser extends SoundInterface {
}
initialize() {
// NOTICE: We override the initialize() method here with custom logic because
// we have a sound sprites instance
this.sfxHandle = new SoundSpritesContainer();
// @ts-ignore
@@ -198,11 +201,11 @@ export class SoundImplBrowser extends SoundInterface {
this.music[musicPath] = music;
}
this.musicMuted = this.app.settings.getAllSettings().musicMuted;
this.soundsMuted = this.app.settings.getAllSettings().soundsMuted;
this.musicVolume = this.app.settings.getAllSettings().musicVolume;
this.soundVolume = this.app.settings.getAllSettings().soundVolume;
if (G_IS_DEV && globalConfig.debug.disableMusic) {
this.musicMuted = true;
this.musicVolume = 0.0;
}
return Promise.resolve();

View File

@@ -103,9 +103,6 @@ export class SoundInterface {
this.pageIsVisible = true;
this.musicMuted = false;
this.soundsMuted = false;
this.musicVolume = 1.0;
this.soundVolume = 1.0;
}
@@ -127,13 +124,11 @@ export class SoundInterface {
this.music[musicPath] = music;
}
this.musicMuted = this.app.settings.getAllSettings().musicMuted;
this.soundsMuted = this.app.settings.getAllSettings().soundsMuted;
this.musicVolume = this.app.settings.getAllSettings().musicVolume;
this.soundVolume = this.app.settings.getAllSettings().soundVolume;
if (G_IS_DEV && globalConfig.debug.disableMusic) {
this.musicMuted = true;
this.musicVolume = 0.0;
}
return Promise.resolve();
@@ -170,47 +165,6 @@ export class SoundInterface {
return Promise.all(...promises);
}
/**
* Returns if the music is muted
* @returns {boolean}
*/
getMusicMuted() {
return this.musicMuted;
}
/**
* Returns if sounds are muted
* @returns {boolean}
*/
getSoundsMuted() {
return this.soundsMuted;
}
/**
* Sets if the music is muted
* @param {boolean} muted
*/
setMusicMuted(muted) {
this.musicMuted = muted;
if (this.musicMuted) {
if (this.currentMusic) {
this.currentMusic.stop();
}
} else {
if (this.currentMusic) {
this.currentMusic.play(this.musicVolume);
}
}
}
/**
* Sets if the sounds are muted
* @param {boolean} muted
*/
setSoundsMuted(muted) {
this.soundsMuted = muted;
}
/**
* Returns the music volume
* @returns {number}
@@ -254,7 +208,7 @@ export class SoundInterface {
this.pageIsVisible = pageIsVisible;
if (this.currentMusic) {
if (pageIsVisible) {
if (!this.currentMusic.isPlaying() && !this.musicMuted) {
if (!this.currentMusic.isPlaying()) {
this.currentMusic.play(this.musicVolume);
}
} else {
@@ -267,9 +221,6 @@ export class SoundInterface {
* @param {string} key
*/
playUiSound(key) {
if (this.soundsMuted) {
return;
}
if (!this.sounds[key]) {
logger.warn("Sound", key, "not found, probably not loaded yet");
return;
@@ -288,7 +239,7 @@ export class SoundInterface {
logger.warn("Music", key, "not found, probably not loaded yet");
return;
}
if (!this.pageIsVisible || this.soundsMuted) {
if (!this.pageIsVisible) {
return;
}
@@ -319,7 +270,7 @@ export class SoundInterface {
this.currentMusic.stop();
}
this.currentMusic = music;
if (music && this.pageIsVisible && !this.musicMuted) {
if (music && this.pageIsVisible) {
logger.log("Starting", this.currentMusic.key);
music.play(this.musicVolume);
}