From 7df56f585597a20b65f1f28c1bad095c4b84c56d Mon Sep 17 00:00:00 2001 From: 2ManyProjects Date: Sun, 9 Mar 2025 12:03:01 -0500 Subject: [PATCH] fixed various selection bugs --- Systems/Game/ChessGame.gd | 4 +- Systems/StateMachine/GameStates/Movement.gd | 50 ++++++++++++++------- 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/Systems/Game/ChessGame.gd b/Systems/Game/ChessGame.gd index f68187d..54bc0dc 100644 --- a/Systems/Game/ChessGame.gd +++ b/Systems/Game/ChessGame.gd @@ -676,7 +676,7 @@ func clearSelection() : func getMovableAreas() -> void: # Get all valid moves for the selected piece - print("HIGHLIGHTING getMovableAreas 1", selectedNode) + print("HIGHLIGHTING getMovableAreas ", selectedNode) resetHighlights() areas.clear() specialArea.clear() @@ -696,8 +696,8 @@ func getMovableAreas() -> void: cardPreview.update_moves_remaining(moves_left) else: cardPreview.hide_preview() - # print("HIGHLIGHTING getMovableAreas 3") var moves = piece.getValidMoves(boardContainer, selectedNode) + print("HIGHLIGHTING getMovableAreas ", moves) areas = moves.regular_moves specialArea = moves.special_moves # print("HIGHLIGHTING getMovableAreas 4") diff --git a/Systems/StateMachine/GameStates/Movement.gd b/Systems/StateMachine/GameStates/Movement.gd index f792b09..b51c2a3 100644 --- a/Systems/StateMachine/GameStates/Movement.gd +++ b/Systems/StateMachine/GameStates/Movement.gd @@ -77,6 +77,10 @@ func handleMovement(location: String, generated: bool = false) -> void: # maybe once u start nmoving a peice global stat var is set # and any moving peice needs ot match that print("HANDLING MOVEMENT ", location, " | ", last_selected, " | ", game.selectedNode) + + + + var node = game.get_node("Flow/" + location) as PieceContainer var prev_last_selected = last_selected if !generated : @@ -85,7 +89,13 @@ func handleMovement(location: String, generated: bool = false) -> void: else: if game.selectedNode == location: last_selected = null - var moves = null; + var moves = { + "regular_moves": game.areas, + "special_moves": game.specialArea + } + + # areas = moves.regular_moves + # specialArea = moves.special_moves # Only try to get piece if we have a selected node if game.selectedNode == "": # print("No Node") @@ -100,15 +110,13 @@ func handleMovement(location: String, generated: bool = false) -> void: # else: # moves = (game.get_node("Flow/" + game.selectedNode) as PieceContainer).get_piece().getValidMoves(game.boardContainer, location) var sourcePiece = node.get_piece() - if sourcePiece: - moves = sourcePiece.getValidMoves(game.boardContainer, location) + # if sourcePiece: + # moves = sourcePiece.getValidMoves(game.boardContainer, location) - if !(location == game.selectedNode): - if !generated and moves != null and !moves.regular_moves.has(game.selectedNode) and !moves.special_moves.has(game.selectedNode): - last_selected = prev_last_selected - print("Invalid Choice") - return + # if !(location == game.selectedNode): + + # print("Valid Choice ", moves) # Now we know we have a selected node, get its piece var sourceContainer = game.get_node("Flow/" + game.selectedNode) as PieceContainer var piece = sourceContainer.get_piece() @@ -122,7 +130,23 @@ func handleMovement(location: String, generated: bool = false) -> void: var piece_id = piece.get_instance_id() var is_multi_moving = piece_id in moves_remaining and moves_remaining[piece_id] > 1 - + if !generated and moves != null and !moves.regular_moves.has(location) and !moves.special_moves.has(location) and !(game.selectedNode == location and location == prev_last_selected): + last_selected = prev_last_selected + print("Invalid Choice ", moves) + if isReselectMove(node): + if !is_multi_moving and multiMoving == "": + print("RESELECT SELECTION*************") + game.selectedNode = location + game.getMovableAreas() + return + + if game.selectedNode == location and location == prev_last_selected: + # print("CAN CLEAR SELECTION************* ", multiMoving, " !is_multi_moving ", !is_multi_moving) + if !is_multi_moving and multiMoving == "": + print("CLEAR SELECTION*************") + game.clearSelection() + return + return if multiMoving.length() > 0: @@ -153,13 +177,7 @@ func handleMovement(location: String, generated: bool = false) -> void: # finished.emit(Constants.POST_MOVE) - if game.selectedNode == location: - if !is_multi_moving and multiMoving == "": - print("CLEAR SELECTION*************") - game.clearSelection() - return - return - elif moves != null and !moves.regular_moves.has(game.selectedNode) and !moves.special_moves.has(game.selectedNode): + if moves != null and !moves.regular_moves.has(game.selectedNode) and !moves.special_moves.has(game.selectedNode): if sourcePiece and sourcePiece.Item_Color == piece.Item_Color: # print("Set Location*************") game.selectedNode = location