Fixed audio not getting correct volume at settings loading. Added back background music

This commit is contained in:
lieght
2025-10-05 01:51:29 +02:00
parent d7d6a49b98
commit 0ab0cd75ba
5 changed files with 13 additions and 4 deletions

View File

@@ -11,6 +11,8 @@ import javafx.scene.Scene;
import javafx.scene.layout.StackPane; import javafx.scene.layout.StackPane;
import javafx.stage.Stage; import javafx.stage.Stage;
import org.toop.framework.asset.resources.SettingsAsset; import org.toop.framework.asset.resources.SettingsAsset;
import org.toop.framework.audio.events.AudioEvents;
import org.toop.framework.eventbus.EventFlow;
import org.toop.local.AppSettings; import org.toop.local.AppSettings;
import java.io.File; import java.io.File;
@@ -65,6 +67,8 @@ public final class App extends Application {
App.isQuitting = false; App.isQuitting = false;
new EventFlow().addPostEvent(new AudioEvents.StartBackgroundMusic()).postEvent();
activate(new MainLayer()); activate(new MainLayer());
} }

View File

@@ -84,7 +84,7 @@ public final class OptionsLayer extends Layer {
container.addSlider(100, currentVolume, (volume) -> { container.addSlider(100, currentVolume, (volume) -> {
currentVolume = volume; currentVolume = volume;
settings.setVolume(volume); settings.setVolume(volume);
new EventFlow().addPostEvent(new AudioEvents.ChangeVolume(volume.doubleValue() / 100.0)).asyncPostEvent(); new EventFlow().addPostEvent(new AudioEvents.ChangeVolume(volume.doubleValue())).asyncPostEvent();
}); });
} }

View File

@@ -2,6 +2,8 @@ package org.toop.local;
import org.toop.app.App; import org.toop.app.App;
import org.toop.framework.asset.resources.SettingsAsset; import org.toop.framework.asset.resources.SettingsAsset;
import org.toop.framework.audio.events.AudioEvents;
import org.toop.framework.eventbus.EventFlow;
import org.toop.framework.settings.Settings; import org.toop.framework.settings.Settings;
import java.io.File; import java.io.File;
@@ -20,6 +22,8 @@ public class AppSettings {
AppContext.setLocale(Locale.of(settingsData.locale)); AppContext.setLocale(Locale.of(settingsData.locale));
App.setFullscreen(settingsData.fullScreen); App.setFullscreen(settingsData.fullScreen);
new EventFlow().addPostEvent(new AudioEvents.ChangeVolume(settingsData.volume)).asyncPostEvent();
} }
public SettingsAsset getPath() { public SettingsAsset getPath() {

Binary file not shown.

View File

@@ -69,15 +69,16 @@ public class SoundManager {
} }
private void handleVolumeChange(AudioEvents.ChangeVolume event) { private void handleVolumeChange(AudioEvents.ChangeVolume event) {
if (event.newVolume() > 1.0) this.volume = 1.0; double newVolume = event.newVolume() / 100;
else this.volume = Math.max(event.newVolume(), 0.0); if (newVolume > 1.0) this.volume = 1.0;
else this.volume = Math.max(newVolume, 0.0);
for (MediaPlayer mediaPlayer : this.activeMusic) { for (MediaPlayer mediaPlayer : this.activeMusic) {
mediaPlayer.setVolume(this.volume); mediaPlayer.setVolume(this.volume);
} }
} }
private void handleGetCurrentVolume(AudioEvents.GetCurrentVolume event) { private void handleGetCurrentVolume(AudioEvents.GetCurrentVolume event) {
new EventFlow().addPostEvent(new AudioEvents.GetCurrentVolumeReponse(volume, event.snowflakeId())) new EventFlow().addPostEvent(new AudioEvents.GetCurrentVolumeReponse(volume * 100, event.snowflakeId()))
.asyncPostEvent(); .asyncPostEvent();
} }