debugging preselected moves
This commit is contained in:
parent
98a56d9e5e
commit
6949893fea
4 changed files with 97 additions and 84 deletions
|
|
@ -1,127 +1,128 @@
|
||||||
class_name SupernovaCard extends Card
|
class_name SupernovaCard extends Card
|
||||||
|
|
||||||
const CAPTURE_RADIUS = 3
|
const CAPTURE_RADIUS = 4
|
||||||
var valid = false;
|
|
||||||
func _init():
|
func _init():
|
||||||
duration = 5
|
|
||||||
super._init()
|
super._init()
|
||||||
cardName = "Supernova"
|
cardName = "Supernova"
|
||||||
rank = Rank.RANK_0
|
rank = Rank.RANK_0
|
||||||
effectType = EffectType.PIECE_EFFECT
|
effectType = EffectType.PIECE_EFFECT
|
||||||
description = "All enemy units within 3 radius of the king are captured"
|
duration = 5
|
||||||
|
description = "All enemy units within 4 radius are captured"
|
||||||
unitWhitelist = ["King"]
|
unitWhitelist = ["King"]
|
||||||
remaining_turns = duration
|
|
||||||
|
|
||||||
func apply_effect(target_piece = null, board_flow = null, game_state = null):
|
func apply_effect(target_piece = null, board_flow = null, game_state = null):
|
||||||
attached_piece = target_piece
|
if !super.apply_effect(target_piece, board_flow, game_state):
|
||||||
if !target_piece or !board_flow or !game_state:
|
|
||||||
print(cardName, " missing input param ")
|
|
||||||
return false
|
return false
|
||||||
setup_persistent_effect(game_state)
|
|
||||||
# dont apply on card attachment
|
|
||||||
if !valid:
|
|
||||||
return true
|
|
||||||
|
|
||||||
|
if !target_piece or !board_flow or !game_state:
|
||||||
|
return false
|
||||||
|
|
||||||
|
# Get king's position
|
||||||
var king_pos = target_piece.get_parent().name.split("-")
|
var king_pos = target_piece.get_parent().name.split("-")
|
||||||
var king_x = int(king_pos[0])
|
var king_x = int(king_pos[0])
|
||||||
var king_y = int(king_pos[1])
|
var king_y = int(king_pos[1])
|
||||||
|
|
||||||
|
# Collect all tiles within radius to check
|
||||||
var tiles_to_check = []
|
var tiles_to_check = []
|
||||||
|
|
||||||
|
# Check in all directions (up, down, left, right and diagonals)
|
||||||
for dx in range(-CAPTURE_RADIUS, CAPTURE_RADIUS + 1):
|
for dx in range(-CAPTURE_RADIUS, CAPTURE_RADIUS + 1):
|
||||||
for dy in range(-CAPTURE_RADIUS, CAPTURE_RADIUS + 1):
|
for dy in range(-CAPTURE_RADIUS, CAPTURE_RADIUS + 1):
|
||||||
|
# Skip if outside Manhattan distance
|
||||||
if abs(dx) + abs(dy) > CAPTURE_RADIUS:
|
if abs(dx) + abs(dy) > CAPTURE_RADIUS:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# Calculate target coordinates
|
||||||
var target_x = king_x + dx
|
var target_x = king_x + dx
|
||||||
var target_y = king_y + dy
|
var target_y = king_y + dy
|
||||||
|
|
||||||
|
# Skip if outside board bounds
|
||||||
if target_x < 0 or target_x >= 8 or target_y < 0 or target_y >= 8:
|
if target_x < 0 or target_x >= 8 or target_y < 0 or target_y >= 8:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# Skip king's own position
|
||||||
if dx == 0 and dy == 0:
|
if dx == 0 and dy == 0:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# Add tile to check list
|
||||||
tiles_to_check.append(str(target_x) + "-" + str(target_y))
|
tiles_to_check.append(str(target_x) + "-" + str(target_y))
|
||||||
|
|
||||||
# Process tiles and add overlay
|
# Process each tile and capture pieces
|
||||||
for tile_name in tiles_to_check:
|
for tile_name in tiles_to_check:
|
||||||
var tile = board_flow.get_node(tile_name)
|
var tile = board_flow.get_node("Flow/" + tile_name)
|
||||||
|
if tile.get_child_count() > 0:
|
||||||
var existing_overlay = tile.get_node_or_null("SupernovaOverlay")
|
|
||||||
if existing_overlay:
|
|
||||||
existing_overlay.queue_free()
|
|
||||||
|
|
||||||
var overlay = ColorRect.new()
|
|
||||||
overlay.name = "SupernovaOverlay"
|
|
||||||
overlay.color = Color(1, 0, 0, 0.3)
|
|
||||||
overlay.size = tile.size
|
|
||||||
overlay.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
||||||
tile.add_child(overlay)
|
|
||||||
overlay.show()
|
|
||||||
|
|
||||||
if tile.get_child_count() > 1: # > 1 because we just added the overlay
|
|
||||||
var piece = tile.get_child(0)
|
var piece = tile.get_child(0)
|
||||||
if piece.Item_Color != target_piece.Item_Color:
|
if piece.Item_Color != target_piece.Item_Color: # Only capture enemy pieces
|
||||||
game_state.updatePoints(piece)
|
game_state.updatePoints(piece)
|
||||||
piece.queue_free()
|
piece.queue_free()
|
||||||
|
|
||||||
# Setup timer to remove overlays
|
# Visual feedback
|
||||||
var timer = Timer.new()
|
|
||||||
board_flow.add_child(timer)
|
|
||||||
timer.wait_time = 0.5
|
|
||||||
timer.one_shot = true
|
|
||||||
timer.timeout.connect(func():
|
|
||||||
for tile_name in tiles_to_check:
|
|
||||||
var tile = board_flow.get_node(tile_name)
|
|
||||||
var overlay = tile.get_node_or_null("SupernovaOverlay")
|
|
||||||
if overlay:
|
|
||||||
overlay.queue_free()
|
|
||||||
timer.queue_free()
|
|
||||||
)
|
|
||||||
timer.start()
|
|
||||||
|
|
||||||
return true
|
|
||||||
|
|
||||||
func reset_tile_styles(board_flow, tiles_to_check):
|
|
||||||
for tile_name in tiles_to_check:
|
for tile_name in tiles_to_check:
|
||||||
var tile = board_flow.get_node(tile_name)
|
var tile = board_flow.get_node("Flow/" + tile_name)
|
||||||
if !tile:
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Reset to original chess board pattern
|
|
||||||
var coords = tile_name.split("-")
|
|
||||||
var isWhite = (int(coords[0]) + int(coords[1])) % 2 == 0
|
|
||||||
var style = StyleBoxFlat.new()
|
var style = StyleBoxFlat.new()
|
||||||
style.bg_color = Color(0.8, 0.8, 0.8, 1) if isWhite else Color(0.2, 0.2, 0.2, 1)
|
style.bg_color = Color(1, 0, 0, 0.3) # Red tint
|
||||||
tile.add_theme_stylebox_override("normal", style)
|
tile.add_theme_stylebox_override("normal", style)
|
||||||
|
|
||||||
|
# Remove highlight after delay
|
||||||
|
var timer = Timer.new()
|
||||||
|
board_flow.add_child(timer)
|
||||||
|
timer.wait_time = 0.5
|
||||||
|
timer.one_shot = true
|
||||||
|
timer.timeout.connect(func():
|
||||||
|
tile.remove_theme_stylebox_override("normal")
|
||||||
|
timer.queue_free()
|
||||||
|
)
|
||||||
|
timer.start()
|
||||||
|
|
||||||
func setup_persistent_effect(game_state):
|
# game_state.stateMachine.transitionToNextState(Constants.POST_MOVE)
|
||||||
|
return true
|
||||||
|
func setup_persistent_effect(king, game_state):
|
||||||
# Connect to the turn change signal if not already connected
|
# Connect to the turn change signal if not already connected
|
||||||
if !game_state.is_connected("turn_changed", on_turn_changed):
|
if !game_state.is_connected("turn_changed", Callable(self, "on_turn_changed")):
|
||||||
game_state.connect("turn_changed", on_turn_changed)
|
game_state.connect("turn_changed", Callable(self, "on_turn_changed"))
|
||||||
|
|
||||||
func on_turn_changed():
|
func on_turn_changed():
|
||||||
# print("TURN CHANGED ==================", attached_piece, " | ", remaining_turns, )
|
if attached_piece and remaining_turns > 0:
|
||||||
|
# Reapply the effect at the start of each turn
|
||||||
if attached_piece.get_parent().get_parent().owner.isPlayerTurn() and attached_piece and remaining_turns > 0:
|
apply_effect(attached_piece, attached_piece.get_parent().get_parent(), attached_piece.get_parent().get_parent().owner)
|
||||||
# print(attached_piece.get_parent().get_parent(), attached_piece.get_parent().get_parent().owner)
|
remaining_turns -= 1
|
||||||
var piece = attached_piece
|
if remaining_turns <= 0:
|
||||||
var flow = attached_piece.get_parent().get_parent()
|
remove_effect()
|
||||||
var state = attached_piece.get_parent().get_parent().owner
|
|
||||||
|
|
||||||
# print("Debug values:")
|
|
||||||
# print("- Piece: ", piece, " is null? ", piece == null)
|
|
||||||
# print("- Board Flow: ", flow, " is null? ", flow == null)
|
|
||||||
# print("- Game State: ", state, " is null? ", state == null)
|
|
||||||
|
|
||||||
# Now try apply_effect with these values
|
|
||||||
valid = true
|
|
||||||
apply_effect(piece, flow, state)
|
|
||||||
|
|
||||||
func remove_effect():
|
func remove_effect():
|
||||||
if attached_piece:
|
if attached_piece:
|
||||||
var game_state = attached_piece.get_parent().get_parent().owner
|
var game_state = attached_piece.get_parent().get_parent().owner
|
||||||
if game_state.is_connected("turn_changed", on_turn_changed):
|
if game_state.is_connected("turn_changed", Callable(self, "on_turn_changed")):
|
||||||
game_state.disconnect("turn_changed", on_turn_changed)
|
game_state.disconnect("turn_changed", Callable(self, "on_turn_changed"))
|
||||||
super.remove_effect()
|
super.remove_effect()
|
||||||
|
|
||||||
|
func update_visual_effect(king, board_flow):
|
||||||
|
# Could be extended with visual feedback like particles or highlighting
|
||||||
|
var radius_tiles = []
|
||||||
|
var king_pos = king.get_parent().name.split("-")
|
||||||
|
var king_x = int(king_pos[0])
|
||||||
|
var king_y = int(king_pos[1])
|
||||||
|
|
||||||
|
for x in range(max(0, king_x - CAPTURE_RADIUS), min(8, king_x + CAPTURE_RADIUS + 1)):
|
||||||
|
for y in range(max(0, king_y - CAPTURE_RADIUS), min(8, king_y + CAPTURE_RADIUS + 1)):
|
||||||
|
if abs(x - king_x) + abs(y - king_y) <= CAPTURE_RADIUS:
|
||||||
|
var tile_name = str(x) + "-" + str(y)
|
||||||
|
radius_tiles.append(board_flow.get_node(tile_name))
|
||||||
|
|
||||||
|
# Highlight affected tiles briefly
|
||||||
|
for tile in radius_tiles:
|
||||||
|
var style = StyleBoxFlat.new()
|
||||||
|
style.bg_color = Color(1, 0, 0, 0.3) # Red tint
|
||||||
|
tile.add_theme_stylebox_override("normal", style)
|
||||||
|
|
||||||
|
# Remove highlight after a short delay
|
||||||
|
var timer = Timer.new()
|
||||||
|
board_flow.add_child(timer)
|
||||||
|
timer.wait_time = 0.5
|
||||||
|
timer.one_shot = true
|
||||||
|
timer.timeout.connect(func():
|
||||||
|
tile.remove_theme_stylebox_override("normal")
|
||||||
|
timer.queue_free()
|
||||||
|
)
|
||||||
|
timer.start()
|
||||||
|
|
|
||||||
|
|
@ -302,12 +302,14 @@ func resetBoard() -> void:
|
||||||
updateTurnIndicator()
|
updateTurnIndicator()
|
||||||
|
|
||||||
func getMovableAreas() -> void:
|
func getMovableAreas() -> void:
|
||||||
|
# print("HIGHLIGHTING getMovableAreas 1")
|
||||||
resetHighlights()
|
resetHighlights()
|
||||||
areas.clear()
|
areas.clear()
|
||||||
specialArea.clear()
|
specialArea.clear()
|
||||||
|
|
||||||
var piece = get_node("Flow/" + selectedNode).get_child(0)
|
var piece = get_node("Flow/" + selectedNode).get_child(0)
|
||||||
var piece_id = piece.get_instance_id()
|
var piece_id = piece.get_instance_id()
|
||||||
|
# print("HIGHLIGHTING getMovableAreas 2")
|
||||||
if deckManager.attached_cards.has(piece_id):
|
if deckManager.attached_cards.has(piece_id):
|
||||||
var card = deckManager.attached_cards[piece_id]
|
var card = deckManager.attached_cards[piece_id]
|
||||||
cardPreview.show_card_preview(card)
|
cardPreview.show_card_preview(card)
|
||||||
|
|
@ -318,12 +320,15 @@ func getMovableAreas() -> void:
|
||||||
cardPreview.update_moves_remaining(moves_left)
|
cardPreview.update_moves_remaining(moves_left)
|
||||||
else:
|
else:
|
||||||
cardPreview.hide_preview()
|
cardPreview.hide_preview()
|
||||||
|
# print("HIGHLIGHTING getMovableAreas 3")
|
||||||
var moves = piece.getValidMoves(boardContainer, selectedNode)
|
var moves = piece.getValidMoves(boardContainer, selectedNode)
|
||||||
areas = moves.regular_moves
|
areas = moves.regular_moves
|
||||||
specialArea = moves.special_moves
|
specialArea = moves.special_moves
|
||||||
|
# print("HIGHLIGHTING getMovableAreas 4")
|
||||||
highlightValidMoves()
|
highlightValidMoves()
|
||||||
|
|
||||||
func highlightValidMoves() -> void:
|
func highlightValidMoves() -> void:
|
||||||
|
# print("HIGHLIGHTING VALID MOVES")
|
||||||
for move in areas:
|
for move in areas:
|
||||||
var button = boardContainer.get_node(move)
|
var button = boardContainer.get_node(move)
|
||||||
var isWhiteSquare = (int(move.split("-")[0]) + int(move.split("-")[1])) % 2 == 0
|
var isWhiteSquare = (int(move.split("-")[0]) + int(move.split("-")[1])) % 2 == 0
|
||||||
|
|
|
||||||
|
|
@ -28,9 +28,9 @@ func exit() -> void:
|
||||||
if game.boardContainer.is_connected("tile_pressed", handleTilePressed):
|
if game.boardContainer.is_connected("tile_pressed", handleTilePressed):
|
||||||
game.boardContainer.disconnect("tile_pressed", handleTilePressed)
|
game.boardContainer.disconnect("tile_pressed", handleTilePressed)
|
||||||
|
|
||||||
game.cardDisplay.selectedCard = null
|
# game.cardDisplay.selectedCard = null
|
||||||
game.selectedNode = ""
|
# game.selectedNode = ""
|
||||||
game.resetHighlights()
|
# game.resetHighlights()
|
||||||
|
|
||||||
func handleTilePressed(location: String) -> void:
|
func handleTilePressed(location: String) -> void:
|
||||||
# print("HANDLING Tile PRESSED ", location)
|
# print("HANDLING Tile PRESSED ", location)
|
||||||
|
|
@ -40,7 +40,13 @@ func handleTilePressed(location: String) -> void:
|
||||||
return
|
return
|
||||||
|
|
||||||
var piece = targetNode.get_child(0)
|
var piece = targetNode.get_child(0)
|
||||||
|
var piece_id = piece.get_instance_id()
|
||||||
var selectedCard = game.cardDisplay.getSelectedCard()
|
var selectedCard = game.cardDisplay.getSelectedCard()
|
||||||
|
if game.deckManager.attached_cards.has(piece_id):
|
||||||
|
var card = game.deckManager.attached_cards[piece_id]
|
||||||
|
game.cardPreview.show_card_preview(card)
|
||||||
|
else:
|
||||||
|
game.cardPreview.hide_preview()
|
||||||
|
|
||||||
if selectedCard and piece:
|
if selectedCard and piece:
|
||||||
var isCorrectColor = (piece.Item_Color == 0 and game.currentPlayer == game.WHITE) or \
|
var isCorrectColor = (piece.Item_Color == 0 and game.currentPlayer == game.WHITE) or \
|
||||||
|
|
|
||||||
|
|
@ -11,9 +11,10 @@ func enter(_previous: String, _data := {}) -> void:
|
||||||
if !game.boardContainer.is_connected("tile_pressed", handleMovement):
|
if !game.boardContainer.is_connected("tile_pressed", handleMovement):
|
||||||
print("Connecting tile_pressed signal")
|
print("Connecting tile_pressed signal")
|
||||||
game.boardContainer.connect("tile_pressed", handleMovement)
|
game.boardContainer.connect("tile_pressed", handleMovement)
|
||||||
game.resetHighlights()
|
|
||||||
if game.selectedNode != "":
|
if game.selectedNode != "":
|
||||||
game.getMovableAreas()
|
game.getMovableAreas()
|
||||||
|
else:
|
||||||
|
game.resetHighlights()
|
||||||
|
|
||||||
moves_remaining.clear()
|
moves_remaining.clear()
|
||||||
multiMoving = ""
|
multiMoving = ""
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue