12var random_draw := false
13var fixed_slots := false
17func configure(cards:Array, active_slot_count:int = 3, pinned_cards:Dictionary = {}, options:Dictionary = {}) -> void:
18 deck = cards.duplicate(true)
21 pinned_slots = pinned_cards.duplicate(true)
22 random_draw = bool(options.get(
"random_draw", false))
23 fixed_slots = bool(options.get(
"fixed_slots", false))
25 for slot
in range(max(1, active_slot_count)):
26 if pinned_slots.has(slot):
27 active_slots.append(pinned_slots[slot])
29 active_slots.append(_draw_next_card())
32func use_slot(slot:int) -> Dictionary:
33 if slot < 0
or slot >= active_slots.size():
35 var card = active_slots[slot]
36 if not card
is Dictionary
or card.is_empty():
38 if pinned_slots.has(slot):
39 return card.duplicate(true)
41 return card.duplicate(true)
42 used_cards.append(card)
43 active_slots[slot] = _draw_next_card()
44 return card.duplicate(true)
47func get_active_slots() -> Array:
48 return active_slots.duplicate(true)
51func get_draw_count() -> int:
55func get_state() -> Dictionary:
57 "deck": deck.duplicate(true),
58 "active_slots": active_slots.duplicate(true),
59 "draw_index": draw_index,
60 "used_cards": used_cards.duplicate(true),
61 "pinned_slots": pinned_slots.duplicate(true),
62 "random_draw": random_draw,
63 "fixed_slots": fixed_slots
67func apply_state(state:Dictionary) -> void:
68 deck = state.get(
"deck", []).duplicate(true)
69 active_slots = state.get(
"active_slots", []).duplicate(true)
70 draw_index =
int(state.get(
"draw_index", 0))
71 used_cards = state.get(
"used_cards", []).duplicate(true)
72 pinned_slots = state.get(
"pinned_slots", {}).duplicate(true)
73 random_draw = bool(state.get(
"random_draw", false))
74 fixed_slots = bool(state.get(
"fixed_slots", false))
77func _draw_next_card() -> Dictionary:
80 if draw_index >= deck.size():
81 deck.append_array(used_cards)
86 for index
in range(deck.size()):
87 if index >= draw_index:
88 available.append(index)
89 if available.is_empty():
91 var picked_index =
int(available[randi() % available.size()])
92 var picked = deck[picked_index]
93 deck.remove_at(picked_index)
94 deck.insert(draw_index, picked)
95 var card = deck[draw_index]
97 return card.duplicate(true)
if card
is Dictionary
else {}
int
Configure a rotating deck.