Skip to content

Commit

Permalink
Cleanup and addressing review feedback
Browse files Browse the repository at this point in the history
-export enemy_attack_time in Battler
-deal_to_hand_limit -> deal_to_starting_hand_size
-simplify discard_random_card
-add _bind_card_input
-_discard_cards -> _discard_random_cards
  • Loading branch information
cheesefrycook committed Dec 13, 2023
1 parent d0a0bc5 commit dfa9f9f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
4 changes: 2 additions & 2 deletions Cards/CardBase.gd
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func on_post_card_played():
# We handle drawing and discarding in on_post_card_played because we want to wait for the
# queued card to discard first so it doesn't influence the amount of cards in our hand
_draw_cards()
_discard_cards()
_discard_random_cards()


# override in child cards if you want to deal damage in a unique way
Expand Down Expand Up @@ -98,5 +98,5 @@ func _draw_cards() -> void:
CardManager.card_container.draw_cards(amount_of_cards_to_draw)


func _discard_cards() -> void:
func _discard_random_cards() -> void:
CardManager.card_container.discard_random_card(amount_of_cards_to_discard)
32 changes: 14 additions & 18 deletions Cards/CardContainer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func is_card_queued() -> bool:
return queued_card != null


func deal_to_hand_limit() -> void:
func deal_to_starting_hand_size() -> void:
# deal to our starting hand size, ignoring amount of cards we already have
var amount_to_draw: int = maxi(0, starting_hand_size - cards_in_hand.size())
draw_cards(amount_to_draw)
Expand All @@ -69,19 +69,11 @@ func discard_all_cards() -> void:


func discard_random_card(amount: int) -> void:
var valid_cards_to_discard: Array[CardWorld] = []

# We don't want to discard the currently queued card
for card: CardWorld in cards_in_hand:
if card != queued_card:
valid_cards_to_discard.append(card)

# Discard - clamping desired amount to the size of our valid cards
var amount_to_discard: int = mini(valid_cards_to_discard.size(), amount)
# Discard - clamping desired amount to the size of our current hand
var amount_to_discard: int = mini(cards_in_hand.size(), amount)
for discarding_index: int in amount_to_discard:
var random_index: int = Helpers.get_random_array_index(valid_cards_to_discard)
discard_card(valid_cards_to_discard[random_index])
valid_cards_to_discard.remove_at(random_index)
var random_index: int = Helpers.get_random_array_index(cards_in_hand)
discard_card(cards_in_hand[random_index])


func discard_card(card: CardWorld) -> void:
Expand Down Expand Up @@ -129,11 +121,15 @@ func _create_card_in_world(card_data: CardBase) -> void:

card_instance.init_card(card_data)

_bind_card_input(card_instance)


func _bind_card_input(card: CardWorld):
# bind mouse events
var card_click_handler: ClickHandler = card_instance.get_click_handler()
card_click_handler.on_click.connect(_on_card_clicked.bind(card_instance))
card_click_handler.on_mouse_hovering.connect(_on_card_hovering.bind(card_instance))
card_click_handler.on_unhover.connect(_on_card_unhovered.bind(card_instance))
var card_click_handler: ClickHandler = card.get_click_handler()
card_click_handler.on_click.connect(_on_card_clicked.bind(card))
card_click_handler.on_mouse_hovering.connect(_on_card_hovering.bind(card))
card_click_handler.on_unhover.connect(_on_card_unhovered.bind(card))


# Final place where a card is discarded and removed from the world
Expand All @@ -157,7 +153,7 @@ func _discard_last_card() -> void:

func _on_phase_changed(new_phase: Enums.Phase, _old_phase: Enums.Phase) -> void:
if new_phase == Enums.Phase.PLAYER_ATTACKING:
deal_to_hand_limit()
deal_to_starting_hand_size()
if new_phase == Enums.Phase.ENEMY_ATTACKING:
discard_all_cards()

Expand Down
3 changes: 2 additions & 1 deletion Core/Battler.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class_name Battler

@export var enemies_to_summon: Array[PackedScene]
@export var enemy_spacing: float = 50.0
@export var enemy_attack_time: float = 1.0

var _enemy_list: Array[Entity]

Expand Down Expand Up @@ -69,7 +70,7 @@ func _on_enemy_start_turn() -> void:
assert(success == true, "Enemy failed to attack.")

# TODO: temporary delay so we can see the draw pile and discard pile working
await get_tree().create_timer(1.0).timeout
await get_tree().create_timer(enemy_attack_time).timeout

PhaseManager.set_phase(Enums.Phase.PLAYER_ATTACKING)

Expand Down

0 comments on commit dfa9f9f

Please sign in to comment.