extends Node

var pause_menu_res = preload('res://ui/pause_menu.tscn')
var pause_menu: PauseMenu

func _ready() -> void:
		pause_menu = pause_menu_res.instantiate()

func load_menu(initial: bool = false):
	if not initial: pause_game(false)
	SceneLoader.load_scene('res://ui/main_menu.tscn')

func start_new_game() -> void:
	SceneLoader.load_scene('res://scenes/world2.tscn')

func world_loaded(_world: World) -> void:
	Input.mouse_mode = Input.MOUSE_MODE_CAPTURED

func _unhandled_input(event: InputEvent) -> void:
	if event.is_action_pressed('ui_cancel'):
		pause_game(not get_tree().paused)

func quit_game():
	get_tree().quit()

func pause_game(pause = true):
	get_tree().paused = pause
	if pause: get_tree().root.add_child(pause_menu)
	else: pause_menu.get_parent().remove_child(pause_menu)
