TableTower/ui/main_rolling_show.gd
RobinFiredrake 2ed91e7acd Spreads can roll cards from other spreads: [[Spread::Card]]
A result's text can name a card in another spread, as "[[Treasure::Loot]]".
It rolls there (its own threads and references resolve in that spread)
and its changes apply to this spread's values. The inspector has
"+ Roll a card from another spread…" to pick one. Links show as
"Treasure › Loot" chips; nodes from there are marked so this spread's
cards aren't lit for them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 14:45:01 -06:00

83 lines
2.6 KiB
GDScript

class_name MainRollingShow
extends RefCounted
## Showing a roll all at once instead of animating it: a fast roll (Shift),
## a roll that asked questions, a long chain, the steps so far before a
## question, and lighting a saved roll's steps (reopening a spread).
## MainRolling keeps one-line delegators.
var m: Main
func _init(p_main: Main) -> void:
m = p_main
## Lights the steps of the running roll so far (Roller.progress) on the board
## and in the tray, all at once. Used just before a question opens.
func show_progress() -> void:
if m.rolling_ctx == null:
return
var steps := Roller.progress(m.rolling_ctx)
m.lit_entries.clear()
m.lit_pipes.clear()
m.lit_texts.clear()
m.lit_columns.clear()
_light_steps(steps)
m._refresh_lit()
_reveal_steps(steps)
m.current["steps"] = steps
m.current["all"] = steps
m.current["fast"] = true
m.refresh_live()
m.tray.render()
## Shows the whole current roll at once: every result and pipe on its path lit,
## long lists scrolled to their result, and the full chain in the tray.
func _finish_fast_roll() -> void:
var all: Array = m.current["all"]
m.rolling.deck_reveal.clear()
_light_steps(all)
m._refresh_lit()
_reveal_steps(all)
m.current["steps"] = all
m.current["done"] = true
m.current["fast"] = true
m.refresh_live()
m.tray.render()
## Scrolls long cards to the last result each table gave in `steps` (one
## reveal per table, so thousands of steps cost one pass).
func _reveal_steps(steps: Array) -> void:
var last := {}
for s: Dictionary in steps:
if s.has("entry_id") and not s.get("stop", false):
last[str(s.get("table_id", ""))] = str(s["entry_id"])
for tid: String in last:
var card := m.card_for(tid)
if card:
card.reveal(last[tid])
if card.table.card_mode and m.sound:
m.sound.play("card_turn")
## Lights the entries and pipes of a roll from its saved steps.
func _light_steps(steps: Array) -> void:
var stack: Array = []
for s: Dictionary in steps:
var d := int(s.get("depth", 0))
stack.resize(d)
stack.append(s)
if s.get("stop", false) or not s.has("entry_id") or s.has("spread"):
continue
var tid := str(s.get("table_id", ""))
var ek := Roller.entry_key(tid, str(s["entry_id"]))
m.lit_entries[ek] = true
m.lit_texts[ek] = str(s.get("text", ""))
TableCardColumns.note_lit(m, ek, s)
if d > 0 and not (s.has("pass") or s.has("after")) and stack[d - 1] is Dictionary and (stack[d - 1] as Dictionary).has("entry_id"):
var p: Dictionary = stack[d - 1]
var ptid := str(p.get("table_id", ""))
var peid := str(p["entry_id"])
m.lit_pipes[Roller.ref_key(ptid, peid, tid) if s.get("inline", false) else Roller.pipe_key(ptid, peid, tid)] = true