Join the inspector and display halves; starting values apply to rolls

- Cards read the inspector's selection ({kind, tid, eid}) and the
  inspector marks the selected row on every card when it changes.
- A variable card's starting value now applies: before a top-level
  roll, each declared variable that isn't set yet and has a starting
  value is set to it (a "starts at 9" Strength no longer reads as 0).
- Check cards in Build no longer repeat "Success Success": a result
  text equal to the outlet name shows as an empty field with a hint.
- test_options switches to the Text view through Main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
RobinFiredrake 2026-11-08 21:36:29 -06:00
parent c61d5c375c
commit adb93c545c
4 changed files with 49 additions and 3 deletions

View file

@ -126,9 +126,28 @@ static func roll_async(board: TowerBoard, table_id: String, ctx: RollContext, de
ctx.halted = ""
ctx.root = {}
ctx.forget_declarations()
apply_starting_values(board, ctx)
return await _chain(board, table_id, depth, ctx)
## A variable card that says "starts at …" gives its variable that value
## the first time a roll needs it: before a top-level roll, each declared
## variable that isn't set yet and has a starting value is set to it (and
## saved like any other change). Variables with no starting value stay unset,
## and collections are left alone.
static func apply_starting_values(board: TowerBoard, ctx: RollContext) -> void:
if board == null:
return
for t in board.tables:
if t.kind != RollTable.KIND_VARIABLE or t.is_collection() or t.var_name == "":
continue
if t.initial.strip_edges() == "" or ctx.get_value("@" + t.var_name) != null:
continue
var r := t.initial_value(ctx)
if str(r.get("error", "")) == "":
ctx.save("@" + t.var_name, r["value"], t.id)
## The steps of the tree built so far (ctx.root), e.g. while a prompt is open.
static func progress(ctx: RollContext) -> Array:
return flatten(ctx.root, [])

View file

@ -549,6 +549,8 @@ func _test_card() -> void:
main.persistent_vars["skill_admin"] = {"value": 0, "source": ""}
# These checks read the stored rule text (the Text view).
RulesView.fallback_plain = false
if main.has_method("set_rules_view"):
main.set_rules_view("text")
main._rebuild_cards()
await process_frame
var card := main.card_for("raise_card")
@ -561,6 +563,8 @@ func _test_card() -> void:
card = main.card_for("raise_card")
_check(_has(card, "only if @terms > 2"), "Build mode shows show_if under the option (edited in the inspector)")
RulesView.fallback_plain = true
if main.has_method("set_rules_view"):
main.set_rules_view("plain")
card.rebuild()
_check(_has(card, "only if Terms is more than 2"), "and in plain words in the Plain view")
var d := TableSettingsDialog.new(t)

View file

@ -93,11 +93,26 @@ func select(sel: Dictionary) -> void:
set_collapsed(false)
selection = sel
rebuild()
_mark_cards()
func clear() -> void:
selection = {}
rebuild()
_mark_cards()
## Puts the copper selection bar on the selected result's row, and clears it
## everywhere else.
func _mark_cards() -> void:
if main == null:
return
var tid := str(selection.get("tid", ""))
var eid := str(selection.get("eid", "")) if str(selection.get("kind", "")) == "result" else ""
for c in main.cards.values():
var card := c as TableCard
if card and card.has_method("set_selected_entry"):
card.set_selected_entry(eid if card.table.id == tid else "")
func set_collapsed(on: bool) -> void:

View file

@ -167,8 +167,12 @@ func rebuild() -> void:
if main.has_method("inspector_selection"):
var sel: Variant = main.call("inspector_selection")
_selected_eid = ""
if sel is Dictionary and str((sel as Dictionary).get("table_id", "")) == table.id:
_selected_eid = str((sel as Dictionary).get("entry_id", ""))
# The inspector reports {kind, tid, eid}; older callers used {table_id, entry_id}.
if sel is Dictionary:
var d := sel as Dictionary
var tid := str(d.get("tid", d.get("table_id", "")))
if tid == table.id and str(d.get("kind", "result")) == "result":
_selected_eid = str(d.get("eid", d.get("entry_id", "")))
var build := main.mode == Main.Mode.BUILD
custom_minimum_size = Vector2(card_width(), 0)
@ -938,7 +942,11 @@ func _make_check_row(e: TableEntry, index: int, build: bool, numw: float) -> Con
nm.size_flags_vertical = SIZE_SHRINK_CENTER
line.add_child(nm)
var edit := _text_edit(e, index, false)
edit.placeholder_text = check_outlet_name(index)
# The outlet name is already shown, so a result text that just repeats
# it ("Success") shows as an empty field with a hint instead.
if e.text.strip_edges() == check_outlet_name(index):
edit.text = ""
edit.placeholder_text = "What happens on a %s (optional)" % check_outlet_name(index).to_lower()
line.add_child(edit)
_add_rule_chips(col, e)
_hook_select(row, e.id)