class_name RollColumns extends RefCounted ## Cards with columns (a multi-column table, RollTable.columns): after a roll ## card with columns picks its result and expands its text, fill() works out ## the other columns. ## ## - "row" (RollTable.COLUMNS_ROW): every column reads the same result's cells. ## - "each" (COLUMNS_EACH): each column after the first is rolled on its own, ## the same way the card was (the thread's dice and rerolls included). The ## first column is the card's own roll, so its result's changes and threads ## happen as usual. ## ## Columns are worked out left to right. A column with "save_as" saves its ## text before the next one starts, so a later column's "when" (only roll it ## if …) can read it. A skipped column saves nothing. ## ## The node gets "columns": [{name, text, index, value?, skipped?}] and its ## summary becomes "Resources: Rich · Water: Plentiful". static func fill(node: Dictionary, f: Dictionary, ctx: RollContext, depth: int) -> void: var t: RollTable = node["table"] var rows: Array = [] var parts := PackedStringArray() var log: Array = [] var why: Array = [] for k in t.columns.size(): var col: Dictionary = t.columns[k] var nm := str(col.get("name", "")) var row := {"name": nm, "text": "", "index": int(node.get("index", -1))} if k > 0: var w := str(col.get("when", "")).strip_edges() if w != "": var r := Expr.evaluate(w, ctx) if r["error"] != "": log.append({"text": "Column %s, only if %s: %s" % [nm, w, r["error"]], "error": true}) if r["error"] != "" or not Expr.truthy(r["value"]): row["skipped"] = true rows.append(row) continue var text := "" if k == 0: text = str(node["summary"]) row["value"] = node.get("value") else: var pick := node if t.column_rolls == RollTable.COLUMNS_EACH: pick = RollCards.pick_for(t, ctx, f) if pick.has("why"): for fact: Dictionary in pick["why"]: var c := fact.duplicate() c["column"] = nm why.append(c) if pick.has("stop"): text = str(pick["summary"]) else: row["index"] = int(pick["index"]) row["value"] = pick.get("value") ctx.depth = depth + 1 var ex: Dictionary = await TextExpander.expand_async(RollTable.cell_text(pick["entry"], k), ctx) ctx.depth = depth text = str(ex["text"]) for c2: Dictionary in ex["children"]: c2["inline"] = true (node["children"] as Array).append(c2) row["text"] = text rows.append(row) var save := str(col.get("save_as", "")).strip_edges() if save != "": ctx.save(save, plain(text), t.id) if Formatter.strip_tags(text).strip_edges() != "": parts.append("%s: %s" % [Formatter.escape_literal(nm), text]) node["columns"] = rows node["summary"] = " · ".join(parts) Roller._log(node, log) Roller._why(node, why) ## A column's text as a value: no formatting, no internal markers. static func plain(text: String) -> String: return Formatter.strip_tags(Formatter.to_export_bbcode(text)).strip_edges()