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)