diff --git a/core/roller.gd b/core/roller.gd index 57f1e9f..891cb62 100644 --- a/core/roller.gd +++ b/core/roller.gd @@ -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, []) diff --git a/tests/test_options.gd b/tests/test_options.gd index 447641a..37a3ab3 100644 --- a/tests/test_options.gd +++ b/tests/test_options.gd @@ -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) diff --git a/ui/inspector.gd b/ui/inspector.gd index 7f7429b..f747301 100644 --- a/ui/inspector.gd +++ b/ui/inspector.gd @@ -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: diff --git a/ui/table_card.gd b/ui/table_card.gd index 29ef3c9..fcec0e9 100644 --- a/ui/table_card.gd +++ b/ui/table_card.gd @@ -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)