Split inspector.gd: result, thread and sync helpers
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
97258b0d2b
commit
03a192f47d
7 changed files with 500 additions and 426 deletions
459
ui/inspector.gd
459
ui/inspector.gd
|
|
@ -172,27 +172,7 @@ func _do_sync() -> void:
|
||||||
|
|
||||||
|
|
||||||
func _signature() -> String:
|
func _signature() -> String:
|
||||||
var t := selected_table()
|
return InspectorSync.signature(self)
|
||||||
if selection.is_empty():
|
|
||||||
return ""
|
|
||||||
if t == null or (selection.has("eid") and selected_entry() == null):
|
|
||||||
return "gone"
|
|
||||||
var d := t.to_dict()
|
|
||||||
for k in ["x", "y", "collapsed"]:
|
|
||||||
d.erase(k)
|
|
||||||
var parts := PackedStringArray([JSON.stringify(d), main.rules_view(), str(main.mode)])
|
|
||||||
for x in main.data.tables:
|
|
||||||
if x.kind == RollTable.KIND_VARIABLE:
|
|
||||||
parts.append("%s|%s|%s" % [x.name, x.var_name, x.var_type])
|
|
||||||
for e in t.entries:
|
|
||||||
for p in e.pipes:
|
|
||||||
var target := main.data.get_table(p)
|
|
||||||
parts.append(("%s|%s" % [target.name, JSON.stringify(target.inputs)]) if target else "-")
|
|
||||||
parts.append(str(main.lit_pipes.has(Roller.pipe_key(t.id, e.id, p))))
|
|
||||||
parts.append(str(main.is_entry_lit(t.id, e.id)))
|
|
||||||
if t.is_collection():
|
|
||||||
parts.append(JSON.stringify(members(t)))
|
|
||||||
return str(hash("\n".join(parts)))
|
|
||||||
|
|
||||||
|
|
||||||
# ---------- Writing ----------
|
# ---------- Writing ----------
|
||||||
|
|
@ -232,136 +212,43 @@ func apply_settings(over: Dictionary, rebuild_panel: bool = false) -> String:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
func set_entry_text(s: String) -> void:
|
## A collection card's members: Array of [item, value] (item without the stem).
|
||||||
var e := selected_entry()
|
func members(t: RollTable) -> Array:
|
||||||
if e and e.text != s:
|
return InspectorSync.members(self, t)
|
||||||
e.text = s
|
|
||||||
e.page = ""
|
|
||||||
wrote(selected_table())
|
|
||||||
|
|
||||||
|
|
||||||
func set_entry_details(s: String) -> void:
|
|
||||||
var e := selected_entry()
|
|
||||||
if e and e.details != s:
|
|
||||||
e.details = s
|
|
||||||
e.page = ""
|
|
||||||
wrote(selected_table())
|
|
||||||
|
|
||||||
|
|
||||||
func set_entry_effects(s: String) -> void:
|
|
||||||
var e := selected_entry()
|
|
||||||
if e and e.effects != s:
|
|
||||||
e.effects = s
|
|
||||||
wrote(selected_table())
|
|
||||||
|
|
||||||
|
|
||||||
func set_entry_show_if(s: String) -> void:
|
|
||||||
var e := selected_entry()
|
|
||||||
if e and e.show_if != s.strip_edges() and TableSettingsDialog.when_error(s) == "":
|
|
||||||
e.show_if = s.strip_edges()
|
|
||||||
wrote(selected_table())
|
|
||||||
|
|
||||||
|
|
||||||
## A router case's condition ("" makes it the Otherwise case).
|
|
||||||
func set_case_when(eid: String, s: String) -> void:
|
|
||||||
var t := 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()
|
|
||||||
wrote(t)
|
|
||||||
|
|
||||||
|
|
||||||
func _pipe_entry() -> TableEntry:
|
|
||||||
return selected_entry()
|
|
||||||
|
|
||||||
|
|
||||||
func set_pipe_when(to: String, s: String) -> void:
|
func set_pipe_when(to: String, s: String) -> void:
|
||||||
var e := _pipe_entry()
|
InspectorThread.set_when(self, to, s)
|
||||||
if e == null or PipePopover.when_error(s) != "" or s.strip_edges() == e.when_for(to):
|
|
||||||
return
|
|
||||||
e.set_pipe_when(to, s)
|
|
||||||
wrote(selected_table())
|
|
||||||
_refresh_otherwise(to)
|
|
||||||
|
|
||||||
|
|
||||||
func set_pipe_otherwise(to: String, on: bool) -> void:
|
func set_pipe_otherwise(to: String, on: bool) -> void:
|
||||||
var e := _pipe_entry()
|
InspectorThread.set_otherwise(self, to, on)
|
||||||
if e == null or on == e.is_otherwise(to):
|
|
||||||
return
|
|
||||||
e.set_pipe_otherwise(to, on)
|
|
||||||
wrote(selected_table())
|
|
||||||
_refresh_otherwise(to)
|
|
||||||
|
|
||||||
|
|
||||||
## Sets one input value passed down the pipe ("" uses the card's default).
|
## Sets one input value passed down the pipe ("" uses the card's default).
|
||||||
func set_pipe_input(to: String, input_name: String, expr: String) -> void:
|
func set_pipe_input(to: String, input_name: String, expr: String) -> void:
|
||||||
var e := _pipe_entry()
|
InspectorThread.set_input(self, to, input_name, expr)
|
||||||
if e == null:
|
|
||||||
return
|
|
||||||
var w := e.with_for(to)
|
|
||||||
var s := expr.strip_edges()
|
|
||||||
if s != "" and InspectorKit.expr_error(s) != "":
|
|
||||||
return
|
|
||||||
if s == "":
|
|
||||||
w.erase(input_name)
|
|
||||||
else:
|
|
||||||
w[input_name] = s
|
|
||||||
if w == e.with_for(to):
|
|
||||||
return
|
|
||||||
e.set_pipe_with(to, w)
|
|
||||||
wrote(selected_table())
|
|
||||||
|
|
||||||
|
|
||||||
func set_pipe_count(to: String, s: String) -> void:
|
func set_pipe_count(to: String, s: String) -> void:
|
||||||
var e := _pipe_entry()
|
InspectorThread.set_count(self, to, s)
|
||||||
if e == null or PipePopover._count_error(s) != "":
|
|
||||||
return
|
|
||||||
var before := e.count_text(to)
|
|
||||||
e.set_pipe_count(to, s.strip_edges() if s.strip_edges() != "" else "1")
|
|
||||||
if e.count_text(to) != before:
|
|
||||||
wrote(selected_table())
|
|
||||||
|
|
||||||
|
|
||||||
func set_pipe_pause(to: String, on: bool) -> void:
|
func set_pipe_pause(to: String, on: bool) -> void:
|
||||||
var e := _pipe_entry()
|
InspectorThread.set_pause(self, to, on)
|
||||||
if e == null or e.pipe_pause.has(to) == on:
|
|
||||||
return
|
|
||||||
if on:
|
|
||||||
e.pipe_pause[to] = true
|
|
||||||
else:
|
|
||||||
e.pipe_pause.erase(to)
|
|
||||||
wrote(selected_table())
|
|
||||||
|
|
||||||
|
|
||||||
func set_pipe_combine(to: String, mode: String) -> void:
|
func set_pipe_combine(to: String, mode: String) -> void:
|
||||||
var e := _pipe_entry()
|
InspectorThread.set_combine(self, to, mode)
|
||||||
if e == null or e.combine_for(to) == mode:
|
|
||||||
return
|
|
||||||
if mode == "all":
|
|
||||||
e.pipe_combine.erase(to)
|
|
||||||
else:
|
|
||||||
e.pipe_combine[to] = mode
|
|
||||||
wrote(selected_table())
|
|
||||||
|
|
||||||
|
|
||||||
func set_pipe_save(to: String, s: String) -> void:
|
func set_pipe_save(to: String, s: String) -> void:
|
||||||
var e := _pipe_entry()
|
InspectorThread.set_save(self, to, s)
|
||||||
if e == null or _save_error(s) != "" or s.strip_edges() == e.save_for(to):
|
|
||||||
return
|
|
||||||
e.set_pipe_save(to, s)
|
|
||||||
wrote(selected_table())
|
|
||||||
|
|
||||||
|
|
||||||
func set_pipe_color(hex: String, to: String) -> void:
|
func set_pipe_color(hex: String, to: String) -> void:
|
||||||
var e := _pipe_entry()
|
InspectorThread.set_color(self, hex, to)
|
||||||
if e == null:
|
|
||||||
return
|
|
||||||
if hex == "":
|
|
||||||
e.pipe_color.erase(to)
|
|
||||||
else:
|
|
||||||
e.pipe_color[to] = hex
|
|
||||||
wrote(selected_table())
|
|
||||||
main.board.geometry_rev += 1
|
|
||||||
|
|
||||||
|
|
||||||
func remove_pipe(to: String) -> void:
|
func remove_pipe(to: String) -> void:
|
||||||
|
|
@ -386,19 +273,26 @@ static func _save_error(s: String) -> String:
|
||||||
|
|
||||||
# ---------- Collections ----------
|
# ---------- Collections ----------
|
||||||
|
|
||||||
## A collection card's members: Array of [item, value] (item without the stem).
|
func set_entry_text(s: String) -> void:
|
||||||
func members(t: RollTable) -> Array:
|
InspectorResult.set_entry_text(self, s)
|
||||||
var out: Array = []
|
|
||||||
var pre := t.var_name + "_"
|
|
||||||
var names: Array = main.persistent_vars.keys()
|
|
||||||
names.sort_custom(func(a: String, b: String) -> bool: return a.naturalnocasecmp_to(b) < 0)
|
|
||||||
for n: String in names:
|
|
||||||
if n.begins_with(pre) and n.length() > pre.length():
|
|
||||||
var v: Variant = main.persistent_vars[n]
|
|
||||||
out.append([n.substr(pre.length()), Expr.format_value(v.get("value") if v is Dictionary else v)])
|
|
||||||
return out
|
|
||||||
|
|
||||||
|
|
||||||
|
func set_entry_details(s: String) -> void:
|
||||||
|
InspectorResult.set_entry_details(self, s)
|
||||||
|
|
||||||
|
|
||||||
|
func set_entry_effects(s: String) -> void:
|
||||||
|
InspectorResult.set_entry_effects(self, s)
|
||||||
|
|
||||||
|
|
||||||
|
func set_entry_show_if(s: String) -> void:
|
||||||
|
InspectorResult.set_entry_show_if(self, s)
|
||||||
|
|
||||||
|
|
||||||
|
## A router case's condition ("" makes it the Otherwise case).
|
||||||
|
func set_case_when(eid: String, s: String) -> void:
|
||||||
|
InspectorResult.set_case_when(self, eid, s)
|
||||||
|
|
||||||
# ---------- Building ----------
|
# ---------- Building ----------
|
||||||
|
|
||||||
func rebuild() -> void:
|
func rebuild() -> void:
|
||||||
|
|
@ -428,9 +322,9 @@ func rebuild() -> void:
|
||||||
else:
|
else:
|
||||||
match str(selection.get("kind", "card")):
|
match str(selection.get("kind", "card")):
|
||||||
"result":
|
"result":
|
||||||
_result_section(t, e)
|
InspectorResult.section(self, t, e)
|
||||||
"pipe":
|
"pipe":
|
||||||
_pipe_section(t, e, str(selection.get("to", "")))
|
InspectorThread.section(self, t, e, str(selection.get("to", "")))
|
||||||
_:
|
_:
|
||||||
InspectorCard.build(self, _content, t)
|
InspectorCard.build(self, _content, t)
|
||||||
_sig = _signature()
|
_sig = _signature()
|
||||||
|
|
@ -494,293 +388,6 @@ static func _title_of(s: String, fallback: String) -> String:
|
||||||
return t if t != "" else fallback
|
return t if t != "" else fallback
|
||||||
|
|
||||||
|
|
||||||
## 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".
|
|
||||||
func _book_line(t: RollTable, e: TableEntry) -> Control:
|
|
||||||
var p := main.data.get_page(e.page)
|
|
||||||
if p == null:
|
|
||||||
var save := InspectorKit.link("Save to the Book", "Keep this result as a Page to reuse on other tables")
|
|
||||||
save.pressed.connect(func() -> void: main.book.save_result(t, e))
|
|
||||||
return save
|
|
||||||
var row := InspectorKit.hbox(8)
|
|
||||||
var open := InspectorKit.link("§ From the Book: %s" % p.label(), "Edit the page; every result using it changes")
|
|
||||||
open.pressed.connect(func() -> void:
|
|
||||||
main.book.set_shown(true)
|
|
||||||
main.book.refresh()
|
|
||||||
main.book.select_page(p.id))
|
|
||||||
row.add_child(open)
|
|
||||||
var unlink := InspectorKit.link("Unlink", "Keep the text here but stop following the page")
|
|
||||||
unlink.pressed.connect(func() -> void:
|
|
||||||
e.page = ""
|
|
||||||
wrote(t, false, true))
|
|
||||||
row.add_child(unlink)
|
|
||||||
return row
|
|
||||||
|
|
||||||
|
|
||||||
## "[1] of [Points ▾]": what picking this option costs (RollCosts).
|
|
||||||
func _cost_row(t: RollTable, e: TableEntry) -> Control:
|
|
||||||
var row := InspectorKit.flow()
|
|
||||||
var amount := InspectorKit.amount(e.cost_amount, "0")
|
|
||||||
amount.tooltip_text = "How much picking this takes away (0 or empty: free)"
|
|
||||||
row.add_child(amount)
|
|
||||||
row.add_child(InspectorKit.word("of"))
|
|
||||||
var picker := ValuePicker.new(main, e.cost_value.trim_prefix("@"))
|
|
||||||
row.add_child(picker)
|
|
||||||
var apply := func() -> void:
|
|
||||||
var a := amount.text.strip_edges()
|
|
||||||
e.cost_amount = "" if a == "" or a == "0" else a
|
|
||||||
if e.cost_amount == "":
|
|
||||||
e.cost_value = ""
|
|
||||||
wrote(t)
|
|
||||||
amount.text_changed.connect(func(_s: String) -> void: apply.call())
|
|
||||||
picker.value_chosen.connect(func(n: String) -> void:
|
|
||||||
e.cost_value = "@" + n.trim_prefix("@")
|
|
||||||
if amount.text.strip_edges() == "":
|
|
||||||
amount.text = "1"
|
|
||||||
apply.call())
|
|
||||||
row.add_child(InspectorKit.note("Greyed out in the pop-up when there isn't enough.", Style.MUTED, 12))
|
|
||||||
return row
|
|
||||||
|
|
||||||
|
|
||||||
func _card_link(t: RollTable) -> Button:
|
|
||||||
var b := InspectorKit.link("On %s · edit the card" % _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: select({"kind": "card", "tid": t.id}))
|
|
||||||
return b
|
|
||||||
|
|
||||||
|
|
||||||
func _result_section(t: RollTable, e: TableEntry) -> void:
|
|
||||||
_content.add_child(_head("Selected result", _title_of(e.text, "(no text)")))
|
|
||||||
_content.add_child(_card_link(t))
|
|
||||||
var plain := main.rules_plain()
|
|
||||||
|
|
||||||
if t.kind != RollTable.KIND_SHEET:
|
|
||||||
var le := InspectorKit.line(e.text, "What this result says")
|
|
||||||
InspectorKit.tag(le, "res.text")
|
|
||||||
le.text_changed.connect(set_entry_text)
|
|
||||||
fields["text"] = le
|
|
||||||
_content.add_child(InspectorKit.field("Text", le))
|
|
||||||
|
|
||||||
var det := InspectorKit.text_box(e.details, "Shown on hover (optional)", 36.0)
|
|
||||||
InspectorKit.tag(det, "res.details")
|
|
||||||
det.text_changed.connect(func() -> void: set_entry_details(det.text))
|
|
||||||
fields["details"] = det
|
|
||||||
_content.add_child(InspectorKit.field("Details", det))
|
|
||||||
_content.add_child(InspectorKit.field("Picture", ImageField.new(main, e.image, func(id: String) -> void:
|
|
||||||
e.image = id
|
|
||||||
e.page = ""
|
|
||||||
wrote(t))))
|
|
||||||
_content.add_child(_book_line(t, e))
|
|
||||||
|
|
||||||
if t.kind == RollTable.KIND_CHOICE and t.choice == "pick" and not (t.is_dynamic() and t.entries.find(e) == 0):
|
|
||||||
show_if_builder = ConditionBuilder.new()
|
|
||||||
show_if_builder.setup(main, e.show_if, not plain, "res.show_if", {"empty_note": "Always offered."})
|
|
||||||
show_if_builder.changed.connect(set_entry_show_if)
|
|
||||||
_content.add_child(InspectorKit.field("Offer only if", show_if_builder))
|
|
||||||
_content.add_child(InspectorKit.field("Costs", _cost_row(t, e)))
|
|
||||||
|
|
||||||
if t.kind == RollTable.KIND_ROUTER:
|
|
||||||
_content.add_child(InspectorCard.case_block(self, t, e))
|
|
||||||
|
|
||||||
effects = EffectsBuilder.new()
|
|
||||||
effects.setup(main, e.effects, t, not plain, "res.fx")
|
|
||||||
effects.changed.connect(set_entry_effects)
|
|
||||||
_content.add_child(InspectorKit.field("When this comes up", 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(_pipe_box(t, e, p))
|
|
||||||
_content.add_child(InspectorKit.field("Then go to", go))
|
|
||||||
_lint_lines(t, e)
|
|
||||||
|
|
||||||
|
|
||||||
func _pipe_section(t: RollTable, e: TableEntry, to: String) -> void:
|
|
||||||
if not e.pipes.has(to):
|
|
||||||
_result_section(t, e)
|
|
||||||
return
|
|
||||||
var target := main.data.get_table(to)
|
|
||||||
_content.add_child(_head("Selected thread", "%s → %s" % [_title_of(e.text, "(no text)"), _title_of(target.name, to) if target else to]))
|
|
||||||
var back := InspectorKit.link("Edit the whole result", "Show the result this thread leaves from")
|
|
||||||
back.add_theme_color_override("font_color", Style.MUTED)
|
|
||||||
back.pressed.connect(func() -> void: select({"kind": "result", "tid": t.id, "eid": e.id}))
|
|
||||||
_content.add_child(back)
|
|
||||||
_content.add_child(_pipe_box(t, e, to))
|
|
||||||
_content.add_child(InspectorKit.field("Thread colour", ColorChoice.new(str(e.pipe_color.get(to, "")), set_pipe_color.bind(to))))
|
|
||||||
_lint_lines(t, e)
|
|
||||||
|
|
||||||
|
|
||||||
## Problems and hints the board check finds on this result's pipes.
|
|
||||||
func _lint_lines(t: RollTable, e: TableEntry) -> void:
|
|
||||||
var box := InspectorKit.vbox(3)
|
|
||||||
var fill := func() -> void:
|
|
||||||
for c in box.get_children():
|
|
||||||
box.remove_child(c)
|
|
||||||
c.queue_free()
|
|
||||||
for it: Dictionary in Roller.lint_pipes(main.data):
|
|
||||||
if str(it["table_id"]) == t.id and str(it["entry_id"]) == e.id:
|
|
||||||
var hint := str(it.get("level", "error")) == "hint" or str(it["message"]).contains("otherwise")
|
|
||||||
box.add_child(InspectorKit.note(("Note: " if hint else "Problem: ") + str(it["message"]) + ".",
|
|
||||||
Style.MUTED if hint else Style.DANGER_INK, 13))
|
|
||||||
box.visible = box.get_child_count() > 0
|
|
||||||
fill.call()
|
|
||||||
_live.append(fill)
|
|
||||||
_content.add_child(box)
|
|
||||||
|
|
||||||
|
|
||||||
func _pipe_box(t: RollTable, e: TableEntry, to: String) -> Control:
|
|
||||||
var target := main.data.get_table(to)
|
|
||||||
var parts := {"inputs": {}}
|
|
||||||
var taken := main.lit_pipes.has(Roller.pipe_key(t.id, e.id, to))
|
|
||||||
var panel := PanelContainer.new()
|
|
||||||
var sb := Style.bordered(Style.box(Style.VALUE_BG if taken else Style.CARD_SOFT, 8, [10, 9, 10, 10]), 1, Style.ACCENT if taken else Style.RULE)
|
|
||||||
panel.add_theme_stylebox_override("panel", sb)
|
|
||||||
var v := InspectorKit.vbox(8)
|
|
||||||
panel.add_child(v)
|
|
||||||
parts["box"] = panel
|
|
||||||
parts["taken"] = taken
|
|
||||||
|
|
||||||
var head := InspectorKit.hbox(8)
|
|
||||||
head.add_child(InspectorKit.word("→", Style.TRIM, true))
|
|
||||||
var tn := Style.make_label(_title_of(target.name, to) if target else to + " (missing)", Style.display(), 19, Style.INK)
|
|
||||||
tn.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
||||||
tn.clip_text = true
|
|
||||||
head.add_child(tn)
|
|
||||||
if taken:
|
|
||||||
head.add_child(_chip("taken last roll", Style.ACCENT_DARK, Style.LIT))
|
|
||||||
elif main.is_entry_lit(t.id, e.id):
|
|
||||||
head.add_child(Style.make_label("not taken", Style.body_bold(), 12, Style.MUTED))
|
|
||||||
v.add_child(head)
|
|
||||||
|
|
||||||
# Inputs the target declares (and any extra names the pipe passes).
|
|
||||||
var w := e.with_for(to)
|
|
||||||
var names: Array = target.input_names() if target else []
|
|
||||||
for nm: String in w:
|
|
||||||
if not names.has(nm):
|
|
||||||
names.append(nm)
|
|
||||||
for nm: String in names:
|
|
||||||
var decl: Dictionary = target.find_input(nm) if target else {}
|
|
||||||
var row := InspectorKit.hbox(6)
|
|
||||||
var lab := str(decl.get("label", "")) if not decl.is_empty() else ""
|
|
||||||
var cap := InspectorKit.word(lab if lab != "" else RollContext.pretty_name(nm))
|
|
||||||
cap.custom_minimum_size = Vector2(64, 0)
|
|
||||||
cap.tooltip_text = "Input %s of %s" % [nm, target.name if target else to]
|
|
||||||
row.add_child(cap)
|
|
||||||
var def := str(decl.get("default", ""))
|
|
||||||
var le := InspectorKit.amount(str(w.get(nm, "")), def if def != "" else "0")
|
|
||||||
le.tooltip_text = "An expression passed as %s. Empty uses the card's default%s." % [nm, (" (" + def + ")") if def != "" else ""]
|
|
||||||
InspectorKit.tag(le, "pipe.%s.in.%s" % [to, nm])
|
|
||||||
var err := InspectorKit.error_label()
|
|
||||||
var nm_c := nm
|
|
||||||
le.text_changed.connect(func(s: String) -> void:
|
|
||||||
var msg := InspectorKit.expr_error(s, "This value")
|
|
||||||
InspectorKit.show_error(err, msg)
|
|
||||||
InspectorKit.mark(le, msg == "")
|
|
||||||
set_pipe_input(to, nm_c, s)
|
|
||||||
)
|
|
||||||
row.add_child(le)
|
|
||||||
if decl.is_empty():
|
|
||||||
row.add_child(InspectorKit.word("(not an input of this card)", Style.MUTED))
|
|
||||||
(parts["inputs"] as Dictionary)[nm] = le
|
|
||||||
v.add_child(row)
|
|
||||||
v.add_child(err)
|
|
||||||
|
|
||||||
# Only if / Otherwise.
|
|
||||||
var cond := ConditionBuilder.new()
|
|
||||||
cond.setup(main, e.when_for(to), not main.rules_plain(), "pipe.%s.when" % to,
|
|
||||||
{"add_label": "+ Only if…" if e.when_for(to) == "" else "+ Add condition"})
|
|
||||||
cond.changed.connect(func(s: String) -> void: set_pipe_when(to, s))
|
|
||||||
parts["when"] = cond
|
|
||||||
var when_box := InspectorKit.vbox(4)
|
|
||||||
when_box.add_child(InspectorKit.flabel("Only if"))
|
|
||||||
when_box.add_child(cond)
|
|
||||||
v.add_child(when_box)
|
|
||||||
var other := InspectorKit.check_box("Otherwise", e.is_otherwise(to))
|
|
||||||
other.tooltip_text = "Runs only when none of this result's \"Only if\" threads is true"
|
|
||||||
other.toggled.connect(func(on: bool) -> void: set_pipe_otherwise(to, on))
|
|
||||||
parts["otherwise"] = other
|
|
||||||
v.add_child(other)
|
|
||||||
var pause := InspectorKit.check_box("Wait for me first", e.pipe_pause.has(to))
|
|
||||||
pause.tooltip_text = "The roll stops here with Continue ▸ in the tray, so you can reveal the next part when you're ready"
|
|
||||||
pause.toggled.connect(func(on: bool) -> void: set_pipe_pause(to, on))
|
|
||||||
parts["pause"] = pause
|
|
||||||
v.add_child(pause)
|
|
||||||
|
|
||||||
# Count and saves as.
|
|
||||||
var cr := InspectorKit.flow()
|
|
||||||
cr.add_child(InspectorKit.word("Rolls"))
|
|
||||||
var count := InspectorKit.amount(e.count_text(to), "1")
|
|
||||||
count.tooltip_text = "A number, or an expression such as @terms, answer or 1d3 (worked out when the thread runs)"
|
|
||||||
InspectorKit.tag(count, "pipe.%s.count" % to)
|
|
||||||
var cerr := InspectorKit.error_label()
|
|
||||||
count.text_changed.connect(func(s: String) -> void:
|
|
||||||
var msg := PipePopover._count_error(s)
|
|
||||||
InspectorKit.show_error(cerr, msg)
|
|
||||||
InspectorKit.mark(count, msg == "")
|
|
||||||
set_pipe_count(to, s)
|
|
||||||
)
|
|
||||||
cr.add_child(count)
|
|
||||||
cr.add_child(InspectorKit.word("times, then"))
|
|
||||||
var then := OptionButton.new()
|
|
||||||
ModalCard.style_popup(then.get_popup())
|
|
||||||
for i in RollCombine.LABELS.size():
|
|
||||||
then.add_item(RollCombine.LABELS[i], i)
|
|
||||||
then.select(maxi(0, RollCombine.MODES.find(e.combine_for(to))))
|
|
||||||
then.tooltip_text = "What to do with the rolls when there's more than one (rerolls, best of two, totals…)"
|
|
||||||
then.item_selected.connect(func(i: int) -> void: set_pipe_combine(to, RollCombine.MODES[i]))
|
|
||||||
cr.add_child(then)
|
|
||||||
parts["combine"] = then
|
|
||||||
var sr := InspectorKit.hbox(6)
|
|
||||||
sr.add_child(InspectorKit.word("Saves as"))
|
|
||||||
var save := InspectorKit.line(e.save_for(to), "nothing (or a name)")
|
|
||||||
save.tooltip_text = "Keep the result as a value: a name lasts one roll, @name is kept between rolls"
|
|
||||||
InspectorKit.tag(save, "pipe.%s.save" % to)
|
|
||||||
save.text_changed.connect(func(s: String) -> void:
|
|
||||||
var msg := _save_error(s)
|
|
||||||
InspectorKit.show_error(cerr, msg)
|
|
||||||
InspectorKit.mark(save, msg == "")
|
|
||||||
set_pipe_save(to, s)
|
|
||||||
)
|
|
||||||
sr.add_child(save)
|
|
||||||
parts["count"] = count
|
|
||||||
parts["save"] = save
|
|
||||||
v.add_child(cr)
|
|
||||||
v.add_child(sr)
|
|
||||||
v.add_child(cerr)
|
|
||||||
|
|
||||||
var rm := InspectorKit.link("Delete thread", "Delete this thread")
|
|
||||||
rm.add_theme_color_override("font_color", Style.DANGER_INK)
|
|
||||||
rm.add_theme_color_override("font_hover_color", Style.DANGER_INK)
|
|
||||||
rm.pressed.connect(func() -> void: remove_pipe(to))
|
|
||||||
v.add_child(rm)
|
|
||||||
pipe_parts[to] = parts
|
|
||||||
_refresh_otherwise(to)
|
|
||||||
return panel
|
|
||||||
|
|
||||||
|
|
||||||
## Otherwise is off and disabled while the pipe has an Only if.
|
|
||||||
func _refresh_otherwise(to: String) -> void:
|
|
||||||
var parts: Dictionary = pipe_parts.get(to, {})
|
|
||||||
var e := _pipe_entry()
|
|
||||||
if parts.is_empty() or e == null:
|
|
||||||
return
|
|
||||||
var cb := parts["otherwise"] as CheckBox
|
|
||||||
var has_when := e.when_for(to) != ""
|
|
||||||
cb.disabled = has_when
|
|
||||||
cb.set_pressed_no_signal(e.is_otherwise(to))
|
|
||||||
cb.tooltip_text = "Turn off \"Only if\" first: a thread with a condition isn't an otherwise thread" if has_when \
|
|
||||||
else "Runs only when none of this result's \"Only if\" threads is true"
|
|
||||||
|
|
||||||
|
|
||||||
static func _chip(text: String, fg: Color, bg: Color) -> Control:
|
|
||||||
var p := PanelContainer.new()
|
|
||||||
p.add_theme_stylebox_override("panel", Style.bordered(Style.box(bg, 9, [7, 1, 7, 2]), 1, Style.ACCENT))
|
|
||||||
p.add_child(Style.make_label(text, Style.body_bold(), 12, fg))
|
|
||||||
p.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
|
||||||
return p
|
|
||||||
|
|
||||||
|
|
||||||
## Closes any open value-picker menu (before an undo rebuilds the board).
|
## Closes any open value-picker menu (before an undo rebuilds the board).
|
||||||
func close_menus() -> void:
|
func close_menus() -> void:
|
||||||
_close_pickers(self)
|
_close_pickers(self)
|
||||||
|
|
|
||||||
145
ui/inspector_result.gd
Normal file
145
ui/inspector_result.gd
Normal file
|
|
@ -0,0 +1,145 @@
|
||||||
|
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 Book", "Keep this result as a Page 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("§ From the Book: %s" % p.label(), "Edit the page; 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 page")
|
||||||
|
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).
|
||||||
|
static func cost_row(insp: Inspector, t: RollTable, e: TableEntry) -> Control:
|
||||||
|
var row := InspectorKit.flow()
|
||||||
|
var amount := InspectorKit.amount(e.cost_amount, "0")
|
||||||
|
amount.tooltip_text = "How much picking this takes away (0 or empty: free)"
|
||||||
|
row.add_child(amount)
|
||||||
|
row.add_child(InspectorKit.word("of"))
|
||||||
|
var picker := ValuePicker.new(insp.main, e.cost_value.trim_prefix("@"))
|
||||||
|
row.add_child(picker)
|
||||||
|
var apply := func() -> void:
|
||||||
|
var a := amount.text.strip_edges()
|
||||||
|
e.cost_amount = "" if a == "" or a == "0" else a
|
||||||
|
if e.cost_amount == "":
|
||||||
|
e.cost_value = ""
|
||||||
|
insp.wrote(t)
|
||||||
|
amount.text_changed.connect(func(_s: String) -> void: apply.call())
|
||||||
|
picker.value_chosen.connect(func(n: String) -> void:
|
||||||
|
e.cost_value = "@" + n.trim_prefix("@")
|
||||||
|
if amount.text.strip_edges() == "":
|
||||||
|
amount.text = "1"
|
||||||
|
apply.call())
|
||||||
|
row.add_child(InspectorKit.note("Greyed out in the pop-up when there isn't enough.", 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
|
||||||
|
|
||||||
|
|
||||||
|
static func section(insp: Inspector, t: RollTable, e: TableEntry) -> void:
|
||||||
|
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")
|
||||||
|
InspectorKit.tag(le, "res.text")
|
||||||
|
le.text_changed.connect(insp.set_entry_text)
|
||||||
|
insp.fields["text"] = le
|
||||||
|
insp._content.add_child(InspectorKit.field("Text", le))
|
||||||
|
|
||||||
|
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
|
||||||
|
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))
|
||||||
|
|
||||||
|
if t.kind == RollTable.KIND_CHOICE and t.choice == "pick" and not (t.is_dynamic() and t.entries.find(e) == 0):
|
||||||
|
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."})
|
||||||
|
insp.show_if_builder.changed.connect(insp.set_entry_show_if)
|
||||||
|
insp._content.add_child(InspectorKit.field("Offer only if", insp.show_if_builder))
|
||||||
|
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.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(insp.selected_table())
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
||||||
1
ui/inspector_result.gd.uid
Normal file
1
ui/inspector_result.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://dsm5jyij51kwv
|
||||||
41
ui/inspector_sync.gd
Normal file
41
ui/inspector_sync.gd
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
class_name InspectorSync
|
||||||
|
extends RefCounted
|
||||||
|
## What the Inspector watches to know when to rebuild: the selection signature
|
||||||
|
## and a collection card's members.
|
||||||
|
|
||||||
|
|
||||||
|
## A collection card's members: Array of [item, value] (item without the stem).
|
||||||
|
static func members(insp: Inspector, t: RollTable) -> Array:
|
||||||
|
var out: Array = []
|
||||||
|
var pre := t.var_name + "_"
|
||||||
|
var names: Array = insp.main.persistent_vars.keys()
|
||||||
|
names.sort_custom(func(a: String, b: String) -> bool: return a.naturalnocasecmp_to(b) < 0)
|
||||||
|
for n: String in names:
|
||||||
|
if n.begins_with(pre) and n.length() > pre.length():
|
||||||
|
var v: Variant = insp.main.persistent_vars[n]
|
||||||
|
out.append([n.substr(pre.length()), Expr.format_value(v.get("value") if v is Dictionary else v)])
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
static func signature(insp: Inspector) -> String:
|
||||||
|
var t := insp.selected_table()
|
||||||
|
if insp.selection.is_empty():
|
||||||
|
return ""
|
||||||
|
if t == null or (insp.selection.has("eid") and insp.selected_entry() == null):
|
||||||
|
return "gone"
|
||||||
|
var d := t.to_dict()
|
||||||
|
for k in ["x", "y", "collapsed"]:
|
||||||
|
d.erase(k)
|
||||||
|
var parts := PackedStringArray([JSON.stringify(d), insp.main.rules_view(), str(insp.main.mode)])
|
||||||
|
for x in insp.main.data.tables:
|
||||||
|
if x.kind == RollTable.KIND_VARIABLE:
|
||||||
|
parts.append("%s|%s|%s" % [x.name, x.var_name, x.var_type])
|
||||||
|
for e in t.entries:
|
||||||
|
for p in e.pipes:
|
||||||
|
var target := insp.main.data.get_table(p)
|
||||||
|
parts.append(("%s|%s" % [target.name, JSON.stringify(target.inputs)]) if target else "-")
|
||||||
|
parts.append(str(insp.main.lit_pipes.has(Roller.pipe_key(t.id, e.id, p))))
|
||||||
|
parts.append(str(insp.main.is_entry_lit(t.id, e.id)))
|
||||||
|
if t.is_collection():
|
||||||
|
parts.append(JSON.stringify(members(insp, t)))
|
||||||
|
return str(hash("\n".join(parts)))
|
||||||
1
ui/inspector_sync.gd.uid
Normal file
1
ui/inspector_sync.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://bhlunutm0j5w6
|
||||||
278
ui/inspector_thread.gd
Normal file
278
ui/inspector_thread.gd
Normal file
|
|
@ -0,0 +1,278 @@
|
||||||
|
class_name InspectorThread
|
||||||
|
extends RefCounted
|
||||||
|
## The Inspector's "Selected thread" section and the pipe edit rules behind it.
|
||||||
|
## Inspector keeps the public set_pipe_* functions and delegates here.
|
||||||
|
|
||||||
|
|
||||||
|
static func set_when(insp: Inspector, to: String, s: String) -> void:
|
||||||
|
var e := insp.selected_entry()
|
||||||
|
if e == null or PipePopover.when_error(s) != "" or s.strip_edges() == e.when_for(to):
|
||||||
|
return
|
||||||
|
e.set_pipe_when(to, s)
|
||||||
|
insp.wrote(insp.selected_table())
|
||||||
|
refresh_otherwise(insp, to)
|
||||||
|
|
||||||
|
|
||||||
|
static func set_otherwise(insp: Inspector, to: String, on: bool) -> void:
|
||||||
|
var e := insp.selected_entry()
|
||||||
|
if e == null or on == e.is_otherwise(to):
|
||||||
|
return
|
||||||
|
e.set_pipe_otherwise(to, on)
|
||||||
|
insp.wrote(insp.selected_table())
|
||||||
|
refresh_otherwise(insp, to)
|
||||||
|
|
||||||
|
|
||||||
|
## Sets one input value passed down the pipe ("" uses the card's default).
|
||||||
|
static func set_input(insp: Inspector, to: String, input_name: String, expr: String) -> void:
|
||||||
|
var e := insp.selected_entry()
|
||||||
|
if e == null:
|
||||||
|
return
|
||||||
|
var w := e.with_for(to)
|
||||||
|
var s := expr.strip_edges()
|
||||||
|
if s != "" and InspectorKit.expr_error(s) != "":
|
||||||
|
return
|
||||||
|
if s == "":
|
||||||
|
w.erase(input_name)
|
||||||
|
else:
|
||||||
|
w[input_name] = s
|
||||||
|
if w == e.with_for(to):
|
||||||
|
return
|
||||||
|
e.set_pipe_with(to, w)
|
||||||
|
insp.wrote(insp.selected_table())
|
||||||
|
|
||||||
|
|
||||||
|
static func set_count(insp: Inspector, to: String, s: String) -> void:
|
||||||
|
var e := insp.selected_entry()
|
||||||
|
if e == null or PipePopover._count_error(s) != "":
|
||||||
|
return
|
||||||
|
var before := e.count_text(to)
|
||||||
|
e.set_pipe_count(to, s.strip_edges() if s.strip_edges() != "" else "1")
|
||||||
|
if e.count_text(to) != before:
|
||||||
|
insp.wrote(insp.selected_table())
|
||||||
|
|
||||||
|
|
||||||
|
static func set_pause(insp: Inspector, to: String, on: bool) -> void:
|
||||||
|
var e := insp.selected_entry()
|
||||||
|
if e == null or e.pipe_pause.has(to) == on:
|
||||||
|
return
|
||||||
|
if on:
|
||||||
|
e.pipe_pause[to] = true
|
||||||
|
else:
|
||||||
|
e.pipe_pause.erase(to)
|
||||||
|
insp.wrote(insp.selected_table())
|
||||||
|
|
||||||
|
|
||||||
|
static func set_combine(insp: Inspector, to: String, mode: String) -> void:
|
||||||
|
var e := insp.selected_entry()
|
||||||
|
if e == null or e.combine_for(to) == mode:
|
||||||
|
return
|
||||||
|
if mode == "all":
|
||||||
|
e.pipe_combine.erase(to)
|
||||||
|
else:
|
||||||
|
e.pipe_combine[to] = mode
|
||||||
|
insp.wrote(insp.selected_table())
|
||||||
|
|
||||||
|
|
||||||
|
static func set_save(insp: Inspector, to: String, s: String) -> void:
|
||||||
|
var e := insp.selected_entry()
|
||||||
|
if e == null or Inspector._save_error(s) != "" or s.strip_edges() == e.save_for(to):
|
||||||
|
return
|
||||||
|
e.set_pipe_save(to, s)
|
||||||
|
insp.wrote(insp.selected_table())
|
||||||
|
|
||||||
|
|
||||||
|
static func set_color(insp: Inspector, hex: String, to: String) -> void:
|
||||||
|
var e := insp.selected_entry()
|
||||||
|
if e == null:
|
||||||
|
return
|
||||||
|
if hex == "":
|
||||||
|
e.pipe_color.erase(to)
|
||||||
|
else:
|
||||||
|
e.pipe_color[to] = hex
|
||||||
|
insp.wrote(insp.selected_table())
|
||||||
|
insp.main.board.geometry_rev += 1
|
||||||
|
|
||||||
|
|
||||||
|
static func section(insp: Inspector, t: RollTable, e: TableEntry, to: String) -> void:
|
||||||
|
if not e.pipes.has(to):
|
||||||
|
InspectorResult.section(insp, t, e)
|
||||||
|
return
|
||||||
|
var target := insp.main.data.get_table(to)
|
||||||
|
insp._content.add_child(insp._head("Selected thread", "%s → %s" % [Inspector._title_of(e.text, "(no text)"), Inspector._title_of(target.name, to) if target else to]))
|
||||||
|
var back := InspectorKit.link("Edit the whole result", "Show the result this thread leaves from")
|
||||||
|
back.add_theme_color_override("font_color", Style.MUTED)
|
||||||
|
back.pressed.connect(func() -> void: insp.select({"kind": "result", "tid": t.id, "eid": e.id}))
|
||||||
|
insp._content.add_child(back)
|
||||||
|
insp._content.add_child(box(insp, t, e, to))
|
||||||
|
insp._content.add_child(InspectorKit.field("Thread colour", ColorChoice.new(str(e.pipe_color.get(to, "")), func(h: String) -> void: set_color(insp, h, to))))
|
||||||
|
lint_lines(insp, t, e)
|
||||||
|
|
||||||
|
|
||||||
|
## Problems and hints the board check finds on this result's pipes.
|
||||||
|
static func lint_lines(insp: Inspector, t: RollTable, e: TableEntry) -> void:
|
||||||
|
var box := InspectorKit.vbox(3)
|
||||||
|
var fill := func() -> void:
|
||||||
|
for c in box.get_children():
|
||||||
|
box.remove_child(c)
|
||||||
|
c.queue_free()
|
||||||
|
for it: Dictionary in Roller.lint_pipes(insp.main.data):
|
||||||
|
if str(it["table_id"]) == t.id and str(it["entry_id"]) == e.id:
|
||||||
|
var hint := str(it.get("level", "error")) == "hint" or str(it["message"]).contains("otherwise")
|
||||||
|
box.add_child(InspectorKit.note(("Note: " if hint else "Problem: ") + str(it["message"]) + ".",
|
||||||
|
Style.MUTED if hint else Style.DANGER_INK, 13))
|
||||||
|
box.visible = box.get_child_count() > 0
|
||||||
|
fill.call()
|
||||||
|
insp._live.append(fill)
|
||||||
|
insp._content.add_child(box)
|
||||||
|
|
||||||
|
|
||||||
|
static func box(insp: Inspector, t: RollTable, e: TableEntry, to: String) -> Control:
|
||||||
|
var target := insp.main.data.get_table(to)
|
||||||
|
var parts := {"inputs": {}}
|
||||||
|
var taken := insp.main.lit_pipes.has(Roller.pipe_key(t.id, e.id, to))
|
||||||
|
var panel := PanelContainer.new()
|
||||||
|
var sb := Style.bordered(Style.box(Style.VALUE_BG if taken else Style.CARD_SOFT, 8, [10, 9, 10, 10]), 1, Style.ACCENT if taken else Style.RULE)
|
||||||
|
panel.add_theme_stylebox_override("panel", sb)
|
||||||
|
var v := InspectorKit.vbox(8)
|
||||||
|
panel.add_child(v)
|
||||||
|
parts["box"] = panel
|
||||||
|
parts["taken"] = taken
|
||||||
|
|
||||||
|
var head := InspectorKit.hbox(8)
|
||||||
|
head.add_child(InspectorKit.word("→", Style.TRIM, true))
|
||||||
|
var tn := Style.make_label(Inspector._title_of(target.name, to) if target else to + " (missing)", Style.display(), 19, Style.INK)
|
||||||
|
tn.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||||
|
tn.clip_text = true
|
||||||
|
head.add_child(tn)
|
||||||
|
if taken:
|
||||||
|
head.add_child(_chip("taken last roll", Style.ACCENT_DARK, Style.LIT))
|
||||||
|
elif insp.main.is_entry_lit(t.id, e.id):
|
||||||
|
head.add_child(Style.make_label("not taken", Style.body_bold(), 12, Style.MUTED))
|
||||||
|
v.add_child(head)
|
||||||
|
|
||||||
|
# Inputs the target declares (and any extra names the pipe passes).
|
||||||
|
var w := e.with_for(to)
|
||||||
|
var names: Array = target.input_names() if target else []
|
||||||
|
for nm: String in w:
|
||||||
|
if not names.has(nm):
|
||||||
|
names.append(nm)
|
||||||
|
for nm: String in names:
|
||||||
|
var decl: Dictionary = target.find_input(nm) if target else {}
|
||||||
|
var row := InspectorKit.hbox(6)
|
||||||
|
var lab := str(decl.get("label", "")) if not decl.is_empty() else ""
|
||||||
|
var cap := InspectorKit.word(lab if lab != "" else RollContext.pretty_name(nm))
|
||||||
|
cap.custom_minimum_size = Vector2(64, 0)
|
||||||
|
cap.tooltip_text = "Input %s of %s" % [nm, target.name if target else to]
|
||||||
|
row.add_child(cap)
|
||||||
|
var def := str(decl.get("default", ""))
|
||||||
|
var le := InspectorKit.amount(str(w.get(nm, "")), def if def != "" else "0")
|
||||||
|
le.tooltip_text = "An expression passed as %s. Empty uses the card's default%s." % [nm, (" (" + def + ")") if def != "" else ""]
|
||||||
|
InspectorKit.tag(le, "pipe.%s.in.%s" % [to, nm])
|
||||||
|
var err := InspectorKit.error_label()
|
||||||
|
var nm_c := nm
|
||||||
|
le.text_changed.connect(func(s: String) -> void:
|
||||||
|
var msg := InspectorKit.expr_error(s, "This value")
|
||||||
|
InspectorKit.show_error(err, msg)
|
||||||
|
InspectorKit.mark(le, msg == "")
|
||||||
|
set_input(insp, to, nm_c, s)
|
||||||
|
)
|
||||||
|
row.add_child(le)
|
||||||
|
if decl.is_empty():
|
||||||
|
row.add_child(InspectorKit.word("(not an input of this card)", Style.MUTED))
|
||||||
|
(parts["inputs"] as Dictionary)[nm] = le
|
||||||
|
v.add_child(row)
|
||||||
|
v.add_child(err)
|
||||||
|
|
||||||
|
# Only if / Otherwise.
|
||||||
|
var cond := ConditionBuilder.new()
|
||||||
|
cond.setup(insp.main, e.when_for(to), not insp.main.rules_plain(), "pipe.%s.when" % to,
|
||||||
|
{"add_label": "+ Only if…" if e.when_for(to) == "" else "+ Add condition"})
|
||||||
|
cond.changed.connect(func(s: String) -> void: set_when(insp, to, s))
|
||||||
|
parts["when"] = cond
|
||||||
|
var when_box := InspectorKit.vbox(4)
|
||||||
|
when_box.add_child(InspectorKit.flabel("Only if"))
|
||||||
|
when_box.add_child(cond)
|
||||||
|
v.add_child(when_box)
|
||||||
|
var other := InspectorKit.check_box("Otherwise", e.is_otherwise(to))
|
||||||
|
other.tooltip_text = "Runs only when none of this result's \"Only if\" threads is true"
|
||||||
|
other.toggled.connect(func(on: bool) -> void: set_otherwise(insp, to, on))
|
||||||
|
parts["otherwise"] = other
|
||||||
|
v.add_child(other)
|
||||||
|
var pause := InspectorKit.check_box("Wait for me first", e.pipe_pause.has(to))
|
||||||
|
pause.tooltip_text = "The roll stops here with Continue ▸ in the tray, so you can reveal the next part when you're ready"
|
||||||
|
pause.toggled.connect(func(on: bool) -> void: set_pause(insp, to, on))
|
||||||
|
parts["pause"] = pause
|
||||||
|
v.add_child(pause)
|
||||||
|
|
||||||
|
# Count and saves as.
|
||||||
|
var cr := InspectorKit.flow()
|
||||||
|
cr.add_child(InspectorKit.word("Rolls"))
|
||||||
|
var count := InspectorKit.amount(e.count_text(to), "1")
|
||||||
|
count.tooltip_text = "A number, or an expression such as @terms, answer or 1d3 (worked out when the thread runs)"
|
||||||
|
InspectorKit.tag(count, "pipe.%s.count" % to)
|
||||||
|
var cerr := InspectorKit.error_label()
|
||||||
|
count.text_changed.connect(func(s: String) -> void:
|
||||||
|
var msg := PipePopover._count_error(s)
|
||||||
|
InspectorKit.show_error(cerr, msg)
|
||||||
|
InspectorKit.mark(count, msg == "")
|
||||||
|
set_count(insp, to, s)
|
||||||
|
)
|
||||||
|
cr.add_child(count)
|
||||||
|
cr.add_child(InspectorKit.word("times, then"))
|
||||||
|
var then := OptionButton.new()
|
||||||
|
ModalCard.style_popup(then.get_popup())
|
||||||
|
for i in RollCombine.LABELS.size():
|
||||||
|
then.add_item(RollCombine.LABELS[i], i)
|
||||||
|
then.select(maxi(0, RollCombine.MODES.find(e.combine_for(to))))
|
||||||
|
then.tooltip_text = "What to do with the rolls when there's more than one (rerolls, best of two, totals…)"
|
||||||
|
then.item_selected.connect(func(i: int) -> void: set_combine(insp, to, RollCombine.MODES[i]))
|
||||||
|
cr.add_child(then)
|
||||||
|
parts["combine"] = then
|
||||||
|
var sr := InspectorKit.hbox(6)
|
||||||
|
sr.add_child(InspectorKit.word("Saves as"))
|
||||||
|
var save := InspectorKit.line(e.save_for(to), "nothing (or a name)")
|
||||||
|
save.tooltip_text = "Keep the result as a value: a name lasts one roll, @name is kept between rolls"
|
||||||
|
InspectorKit.tag(save, "pipe.%s.save" % to)
|
||||||
|
save.text_changed.connect(func(s: String) -> void:
|
||||||
|
var msg := Inspector._save_error(s)
|
||||||
|
InspectorKit.show_error(cerr, msg)
|
||||||
|
InspectorKit.mark(save, msg == "")
|
||||||
|
set_save(insp, to, s)
|
||||||
|
)
|
||||||
|
sr.add_child(save)
|
||||||
|
parts["count"] = count
|
||||||
|
parts["save"] = save
|
||||||
|
v.add_child(cr)
|
||||||
|
v.add_child(sr)
|
||||||
|
v.add_child(cerr)
|
||||||
|
|
||||||
|
var rm := InspectorKit.link("Delete thread", "Delete this thread")
|
||||||
|
rm.add_theme_color_override("font_color", Style.DANGER_INK)
|
||||||
|
rm.add_theme_color_override("font_hover_color", Style.DANGER_INK)
|
||||||
|
rm.pressed.connect(func() -> void: insp.remove_pipe(to))
|
||||||
|
v.add_child(rm)
|
||||||
|
insp.pipe_parts[to] = parts
|
||||||
|
refresh_otherwise(insp, to)
|
||||||
|
return panel
|
||||||
|
|
||||||
|
|
||||||
|
## Otherwise is off and disabled while the pipe has an Only if.
|
||||||
|
static func refresh_otherwise(insp: Inspector, to: String) -> void:
|
||||||
|
var parts: Dictionary = insp.pipe_parts.get(to, {})
|
||||||
|
var e := insp.selected_entry()
|
||||||
|
if parts.is_empty() or e == null:
|
||||||
|
return
|
||||||
|
var cb := parts["otherwise"] as CheckBox
|
||||||
|
var has_when := e.when_for(to) != ""
|
||||||
|
cb.disabled = has_when
|
||||||
|
cb.set_pressed_no_signal(e.is_otherwise(to))
|
||||||
|
cb.tooltip_text = "Turn off \"Only if\" first: a thread with a condition isn't an otherwise thread" if has_when \
|
||||||
|
else "Runs only when none of this result's \"Only if\" threads is true"
|
||||||
|
|
||||||
|
|
||||||
|
static func _chip(text: String, fg: Color, bg: Color) -> Control:
|
||||||
|
var p := PanelContainer.new()
|
||||||
|
p.add_theme_stylebox_override("panel", Style.bordered(Style.box(bg, 9, [7, 1, 7, 2]), 1, Style.ACCENT))
|
||||||
|
p.add_child(Style.make_label(text, Style.body_bold(), 12, fg))
|
||||||
|
p.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
||||||
|
return p
|
||||||
1
ui/inspector_thread.gd.uid
Normal file
1
ui/inspector_thread.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://c7ox37828p5on
|
||||||
Loading…
Reference in a new issue