added card attachment Ui and card removal

This commit is contained in:
2ManyProjects 2025-01-30 18:48:24 -06:00
parent 61e4cd88ba
commit a9f79d673c
8 changed files with 123 additions and 16 deletions

View file

@ -42,6 +42,8 @@ func drawCard():
if !deck.is_empty() && hand.size() < hand_size:
hand.append(deck.pop_back())
emit_signal("hand_updated", hand)
signal hand_updated
@ -51,8 +53,12 @@ signal hand_updated
func playCard(card: Card, target_piece: Pawn, board_flow = null, game_state = null):
if !hand.has(card):
return false
if card.duration > 0:
attached_cards[target_piece.get_instance_id()] = card
if card.apply_effect(target_piece, board_flow, game_state):
if card.duration > 0:
attached_cards[target_piece.get_instance_id()] = card
hand.erase(card)
emit_signal("hand_updated", hand)
@ -69,8 +75,6 @@ func playCard(card: Card, target_piece: Pawn, board_flow = null, game_state = nu
deck.append(card)
shuffleDeck()
if card.duration > 0:
attached_cards[target_piece.get_instance_id()] = card
return true
return false
@ -80,11 +84,20 @@ func updateCardDurations():
for piece_id in attached_cards:
var card = attached_cards[piece_id]
card.update_duration()
print("Card: ", card.id, " | ", card.card_name, " | ", card.remaining_turns)
if card.remaining_turns <= 0:
expired_cards.append(piece_id)
else:
var piece_node = instance_from_id(piece_id)
if is_instance_valid(piece_node):
piece_node.update_appearance()
for piece_id in expired_cards:
attached_cards.erase(piece_id)
var piece_node = instance_from_id(piece_id)
if is_instance_valid(piece_node):
piece_node.update_appearance()
# print("updateCardDurations", attached_cards)
# Shop functionality
func getShopCards(num_cards: int = 3) -> Array:

View file

@ -362,10 +362,11 @@ func resolveMoveEffects() -> void:
Turn = 1 if Turn == 0 else 0
updateTurnIndicator()
resetHighlights()
deckManager.updateCardDurations()
hasMoved = false
currentlyMovingPiece = null
func isPlayerTurn() -> bool:
return currentPlayer == WHITE
func resetHighlights():
for button in boardContainer.get_children():

View file

@ -17,7 +17,7 @@ func enter(_previous: String, _data := {}) -> void:
game.boardContainer.connect("tile_pressed", handleTilePressed)
timer.start(ATTACHMENT_PHASE_DURATION)
if game.deckManager.hand.is_empty():
if game.deckManager.hand.is_empty() or (game.currentPlayer == game.BLACK):
complete_attachment_phase()
func exit() -> void:
@ -46,7 +46,8 @@ func handleTilePressed(location: String) -> void:
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)
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:

View file

@ -2,7 +2,8 @@ extends "res://Systems/StateMachine/ChessGameState.gd"
func enter(_previous: String, _data := {}) -> void:
print("ENTERING STATE ", Constants.DRAW_PHASE)
# deckManager.drawCards()
if (game.isPlayerTurn()):
game.deckManager.drawCard()
finished.emit(Constants.PERSISTENT_EFFECTS)

View file

@ -1,9 +1,41 @@
extends "res://Systems/StateMachine/ChessGameState.gd"
func enter(_previous: String, _data := {}) -> void:
print("ENTERING STATE ", Constants.HAND_SETUP)
# prepareHand()
if (game.currentPlayer == game.BLACK):
finished.emit(Constants.DRAW_PHASE)
return
# game.deckManager.updateCardDurations();
finished.emit(Constants.DRAW_PHASE)
# Go through all attached cards and update their durations
# var expired_cards = []
# for piece_id in game.deckManager.attached_cards:
# var card = game.deckManager.attached_cards[piece_id]
# card.remaining_turns -= 1
# print("Card DUration ", card.remaining_turns);
# # If card duration is expired, add to removal list
# if card.remaining_turns <= 0:
# expired_cards.append(piece_id)
# # Update the piece's visual appearance to show new duration
# var piece_node = instance_from_id(piece_id)
# if is_instance_valid(piece_node):
# piece_node.update_appearance()
# # Remove all expired cards
# for piece_id in expired_cards:
# var piece_node = instance_from_id(piece_id)
# if is_instance_valid(piece_node):
# piece_node.update_appearance() # Update appearance one final time
# game.deckManager.attached_cards.erase(piece_id)
# Move to draw phase
# finished.emit(Constants.DRAW_PHASE)
# func prepareHand() -> void:
# if deckManager.hand.size() < 5:

View file

@ -18,7 +18,7 @@ func exit() -> void:
game.boardContainer.disconnect("tile_pressed", handleMovement)
func handleMovement(location: String) -> void:
print("HANDLING MOVEMENT ", location)
# print("HANDLING MOVEMENT ", location)
var node = game.get_node("Flow/" + location)
if game.selectedNode == "":
if node.get_child_count() != 0 && node.get_child(0).Item_Color == game.Turn:

View file

@ -3,4 +3,7 @@ extends "res://Systems/StateMachine/ChessGameState.gd"
func enter(_previous: String, _data := {}) -> void:
print("ENTERING STATE ", Constants.POST_MOVE)
# game.resolveMoveEffects()
if (game.isPlayerTurn()):
game.deckManager.updateCardDurations()
finished.emit(Constants.EVALUATE_POSITION)

View file

@ -11,22 +11,78 @@ class_name Pawn
@export var Points = 1
var attached_card_label: Label
var duration_label: Label
var Temp_Color = 0
var Double_Start = true
var En_Passant = false
const BASE_SIZE = Vector2(40, 40)
const EFFECT_TINT_COLOR = Color(0.3, 0.8, 0.3, 0.5) # Green tint for card effects
func _ready():
modulate = Color.WHITE if Item_Color == 0 else Color.BLACK
func _init() -> void:
self.texture = load("res://addons/Chess/Textures/WPawn.svg")
var background_style = StyleBoxFlat.new()
background_style.bg_color = Color.WHITE
background_style.corner_radius_top_left = 2
background_style.corner_radius_top_right = 2
background_style.corner_radius_bottom_left = 2
background_style.corner_radius_bottom_right = 2
background_style.content_margin_left = 2
background_style.content_margin_right = 2
background_style.content_margin_top = 1
background_style.content_margin_bottom = 1
duration_label = Label.new()
duration_label.add_theme_stylebox_override("normal", background_style)
duration_label.add_theme_color_override("font_color", Color.BLACK)
duration_label.position = Vector2(-20, -20) # Position above the piece
add_child(duration_label)
duration_label.hide()
func _process(_delta):
if Item_Color != Temp_Color:
Temp_Color = Item_Color
if Item_Color == 0:
self.texture = load("res://addons/Chess/Textures/WPawn.svg")
elif Item_Color == 1:
self.texture = load("res://addons/Chess/Textures/BPawn.svg")
# func _process(_delta):
# if Item_Color != Temp_Color:
# Temp_Color = Item_Color
# if Item_Color == 0:
# self.texture = load("res://addons/Chess/Textures/WPawn.svg")
# elif Item_Color == 1:
# self.texture = load("res://addons/Chess/Textures/BPawn.svg")
func update_appearance() -> void:
print("update_appearance")
if !is_instance_valid(get_tree()) || !get_tree().get_root().has_node("Board"):
return
var chess_game = get_tree().get_root().get_node("Board")
if !chess_game.deckManager:
return
var deck_manager = chess_game.deckManager
var has_card = deck_manager.attached_cards.has(get_instance_id())
if has_card:
# Apply tint while keeping the piece color
var base_color = Color.WHITE if Item_Color == 0 else Color.BLACK
modulate = base_color * EFFECT_TINT_COLOR
# Update duration display
var card = deck_manager.attached_cards[get_instance_id()]
if is_instance_valid(duration_label):
duration_label.text = str(card.remaining_turns)
duration_label.show()
else:
# Reset to normal color
modulate = Color.WHITE if Item_Color == 0 else Color.BLACK
if is_instance_valid(duration_label):
duration_label.hide()
func on_card_effect_changed() -> void:
update_appearance()
# Movement interface method that all pieces will implement
# In Pawn.gd
func getValidMoves(board_flow, current_location: String) -> Dictionary: