-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpast_hands.gd
51 lines (44 loc) · 1.79 KB
/
past_hands.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
extends Control
class_name PastHands
@onready var past_hands_list: VBoxContainer = %PastHandsList
@onready var empty_message: Panel = $ScrollContainer/VBoxContainer/EmptyMessage
@onready var event_handler: EventHandler = $EventHandler
const PAST_HAND_DISPLAY = preload("res://objects/past_hands/past_hand_display.tscn")
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
event_handler.register_handler(Event.Type.ITEMS_CHANGED, on_items_changed)
populate_hands_list()
func populate_hands_list() -> void:
for child in past_hands_list.get_children():
child.queue_free()
var enemy_turns := GameState.played_hands
for i in range(enemy_turns.size()):
var hand := enemy_turns[i].cards
var new_display := PAST_HAND_DISPLAY.instantiate() as PastHandDisplay
new_display.hand = hand
new_display.player_id = i
new_display.round_number = enemy_turns[i].round_num
past_hands_list.add_child(new_display)
if enemy_turns.size() > 0:
empty_message.visible = false
await get_tree().create_timer(0.05, false).timeout
call_deferred("request_score_calculations")
func request_score_calculations() -> void:
for child in past_hands_list.get_children():
var past_display := child as PastHandDisplay
if past_display:
past_display.total_score = 0
for i in range(GameState.played_hands.size()):
var hand = GameState.played_hands[i].cards
start_hand_score_calculate(hand, i)
func reset_base_values(cards :Array[Card]) -> void:
for card in cards:
card.value = card.base_value
func start_hand_score_calculate(hand: Array[Card], player_num: int) -> void:
var event := EventHandPlayed.new()
reset_base_values(hand)
event.cards = hand
event.played_by_id = player_num
EventBus.queue_event(event)
func on_items_changed(event: EventItemsChanged) -> void:
request_score_calculations()