aboutsummaryrefslogtreecommitdiff
path: root/game/src/Game/Autoload
diff options
context:
space:
mode:
author Nemrav <50055236+Nemrav@users.noreply.github.com>2024-08-06 01:48:36 +0200
committer GitHub <noreply@github.com>2024-08-06 01:48:36 +0200
commit82b16bcca7c74607a8885b882ec36f5202e7ef70 (patch)
tree0a9bd4f52c01315c3b38ce641a78c33bd8562be2 /game/src/Game/Autoload
parentfde15e554dc9ed458a838683c69d10262764db12 (diff)
parent9506f4160f0bd351f0853e6e8263ea927d9ec771 (diff)
Merge pull request #243 from Nemrav/music
Music and sound effects
Diffstat (limited to 'game/src/Game/Autoload')
-rw-r--r--game/src/Game/Autoload/SoundManager.gd20
1 files changed, 17 insertions, 3 deletions
diff --git a/game/src/Game/Autoload/SoundManager.gd b/game/src/Game/Autoload/SoundManager.gd
index 35c715c..01562f8 100644
--- a/game/src/Game/Autoload/SoundManager.gd
+++ b/game/src/Game/Autoload/SoundManager.gd
@@ -18,7 +18,7 @@ func _ready() -> void:
"ogg", "wav", "mp3":
_loaded_sound[fname.get_basename()] = load(_audio_directory_path.path_join(fname)) # SND-10
-func play_stream(sound : AudioStream, bus_type : String) -> void:
+func play_stream(sound : AudioStream, bus_type : String, volume : float = 1.0) -> void:
var player : AudioStreamPlayer = _bus_to_stream_player.get(bus_type)
if player == null:
player = AudioStreamPlayer.new()
@@ -28,6 +28,7 @@ func play_stream(sound : AudioStream, bus_type : String) -> void:
add_child(player)
player.play()
var poly_playback : AudioStreamPlaybackPolyphonic = player.get_stream_playback()
+ player.volume_db = linear_to_db(volume)
poly_playback.play_stream(sound)
func play(sound : String, bus_type : String) -> void:
@@ -35,8 +36,21 @@ func play(sound : String, bus_type : String) -> void:
# REQUIREMENTS:
# * SND-7
-func play_effect_stream(sound : AudioStream) -> void:
- play_stream(sound, "SFX")
+func play_effect_stream(sound : AudioStream, volume : float = 1.0) -> void:
+ play_stream(sound, "SFX", volume)
func play_effect(sound : String) -> void:
play(sound, "SFX")
+
+func play_effect_compat(sfx : String, fallback : AudioStream=null) -> void:
+ var sound:AudioStreamWAV = SoundSingleton.get_sound_stream(sfx)
+ var volume:float = SoundSingleton.get_sound_base_volume(sfx)
+
+ if sound != null:
+ play_effect_stream(sound,volume)
+ elif fallback != null:
+ push_warning("Failed to find sound %s, playing fallback instead" % sfx)
+ play_effect_stream(fallback)
+ else:
+ push_warning("Failed to find sound %s" % sfx)
+