TableTower/ui/inspector_threads.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

57 lines
2.4 KiB
GDScript

class_name InspectorThreads
extends RefCounted
## The card inspector's "Threads in" and "Threads out" lists: every thread
## leading into the card (from which card and result) and out of it (from
## which result, to which card). Card threads (CardThreads) list as "After any
## result" or "If no thread ran". Clicking one selects that thread.
static func build(insp: Inspector, box: VBoxContainer, t: RollTable) -> void:
var board := insp.main.data
var ins := VBoxContainer.new()
for src in board.tables:
for e in src.thread_sources():
if e.pipes.has(t.id):
ins.add_child(_link(insp, src, e, t.id, "%s · %s" % [_name(src.name), _result(src, e, t.id)]))
var outs := VBoxContainer.new()
for e in t.thread_sources():
for to in e.pipes:
var target := board.get_table(to)
outs.add_child(_link(insp, t, e, to, "%s → %s" % [_result(t, e, to), _name(target.name) if target else to + " (missing)"]))
if ins.get_child_count() == 0:
ins.add_child(InspectorKit.note("Nothing leads here yet."))
if outs.get_child_count() == 0:
outs.add_child(InspectorKit.note("No threads leave this card."))
box.add_child(InspectorKit.field("Threads in (%d)" % _count(ins), ins))
if t.outlet.pipes.is_empty():
outs.add_child(InspectorKit.note("To roll another card after any result, drag from the dot on this card's bottom edge (a card thread)."))
box.add_child(InspectorKit.field("Threads out (%d)" % _count(outs), outs))
static func _link(insp: Inspector, from: RollTable, e: TableEntry, to: String, text: String) -> Button:
var key := Roller.pipe_key(from.id, e.id, to)
var b := InspectorKit.link(text, "Select this thread")
b.text_overrun_behavior = TextServer.OVERRUN_TRIM_ELLIPSIS
b.clip_text = true
b.size_flags_horizontal = Control.SIZE_EXPAND_FILL
var own := str(e.pipe_color.get(to, ""))
if own != "":
b.add_theme_color_override("font_color", Color(own))
b.pressed.connect(func() -> void: insp.main.inspecting.select_pipe(key))
return b
static func _count(v: VBoxContainer) -> int:
return v.get_children().filter(func(c: Node) -> bool: return c is Button).size()
static func _name(s: String) -> String:
return Inspector._title_of(s, "(no name)")
static func _result(t: RollTable, e: TableEntry, to: String) -> String:
if e == t.outlet:
if e.when_for(to) != "":
return "After any result, if…"
return "If no thread ran" if e.is_otherwise(to) else "After any result"
return Inspector._title_of(e.text, "(no text)")