extends Node2D

@onready var music : Dictionary = {}
@onready var sfx : Dictionary = {}

var music_muted = false
var sfx_muted = false
var all_muted = false


#### ACCESSORS ####



#### BUILT-IN ####

func _ready() -> void:
	for m in AUDIO_SCENE.get_node("music").get_children():
		music[m.name] = m
	for s in AUDIO_SCENE.get_node("sfx").get_children():
		sfx[s.name] = s


#### VIRTUALS ####





#### LOGIC ####

func play_music(m_name : String) -> void:
	if !music[m_name].playing and !music_muted and !all_muted:
		stop_music()
		music[m_name].play()


func stop_music() -> void:
	for m in music.values():
		m.stop()


func play_sfx(m_name : String, pitch_scale : float = 1.0) -> void:
	if !sfx_muted and !all_muted:
		sfx[m_name].pitch_scale = pitch_scale
		sfx[m_name].play()


func set_music_db(db : float) -> void:
	for m in music.values():
		m.volume_db = db


func get_music_db() -> float:
	return music.values()[0].volume_db


func set_sfx_db(db : float) -> void:
	for s in sfx.values():
		s.volume_db = db


func get_sfx_db() -> float:
	return sfx.values()[0].volume_db


func set_single_sfx_db(sfx_name : String, value : float) -> void:
	sfx[sfx_name].volume_db = value

func set_master_volume(db : float) -> void:
	AudioServer.set_bus_volume_db(AudioServer.get_bus_index("Master"), db)


func get_master_volume() -> float:
	return AudioServer.get_bus_volume_db(AudioServer.get_bus_index("Master"))


func mute_music() -> void:
	music_muted = true
	stop_music()


func unmute_music() -> void:
	music_muted = false


func mute_sfx() -> void:
	sfx_muted = true


func unmute_sfx() -> void:
	sfx_muted = false


func mute_all() -> void:
	all_muted = true
	stop_music()


func unmute_all() -> void:
	all_muted = false

#### INPUTS ####




#### SIGNAL RESPONSES ####
