extends "res://Systems/StateMachine/ChessGameState.gd" const ATTACHMENT_PHASE_DURATION = 30 # Duration in seconds var timer: Timer var tile_pressed_connection: Signal func _ready() -> void: super._ready() timer = Timer.new() timer.one_shot = true timer.timeout.connect(_on_timer_timeout) add_child(timer) func enter(_previous: String, _data := {}) -> void: print("ENTERING STATE ", Constants.ATTACH_CARDS) if !game.boardContainer.is_connected("tile_pressed", handleTilePressed): game.boardContainer.connect("tile_pressed", handleTilePressed) timer.start(ATTACHMENT_PHASE_DURATION) if game.deckManager.hand.is_empty() or (game.currentPlayer == game.BLACK): complete_attachment_phase() func exit() -> void: if game.boardContainer.is_connected("tile_pressed", handleTilePressed): game.boardContainer.disconnect("tile_pressed", handleTilePressed) game.cardDisplay.selected_card = null game.selectedNode = "" game.resetHighlights() func handleTilePressed(location: String) -> void: print("HANDLING Tile PRESSED ", location) var targetNode = game.get_node("Flow/" + location) if targetNode.get_child_count() == 0: return var piece = targetNode.get_child(0) var selectedCard = game.cardDisplay.get_selected_card() if selectedCard and piece: var isCorrectColor = (piece.Item_Color == 0 and game.currentPlayer == game.WHITE) or \ (piece.Item_Color == 1 and game.currentPlayer == game.BLACK) if isCorrectColor and selectedCard.can_attach_to_piece(piece) and \ !game.deckManager.attached_cards.has(piece.get_instance_id()): if game.deckManager.playCard(selectedCard, piece, game.boardContainer, game): print("Successfully attached card ", selectedCard.card_name, " to ", piece.name, " at ", location) piece.on_card_effect_changed() if game.deckManager.hand.is_empty(): complete_attachment_phase() else: print("Failed to attach card") func _on_timer_timeout() -> void: print("Card attachment phase timed out") finished.emit(Constants.APPLY_CARD_EFFECTS) func complete_attachment_phase() -> void: if timer.time_left > 0: timer.stop() _on_timer_timeout()