Audio Manager sound override rework and fixes (#617)

* Reworked the sound override system to prevent non-playing sounds

* Weird bug where it would call to stop a non-existant hammer sound on death
This commit is contained in:
guzlad
2025-10-17 21:26:04 +02:00
committed by GitHub
parent 7d6652a242
commit 9a0d61d1e1
2 changed files with 11 additions and 7 deletions

View File

@@ -101,6 +101,7 @@ const MUSIC_BASE = preload("uid://da4vqkrpqnma0")
var character_sfx_map := {}
var audio_override_queue := []
#var audio_override_queue: Array[Dictionary] = []
func play_sfx(stream_name = "", position := Vector2.ZERO, pitch := 1.0) -> void:
@@ -159,6 +160,8 @@ func kill_sfx(sfx_name := "") -> void:
func set_music_override(stream: MUSIC_OVERRIDES, priority := 0, stop_on_finish := true, restart := true) -> void:
if audio_override_queue.has(stream):
if current_music_override == stream and restart:
music_override_player.stream = create_stream_from_json(OVERRIDE_STREAMS[stream])
music_override_player.bus = "Music" if stream != MUSIC_OVERRIDES.FLAG_POLE else "SFX"
music_override_player.play()
return
if music_override_priority > priority:
@@ -176,7 +179,6 @@ func set_music_override(stream: MUSIC_OVERRIDES, priority := 0, stop_on_finish :
await music_override_player.finished
stop_music_override(stream)
func stop_music_override(stream: MUSIC_OVERRIDES, force := false) -> void:
if not force:
if stream == null:
@@ -184,16 +186,17 @@ func stop_music_override(stream: MUSIC_OVERRIDES, force := false) -> void:
elif stream != current_music_override:
audio_override_queue.erase(stream)
return
else:
audio_override_queue.clear()
audio_override_queue.pop_back()
current_music_override = MUSIC_OVERRIDES.NONE
music_override_player.stop()
music_override_priority = -1
if audio_override_queue.is_empty():
audio_override_queue.clear()
music_override_priority = -1
current_music_override = MUSIC_OVERRIDES.NONE
music_override_player.stop()
else:
current_music_override = audio_override_queue[audio_override_queue.size() - 1]
set_music_override(audio_override_queue[audio_override_queue.size() - 1])
func load_sfx_map(json := {}) -> void:
@@ -246,8 +249,9 @@ func handle_music_override() -> void:
music_override_player.get_stream_playback().switch_to_clip(0)
func create_stream_from_json(json_path := "") -> AudioStream:
var path := ""
if json_path.contains(".json") == false:
var path = ResourceSetter.get_pure_resource_path(json_path)
path = ResourceSetter.get_pure_resource_path(json_path)
if path.contains(Global.config_path):
match json_path.get_slice(".", 1):
"wav":
@@ -259,8 +263,7 @@ func create_stream_from_json(json_path := "") -> AudioStream:
elif path.contains("res://"):
return load(path)
var bgm_file = $ResourceSetterNew.get_variation_json(JSON.parse_string(FileAccess.open(ResourceSetter.get_pure_resource_path(json_path), FileAccess.READ).get_as_text()).variations).source
var path = json_path.replace(json_path.get_file(), bgm_file)
path = ResourceSetter.get_pure_resource_path(path)
path = ResourceSetter.get_pure_resource_path(json_path.replace(json_path.get_file(), bgm_file))
var stream = null
if path.get_file().contains(".bgm"):
stream = generate_interactive_stream(JSON.parse_string(FileAccess.open(path, FileAccess.READ).get_as_text()))

View File

@@ -299,5 +299,6 @@ func get_animation_name() -> String:
return "Fall"
func exit() -> void:
owner.on_hammer_timeout()
if owner.has_hammer:
owner.on_hammer_timeout()
owner.skidding = false