62 lines
3.2 KiB
GDScript3
62 lines
3.2 KiB
GDScript3
|
|
class_name TableCardRowText
|
||
|
|
extends RefCounted
|
||
|
|
## Works out the text a result row shows in Play mode. A lit row shows what
|
||
|
|
## was just rolled; other rows show the entry as written, with references
|
||
|
|
## made readable. Some card kinds add a lead-in: loop rows say "Each time ·",
|
||
|
|
## a router case starts with its condition, a check outlet with its name, a
|
||
|
|
## dynamic pick's first row with "Chosen ·", and a number/text choice with
|
||
|
|
## "Answer ·". TableCardRows calls text_for().
|
||
|
|
|
||
|
|
|
||
|
|
## The Play-mode text (BBCode) of one row of the card that `rows` belongs to.
|
||
|
|
static func text_for(rows: TableCardRows, entry: TableEntry) -> String:
|
||
|
|
var card := rows.card
|
||
|
|
var table := card.table
|
||
|
|
var main := card.main
|
||
|
|
var columns_ui := rows.columns_ui
|
||
|
|
var rolled := main.lit_text(table.id, entry.id)
|
||
|
|
if columns_ui.active():
|
||
|
|
# The lit text is "Resources: Rich · Water: …"; this row shows column 0.
|
||
|
|
rolled = str(columns_ui.rolled_cell(table.entries.find(entry), 0).get("text", ""))
|
||
|
|
var text := RichText.decorate(rolled) if rolled != "" else RichText.preview(entry.text, main.data)
|
||
|
|
var muted := Style.MUTED.to_html(false)
|
||
|
|
if table.kind == RollTable.KIND_LOOP:
|
||
|
|
var index := table.entries.find(entry)
|
||
|
|
var caption: String = TableCardRows.LOOP_ROWS[clampi(index, 0, 1)]
|
||
|
|
var plain_text := Formatter.strip_tags(entry.text).strip_edges()
|
||
|
|
if plain_text == "" or plain_text == caption:
|
||
|
|
text = "[b]%s[/b]" % caption
|
||
|
|
else:
|
||
|
|
text = "[color=#%s]%s ·[/color] %s" % [muted, caption, text]
|
||
|
|
elif table.kind == RollTable.KIND_ROUTER:
|
||
|
|
var bad := entry.when.strip_edges() != "" and Expr.check(entry.when.strip_edges()) != ""
|
||
|
|
var label := RulesView.case_label(entry, main.data, card.plain)
|
||
|
|
var condition := "[color=#%s][b]%s[/b][/color]" % [(Style.DANGER_INK if bad else Style.TRIM_DARK).to_html(false), RichText.plain(label)]
|
||
|
|
var plain_text := Formatter.strip_tags(entry.text).strip_edges()
|
||
|
|
if plain_text == "" or plain_text == TableCardText.case_label(entry) or plain_text == label or plain_text == "if …" or (plain_text == "Otherwise" and entry.when.strip_edges() == ""):
|
||
|
|
text = condition
|
||
|
|
else:
|
||
|
|
text = "%s\n%s" % [condition, text]
|
||
|
|
elif table.kind == RollTable.KIND_CHECK:
|
||
|
|
var index := table.entries.find(entry)
|
||
|
|
var outlet_name := TableCardText.check_outlet_name(index)
|
||
|
|
var head := "[color=#%s][b]%s[/b][/color]" % [TableCardText.check_outlet_color(index).to_html(false), outlet_name]
|
||
|
|
var own := Formatter.strip_tags(rolled if rolled != "" else entry.text).strip_edges()
|
||
|
|
text = head if own == "" or own == outlet_name else "%s · %s" % [head, text]
|
||
|
|
elif table.is_dynamic() and table.entries.find(entry) == 0:
|
||
|
|
var own := Formatter.strip_tags(entry.text).strip_edges()
|
||
|
|
if rolled != "":
|
||
|
|
text = "[color=#%s]Chosen ·[/color] [b]%s[/b]" % [muted, RichText.decorate(rolled)]
|
||
|
|
elif own == "" or own == Roller.CHOSEN:
|
||
|
|
text = "[i][color=#%s]Chosen: the picked option[/color][/i]" % muted
|
||
|
|
else:
|
||
|
|
text = "[color=#%s]Chosen ·[/color] %s" % [muted, text]
|
||
|
|
elif table.kind == RollTable.KIND_CHOICE and table.choice != "pick":
|
||
|
|
if rolled != "":
|
||
|
|
text = "[color=#%s]Answer ·[/color] [b]%s[/b]" % [muted, RichText.decorate(rolled)]
|
||
|
|
else:
|
||
|
|
text = "[i][color=#%s]Answer[/color][/i]" % muted
|
||
|
|
if entry.details.strip_edges() != "":
|
||
|
|
text += RichText.info_mark()
|
||
|
|
return text
|