2026-11-08 21:24:25 -06:00
|
|
|
|
class_name EffectsBuilder
|
|
|
|
|
|
extends VBoxContainer
|
|
|
|
|
|
## The inspector's "When this comes up" editor: one row per effect statement
|
|
|
|
|
|
## (Builder.parse_effects), each `[op ▾] [amount] to/from [value ▾] ×`, plus
|
UI for scales: make, show and edit ordered-step values
- Making one: Scale (ordered steps) in + Card, the inspector's Type switch
and the settings dialog; steps one per line and a starting step dropdown
(InspectorScale); new scales get Low, Medium, High.
- Showing one: the variable card shows the current step and the steps in a
row with the current one marked; the Variables tab stores a typed step
number or name as the step.
- Plain words: Builder ops step_up, step_down, toward, at_least, at_most
(BuilderScales; step_up/down need the board), DescribeScales phrases,
scale effect rows (EffectsScaleRow) and step dropdowns in conditions.
- Help: a Scales topic after Values and changes.
- Tests: test_ui_scales, plus builder and describe cases.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 21:25:30 -06:00
|
|
|
|
## "+ Add a change". A scale value's row is EffectsScaleRow. A statement the builder can't show stays a text field
|
2026-11-08 21:24:25 -06:00
|
|
|
|
## with its problem. "Edit as text" switches to the whole effects text, and
|
|
|
|
|
|
## "Use the builder" switches back when every statement parses.
|
|
|
|
|
|
## Emits `changed(text)` with the statements (Builder.effect_text) joined by
|
|
|
|
|
|
## newlines; rows not filled in yet are left out.
|
|
|
|
|
|
|
|
|
|
|
|
signal changed(text: String)
|
|
|
|
|
|
|
|
|
|
|
|
const OPS := ["set", "add", "subtract", "multiply", "divide", "reset", "append", "remove"]
|
Terminology pass: one set of kind and choice names, 2d6, result/change wording
- Describe.kind_label / choice_label / choice_labels replace six drifting
label tables. Search no longer calls Check and Router cards "Table", and
a Check card's dialog is titled "Check settings".
- Choice types read "Which option / How many / Open ended" everywhere
(menu, settings, inspector, card, preview, details).
- Plain dice read "2d6" / "d6" instead of the 2D-game "2D" / "1D".
- The built-in "2D skill check" template becomes "Skill check (2d6 vs
target)" (builtin:skill-check), a real Check card with Success and Failure.
- User text says "result" and "change" instead of "entry", "row" and "effect"
(Test board, settings dialog, lint, variables panel, pipe options).
- Pipes are deleted (link, toast, undo label), like cards and results; the
reset statement reads "Reset" in the builder and "Reset all X" for
prefixes. "Clear" stays for a value that really was erased.
- The template-saved toast points at "+ Card ▾".
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 09:14:30 -06:00
|
|
|
|
const OP_LABELS := ["Set", "Add", "Subtract", "Multiply", "Divide", "Reset", "Add to list", "Remove from list"]
|
2026-11-08 21:24:25 -06:00
|
|
|
|
|
|
|
|
|
|
var main: Main
|
|
|
|
|
|
var table: RollTable
|
|
|
|
|
|
## Each row: a Builder model ({ok, op, var, amount}) or {ok: false, src, error}.
|
|
|
|
|
|
var rows: Array[Dictionary] = []
|
|
|
|
|
|
var text_mode := false
|
|
|
|
|
|
var _raw := ""
|
|
|
|
|
|
var _key := "fx"
|
2026-11-14 13:40:20 -06:00
|
|
|
|
## The result's own text: what "Add to list" adds unless you type something else.
|
|
|
|
|
|
var item_hint := ""
|
2026-11-08 21:24:25 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func setup(p_main: Main, text: String, p_table: RollTable, as_text: bool, key: String = "fx") -> void:
|
|
|
|
|
|
main = p_main
|
|
|
|
|
|
table = p_table
|
|
|
|
|
|
_key = key
|
|
|
|
|
|
_raw = text
|
|
|
|
|
|
add_theme_constant_override("separation", 6)
|
|
|
|
|
|
size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
|
|
|
|
rows.clear()
|
UI for scales: make, show and edit ordered-step values
- Making one: Scale (ordered steps) in + Card, the inspector's Type switch
and the settings dialog; steps one per line and a starting step dropdown
(InspectorScale); new scales get Low, Medium, High.
- Showing one: the variable card shows the current step and the steps in a
row with the current one marked; the Variables tab stores a typed step
number or name as the step.
- Plain words: Builder ops step_up, step_down, toward, at_least, at_most
(BuilderScales; step_up/down need the board), DescribeScales phrases,
scale effect rows (EffectsScaleRow) and step dropdowns in conditions.
- Help: a Scales topic after Values and changes.
- Tests: test_ui_scales, plus builder and describe cases.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 21:25:30 -06:00
|
|
|
|
for m in Builder.parse_effects(text, _board()):
|
2026-11-08 21:24:25 -06:00
|
|
|
|
rows.append(m)
|
|
|
|
|
|
# One unreadable statement doesn't turn the whole field into text: it
|
|
|
|
|
|
# shows as a text row among the others. Text mode starts as text.
|
|
|
|
|
|
text_mode = as_text
|
|
|
|
|
|
_render()
|
|
|
|
|
|
|
|
|
|
|
|
|
UI for scales: make, show and edit ordered-step values
- Making one: Scale (ordered steps) in + Card, the inspector's Type switch
and the settings dialog; steps one per line and a starting step dropdown
(InspectorScale); new scales get Low, Medium, High.
- Showing one: the variable card shows the current step and the steps in a
row with the current one marked; the Variables tab stores a typed step
number or name as the step.
- Plain words: Builder ops step_up, step_down, toward, at_least, at_most
(BuilderScales; step_up/down need the board), DescribeScales phrases,
scale effect rows (EffectsScaleRow) and step dropdowns in conditions.
- Help: a Scales topic after Values and changes.
- Tests: test_ui_scales, plus builder and describe cases.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 21:25:30 -06:00
|
|
|
|
func _board() -> TowerBoard:
|
|
|
|
|
|
return main.data if main else null
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-11-08 21:24:25 -06:00
|
|
|
|
static func _all_ok(text: String) -> bool:
|
|
|
|
|
|
for m in Builder.parse_effects(text):
|
|
|
|
|
|
if not m["ok"]:
|
|
|
|
|
|
return false
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## The effects text the rows stand for.
|
|
|
|
|
|
func text() -> String:
|
|
|
|
|
|
if text_mode:
|
|
|
|
|
|
return _raw.strip_edges()
|
|
|
|
|
|
var parts := PackedStringArray()
|
|
|
|
|
|
for m in rows:
|
|
|
|
|
|
var t := ""
|
|
|
|
|
|
if m["ok"]:
|
|
|
|
|
|
t = Builder.effect_text(m)
|
|
|
|
|
|
else:
|
|
|
|
|
|
t = str(m.get("src", "")).strip_edges()
|
|
|
|
|
|
if t != "":
|
|
|
|
|
|
parts.append(t)
|
|
|
|
|
|
return "\n".join(parts)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _emit() -> void:
|
|
|
|
|
|
changed.emit(text())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _known_names() -> Array:
|
|
|
|
|
|
var out: Array = []
|
|
|
|
|
|
if main:
|
|
|
|
|
|
for k: Dictionary in Builder.known_values(main.data):
|
|
|
|
|
|
if not str(k["name"]).begins_with("@"):
|
|
|
|
|
|
out.append(str(k["name"]))
|
|
|
|
|
|
if table:
|
|
|
|
|
|
out.append_array(table.input_names())
|
|
|
|
|
|
return out
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ---------- Editing (also used by tests) ----------
|
|
|
|
|
|
|
|
|
|
|
|
func add_row() -> void:
|
|
|
|
|
|
rows.append({"ok": true, "op": "add", "var": "", "amount": "1"})
|
|
|
|
|
|
_render()
|
|
|
|
|
|
_emit()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func remove_row(i: int) -> void:
|
|
|
|
|
|
if i < 0 or i >= rows.size():
|
|
|
|
|
|
return
|
|
|
|
|
|
rows.remove_at(i)
|
|
|
|
|
|
_render()
|
|
|
|
|
|
_emit()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func set_row_op(i: int, op: String) -> void:
|
|
|
|
|
|
var m := rows[i]
|
UI for scales: make, show and edit ordered-step values
- Making one: Scale (ordered steps) in + Card, the inspector's Type switch
and the settings dialog; steps one per line and a starting step dropdown
(InspectorScale); new scales get Low, Medium, High.
- Showing one: the variable card shows the current step and the steps in a
row with the current one marked; the Variables tab stores a typed step
number or name as the step.
- Plain words: Builder ops step_up, step_down, toward, at_least, at_most
(BuilderScales; step_up/down need the board), DescribeScales phrases,
scale effect rows (EffectsScaleRow) and step dropdowns in conditions.
- Help: a Scales topic after Values and changes.
- Tests: test_ui_scales, plus builder and describe cases.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 21:25:30 -06:00
|
|
|
|
if not m["ok"] or not (OPS.has(op) or BuilderScales.OPS.has(op)):
|
|
|
|
|
|
return
|
|
|
|
|
|
var steps := ScaleFields.steps_of(main, str(m["var"]))
|
|
|
|
|
|
if BuilderScales.OPS.has(op) or (not steps.is_empty() and (op == "set" or op == "reset")) or BuilderScales.OPS.has(str(m["op"])):
|
|
|
|
|
|
EffectsScaleRow.set_op(m, op, steps)
|
|
|
|
|
|
_render()
|
|
|
|
|
|
_emit()
|
2026-11-08 21:24:25 -06:00
|
|
|
|
return
|
|
|
|
|
|
var was := str(m["op"])
|
|
|
|
|
|
m["op"] = op
|
|
|
|
|
|
var amt := str(m.get("amount", ""))
|
|
|
|
|
|
var listy := op == "append" or op == "remove"
|
|
|
|
|
|
var was_listy := was == "append" or was == "remove"
|
|
|
|
|
|
if op == "reset":
|
|
|
|
|
|
m["amount"] = ""
|
|
|
|
|
|
elif listy and not was_listy:
|
2026-11-14 13:40:20 -06:00
|
|
|
|
# A fresh row's "1" isn't an item anyone means: offer the result itself.
|
|
|
|
|
|
m["amount"] = item_hint if item_hint != "" and (amt == "" or amt == "1") else Builder.unquote(amt)
|
2026-11-08 21:24:25 -06:00
|
|
|
|
elif not listy and was_listy:
|
|
|
|
|
|
m["amount"] = InspectorKit.amount_expr(amt, _known_names()) if amt != "" else ""
|
|
|
|
|
|
elif amt == "" and was == "reset":
|
|
|
|
|
|
m["amount"] = "1"
|
UI for scales: make, show and edit ordered-step values
- Making one: Scale (ordered steps) in + Card, the inspector's Type switch
and the settings dialog; steps one per line and a starting step dropdown
(InspectorScale); new scales get Low, Medium, High.
- Showing one: the variable card shows the current step and the steps in a
row with the current one marked; the Variables tab stores a typed step
number or name as the step.
- Plain words: Builder ops step_up, step_down, toward, at_least, at_most
(BuilderScales; step_up/down need the board), DescribeScales phrases,
scale effect rows (EffectsScaleRow) and step dropdowns in conditions.
- Help: a Scales topic after Values and changes.
- Tests: test_ui_scales, plus builder and describe cases.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 21:25:30 -06:00
|
|
|
|
if not steps.is_empty():
|
|
|
|
|
|
EffectsScaleRow.on_var(m, steps)
|
2026-11-08 21:24:25 -06:00
|
|
|
|
_render()
|
|
|
|
|
|
_emit()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Sets a row's amount from what a person typed (quoted when it's text).
|
|
|
|
|
|
func set_row_amount(i: int, typed: String, render: bool = false) -> void:
|
|
|
|
|
|
var m := rows[i]
|
|
|
|
|
|
if not m["ok"]:
|
|
|
|
|
|
return
|
UI for scales: make, show and edit ordered-step values
- Making one: Scale (ordered steps) in + Card, the inspector's Type switch
and the settings dialog; steps one per line and a starting step dropdown
(InspectorScale); new scales get Low, Medium, High.
- Showing one: the variable card shows the current step and the steps in a
row with the current one marked; the Variables tab stores a typed step
number or name as the step.
- Plain words: Builder ops step_up, step_down, toward, at_least, at_most
(BuilderScales; step_up/down need the board), DescribeScales phrases,
scale effect rows (EffectsScaleRow) and step dropdowns in conditions.
- Help: a Scales topic after Values and changes.
- Tests: test_ui_scales, plus builder and describe cases.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 21:25:30 -06:00
|
|
|
|
var listy := ["append", "remove", "toward", "at_least", "at_most"].has(str(m["op"]))
|
2026-11-08 21:24:25 -06:00
|
|
|
|
m["amount"] = typed.strip_edges() if listy else InspectorKit.amount_expr(typed, _known_names())
|
|
|
|
|
|
if render:
|
|
|
|
|
|
_render()
|
|
|
|
|
|
_emit()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func set_row_var(i: int, n: String) -> void:
|
|
|
|
|
|
var m := rows[i]
|
|
|
|
|
|
if not m["ok"]:
|
|
|
|
|
|
return
|
|
|
|
|
|
m["var"] = n
|
UI for scales: make, show and edit ordered-step values
- Making one: Scale (ordered steps) in + Card, the inspector's Type switch
and the settings dialog; steps one per line and a starting step dropdown
(InspectorScale); new scales get Low, Medium, High.
- Showing one: the variable card shows the current step and the steps in a
row with the current one marked; the Variables tab stores a typed step
number or name as the step.
- Plain words: Builder ops step_up, step_down, toward, at_least, at_most
(BuilderScales; step_up/down need the board), DescribeScales phrases,
scale effect rows (EffectsScaleRow) and step dropdowns in conditions.
- Help: a Scales topic after Values and changes.
- Tests: test_ui_scales, plus builder and describe cases.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 21:25:30 -06:00
|
|
|
|
EffectsScaleRow.on_var(m, ScaleFields.steps_of(main, n))
|
|
|
|
|
|
_render()
|
|
|
|
|
|
_emit()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## A scale row's step (Set writes it quoted; Move toward, Raise and Lower as
|
|
|
|
|
|
## the name).
|
|
|
|
|
|
func set_row_step(i: int, step: String) -> void:
|
|
|
|
|
|
var m := rows[i]
|
|
|
|
|
|
if not m["ok"]:
|
|
|
|
|
|
return
|
|
|
|
|
|
m["amount"] = Builder.quote(step) if str(m["op"]) == "set" else step
|
2026-11-08 21:24:25 -06:00
|
|
|
|
_render()
|
|
|
|
|
|
_emit()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## A text row's statement.
|
|
|
|
|
|
func set_row_src(i: int, src: String) -> void:
|
|
|
|
|
|
var m := rows[i]
|
|
|
|
|
|
m["src"] = src
|
UI for scales: make, show and edit ordered-step values
- Making one: Scale (ordered steps) in + Card, the inspector's Type switch
and the settings dialog; steps one per line and a starting step dropdown
(InspectorScale); new scales get Low, Medium, High.
- Showing one: the variable card shows the current step and the steps in a
row with the current one marked; the Variables tab stores a typed step
number or name as the step.
- Plain words: Builder ops step_up, step_down, toward, at_least, at_most
(BuilderScales; step_up/down need the board), DescribeScales phrases,
scale effect rows (EffectsScaleRow) and step dropdowns in conditions.
- Help: a Scales topic after Values and changes.
- Tests: test_ui_scales, plus builder and describe cases.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 21:25:30 -06:00
|
|
|
|
var p := Builder.parse_effect(src, _board())
|
2026-11-08 21:24:25 -06:00
|
|
|
|
m["error"] = str(p.get("error", ""))
|
|
|
|
|
|
_emit()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func set_text_mode(on: bool) -> void:
|
|
|
|
|
|
if on == text_mode:
|
|
|
|
|
|
return
|
|
|
|
|
|
if on:
|
|
|
|
|
|
_raw = text()
|
|
|
|
|
|
text_mode = true
|
|
|
|
|
|
else:
|
|
|
|
|
|
if not _all_ok(_raw):
|
|
|
|
|
|
return
|
|
|
|
|
|
rows.clear()
|
UI for scales: make, show and edit ordered-step values
- Making one: Scale (ordered steps) in + Card, the inspector's Type switch
and the settings dialog; steps one per line and a starting step dropdown
(InspectorScale); new scales get Low, Medium, High.
- Showing one: the variable card shows the current step and the steps in a
row with the current one marked; the Variables tab stores a typed step
number or name as the step.
- Plain words: Builder ops step_up, step_down, toward, at_least, at_most
(BuilderScales; step_up/down need the board), DescribeScales phrases,
scale effect rows (EffectsScaleRow) and step dropdowns in conditions.
- Help: a Scales topic after Values and changes.
- Tests: test_ui_scales, plus builder and describe cases.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 21:25:30 -06:00
|
|
|
|
for m in Builder.parse_effects(_raw, _board()):
|
2026-11-08 21:24:25 -06:00
|
|
|
|
rows.append(m)
|
|
|
|
|
|
text_mode = false
|
|
|
|
|
|
_render()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func set_raw(t: String) -> void:
|
|
|
|
|
|
_raw = t
|
|
|
|
|
|
_emit()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ---------- UI ----------
|
|
|
|
|
|
|
|
|
|
|
|
func _render() -> void:
|
2026-11-09 08:21:26 -06:00
|
|
|
|
var focus_key := InspectorKit.focused_tag(self)
|
|
|
|
|
|
InspectorKit.clear(self)
|
2026-11-08 21:24:25 -06:00
|
|
|
|
if text_mode:
|
|
|
|
|
|
_render_text()
|
|
|
|
|
|
else:
|
|
|
|
|
|
for i in rows.size():
|
|
|
|
|
|
add_child(_row(i))
|
|
|
|
|
|
var foot := InspectorKit.hbox(12)
|
|
|
|
|
|
var add := InspectorKit.link("+ Add a change", "Add a statement that changes a value")
|
|
|
|
|
|
add.pressed.connect(add_row)
|
|
|
|
|
|
InspectorKit.tag(add, _key + ".add")
|
|
|
|
|
|
foot.add_child(add)
|
2026-11-09 08:21:26 -06:00
|
|
|
|
foot.add_child(InspectorKit.as_text_link("Edit these changes as rule text", set_text_mode.bind(true)))
|
2026-11-08 21:24:25 -06:00
|
|
|
|
add_child(foot)
|
2026-11-09 08:21:26 -06:00
|
|
|
|
InspectorKit.refocus(self, focus_key)
|
2026-11-08 21:24:25 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _render_text() -> void:
|
|
|
|
|
|
var te := InspectorKit.text_box(_raw, "@luck -= 1", 60.0)
|
|
|
|
|
|
InspectorKit.code(te)
|
|
|
|
|
|
InspectorKit.tag(te, _key + ".raw")
|
|
|
|
|
|
var err := InspectorKit.error_label()
|
|
|
|
|
|
var back := InspectorKit.link("Use the builder", "Show these changes as rows again")
|
|
|
|
|
|
var check := func() -> void:
|
|
|
|
|
|
var problems := Effects.validate(_raw)
|
|
|
|
|
|
var lines := PackedStringArray()
|
|
|
|
|
|
for p: Dictionary in problems:
|
|
|
|
|
|
lines.append("Line %d (%s) can't be used: %s" % [int(p["index"]) + 1, p["src"], p["error"]])
|
|
|
|
|
|
InspectorKit.show_error(err, "\n".join(lines))
|
|
|
|
|
|
InspectorKit.mark(te, problems.is_empty())
|
|
|
|
|
|
back.disabled = not _all_ok(_raw)
|
|
|
|
|
|
back.tooltip_text = "Show these changes as rows again" if not back.disabled else "Some of this text doesn't fit the builder, so it stays as text"
|
|
|
|
|
|
te.text_changed.connect(func() -> void:
|
|
|
|
|
|
_raw = te.text
|
|
|
|
|
|
check.call()
|
|
|
|
|
|
if Effects.validate(_raw).is_empty():
|
|
|
|
|
|
_emit()
|
|
|
|
|
|
)
|
|
|
|
|
|
add_child(te)
|
|
|
|
|
|
add_child(err)
|
|
|
|
|
|
back.pressed.connect(func() -> void: set_text_mode(false))
|
|
|
|
|
|
add_child(back)
|
|
|
|
|
|
check.call()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _row(i: int) -> Control:
|
|
|
|
|
|
var m := rows[i]
|
|
|
|
|
|
var v := InspectorKit.vbox(3)
|
|
|
|
|
|
var f := InspectorKit.flow()
|
|
|
|
|
|
v.add_child(f)
|
|
|
|
|
|
var x := InspectorKit.xbutton("Remove this change")
|
|
|
|
|
|
x.pressed.connect(remove_row.bind(i))
|
|
|
|
|
|
if not m["ok"]:
|
|
|
|
|
|
var le := InspectorKit.line(str(m.get("src", "")), "@luck -= 1")
|
|
|
|
|
|
InspectorKit.code(le)
|
|
|
|
|
|
InspectorKit.tag(le, "%s.%d.src" % [_key, i])
|
|
|
|
|
|
le.custom_minimum_size = Vector2(200, 0)
|
|
|
|
|
|
var err := InspectorKit.error_label()
|
|
|
|
|
|
var check := func() -> void:
|
|
|
|
|
|
var e := Effects.validate(str(m.get("src", "")))
|
|
|
|
|
|
var msg := ""
|
|
|
|
|
|
if not e.is_empty():
|
|
|
|
|
|
msg = "This can't be used: %s" % e[0]["error"]
|
|
|
|
|
|
else:
|
|
|
|
|
|
msg = "The builder can't show this, so it stays as text. It works as written."
|
|
|
|
|
|
InspectorKit.show_error(err, msg)
|
|
|
|
|
|
err.add_theme_color_override("font_color", Style.DANGER_INK if not e.is_empty() else Style.MUTED)
|
|
|
|
|
|
InspectorKit.mark(le, e.is_empty())
|
|
|
|
|
|
le.text_changed.connect(func(s: String) -> void:
|
|
|
|
|
|
set_row_src(i, s)
|
|
|
|
|
|
check.call()
|
|
|
|
|
|
)
|
|
|
|
|
|
f.add_child(le)
|
|
|
|
|
|
f.add_child(x)
|
|
|
|
|
|
v.add_child(err)
|
|
|
|
|
|
check.call()
|
|
|
|
|
|
return v
|
|
|
|
|
|
var op := str(m["op"])
|
UI for scales: make, show and edit ordered-step values
- Making one: Scale (ordered steps) in + Card, the inspector's Type switch
and the settings dialog; steps one per line and a starting step dropdown
(InspectorScale); new scales get Low, Medium, High.
- Showing one: the variable card shows the current step and the steps in a
row with the current one marked; the Variables tab stores a typed step
number or name as the step.
- Plain words: Builder ops step_up, step_down, toward, at_least, at_most
(BuilderScales; step_up/down need the board), DescribeScales phrases,
scale effect rows (EffectsScaleRow) and step dropdowns in conditions.
- Help: a Scales topic after Values and changes.
- Tests: test_ui_scales, plus builder and describe cases.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 21:25:30 -06:00
|
|
|
|
if EffectsScaleRow.shows(m, ScaleFields.steps_of(main, str(m["var"]))):
|
|
|
|
|
|
var sp := ValuePicker.new(main, str(m["var"]))
|
|
|
|
|
|
sp.value_chosen.connect(func(n: String) -> void: set_row_var(i, n))
|
|
|
|
|
|
var serr := InspectorKit.error_label()
|
|
|
|
|
|
EffectsScaleRow.fill(self, i, f, sp, x, serr)
|
|
|
|
|
|
v.add_child(serr)
|
|
|
|
|
|
return v
|
2026-11-08 21:24:25 -06:00
|
|
|
|
var dd := InspectorKit.dropdown(OP_LABELS, OPS.find(op))
|
|
|
|
|
|
dd.tooltip_text = "What to do"
|
|
|
|
|
|
dd.item_selected.connect(func(k: int) -> void: set_row_op(i, OPS[k]))
|
|
|
|
|
|
f.add_child(dd)
|
|
|
|
|
|
var picker := ValuePicker.new(main, str(m["var"]))
|
|
|
|
|
|
picker.allow_patterns = op == "reset"
|
|
|
|
|
|
if op == "append" or op == "remove":
|
|
|
|
|
|
picker.kinds = ["list", "text"]
|
|
|
|
|
|
picker.value_chosen.connect(func(n: String) -> void: set_row_var(i, n))
|
|
|
|
|
|
var amt_le: LineEdit = null
|
|
|
|
|
|
var err := InspectorKit.error_label()
|
|
|
|
|
|
if op != "reset":
|
|
|
|
|
|
var listy := op == "append" or op == "remove"
|
|
|
|
|
|
var shown := str(m["amount"]) if listy else InspectorKit.shown_token(str(m["amount"]))
|
|
|
|
|
|
amt_le = InspectorKit.amount(shown, "item" if listy else "1")
|
|
|
|
|
|
amt_le.tooltip_text = "A number, dice such as 1d6, or a value" if not listy else "The item's text"
|
|
|
|
|
|
InspectorKit.tag(amt_le, "%s.%d.amount" % [_key, i])
|
|
|
|
|
|
var le := amt_le
|
|
|
|
|
|
le.text_changed.connect(func(s: String) -> void:
|
|
|
|
|
|
set_row_amount(i, s)
|
|
|
|
|
|
_check_row(i, le, err)
|
|
|
|
|
|
)
|
|
|
|
|
|
match op:
|
|
|
|
|
|
"set":
|
|
|
|
|
|
f.add_child(picker)
|
|
|
|
|
|
f.add_child(InspectorKit.word("to"))
|
|
|
|
|
|
f.add_child(amt_le)
|
|
|
|
|
|
"add", "append":
|
|
|
|
|
|
f.add_child(amt_le)
|
|
|
|
|
|
f.add_child(InspectorKit.word("to"))
|
|
|
|
|
|
f.add_child(picker)
|
|
|
|
|
|
"subtract", "remove":
|
|
|
|
|
|
f.add_child(amt_le)
|
|
|
|
|
|
f.add_child(InspectorKit.word("from"))
|
|
|
|
|
|
f.add_child(picker)
|
|
|
|
|
|
"multiply", "divide":
|
|
|
|
|
|
f.add_child(picker)
|
|
|
|
|
|
f.add_child(InspectorKit.word("by"))
|
|
|
|
|
|
f.add_child(amt_le)
|
|
|
|
|
|
"reset":
|
|
|
|
|
|
f.add_child(picker)
|
|
|
|
|
|
f.add_child(x)
|
|
|
|
|
|
v.add_child(err)
|
|
|
|
|
|
_check_row(i, amt_le, err)
|
|
|
|
|
|
return v
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _check_row(i: int, amt_le: LineEdit, err: Label) -> void:
|
|
|
|
|
|
var m := rows[i]
|
|
|
|
|
|
var msg := ""
|
|
|
|
|
|
if str(m["var"]) == "":
|
|
|
|
|
|
msg = "Pick the value to change."
|
|
|
|
|
|
elif str(m["op"]) != "reset":
|
|
|
|
|
|
var a := str(m["amount"]).strip_edges()
|
|
|
|
|
|
if a == "":
|
|
|
|
|
|
msg = "Fill in the amount."
|
|
|
|
|
|
elif str(m["op"]) != "append" and str(m["op"]) != "remove":
|
|
|
|
|
|
msg = InspectorKit.expr_error(a, "The amount")
|
|
|
|
|
|
InspectorKit.show_error(err, msg)
|
|
|
|
|
|
if amt_le:
|
|
|
|
|
|
InspectorKit.mark(amt_le, msg == "" or str(m["var"]) == "")
|