extends AudioStreamPlayer

var mute_status : bool = false

var main_theme : AudioStreamOGGVorbis = preload("res://Audio/Music/SpaceMainTheme_r1_session.ogg")
var combat_theme : AudioStreamOGGVorbis = preload("res://Audio/Music/CombatThemeLBRY_r1_session.ogg")
var streaming_2 : AudioStreamOGGVorbis = preload("res://Audio/Music/Streaming2_draft_r2_session.ogg")

var music_dict = {"main" : [ main_theme ], "combat" : [ combat_theme, streaming_2 ]}

var current_music_array : String = "main"

func switch_theme(name : String) -> void:
	if name in music_dict.keys():
		var music_list = music_dict[name]
		music_list.shuffle()
		stream = music_list[0]
		current_music_array = name
	else:
		get_parent().console_print("Could not find music array of name, " + name)
	playing = true

func _process(delta : float) -> void:
	if Input.is_action_just_pressed("mute") :
		if mute_status:
			AudioServer.set_bus_mute(AudioServer.get_bus_index("Master"), false)
		else:
			AudioServer.set_bus_mute(AudioServer.get_bus_index("Master"), true)
		mute_status = !mute_status
	


func _on_finished():
	switch_theme(current_music_array)
