Deck mode: a drawn result fades only once the animation reveals it

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>
This commit is contained in:
RobinFiredrake 2026-11-11 08:19:34 -06:00
parent f731c6ffbf
commit 4f0d2e2c4e
6 changed files with 107 additions and 2 deletions

View file

@ -39,4 +39,35 @@ func _init() -> void:
await process_frame
_check(main.current.get("done", false) and main.current.get("fast", false), "the interrupted roll doesn't overwrite the fast result")
await _test_deck_waits()
finish()
## Deck mode: an animated roll fades the drawn result only once it lights;
## a fast roll fades it at once.
func _test_deck_waits() -> void:
var t := main.data.get_table("wilderness")
t.card_mode = true
main.reshuffle_table(t.id)
main.layout._board_changed()
await _frames()
var total := main.cards_left(t.id).y
main.start_roll(t.id)
var eid := ""
for st: Dictionary in main.current["all"]:
if st.get("table_id") == t.id and st.has("entry_id"):
eid = st["entry_id"]
var card := main.card_for(t.id)
_check(eid != "" and card.rows[eid].modulate.a == 1.0, "mid-animation the drawn result isn't faded yet")
_check(main.cards_left(t.id).x == total, "mid-animation the count hasn't dropped")
var until := Time.get_ticks_msec() + 15000
while not main.current.get("done", false) and Time.get_ticks_msec() < until:
await process_frame
card = main.card_for(t.id)
var gone := (main.decks[t.id] as DeckState).remaining(t, t.find_entry(eid)) <= 0
_check(main.current.get("done", false), "the animated roll finished")
_check(card.rows[eid].modulate.a < 1.0 if gone else true, "after the animation the result fades")
_check(main.cards_left(t.id).x == total - 1, "after the animation the count drops")
main.start_roll(t.id, true)
_check(main.cards_left(t.id).x == total - 2, "a fast roll drops the count at once")
t.card_mode = false

60
ui/deck_reveal.gd Normal file
View file

@ -0,0 +1,60 @@
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

1
ui/deck_reveal.gd.uid Normal file
View file

@ -0,0 +1 @@
uid://716lsgmj6u82

View file

@ -15,11 +15,14 @@ var _pulse_tween: Tween
var _choice: ChoiceDialog
## Rolls waiting at a paused thread.
var pauses: RollPauses
## Deck-mode draws not shown yet in an animated roll.
var deck_reveal: DeckReveal
func _init(p_main: Main) -> void:
m = p_main
pauses = RollPauses.new(p_main)
deck_reveal = DeckReveal.new(self)
## Rolls a table and plays the result down its pipes. A fast roll (Shift held
@ -82,10 +85,14 @@ func start_roll(tid: String, fast: bool = false) -> void:
if fast or prompted or (m.current["all"] as Array).size() > LONG_CHAIN:
_finish_fast_roll()
return
deck_reveal.hold(m.current["all"], my)
m._refresh_lit()
m.tray.render()
await _play_node(tree, my)
if my == _token:
deck_reveal.clear()
for c in m.cards.values():
(c as TableCard).update_deck()
m.current["steps"] = m.current["all"]
m.current["done"] = true
m.tray.render()
@ -236,6 +243,7 @@ func _play_one(n: Dictionary, my: int, depth: int) -> void:
m.lit_entries[ek] = true
m.lit_texts[ek] = str(n.get("summary", e.text))
TableCardColumns.note_lit(m, ek, n)
deck_reveal.release(t.id, e.id)
m._refresh_lit()
if card:
card.reveal(e.id)
@ -248,6 +256,7 @@ func _play_one(n: Dictionary, my: int, depth: int) -> void:
## long lists scrolled to their result, and the full chain in the tray.
func _finish_fast_roll() -> void:
var all: Array = m.current["all"]
deck_reveal.clear()
_light_steps(all)
m._refresh_lit()
_reveal_steps(all)

View file

@ -100,7 +100,10 @@ func cards_left(tid: String) -> Vector2i:
if t == null:
return Vector2i.ZERO
var deck: DeckState = m.decks.get(tid)
return deck.cards_left(t) if deck else DeckState.new().cards_left(t)
var left := deck.cards_left(t) if deck else DeckState.new().cards_left(t)
# Draws of an animated roll count as still in the deck until they show.
left.x = mini(left.y, left.x + m.rolling.deck_reveal.held_total(tid))
return left
func reshuffle_table(tid: String) -> void:

View file

@ -87,7 +87,8 @@ func dim_drawn() -> void:
var row: Control = card.rows.get(e.id)
if row == null or not is_instance_valid(row):
continue
var gone := deck != null and deck.remaining(card.table, e) <= 0
var held := card.main.rolling.deck_reveal.held(card.table.id, e.id)
var gone := deck != null and deck.remaining(card.table, e) + held <= 0
row.modulate.a = 0.38 if gone else 1.0
row.tooltip_text = "Already drawn: Shuffle the deck to put it back" if gone else ""