class_name Game extends Node # This script can be attached to your main Game node that contains both # the menu and the chess game components @onready var menuContainer = $MenuContainer @onready var chessGame = $ChessGame @onready var stateMachine = $StateMachine func _ready(): # Show menu on startup if menuContainer: menuContainer.visible = true # Hide chess game initially if chessGame: chessGame.visible = false # Connect menu signals 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...") # Show chess game if chessGame: chessGame.visible = true # You can add additional game initialization logic here if needed # For example, configuring game options based on menu selections # Ensure the chess game is properly initialized if !chessGame.is_inside_tree(): await chessGame.ready # Start game logic _start_game_logic() func _start_game_logic(): # If StateMachine is already initialized in the Chess game, this may not be needed if stateMachine and stateMachine.has_method("transitionToNextState"): stateMachine.transitionToNextState(Constants.WHITE_TURN) # Add any additional game start logic here # If you need to open a specific scene or create nodes dynamically: # var chess_scene = load("res://Scenes/ChessGame.tscn").instantiate() # add_child(chess_scene) # Handle escape key to show menu during game 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 # Optional: Pause game when menu is visible if menuContainer.visible and chessGame: # You might want to pause the game or disable input pass