fixed various selection bugs

This commit is contained in:
2ManyProjects 2025-03-09 12:03:01 -05:00
parent ef6cee7883
commit 7df56f5855
2 changed files with 36 additions and 18 deletions

View file

@ -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")

View file

@ -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