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

162 lines
7 KiB
GDScript

class_name InspectorResult
extends RefCounted
## The Inspector's "Selected result" section: text, details, picture, Book link,
## costs, effects and the threads leaving it.
## A link back to the card the result or pipe belongs to.
## "From the Book page X · unlink" for a linked result, else "Save to the Book".
static func book_line(insp: Inspector, t: RollTable, e: TableEntry) -> Control:
var p := insp.main.data.get_page(e.page)
if p == null:
var save := InspectorKit.link("Save to the Lore Index", "Keep this result as a Lore Entry to reuse on other tables")
save.pressed.connect(func() -> void: insp.main.book.save_result(t, e))
return save
var row := InspectorKit.hbox(8)
var open := InspectorKit.link("§ Lore Entry: %s" % p.label(), "Edit the Lore Entry; every result using it changes")
open.pressed.connect(func() -> void:
insp.main.book.set_shown(true)
insp.main.book.refresh()
insp.main.book.select_page(p.id))
row.add_child(open)
var unlink := InspectorKit.link("Unlink", "Keep the text here but stop following the Lore Entry")
unlink.pressed.connect(func() -> void:
e.page = ""
insp.wrote(t, false, true))
row.add_child(unlink)
return row
## "[1] of [Points ▾]": what picking this option costs (RollCosts).
## "Costs [1] of [value]": for a choice option (`holder` a TableEntry) or a
## whole card (`holder` the RollTable). `note` sits under it.
static func cost_row(insp: Inspector, t: RollTable, holder: Object, note: String = "Greyed out in the pop-up when there isn't enough.") -> Control:
var row := InspectorKit.flow()
var amount := InspectorKit.amount(str(holder.get("cost_amount")), "0")
amount.tooltip_text = "How much it takes away (0 or empty: free)"
row.add_child(amount)
row.add_child(InspectorKit.word("of"))
var picker := ValuePicker.new(insp.main, str(holder.get("cost_value")).trim_prefix("@"))
row.add_child(picker)
var apply := func() -> void:
var typed := amount.text.strip_edges()
holder.set("cost_amount", "" if typed == "" or typed == "0" else typed)
if str(holder.get("cost_amount")) == "":
holder.set("cost_value", "")
insp.wrote(t)
amount.text_changed.connect(func(_s: String) -> void: apply.call())
picker.value_chosen.connect(func(n: String) -> void:
holder.set("cost_value", "@" + n.trim_prefix("@"))
if amount.text.strip_edges() == "":
amount.text = "1"
apply.call())
row.add_child(InspectorKit.note(note, Style.MUTED, 12))
return row
static func card_link(insp: Inspector, t: RollTable) -> Button:
var b := InspectorKit.link("On %s · edit the card" % Inspector._title_of(t.name, "this card"), "Show the card's settings")
b.add_theme_color_override("font_color", Style.MUTED)
b.pressed.connect(func() -> void: insp.select({"kind": "card", "tid": t.id}))
return b
## `with_head`: false inside the inspector's list, which has its own headers.
static func section(insp: Inspector, t: RollTable, e: TableEntry, with_head: bool = true) -> void:
if with_head:
insp._content.add_child(insp._head("Selected result", Inspector._title_of(e.text, "(no text)")))
insp._content.add_child(card_link(insp, t))
var plain := insp.main.rules_plain()
if t.kind != RollTable.KIND_SHEET:
var le := InspectorKit.line(e.text, "What this result says")
FormatMenu.attach(le)
InspectorKit.tag(le, "res.text")
le.text_changed.connect(insp.set_entry_text)
var link := InspectorKit.link("+ Roll a card from another spread…", "Puts [[Spread::Card]] in the text: that card rolls when this result comes up")
link.pressed.connect(func() -> void: SpreadLinkDialog.open(insp.main, func(ref: String) -> void:
le.text = (le.text.strip_edges() + " " + ref).strip_edges()
insp.set_entry_text(le.text)))
insp.fields["text"] = le
SpellUnderline.attach(le, insp.main)
insp._content.add_child(InspectorKit.field(Inspector._title_of(str(t.columns[0].get("name", "")), "Text") if t.has_columns() else "Text", le))
insp._content.add_child(link)
InspectorColumns.result_cells(insp, t, e)
var det := InspectorKit.text_box(e.details, "Shown on hover (optional)", 36.0)
InspectorKit.tag(det, "res.details")
det.text_changed.connect(func() -> void: insp.set_entry_details(det.text))
insp.fields["details"] = det
SpellUnderline.attach(det, insp.main)
insp._content.add_child(InspectorKit.field("Details", det))
insp._content.add_child(InspectorKit.field("Picture", ImageField.new(insp.main, e.image, func(id: String) -> void:
e.image = id
e.page = ""
insp.wrote(t))))
insp._content.add_child(book_line(insp, t, e))
var pick := t.kind == RollTable.KIND_CHOICE and t.choice == "pick"
if (pick and not (t.is_dynamic() and t.entries.find(e) == 0)) or t.kind == RollTable.KIND_ROLL:
insp.show_if_builder = ConditionBuilder.new()
insp.show_if_builder.setup(insp.main, e.show_if, not plain, "res.show_if",
{"empty_note": "Always offered." if pick else "Can always come up."})
insp.show_if_builder.changed.connect(insp.set_entry_show_if)
insp._content.add_child(InspectorKit.field("Offer only if" if pick else "Can come up only if", insp.show_if_builder))
if pick and not (t.is_dynamic() and t.entries.find(e) == 0):
insp._content.add_child(InspectorKit.field("Costs", cost_row(insp, t, e)))
if t.kind == RollTable.KIND_ROUTER:
insp._content.add_child(InspectorCard.case_block(insp, t, e))
insp.effects = EffectsBuilder.new()
insp.effects.item_hint = Formatter.strip_tags(e.text).strip_edges()
insp.effects.setup(insp.main, e.effects, t, not plain, "res.fx")
insp.effects.changed.connect(insp.set_entry_effects)
insp._content.add_child(InspectorKit.field("When this comes up", insp.effects))
var go := InspectorKit.vbox(8)
if e.pipes.is_empty():
go.add_child(InspectorKit.note("No threads yet. Drag from the ● at the end of this result to a card.", Style.MUTED, 14))
for p in e.pipes:
go.add_child(InspectorThread.box(insp, t, e, p))
insp._content.add_child(InspectorKit.field("Then go to", go))
InspectorThread.lint_lines(insp, t, e)
static func set_entry_text(insp: Inspector, s: String) -> void:
var e := insp.selected_entry()
if e and e.text != s:
e.text = s
e.page = ""
insp.wrote_text(insp.selected_table(), e.id)
static func set_entry_details(insp: Inspector, s: String) -> void:
var e := insp.selected_entry()
if e and e.details != s:
e.details = s
e.page = ""
insp.wrote(insp.selected_table())
static func set_entry_effects(insp: Inspector, s: String) -> void:
var e := insp.selected_entry()
if e and e.effects != s:
e.effects = s
insp.wrote(insp.selected_table())
static func set_entry_show_if(insp: Inspector, s: String) -> void:
var e := insp.selected_entry()
if e and e.show_if != s.strip_edges() and TableSettingsDialog.when_error(s) == "":
e.show_if = s.strip_edges()
insp.wrote(insp.selected_table())
## A router case's condition ("" makes it the Otherwise case).
static func set_case_when(insp: Inspector, eid: String, s: String) -> void:
var t := insp.selected_table()
var e := t.find_entry(eid) if t else null
if e and e.when != s.strip_edges() and TableSettingsDialog.when_error(s) == "":
e.when = s.strip_edges()
insp.wrote(t)