extends Node

export (PackedScene) var battle_scene
export (PackedScene) var pause_control_scene
export (PackedScene) var menu_control_scene

onready var menu_control = $CanvasLayer/MenuControl
var battle_inst = null
var pause_control_inst = null

func _ready():
	randomize()
	menu_control.connect("new_game", self, "start_new_game")
	Global.main_node = self

func start_new_game(extras):
	yield(get_tree().create_timer(0.1), "timeout")
	$Music.stream = load("res://Assets/Music/Battle.ogg")
	$Music.play()
	battle_inst = battle_scene.instance()
	if extras.has("infinite_mode"):
		if extras.infinite_mode:
			battle_inst.current_level = battle_inst.levels.size()-1
	add_child(battle_inst)
	if extras.has("player_class"):
		battle_inst.player.set_class(extras.player_class)
	
	pause_control_inst = pause_control_scene.instance()
	$CanvasLayer.add_child(pause_control_inst)
	
	menu_control.queue_free()

func _on_Main_tree_exiting():
	Global.main_node = null
