45 lines
No EOL
1.2 KiB
GDScript
45 lines
No EOL
1.2 KiB
GDScript
class_name Game extends Node
|
|
|
|
|
|
@onready var menuContainer = $MenuContainer
|
|
@onready var chessGame = $ChessGame
|
|
@onready var stateMachine = $StateMachine
|
|
|
|
func _ready():
|
|
if menuContainer:
|
|
menuContainer.visible = true
|
|
|
|
if chessGame:
|
|
chessGame.visible = false
|
|
|
|
if menuContainer and menuContainer.has_signal("new_game_requested"):
|
|
menuContainer.connect("new_game_requested", Callable(self, "_on_new_game_started"))
|
|
|
|
func _on_new_game_started():
|
|
print("Starting new game...")
|
|
|
|
if chessGame:
|
|
chessGame.visible = true
|
|
|
|
|
|
if !chessGame.is_inside_tree():
|
|
await chessGame.ready
|
|
|
|
_start_game_logic()
|
|
|
|
func _start_game_logic():
|
|
if stateMachine and stateMachine.has_method("transitionToNextState"):
|
|
stateMachine.transitionToNextState(Constants.WHITE_TURN)
|
|
|
|
|
|
func _unhandled_input(event):
|
|
if event is InputEventKey:
|
|
if event.pressed and event.keycode == KEY_ESCAPE:
|
|
_toggle_menu()
|
|
|
|
func _toggle_menu():
|
|
if menuContainer:
|
|
menuContainer.visible = !menuContainer.visible
|
|
|
|
if menuContainer.visible and chessGame:
|
|
pass |