added card attachement to peices, and timer to transiton certain states (attach cards)
This commit is contained in:
parent
54d6e33c8c
commit
61e4cd88ba
10 changed files with 203 additions and 93 deletions
|
|
@ -18,9 +18,11 @@ var burned: bool = false
|
|||
var effect_type: EffectType
|
||||
var remaining_turns: int = 0
|
||||
var unit_whitelist: Array[String] = [] # List of piece types this card can be attached to
|
||||
var id: String = Utils.generate_guid()
|
||||
|
||||
func _init():
|
||||
remaining_turns = duration
|
||||
# print(id)
|
||||
|
||||
func can_attach_to_piece(piece: Pawn) -> bool:
|
||||
if unit_whitelist.is_empty():
|
||||
|
|
|
|||
|
|
@ -3,27 +3,30 @@ class_name CardDisplay
|
|||
|
||||
var card_displays = []
|
||||
var selected_card = null
|
||||
const CARD_WIDTH = 100
|
||||
const CARD_HEIGHT = 150
|
||||
const CARD_WIDTH = 150
|
||||
const CARD_HEIGHT = 250
|
||||
const CARD_MARGIN = 10
|
||||
var container: HBoxContainer
|
||||
@onready var container: HBoxContainer
|
||||
|
||||
func _ready():
|
||||
container = HBoxContainer.new()
|
||||
container.name = "CardContainer"
|
||||
container.name = "Hand"
|
||||
container.set_position(Vector2(10, 500))
|
||||
add_child(container)
|
||||
|
||||
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: Card):
|
||||
func add_card_display(card):
|
||||
var card_panel = PanelContainer.new()
|
||||
card_panel.custom_minimum_size = Vector2(CARD_WIDTH, CARD_HEIGHT)
|
||||
|
||||
var vbox = VBoxContainer.new()
|
||||
vbox.set_meta("card_id", card.id)
|
||||
card_panel.add_child(vbox)
|
||||
|
||||
var name_label = Label.new()
|
||||
|
|
@ -42,22 +45,48 @@ func add_card_display(card: Card):
|
|||
desc_label.custom_minimum_size = Vector2(CARD_WIDTH - 10, 0)
|
||||
vbox.add_child(desc_label)
|
||||
|
||||
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)
|
||||
|
||||
|
||||
card_panel.gui_input.connect(func(event): _on_card_clicked(event, card))
|
||||
|
||||
card_displays.append(card_panel)
|
||||
container.add_child(card_panel)
|
||||
|
||||
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
|
||||
highlight_selected_card(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)
|
||||
# container.emit_signal("card_pressed", card)
|
||||
|
||||
func highlight_selected_card(selected: Card):
|
||||
func highlight_selected_card(selected: Card) -> void:
|
||||
for display in card_displays:
|
||||
var style = StyleBoxFlat.new()
|
||||
style.bg_color = Color(0.2, 0.2, 0.2, 1)
|
||||
if display.get_child(0).get_child(0).text == selected.card_name:
|
||||
style.bg_color = Color(0.4, 0.6, 0.4, 1)
|
||||
style.bg_color = Color(0.2, 0.2, 0.2, 1) # Default color
|
||||
|
||||
var vbox = display.get_child(0)
|
||||
if selected && vbox.get_meta("card_id") == selected.id:
|
||||
style.bg_color = Color(0.4, 0.6, 0.4, 1) # Selected color
|
||||
|
||||
display.add_theme_stylebox_override("panel", style)
|
||||
|
||||
func get_card_by_uuid(uuid: String) -> Card:
|
||||
for display in card_displays:
|
||||
var vbox = display.get_child(0)
|
||||
if vbox.get_meta("card_id") == uuid:
|
||||
return selected_card
|
||||
return null
|
||||
|
||||
func get_selected_card() -> Card:
|
||||
return selected_card
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,14 @@
|
|||
class DoubleTimeCard extends Card:
|
||||
class_name DoubleTimeCard extends Card
|
||||
|
||||
func _init():
|
||||
super._init()
|
||||
# id = Utils.generate_guid()
|
||||
card_name = "Double Time"
|
||||
rank = Rank.RANK_2
|
||||
effect_type = EffectType.MOVEMENT_MODIFIER
|
||||
description = "Piece can move twice in one turn"
|
||||
duration = 2 # Lasts for 2 turns
|
||||
unit_whitelist = []
|
||||
|
||||
func modify_moves() -> Dictionary:
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
class DrunkDrivingCard extends Card:
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
class SupernovaCard extends Card:
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
extends Node
|
||||
class_name DeckManager
|
||||
|
||||
const DoubleTimeCard = preload("res://Systems/Cards/Doubletime.gd")
|
||||
|
||||
|
||||
var deck: Array = []
|
||||
var hand: Array = []
|
||||
var discard: Array = []
|
||||
|
|
@ -19,9 +22,8 @@ func _init():
|
|||
initializeStartingDeck()
|
||||
|
||||
func initializeStartingDeck():
|
||||
# Add basic Rank 3 and 4 cards as per design doc
|
||||
for i in range(10):
|
||||
deck.append(Card.new()) # Basic movement cards
|
||||
deck.append(DoubleTimeCard.new())
|
||||
shuffleDeck()
|
||||
drawStartingHand()
|
||||
|
||||
|
|
@ -49,10 +51,10 @@ signal hand_updated
|
|||
func playCard(card: Card, target_piece: Pawn, board_flow = null, game_state = null):
|
||||
if !hand.has(card):
|
||||
return false
|
||||
emit_signal("hand_updated", hand)
|
||||
|
||||
if card.apply_effect(target_piece, board_flow, game_state):
|
||||
hand.erase(card)
|
||||
emit_signal("hand_updated", hand)
|
||||
|
||||
match card.rank:
|
||||
Card.Rank.RANK_0:
|
||||
|
|
|
|||
|
|
@ -84,6 +84,13 @@ func initializeDeckSystem() -> void:
|
|||
cardDisplay = CardDisplay.new()
|
||||
add_child(deckManager)
|
||||
add_child(cardDisplay)
|
||||
|
||||
if !deckManager.has_user_signal("card_pressed"):
|
||||
deckManager.add_user_signal("card_pressed")
|
||||
|
||||
if !deckManager.has_user_signal("hand_updated"):
|
||||
deckManager.add_user_signal("hand_updated")
|
||||
|
||||
cardDisplay.update_hand(deckManager.hand)
|
||||
deckManager.connect("hand_updated", func(hand): cardDisplay.update_hand(hand))
|
||||
|
||||
|
|
|
|||
|
|
@ -1,21 +1,63 @@
|
|||
extends "res://Systems/StateMachine/ChessGameState.gd"
|
||||
|
||||
const ATTACHMENT_PHASE_DURATION = 30 # Duration in seconds
|
||||
var timer: Timer
|
||||
var tile_pressed_connection: Signal
|
||||
|
||||
func _ready() -> void:
|
||||
super._ready()
|
||||
timer = Timer.new()
|
||||
timer.one_shot = true
|
||||
timer.timeout.connect(_on_timer_timeout)
|
||||
add_child(timer)
|
||||
|
||||
func enter(_previous: String, _data := {}) -> void:
|
||||
# finished.emit(Constants.APPLY_CARD_EFFECTS)
|
||||
print("ENTERING STATE ", Constants.ATTACH_CARDS)
|
||||
if !game.boardContainer.is_connected("card_pressed", handleCardPressed):
|
||||
print("Connecting card_pressed signal")
|
||||
game.boardContainer.connect("card_pressed", handleCardPressed)
|
||||
if !game.boardContainer.is_connected("tile_pressed", handleTilePressed):
|
||||
game.boardContainer.connect("tile_pressed", handleTilePressed)
|
||||
|
||||
timer.start(ATTACHMENT_PHASE_DURATION)
|
||||
if game.deckManager.hand.is_empty():
|
||||
complete_attachment_phase()
|
||||
|
||||
func exit() -> void:
|
||||
if game.boardContainer.is_connected("card_pressed", handleCardPressed):
|
||||
game.boardContainer.disconnect("card_pressed", handleCardPressed)
|
||||
|
||||
if game.boardContainer.is_connected("tile_pressed", handleTilePressed):
|
||||
game.boardContainer.disconnect("tile_pressed", handleTilePressed)
|
||||
|
||||
func handleCardPressed(location: String) -> void:
|
||||
print("HANDLING MOVEMENT ", location)
|
||||
var node = game.get_node("Flow/" + location)
|
||||
game.cardDisplay.selected_card = null
|
||||
game.selectedNode = ""
|
||||
game.resetHighlights()
|
||||
|
||||
func handleTilePressed(location: String) -> void:
|
||||
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()
|
||||
|
||||
if selectedCard and piece:
|
||||
var isCorrectColor = (piece.Item_Color == 0 and game.currentPlayer == game.WHITE) or \
|
||||
(piece.Item_Color == 1 and game.currentPlayer == game.BLACK)
|
||||
|
||||
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)
|
||||
if game.deckManager.hand.is_empty():
|
||||
complete_attachment_phase()
|
||||
else:
|
||||
print("Failed to attach card")
|
||||
|
||||
func _on_timer_timeout() -> void:
|
||||
print("Card attachment phase timed out")
|
||||
finished.emit(Constants.APPLY_CARD_EFFECTS)
|
||||
|
||||
func complete_attachment_phase() -> void:
|
||||
if timer.time_left > 0:
|
||||
timer.stop()
|
||||
_on_timer_timeout()
|
||||
|
||||
23
Utils/Utils.gd
Normal file
23
Utils/Utils.gd
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
class_name Utils
|
||||
extends Object
|
||||
|
||||
static func generate_guid() -> String:
|
||||
var guid = ""
|
||||
var time = Time.get_ticks_msec()
|
||||
var rng = RandomNumberGenerator.new()
|
||||
rng.randomize()
|
||||
|
||||
# Format: xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
|
||||
guid += "%08x" % time
|
||||
guid += "-"
|
||||
guid += "%04x" % rng.randi()
|
||||
guid += "-"
|
||||
guid += "4"
|
||||
guid += "%03x" % rng.randi()
|
||||
guid += "-"
|
||||
guid += "%x" % (8 + rng.randi() % 4)
|
||||
guid += "%03x" % rng.randi()
|
||||
guid += "-"
|
||||
guid += "%012x" % rng.randi()
|
||||
|
||||
return guid
|
||||
|
|
@ -72,7 +72,7 @@ offset_top = 65.0
|
|||
offset_right = 1142.0
|
||||
offset_bottom = 104.0
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="."]
|
||||
[node name="Hand" type="HBoxContainer" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 7
|
||||
anchor_left = 0.5
|
||||
|
|
|
|||
Loading…
Reference in a new issue