extends Node3D

enum GameState { MAIN_MENU, GAME, LOSS, SUCCESS }
var current_game_state: GameState = GameState.MAIN_MENU
var manager

func _ready():
	$MainMenu.main_menu_interacted.connect(_on_main_menu_interacted)

func transition():
	if current_game_state == GameState.MAIN_MENU:
		current_game_state = GameState.GAME
		%MenuMusic.stop()
		%BackGroundMusic.play()
	elif current_game_state == GameState.GAME:
		current_game_state = GameState.LOSS
		manager.queue_free()
		%BackGroundMusic.stop()
		%TheEndSound.play()
		$ScrollingBackgroundEngine.end_it()
	elif current_game_state == GameState.LOSS:
		current_game_state = GameState.GAME
		%MenuMusic.stop()
		%BackGroundMusic.play()

func _on_main_menu_interacted():
	transition()
	add_child(manager)
	manager.failed.connect(_on_loss)

func _on_loss():
	transition()

func _reload_self():
	get_tree().reload_current_scene()
