mirror of
https://github.com/JHDev2006/Super-Mario-Bros.-Remastered-Public.git
synced 2025-10-22 07:28:14 +00:00
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:
@@ -101,6 +101,7 @@ const MUSIC_BASE = preload("uid://da4vqkrpqnma0")
|
|||||||
var character_sfx_map := {}
|
var character_sfx_map := {}
|
||||||
|
|
||||||
var audio_override_queue := []
|
var audio_override_queue := []
|
||||||
|
#var audio_override_queue: Array[Dictionary] = []
|
||||||
|
|
||||||
func play_sfx(stream_name = "", position := Vector2.ZERO, pitch := 1.0) -> void:
|
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:
|
func set_music_override(stream: MUSIC_OVERRIDES, priority := 0, stop_on_finish := true, restart := true) -> void:
|
||||||
if audio_override_queue.has(stream):
|
if audio_override_queue.has(stream):
|
||||||
if current_music_override == stream and restart:
|
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()
|
music_override_player.play()
|
||||||
return
|
return
|
||||||
if music_override_priority > priority:
|
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
|
await music_override_player.finished
|
||||||
stop_music_override(stream)
|
stop_music_override(stream)
|
||||||
|
|
||||||
|
|
||||||
func stop_music_override(stream: MUSIC_OVERRIDES, force := false) -> void:
|
func stop_music_override(stream: MUSIC_OVERRIDES, force := false) -> void:
|
||||||
if not force:
|
if not force:
|
||||||
if stream == null:
|
if stream == null:
|
||||||
@@ -184,16 +186,17 @@ func stop_music_override(stream: MUSIC_OVERRIDES, force := false) -> void:
|
|||||||
elif stream != current_music_override:
|
elif stream != current_music_override:
|
||||||
audio_override_queue.erase(stream)
|
audio_override_queue.erase(stream)
|
||||||
return
|
return
|
||||||
|
else:
|
||||||
|
audio_override_queue.clear()
|
||||||
audio_override_queue.pop_back()
|
audio_override_queue.pop_back()
|
||||||
current_music_override = MUSIC_OVERRIDES.NONE
|
|
||||||
music_override_player.stop()
|
music_override_player.stop()
|
||||||
music_override_priority = -1
|
|
||||||
if audio_override_queue.is_empty():
|
if audio_override_queue.is_empty():
|
||||||
audio_override_queue.clear()
|
audio_override_queue.clear()
|
||||||
music_override_priority = -1
|
music_override_priority = -1
|
||||||
current_music_override = MUSIC_OVERRIDES.NONE
|
current_music_override = MUSIC_OVERRIDES.NONE
|
||||||
music_override_player.stop()
|
music_override_player.stop()
|
||||||
else:
|
else:
|
||||||
|
current_music_override = audio_override_queue[audio_override_queue.size() - 1]
|
||||||
set_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:
|
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)
|
music_override_player.get_stream_playback().switch_to_clip(0)
|
||||||
|
|
||||||
func create_stream_from_json(json_path := "") -> AudioStream:
|
func create_stream_from_json(json_path := "") -> AudioStream:
|
||||||
|
var path := ""
|
||||||
if json_path.contains(".json") == false:
|
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):
|
if path.contains(Global.config_path):
|
||||||
match json_path.get_slice(".", 1):
|
match json_path.get_slice(".", 1):
|
||||||
"wav":
|
"wav":
|
||||||
@@ -259,8 +263,7 @@ func create_stream_from_json(json_path := "") -> AudioStream:
|
|||||||
elif path.contains("res://"):
|
elif path.contains("res://"):
|
||||||
return load(path)
|
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 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(json_path.replace(json_path.get_file(), bgm_file))
|
||||||
path = ResourceSetter.get_pure_resource_path(path)
|
|
||||||
var stream = null
|
var stream = null
|
||||||
if path.get_file().contains(".bgm"):
|
if path.get_file().contains(".bgm"):
|
||||||
stream = generate_interactive_stream(JSON.parse_string(FileAccess.open(path, FileAccess.READ).get_as_text()))
|
stream = generate_interactive_stream(JSON.parse_string(FileAccess.open(path, FileAccess.READ).get_as_text()))
|
||||||
|
@@ -299,5 +299,6 @@ func get_animation_name() -> String:
|
|||||||
return "Fall"
|
return "Fall"
|
||||||
|
|
||||||
func exit() -> void:
|
func exit() -> void:
|
||||||
|
if owner.has_hammer:
|
||||||
owner.on_hammer_timeout()
|
owner.on_hammer_timeout()
|
||||||
owner.skidding = false
|
owner.skidding = false
|
||||||
|
Reference in New Issue
Block a user