TableTower/ui/table_card_text.gd
RobinFiredrake 5e34592fec 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

99 lines
3.7 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

class_name TableCardText
extends RefCounted
## The short texts a table card shows for its rules (check badges and
## sentences, input lines, router case labels, loop rules, effect summaries).
## Static; TableCard keeps delegators for the ones other files call on it.
## The check card's "2D" badge (its dice in plain words, "Roll" when long).
static func check_badge(t: RollTable) -> String:
var d := Describe.dice(t.check_dice, null)
return d if d.length() <= 5 else "Roll"
## The check card's sentence under its header, as BBCode: "Roll 2d6 +
## Strength modifier, need [b]8 or more[/b]" (plain) or "[code]2d6 + dm(@str)
## vs 8+[/code]" style text.
static func check_sentence(t: RollTable, board: TowerBoard, plain: bool) -> String:
var s := RulesView.check_line(t, board, plain)
if not plain:
return "[color=#%s]%s[/color]" % [Style.COPPER_DARK.to_html(false), RichText.plain(s)]
var at := s.rfind(", need ")
if at < 0:
return RichText.plain(s)
return "%s, need [b]%s[/b]" % [RichText.plain(s.substr(0, at)), RichText.plain(s.substr(at + 7))]
## One input as BBCode: "Input [b]Tier[/b] · starts at [b]1[/b]".
static func input_line(inp: Dictionary, board: TowerBoard, plain: bool) -> String:
var nm := str(inp.get("name", ""))
var def := str(inp.get("default", "")).strip_edges()
var ink := Style.INK.to_html(false)
if not plain:
return "input [color=#%s]%s[/color] · default [color=#%s]%s[/color]" % [ink, RichText.plain(nm), ink, RichText.plain(def if def != "" else "0")]
var lab := str(inp.get("label", "")).strip_edges()
if lab == "":
lab = Describe.label(nm, board)
var shown := Describe.dice(def, board) if def != "" else "0"
return "Input [color=#%s][b]%s[/b][/color] · starts at [color=#%s][b]%s[/b][/color]" % [ink, RichText.plain(lab), ink, RichText.plain(shown)]
## "Options from @skill_* · where option_value >= 1" for a dynamic pick card.
static func options_line(t: RollTable) -> String:
var s := "Options from " + t.options_from.strip_edges()
if t.options_where.strip_edges() != "":
s += " · where " + t.options_where.strip_edges()
return s
## A router case's condition as shown: "if @str >= 8", or "Otherwise".
static func case_label(e: TableEntry) -> String:
var w := e.when.strip_edges()
return "Otherwise" if w == "" else "if " + w
## "× @answer", "while @alive = 1", "until @done".
static func loop_rule(t: RollTable) -> String:
var e := t.loop_expr.strip_edges()
if e == "":
e = "?"
match t.loop_mode:
"while":
return "while " + e
"until":
return "until " + e
return "× " + e
static func check_outlet_name(index: int) -> String:
return "Success" if index == 0 else ("Failure" if index == 1 else "Result %d" % (index + 1))
static func check_outlet_color(index: int) -> Color:
return Style.OK_INK if index == 0 else Style.NO_INK
## A short summary of effect text as written: the first two statements, with
## declared variables by their card's name ("STR = 2d6 · Terms += 1 · +3").
static func effect_summary(text: String, board: TowerBoard) -> String:
var list := Effects.split(text)
var parts := PackedStringArray()
for k in mini(2, list.size()):
var st := Effects.parse_statement(list[k])
if st.has("error"):
parts.append("⚠ " + list[k])
continue
var target: String = st["target"]
var shown := target
if board != null and target.begins_with("@") and not target.ends_with("*"):
for t in board.tables:
if t.kind == RollTable.KIND_VARIABLE and t.var_name == target.substr(1):
shown = Formatter.strip_tags(t.name).strip_edges()
break
if st["op"] == "reset":
parts.append("reset " + shown)
else:
parts.append("%s %s %s" % [shown, st["op"], st["expr"]])
if list.size() > 2:
parts.append("+%d" % (list.size() - 2))
return " · ".join(parts)