Working audio rocker in settings menu.

This commit is contained in:
lieght
2025-10-03 04:42:48 +02:00
parent 83130806a8
commit 5a200a8a70
3 changed files with 60 additions and 2 deletions

View File

@@ -37,6 +37,7 @@ public class SoundManager {
.listen(this::handleStopSound)
.listen(this::handleMusicStart)
.listen(this::handleVolumeChange)
.listen(this::handleGetCurrentVolume)
.listen(AudioEvents.playOnClickButton.class, _ -> {
try {
playSound("hitsound0.wav", false);
@@ -70,6 +71,12 @@ public class SoundManager {
for (MediaPlayer mediaPlayer : this.activeMusic) {
mediaPlayer.setVolume(this.volume);
}
IO.println("Volume: " + this.volume);
}
private void handleGetCurrentVolume(AudioEvents.GetCurrentVolume event) {
new EventFlow().addPostEvent(new AudioEvents.GetCurrentVolumeReponse(volume, event.snowflakeId()))
.asyncPostEvent();
}
private void handleMusicStart(AudioEvents.StartBackgroundMusic e) {

View File

@@ -1,9 +1,12 @@
package org.toop.framework.audio.events;
import org.toop.framework.asset.resources.MusicAsset;
import org.toop.framework.eventbus.events.EventWithSnowflake;
import org.toop.framework.eventbus.events.EventWithoutSnowflake;
import org.toop.framework.eventbus.events.EventsBase;
import java.util.Map;
public class AudioEvents extends EventsBase {
/** Starts playing a sound. */
public record PlayAudio(String fileName, boolean loop)
@@ -13,5 +16,27 @@ public class AudioEvents extends EventsBase {
public record StartBackgroundMusic() implements EventWithoutSnowflake {}
public record ChangeVolume(double newVolume) implements EventWithoutSnowflake {}
public record GetCurrentVolume(long snowflakeId) implements EventWithSnowflake {
@Override
public Map<String, Object> result() {
return Map.of();
}
@Override
public long eventSnowflake() {
return snowflakeId;
}
}
public record GetCurrentVolumeReponse(double currentVolume, long snowflakeId) implements EventWithSnowflake {
@Override
public Map<String, Object> result() {
return Map.of();
}
@Override
public long eventSnowflake() {
return snowflakeId;
}
}
public record playOnClickButton() implements EventWithoutSnowflake {}
}