extends Node

const dialogue_continue = preload("res://Audio/SFX/dialog_page.wav")

@export var sounds: Dictionary = {
	&"melee": preload("res://Audio/SFX/melee.tres"),
	&"melee_hit": preload("res://Audio/SFX/melee_hit.tres"),
	&"effect_smoke": preload("res://Audio/SFX/puff_smoke.wav"),
	&"pause": preload("res://Audio/SFX/pause.wav"),
	&"unpause": preload("res://Audio/SFX/accept.wav"),
	&"dialogue_open": preload("res://Audio/SFX/dialog_open.wav"),
	&"dialogue_continue": preload("res://Audio/SFX/dialog_page.wav")
}

@onready var queue = $SoundQueue

var timer = 0.0

func play_sound(sound_name: StringName):
	var item = sounds.get(sound_name)
	if not item is AudioStream:
		push_error("The sound with name {0} is not an AudioStream!".format([sound_name]))
	else:
		queue.play_sound(item)

func _on_game_pause_toggled(paused: bool):
	play_sound("pause" if paused else "unpause")

func _on_ui_dialogue_opened():
	play_sound("dialogue_open")

func _on_ui_dialogue_continued():
	play_sound("dialogue_continue")

func _on_character_got_hurt(_new_health: int):
	play_sound("melee_hit")

func _on_humanoid_character_attacked():
	play_sound("melee")

func _on_reed_ai_range_attack_initiated(by):
	play_sound("energy_blast")
