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)")