DeckReveal holds an animated roll's draws until each result lights; the cards-left count waits too. Fast rolls and any newer roll drop the holds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
60 lines
1.6 KiB
GDScript
60 lines
1.6 KiB
GDScript
class_name DeckReveal
|
|
extends RefCounted
|
|
## Deck mode during an animated roll. The roll draws its cards before the
|
|
## animation starts; this holds those draws back so a card's result doesn't
|
|
## fade (and the count doesn't drop) until its result lights up. Holds belong
|
|
## to one roll: once any newer roll replaces it, they no longer count. Fast
|
|
## rolls never hold anything.
|
|
|
|
var rolling: MainRolling
|
|
## table id -> {entry id: draws not yet shown}
|
|
var _held: Dictionary = {}
|
|
var _token := -1
|
|
|
|
|
|
func _init(p_rolling: MainRolling) -> void:
|
|
rolling = p_rolling
|
|
|
|
|
|
## Holds every Deck-mode draw among a roll's steps (Roller.flatten).
|
|
func hold(steps: Array, token: int) -> void:
|
|
_held.clear()
|
|
_token = token
|
|
for st: Dictionary in steps:
|
|
if st.get("stop", false) or not st.has("entry_id"):
|
|
continue
|
|
var t := rolling.m.data.get_table(str(st.get("table_id", "")))
|
|
if t and t.card_mode:
|
|
var per: Dictionary = _held.get_or_add(t.id, {})
|
|
var eid := str(st["entry_id"])
|
|
per[eid] = int(per.get(eid, 0)) + 1
|
|
|
|
|
|
## A held draw has been shown.
|
|
func release(tid: String, eid: String) -> void:
|
|
var per: Dictionary = _held.get(tid, {})
|
|
if per.has(eid):
|
|
per[eid] = int(per[eid]) - 1
|
|
if int(per[eid]) <= 0:
|
|
per.erase(eid)
|
|
|
|
|
|
func clear() -> void:
|
|
_held.clear()
|
|
|
|
|
|
## Draws of one result not shown yet.
|
|
func held(tid: String, eid: String) -> int:
|
|
if _token != rolling._token:
|
|
return 0
|
|
return int((_held.get(tid, {}) as Dictionary).get(eid, 0))
|
|
|
|
|
|
## Draws of a table not shown yet.
|
|
func held_total(tid: String) -> int:
|
|
if _token != rolling._token:
|
|
return 0
|
|
var n := 0
|
|
for c: int in (_held.get(tid, {}) as Dictionary).values():
|
|
n += c
|
|
return n
|