class_name Main
extends Node
## Main scene is our application's entry-point.
## Main acts like a Controller between its children Screens and Game in an attempt to adhere to the Model-View-Controller (MVC) pattern.

var is_in_game : bool = false

@onready var game: Node2D = $Game
@onready var screens: CanvasLayer = $Screens

#region 

func _ready() -> void:
	# Screens signals
	screens.game_started.connect(_on_game_started)
	screens.game_ended.connect(_on_game_ended)
	
	# Game signals
	game.player_failure.connect(_on_player_failure)
	game.player_success.connect(_on_player_success)
	game.game_paused.connect(_on_game_paused)
	
	
	# Play BGM
	# AudioManager.play_bgm(GameConstants.BGM_2)
	
#region SCREENS_SIGNAL_HANDLERS

func _on_game_started() -> void:
	is_in_game = true
	game.new_game()


func _on_game_ended() -> void:
	is_in_game = false
	game.reset_game()
	
#endregion

#region GAME_SIGNAL_HANDLERS

func _on_player_failure() -> void:
	is_in_game = false
	screens.failure()
	game.reset_game()


func _on_player_success() -> void:
	is_in_game = false
	screens.success()
	game.reset_game()


func _on_game_paused() -> void:
	screens.pause_game()
