implemnting double move card
This commit is contained in:
parent
a9f79d673c
commit
396298b492
11 changed files with 297 additions and 134 deletions
|
|
@ -9,15 +9,15 @@ enum EffectType {
|
|||
SPECIAL_ACTION
|
||||
}
|
||||
|
||||
var card_name: String
|
||||
var cardName: String
|
||||
var rank: Rank
|
||||
var description: String
|
||||
var duration: int = 0
|
||||
var attached_piece: Pawn = null
|
||||
var burned: bool = false
|
||||
var effect_type: EffectType
|
||||
var effectType: EffectType
|
||||
var remaining_turns: int = 0
|
||||
var unit_whitelist: Array[String] = [] # List of piece types this card can be attached to
|
||||
var unitWhitelist: Array[String] = [] # List of piece types this card can be attached to
|
||||
var id: String = Utils.generate_guid()
|
||||
|
||||
func _init():
|
||||
|
|
@ -25,9 +25,9 @@ func _init():
|
|||
# print(id)
|
||||
|
||||
func can_attach_to_piece(piece: Pawn) -> bool:
|
||||
if unit_whitelist.is_empty():
|
||||
if unitWhitelist.is_empty():
|
||||
return true
|
||||
return unit_whitelist.has(piece.name)
|
||||
return unitWhitelist.has(piece.name)
|
||||
|
||||
func apply_effect(target_piece = null, board_flow = null, game_state = null):
|
||||
if burned || (target_piece && !can_attach_to_piece(target_piece)):
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
extends Control
|
||||
class_name CardDisplay
|
||||
|
||||
var card_displays = []
|
||||
var selected_card = null
|
||||
var cardDisplays = []
|
||||
var selectedCard = null
|
||||
const CARD_WIDTH = 150
|
||||
const CARD_HEIGHT = 250
|
||||
const CARD_MARGIN = 10
|
||||
|
|
@ -16,61 +16,59 @@ func _ready():
|
|||
|
||||
func update_hand(hand: Array):
|
||||
clear_cards()
|
||||
print("update_hand")
|
||||
for card in hand:
|
||||
print(card.id)
|
||||
add_card_display(card)
|
||||
|
||||
func add_card_display(card):
|
||||
var card_panel = PanelContainer.new()
|
||||
card_panel.custom_minimum_size = Vector2(CARD_WIDTH, CARD_HEIGHT)
|
||||
var cardPanel = PanelContainer.new()
|
||||
cardPanel.custom_minimum_size = Vector2(CARD_WIDTH, CARD_HEIGHT)
|
||||
|
||||
var vbox = VBoxContainer.new()
|
||||
vbox.set_meta("card_id", card.id)
|
||||
card_panel.add_child(vbox)
|
||||
cardPanel.add_child(vbox)
|
||||
|
||||
var name_label = Label.new()
|
||||
name_label.text = card.card_name
|
||||
name_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
vbox.add_child(name_label)
|
||||
var nameLabel = Label.new()
|
||||
nameLabel.text = card.cardName
|
||||
nameLabel.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
vbox.add_child(nameLabel)
|
||||
|
||||
var rank_label = Label.new()
|
||||
rank_label.text = "Rank " + str(card.rank)
|
||||
rank_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
vbox.add_child(rank_label)
|
||||
var rankLabel = Label.new()
|
||||
rankLabel.text = "Rank " + str(card.rank)
|
||||
rankLabel.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
vbox.add_child(rankLabel)
|
||||
|
||||
var desc_label = Label.new()
|
||||
desc_label.text = card.description
|
||||
desc_label.autowrap_mode = TextServer.AUTOWRAP_WORD
|
||||
desc_label.custom_minimum_size = Vector2(CARD_WIDTH - 10, 0)
|
||||
vbox.add_child(desc_label)
|
||||
var descLabel = Label.new()
|
||||
descLabel.text = card.description
|
||||
descLabel.autowrap_mode = TextServer.AUTOWRAP_WORD
|
||||
descLabel.custom_minimum_size = Vector2(CARD_WIDTH - 10, 0)
|
||||
vbox.add_child(descLabel)
|
||||
|
||||
var id_label = Label.new()
|
||||
id_label.text = card.id
|
||||
id_label.autowrap_mode = true
|
||||
id_label.custom_minimum_size = Vector2(CARD_WIDTH - 10, 0)
|
||||
vbox.add_child(id_label)
|
||||
var idLabel = Label.new()
|
||||
idLabel.text = card.id.substr(card.id.length() - 8, -1)
|
||||
idLabel.autowrap_mode = true
|
||||
idLabel.custom_minimum_size = Vector2(CARD_WIDTH - 10, 0)
|
||||
vbox.add_child(idLabel)
|
||||
|
||||
|
||||
card_panel.gui_input.connect(func(event): _on_card_clicked(event, card))
|
||||
cardPanel.gui_input.connect(func(event): _on_card_clicked(event, card))
|
||||
|
||||
card_displays.append(card_panel)
|
||||
container.add_child(card_panel)
|
||||
cardDisplays.append(cardPanel)
|
||||
container.add_child(cardPanel)
|
||||
|
||||
func _on_card_clicked(event: InputEvent, card: Card):
|
||||
if event is InputEventMouseButton and event.pressed:
|
||||
if selected_card == null || selected_card.id != card.id:
|
||||
selected_card = card
|
||||
if selectedCard == null || selectedCard.id != card.id:
|
||||
selectedCard = card
|
||||
container.emit_signal("card_pressed", card)
|
||||
elif selected_card.id == card.id:
|
||||
selected_card = null
|
||||
highlight_selected_card(selected_card)
|
||||
# selected_card = card
|
||||
# highlight_selected_card(card)
|
||||
elif selectedCard.id == card.id:
|
||||
selectedCard = null
|
||||
highlight_selectedCard(selectedCard)
|
||||
# selectedCard = card
|
||||
# highlight_selectedCard(card)
|
||||
# container.emit_signal("card_pressed", card)
|
||||
|
||||
func highlight_selected_card(selected: Card) -> void:
|
||||
for display in card_displays:
|
||||
func highlight_selectedCard(selected: Card) -> void:
|
||||
for display in cardDisplays:
|
||||
var style = StyleBoxFlat.new()
|
||||
style.bg_color = Color(0.2, 0.2, 0.2, 1) # Default color
|
||||
|
||||
|
|
@ -81,17 +79,17 @@ func highlight_selected_card(selected: Card) -> void:
|
|||
display.add_theme_stylebox_override("panel", style)
|
||||
|
||||
func get_card_by_uuid(uuid: String) -> Card:
|
||||
for display in card_displays:
|
||||
for display in cardDisplays:
|
||||
var vbox = display.get_child(0)
|
||||
if vbox.get_meta("card_id") == uuid:
|
||||
return selected_card
|
||||
return selectedCard
|
||||
return null
|
||||
|
||||
func get_selected_card() -> Card:
|
||||
return selected_card
|
||||
func getSelectedCard() -> Card:
|
||||
return selectedCard
|
||||
|
||||
func clear_cards():
|
||||
for display in card_displays:
|
||||
for display in cardDisplays:
|
||||
display.queue_free()
|
||||
card_displays.clear()
|
||||
selected_card = null
|
||||
cardDisplays.clear()
|
||||
selectedCard = null
|
||||
93
Systems/CardPreview.gd
Normal file
93
Systems/CardPreview.gd
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
extends Control
|
||||
class_name CardPreview
|
||||
|
||||
const PREVIEW_WIDTH = 150
|
||||
const PREVIEW_HEIGHT = 200
|
||||
const SCREEN_MARGIN = 20
|
||||
|
||||
var currentCard: Card = null
|
||||
var previewPanel: PanelContainer
|
||||
|
||||
func _init() -> void:
|
||||
|
||||
previewPanel = PanelContainer.new()
|
||||
previewPanel.custom_minimum_size = Vector2(PREVIEW_WIDTH, PREVIEW_HEIGHT)
|
||||
|
||||
|
||||
position = Vector2(0, 0)
|
||||
|
||||
var vbox = VBoxContainer.new()
|
||||
previewPanel.add_child(vbox)
|
||||
|
||||
var style = StyleBoxFlat.new()
|
||||
style.bg_color = Color(0.2, 0.2, 0.2, 0.9)
|
||||
style.corner_radius_top_left = 10
|
||||
style.corner_radius_top_right = 10
|
||||
style.corner_radius_bottom_left = 10
|
||||
style.corner_radius_bottom_right = 10
|
||||
previewPanel.add_theme_stylebox_override("panel", style)
|
||||
|
||||
previewPanel.hide()
|
||||
add_child(previewPanel)
|
||||
|
||||
func show_card_preview(card: Card) -> void:
|
||||
if card == null:
|
||||
previewPanel.hide()
|
||||
currentCard = null
|
||||
return
|
||||
|
||||
currentCard = card
|
||||
var vbox = previewPanel.get_child(0)
|
||||
|
||||
for child in vbox.get_children():
|
||||
child.queue_free()
|
||||
|
||||
var nameLabel = Label.new()
|
||||
nameLabel.text = card.cardName
|
||||
nameLabel.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
nameLabel.add_theme_font_size_override("font_size", 18)
|
||||
vbox.add_child(nameLabel)
|
||||
|
||||
var rankLabel = Label.new()
|
||||
rankLabel.text = "Rank " + str(card.rank)
|
||||
rankLabel.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
vbox.add_child(rankLabel)
|
||||
|
||||
var idLabel = Label.new()
|
||||
idLabel.text = "ID: " + card.id.substr(card.id.length() - 8, -1)
|
||||
idLabel.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
vbox.add_child(idLabel)
|
||||
|
||||
var durationLabel = Label.new()
|
||||
durationLabel.text = str(card.remaining_turns) + " turns remaining"
|
||||
durationLabel.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
vbox.add_child(durationLabel)
|
||||
|
||||
var descLabel = Label.new()
|
||||
descLabel.text = card.description
|
||||
descLabel.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
descLabel.autowrap_mode = TextServer.AUTOWRAP_WORD
|
||||
descLabel.custom_minimum_size = Vector2(PREVIEW_WIDTH - 20, 0)
|
||||
vbox.add_child(descLabel)
|
||||
|
||||
previewPanel.show()
|
||||
|
||||
func hide_preview() -> void:
|
||||
previewPanel.hide()
|
||||
currentCard = null
|
||||
|
||||
func update_moves_remaining(moves: int) -> void:
|
||||
if currentCard == null:
|
||||
return
|
||||
|
||||
var vbox = previewPanel.get_child(0)
|
||||
var movesLabel = Label.new()
|
||||
movesLabel.text = "Moves remaining this turn: " + str(moves)
|
||||
movesLabel.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
|
||||
# Remove old moves label if it exists
|
||||
for child in vbox.get_children():
|
||||
if child.text.begins_with("Moves remaining this turn:"):
|
||||
child.queue_free()
|
||||
|
||||
vbox.add_child(movesLabel)
|
||||
|
|
@ -3,12 +3,12 @@ class_name DoubleTimeCard extends Card
|
|||
func _init():
|
||||
super._init()
|
||||
# id = Utils.generate_guid()
|
||||
card_name = "Double Time"
|
||||
cardName = "Double Time"
|
||||
rank = Rank.RANK_2
|
||||
effect_type = EffectType.MOVEMENT_MODIFIER
|
||||
effectType = EffectType.MOVEMENT_MODIFIER
|
||||
description = "Piece can move twice in one turn"
|
||||
duration = 2 # Lasts for 2 turns
|
||||
unit_whitelist = []
|
||||
unitWhitelist = []
|
||||
|
||||
func modify_moves() -> Dictionary:
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -1,20 +1,20 @@
|
|||
class_name DrunkDrivingCard extends Card
|
||||
func _init():
|
||||
super._init()
|
||||
# id = Utils.generate_guid()
|
||||
card_name = "Drunk Driving"
|
||||
rank = Rank.RANK_1
|
||||
effect_type = EffectType.SPECIAL_ACTION
|
||||
description = "Force Rook to move to opposite end"
|
||||
unit_whitelist = ["Rook"] # Can only be attached to Rooks
|
||||
|
||||
super._init()
|
||||
# id = Utils.generate_guid()
|
||||
cardName = "Drunk Driving"
|
||||
rank = Rank.RANK_1
|
||||
effectType = EffectType.SPECIAL_ACTION
|
||||
description = "Force Rook to move to opposite end"
|
||||
unitWhitelist = ["Rook"] # Can only be attached to Rooks
|
||||
|
||||
func apply_effect(target_piece = null, board_flow = null, game_state = null):
|
||||
if !super.apply_effect(target_piece, board_flow, game_state):
|
||||
return false
|
||||
|
||||
if target_piece:
|
||||
var current_pos = target_piece.get_parent().name.split("-")
|
||||
var target_x = current_pos[0]
|
||||
var target_y = "0" if target_piece.Item_Color == 0 else "7"
|
||||
return [target_x + "-" + target_y]
|
||||
return false
|
||||
if !super.apply_effect(target_piece, board_flow, game_state):
|
||||
return false
|
||||
|
||||
if target_piece:
|
||||
var current_pos = target_piece.get_parent().name.split("-")
|
||||
var target_x = current_pos[0]
|
||||
var target_y = "0" if target_piece.Item_Color == 0 else "7"
|
||||
return [target_x + "-" + target_y]
|
||||
return false
|
||||
|
|
|
|||
|
|
@ -1,21 +1,21 @@
|
|||
class_name SupernovaCard extends Card
|
||||
func _init():
|
||||
super._init()
|
||||
# id = Utils.generate_guid()
|
||||
card_name = "Supernova"
|
||||
rank = Rank.RANK_0
|
||||
effect_type = EffectType.PIECE_EFFECT
|
||||
description = "Remove all abilities from enemy pieces"
|
||||
unit_whitelist = ["King"] # Can only be used by Kings
|
||||
|
||||
super._init()
|
||||
# id = Utils.generate_guid()
|
||||
cardName = "Supernova"
|
||||
rank = Rank.RANK_0
|
||||
effectType = EffectType.PIECE_EFFECT
|
||||
description = "Remove all abilities from enemy pieces"
|
||||
unitWhitelist = ["King"] # Can only be used by Kings
|
||||
|
||||
func apply_effect(target_piece = null, board_flow = null, game_state = null):
|
||||
if !super.apply_effect(target_piece, board_flow, game_state):
|
||||
return false
|
||||
|
||||
if board_flow:
|
||||
for cell in board_flow.get_children():
|
||||
if cell.get_child_count() > 0:
|
||||
var piece = cell.get_child(0)
|
||||
if piece.Item_Color != target_piece.Item_Color:
|
||||
pass
|
||||
return true
|
||||
if !super.apply_effect(target_piece, board_flow, game_state):
|
||||
return false
|
||||
|
||||
if board_flow:
|
||||
for cell in board_flow.get_children():
|
||||
if cell.get_child_count() > 0:
|
||||
var piece = cell.get_child(0)
|
||||
if piece.Item_Color != target_piece.Item_Color:
|
||||
pass
|
||||
return true
|
||||
|
|
|
|||
|
|
@ -36,6 +36,15 @@ func drawStartingHand():
|
|||
|
||||
func drawCard():
|
||||
if deck.is_empty() && !discard.is_empty():
|
||||
print("*******************************")
|
||||
print("*******************************")
|
||||
print("*******************************")
|
||||
print("*******************************")
|
||||
print("********ADDING DISCARD TO DECK*")
|
||||
print("*******************************")
|
||||
print("*******************************")
|
||||
print("*******************************")
|
||||
print("*******************************")
|
||||
deck = discard.duplicate()
|
||||
discard.clear()
|
||||
shuffleDeck()
|
||||
|
|
@ -61,19 +70,6 @@ func playCard(card: Card, target_piece: Pawn, board_flow = null, game_state = nu
|
|||
attached_cards[target_piece.get_instance_id()] = card
|
||||
hand.erase(card)
|
||||
emit_signal("hand_updated", hand)
|
||||
|
||||
match card.rank:
|
||||
Card.Rank.RANK_0:
|
||||
# Burned permanently
|
||||
pass
|
||||
Card.Rank.RANK_1:
|
||||
# Burned until next match
|
||||
pass
|
||||
Card.Rank.RANK_2:
|
||||
discard.append(card)
|
||||
Card.Rank.RANK_3:
|
||||
deck.append(card)
|
||||
shuffleDeck()
|
||||
|
||||
|
||||
return true
|
||||
|
|
@ -84,9 +80,28 @@ 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)
|
||||
print("Card: ", card.id, " | ", card.cardName, " | ", card.remaining_turns)
|
||||
if card.remaining_turns <= 0:
|
||||
expired_cards.append(piece_id)
|
||||
|
||||
|
||||
match card.rank:
|
||||
Card.Rank.RANK_0:
|
||||
# Burned permanently
|
||||
pass
|
||||
Card.Rank.RANK_1:
|
||||
# Burned until next match
|
||||
pass
|
||||
Card.Rank.RANK_2:
|
||||
print("Rank 2 add to Discard")
|
||||
discard.append(card)
|
||||
# continue
|
||||
pass
|
||||
Card.Rank.RANK_3:
|
||||
deck.append(card)
|
||||
# continue
|
||||
print("Rank 1 add to Deck")
|
||||
pass
|
||||
else:
|
||||
var piece_node = instance_from_id(piece_id)
|
||||
if is_instance_valid(piece_node):
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ var Turn: int = 0
|
|||
@onready var p2String: RichTextLabel = $Player2Points
|
||||
@onready var deckManager: DeckManager
|
||||
@onready var cardDisplay: CardDisplay
|
||||
@onready var cardPreview: CardPreview
|
||||
|
||||
@export var boardXSize = 8
|
||||
@export var boardYSize = 8
|
||||
|
|
@ -55,7 +56,11 @@ func initializeGame() -> void:
|
|||
initializeBoard()
|
||||
setupUI()
|
||||
initializeDeckSystem()
|
||||
|
||||
initializeCardPreview()
|
||||
|
||||
func initializeCardPreview() -> void:
|
||||
cardPreview = CardPreview.new()
|
||||
add_child(cardPreview)
|
||||
|
||||
|
||||
func initializeBoard() -> void:
|
||||
|
|
@ -132,6 +137,7 @@ func createTile(x: int, y: int, isWhite: bool) -> void:
|
|||
func clearSelection() :
|
||||
resetHighlights()
|
||||
selectedNode = ""
|
||||
cardPreview.hide_preview()
|
||||
return
|
||||
|
||||
|
||||
|
|
@ -254,10 +260,10 @@ func applyTileEffects() -> void:
|
|||
|
||||
func attachSelectedCards() -> void:
|
||||
# Logic for attaching selected cards to pieces
|
||||
var selectedCard = cardDisplay.get_selected_card()
|
||||
var selectedCard = cardDisplay.getSelectedCard()
|
||||
if selectedCard and selectedNode:
|
||||
var piece = get_node("Flow/" + selectedNode).get_child(0)
|
||||
if piece and selectedCard.can_attach_to_piece(piece):
|
||||
if piece and selectedCard.can_attach_to_piece(piece) and !deckManager.attached_cards.has(get_instance_id()):
|
||||
deckManager.playCard(selectedCard, piece, boardContainer, self)
|
||||
|
||||
|
||||
|
|
@ -303,12 +309,17 @@ func getMovableAreas() -> void:
|
|||
specialArea.clear()
|
||||
|
||||
var piece = get_node("Flow/" + selectedNode).get_child(0)
|
||||
# print("Flow/" + selectedNode)
|
||||
# print("PEICE ", piece)
|
||||
# var flowNodes = get_tree().get_nodes_in_group("Flow")
|
||||
# print("Flow nodes:", flowNodes)
|
||||
# if !piece:
|
||||
# return
|
||||
var piece_id = piece.get_instance_id()
|
||||
if deckManager.attached_cards.has(piece_id):
|
||||
var card = deckManager.attached_cards[piece_id]
|
||||
cardPreview.show_card_preview(card)
|
||||
if stateMachine.state.name == Constants.MOVEMENT:
|
||||
var movement_state = stateMachine.state
|
||||
if piece_id in movement_state.moves_remaining:
|
||||
var moves_left = movement_state.moves_remaining[piece_id] - 1
|
||||
cardPreview.update_moves_remaining(moves_left)
|
||||
else:
|
||||
cardPreview.hide_preview()
|
||||
var moves = piece.getValidMoves(boardContainer, selectedNode)
|
||||
areas = moves.regular_moves
|
||||
specialArea = moves.special_moves
|
||||
|
|
|
|||
|
|
@ -25,19 +25,19 @@ func exit() -> void:
|
|||
if game.boardContainer.is_connected("tile_pressed", handleTilePressed):
|
||||
game.boardContainer.disconnect("tile_pressed", handleTilePressed)
|
||||
|
||||
game.cardDisplay.selected_card = null
|
||||
game.cardDisplay.selectedCard = null
|
||||
game.selectedNode = ""
|
||||
game.resetHighlights()
|
||||
|
||||
func handleTilePressed(location: String) -> void:
|
||||
print("HANDLING Tile PRESSED ", location)
|
||||
# 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()
|
||||
var selectedCard = game.cardDisplay.getSelectedCard()
|
||||
|
||||
if selectedCard and piece:
|
||||
var isCorrectColor = (piece.Item_Color == 0 and game.currentPlayer == game.WHITE) or \
|
||||
|
|
@ -46,7 +46,7 @@ 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, " at ", location)
|
||||
# print("Successfully attached card ", selectedCard.cardName, " to ", piece.name, " at ", location)
|
||||
piece.on_card_effect_changed()
|
||||
if game.deckManager.hand.is_empty():
|
||||
complete_attachment_phase()
|
||||
|
|
@ -62,3 +62,4 @@ func complete_attachment_phase() -> void:
|
|||
timer.stop()
|
||||
_on_timer_timeout()
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
extends "res://Systems/StateMachine/ChessGameState.gd"
|
||||
|
||||
var moves_remaining = {}
|
||||
var multiMoving = false
|
||||
|
||||
func _ready() -> void:
|
||||
print("Movement state ready")
|
||||
|
|
@ -13,6 +15,14 @@ func enter(_previous: String, _data := {}) -> void:
|
|||
if game.selectedNode != "":
|
||||
game.getMovableAreas()
|
||||
|
||||
moves_remaining.clear()
|
||||
multiMoving = false
|
||||
for piece_id in game.deckManager.attached_cards:
|
||||
var card = game.deckManager.attached_cards[piece_id]
|
||||
if card is DoubleTimeCard:
|
||||
var effects = card.modify_moves()
|
||||
moves_remaining[piece_id] = effects.get("extra_moves", 0) + 1
|
||||
|
||||
func exit() -> void:
|
||||
if game.boardContainer.is_connected("tile_pressed", handleMovement):
|
||||
game.boardContainer.disconnect("tile_pressed", handleMovement)
|
||||
|
|
@ -20,12 +30,32 @@ func exit() -> void:
|
|||
func handleMovement(location: String) -> void:
|
||||
# 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:
|
||||
game.selectedNode = location
|
||||
game.getMovableAreas()
|
||||
elif game.selectedNode == location:
|
||||
game.clearSelection()
|
||||
return
|
||||
var piece = game.get_node("Flow/" + game.selectedNode).get_child(0)
|
||||
var piece_id = piece.get_instance_id()
|
||||
var is_multi_moving = piece_id in moves_remaining and moves_remaining[piece_id] > 1
|
||||
|
||||
# print(moves_remaining, " | ", piece_id, " | ",is_multi_moving)
|
||||
var consumeMove = true;
|
||||
|
||||
if is_multi_moving:
|
||||
moves_remaining[piece_id] -= 1
|
||||
consumeMove = false;
|
||||
else:
|
||||
# No more moves remaining, end turn
|
||||
if piece_id in moves_remaining:
|
||||
moves_remaining.erase(piece_id)
|
||||
# finished.emit(Constants.POST_MOVE)
|
||||
|
||||
if game.selectedNode == location:
|
||||
if !is_multi_moving and !multiMoving:
|
||||
print("CLEAR SELECTION*************")
|
||||
game.clearSelection()
|
||||
elif isCastlingMove(node, location):
|
||||
handleCastling(node)
|
||||
finished.emit(Constants.POST_MOVE)
|
||||
|
|
@ -34,20 +64,41 @@ func handleMovement(location: String) -> void:
|
|||
handleEnPassant(node)
|
||||
# Reselect piece
|
||||
elif isReselectMove(node):
|
||||
game.selectedNode = location
|
||||
game.getMovableAreas()
|
||||
if !is_multi_moving and !multiMoving:
|
||||
print("RESELECT SELECTION*************")
|
||||
game.selectedNode = location
|
||||
game.getMovableAreas()
|
||||
# Capture piece
|
||||
elif isCaptureMove(node):
|
||||
handleCapture(node)
|
||||
finished.emit(Constants.POST_MOVE)
|
||||
# Regular move
|
||||
elif isRegularMove(node):
|
||||
handleRegularMove(node)
|
||||
finished.emit(Constants.POST_MOVE)
|
||||
# elif isRegularMove(node):
|
||||
# handleRegularMove(node)
|
||||
# finished.emit(Constants.POST_MOVE)
|
||||
else:
|
||||
if game.isValidMove(location):
|
||||
executeMove(location)
|
||||
# executeMove(location)
|
||||
handleRegularMove(node, consumeMove)
|
||||
if consumeMove:
|
||||
multiMoving = false
|
||||
game.clearSelection()
|
||||
finished.emit(Constants.POST_MOVE)
|
||||
else:
|
||||
multiMoving = true
|
||||
|
||||
game.selectedNode = location # Keep the piece selected for another move
|
||||
|
||||
# game.selectedNode = ""
|
||||
game.hasMoved = false
|
||||
game.currentlyMovingPiece = null
|
||||
game.getMovableAreas()
|
||||
print("ANOTHER MOVE")
|
||||
game.resetHighlights()
|
||||
if game.selectedNode != "":
|
||||
game.getMovableAreas()
|
||||
# finished.emit(Constants.POST_MOVE)
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -112,15 +163,16 @@ func handleCapture(node: Node) -> void:
|
|||
game.currentlyMovingPiece = piece
|
||||
game.resolveMoveEffects()
|
||||
|
||||
func handleRegularMove(node: Node) -> void:
|
||||
func handleRegularMove(node: Node, consume: bool) -> void:
|
||||
print("handleRegularMove", node)
|
||||
for i in game.areas:
|
||||
if i == node.name:
|
||||
var piece = game.get_node("Flow/" + game.selectedNode).get_child(0)
|
||||
piece.reparent(node)
|
||||
piece.position = Vector2(25, 25)
|
||||
game.currentlyMovingPiece = piece
|
||||
game.resolveMoveEffects()
|
||||
if consume:
|
||||
game.currentlyMovingPiece = piece
|
||||
game.resolveMoveEffects()
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ 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
|
||||
var id: String = Utils.generate_guid()
|
||||
|
||||
func _ready():
|
||||
modulate = Color.WHITE if Item_Color == 0 else Color.BLACK
|
||||
|
|
@ -41,17 +42,9 @@ func _init() -> void:
|
|||
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 update_appearance() -> void:
|
||||
print("update_appearance")
|
||||
# print("update_appearance")
|
||||
if !is_instance_valid(get_tree()) || !get_tree().get_root().has_node("Board"):
|
||||
return
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue