extends Control

signal startGame

var load_list = ["Back"]
@export var level_folder = "res://Assets/Levels"

func _ready():
	var dir = DirAccess.open(level_folder)
	if dir:
		dir.list_dir_begin()
		var file_name = dir.get_next()
		while file_name != "":
			load_list.append(file_name)
			$ItemList.add_item(file_name.replace(".tscn", ""),null,false)
			file_name = dir.get_next()
	
func _on_exit_pressed():
	get_tree().quit()


func _on_start_pressed():
	GlobalSettings.current_map = "res://Assets/Levels/TestMapHospitalTextures.tscn"
	emit_signal("startGame")

func _on_settings_pressed():
	pass # Replace with function body.


func _on_load_level_pressed():
	$VBoxContainer.hide()
	$ItemList.show()

func _on_item_list_item_clicked(index, at_position, mouse_button_index):
	if index == 0:
		$ItemList.hide()
		$VBoxContainer.show()
	else:
		GlobalSettings.current_map = "res://Assets/Levels/" + load_list[index]
		emit_signal("startGame")
