extends Control

func _ready() -> void:
	load_settings()
	
func load_settings():
	var config = ConfigFile.new()
	var err = config.load("user://settings.cfg")
	if err == OK:
		# Load resolution
		var width = config.get_value("screen", "width", -1)
		var height = config.get_value("screen", "height", -1)
		var res_to_set = null
		if width != -1 and height != -1:
			res_to_set = Vector2i(width, height)

		var mode = config.get_value("screen", "mode", 0)  # Default to 0 = Windowed

		match mode:
			0:  # Windowed
				DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
			1:  # Fullscreen
				DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)
			2:  # Borderless / Exclusive fullscreen
				DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_EXCLUSIVE_FULLSCREEN)

		# Apply screen size only if mode is not Fullscreen, and resolution is valid
		if mode != 1 and res_to_set != null:
			DisplayServer.window_set_size(res_to_set)



func _on_button_pressed() -> void:
	get_tree().change_scene_to_file("res://Game/Menu/mapselector.tscn")


func _on_button_2_pressed() -> void:
	get_tree().change_scene_to_file("res://Game/Menu/options.tscn")
	pass # Replace with function body.

func _on_button_3_pressed() -> void:
	get_tree().quit()
	pass # Replace with function body.
