TableTower/ui/main_rolling_show.gd
RobinFiredrake 1735ed09fd Card threads, Morgan's welcome, and typing/scroll/wheel papercuts
- Card threads: a port on each card's bottom edge. Plain runs after any
  result (once the result's own threads finish); Otherwise runs only when
  no thread of the result ran. Saved as card_threads (LOGIC.md 3g).
- Typing on long cards no longer rebuilds the inspector or the card per
  key (~175 ms -> ~7 ms). Timing tool: tests/perf_typing.gd.
- "+ Add result" scrolls to the new row and focuses it.
- Mouse wheel zooms; Shift+wheel pans sideways; scrolling lists keep it.
- "SPREAD" caption over the switcher; Morgan's first-run welcome.
- docs/MECHANICS.md: checklist of table mechanics for planning.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 10:41:13 -06:00

83 lines
2.7 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 := RollTable.OUTLET_ID if s.get("card_thread", false) else 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