extends Node2D


var current_track = ""
var tracks = {};
var volumes = {};
export var GameComplete = false;
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
func play_track(name):
	if ( name != current_track and name in tracks ):
		tracks[name]
		current_track = name;
		if $Music.volume_db > -80:
			$Music.volume_db = volumes[name];
		$Music.stream = load(tracks[name]);
		$Music.play();

func playdeath():
	$DeathSFX.play();

func playwin():
	$WinSFX.play();
	
func playblockdestroy():
	$BlockDestroy.play();

# Called when the node enters the scene tree for the first time.
func _ready():
	tracks = {
		"preparefall": "res://Music/PrepareForTheFall.ogg",
		"fallfaster": "res://Music/FallFaster.ogg",
		"finalfall": "res://Music/FinalFall.ogg",
		"run": "res://Music/run.ogg"
	}
	volumes = {
		"": -6,
		"preparefall": -6,
		"fallfaster": -10,
		"finalfall": -13,
		"run": -5
	}
	$CanvasLayer/MusicToggle.connect("button_up", self, "toggle_music")
	$CanvasLayer/SFXToggle.connect("button_up", self, "toggle_sfx")
	pass # Replace with function body.


func toggle_sfx():
	if AudioServer.get_bus_volume_db(1) > -80:
		AudioServer.set_bus_volume_db(1, -81);
		$CanvasLayer/SFXToggle.text = 'b';
	else:
		AudioServer.set_bus_volume_db(1, -10);
		$CanvasLayer/SFXToggle.text = 'B';
	

func toggle_music():
	if $Music.volume_db > -80:
		$Music.volume_db = -89
		$CanvasLayer/MusicToggle.text = 'a';
	else:
		$Music.volume_db = volumes[current_track];
		$CanvasLayer/MusicToggle.text = 'A';

# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
#	pass
