forked from StarDice-Games/two-sides
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAudioManager.gd
49 lines (38 loc) · 1.08 KB
/
AudioManager.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
extends Node
@export var num_players = 8
@export var bus = "Sfx"
@export var mute = false
var available = [] # The available players.
#TODO fix how the queue is managed
var queue = [] # The queue of sounds to play.
func _ready():
# Create the pool of AudioStreamPlayer nodes.
for i in num_players:
var p = AudioStreamPlayer.new()
p.connect("finished", _on_stream_finished)
p.bus = bus
add_child(p)
available.append(p)
func _on_stream_finished():
# When finished playing a stream, make the player available again.
# available.append()
pass
#func play(sound_path):
# queue.append(sound_path)
func play(sound : AudioStream):
if sound != null:
queue.append(sound)
func _process(delta):
# Play a queued sound if any players are available.
if not queue.is_empty():
var notPlaying = available.filter(isStreamStopped)
if not notPlaying.is_empty():
var player = notPlaying.pop_front()
player.stream = queue.pop_front()
if Global.sfxMuted:
player.volume_db = -80
else:
player.volume_db = 0
player.play()
func isStreamStopped(player):
return not player.playing