extends Node

var config: Config = Config.new("config")

func _ready() -> void: 
	config.load()
	toggle_fullscreen()

func _process(_delta: float) -> void:
	if Input.is_action_just_pressed("fullscreen"):
		config.fullscreen = !config.fullscreen
		config.save()
		toggle_fullscreen()

func _notification(what: int) -> void:
	if what == Window.NOTIFICATION_APPLICATION_FOCUS_OUT:
		Input.mouse_mode = Input.MOUSE_MODE_VISIBLE

func toggle_fullscreen() -> void:
	if config.fullscreen:
		if OS.get_name() == "Windows":
			DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_EXCLUSIVE_FULLSCREEN)
		else:
			DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)
	else:
		DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
