aboutsummaryrefslogtreecommitdiff
path: root/game/src/Game/Autoload/SoundManager.gd
diff options
context:
space:
mode:
author Spartan322 <Megacake1234@gmail.com>2023-06-03 20:37:10 +0200
committer Spartan322 <Megacake1234@gmail.com>2023-06-03 20:37:10 +0200
commitcef940108fe15752c3ef66f43f5169403fa2f71d (patch)
treefe4de5a05830e3bddeae78f74f729503b7cee1e9 /game/src/Game/Autoload/SoundManager.gd
parent73e29d02e48739aba5ca5db1b9575c67e795400f (diff)
Reorganize the file structure of the files in `game/src`
Diffstat (limited to 'game/src/Game/Autoload/SoundManager.gd')
-rw-r--r--game/src/Game/Autoload/SoundManager.gd42
1 files changed, 42 insertions, 0 deletions
diff --git a/game/src/Game/Autoload/SoundManager.gd b/game/src/Game/Autoload/SoundManager.gd
new file mode 100644
index 0000000..c58ce1a
--- /dev/null
+++ b/game/src/Game/Autoload/SoundManager.gd
@@ -0,0 +1,42 @@
+extends Node
+
+# REQUIREMENTS:
+# * SS-68
+
+const _audio_directory_path : StringName = &"res://audio/sfx/"
+
+var _loaded_sound : Dictionary = {}
+
+var _bus_to_stream_player : Dictionary = {}
+
+# REQUIREMENTS:
+# * SND-10
+func _ready():
+ var dir = DirAccess.open(_audio_directory_path)
+ for fname in dir.get_files():
+ match fname.get_extension():
+ "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:
+ var player : AudioStreamPlayer = _bus_to_stream_player.get(bus_type)
+ if player == null:
+ player = AudioStreamPlayer.new()
+ player.bus = bus_type
+ player.stream = AudioStreamPolyphonic.new()
+ _bus_to_stream_player[bus_type] = player
+ add_child(player)
+ player.play()
+ var poly_playback : AudioStreamPlaybackPolyphonic = player.get_stream_playback()
+ poly_playback.play_stream(sound)
+
+func play(sound : String, bus_type : String) -> void:
+ play_stream(_loaded_sound[sound], bus_type)
+
+# REQUIREMENTS:
+# * SND-7
+func play_effect_stream(sound : AudioStream) -> void:
+ play_stream(sound, "SFX")
+
+func play_effect(sound : String) -> void:
+ play(sound, "SFX")