TableTower/core/roll_lint_book.gd
RobinFiredrake e3cc925e42 Engine: scale values, cards with columns, thread dice override and rerolls
- Scales: var_type scale with steps; stored as step names, read as step
  numbers in rules (a quoted step name beside a scale reads as its number);
  += / -= move steps and stop at the ends; toward().
- Columns: RollTable.columns / column_rolls (row or each), TableEntry.cells;
  RollColumns fills the other columns, saves each, honours a column's when.
- Threads: dice (roll with other dice instead) and reroll (result ids).
- RollTable save/load split into RollTableIO; Expr's base into ExprBase.
- RollLintBook checks; JSON canon keeps the new keys; tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 21:12:47 -06:00

48 lines
2.1 KiB
GDScript

class_name RollLintBook
extends RefCounted
## Board checks for the book-table features: threads that roll with other dice
## or roll again on some results, cards with columns, and scale values.
## Items are {table_id, entry_id, message, kind: "book", level: "error"|"hint"}.
static func lint(board: TowerBoard, t: RollTable) -> Array[Dictionary]:
var out: Array[Dictionary] = []
for e in t.entries:
for p in e.pipes:
var to := board.get_table(p)
if to == null:
continue
var dice := e.dice_for(p)
if dice != "":
if not to.is_ranged() or to.kind != RollTable.KIND_ROLL:
out.append(_item(t, e.id, "The thread to %s rolls with %s, but only a card with numbered ranges can use other dice." % [_n(to), dice], "hint"))
elif not Dice.parse(dice).valid and Expr.check(dice) != "":
out.append(_item(t, e.id, "The thread to %s rolls with %s: %s" % [_n(to), dice, Expr.check(dice)], "error"))
var again := e.reroll_for(p)
if not again.is_empty():
var left := 0
for x in to.entries:
if again.has(x.id):
continue
left += 1
var missing := again.filter(func(id: String) -> bool: return to.find_entry(id) == null)
if left == 0:
out.append(_item(t, e.id, "The thread to %s rolls again on every result, so it can never finish." % _n(to), "error"))
if not missing.is_empty():
out.append(_item(t, e.id, "The thread to %s rolls again on results that aren't on that card any more." % _n(to), "hint"))
if t.has_columns():
for c: Dictionary in t.columns:
var w := str(c.get("when", ""))
if w != "" and Expr.check(w) != "":
out.append(_item(t, "", "Column %s, only if %s: %s" % [c.get("name", ""), w, Expr.check(w)], "error"))
if t.is_scale() and t.steps.size() < 2:
out.append(_item(t, "", "The scale %s needs at least two steps." % _n(t), "error"))
return out
static func _n(t: RollTable) -> String:
return Formatter.strip_tags(t.name).strip_edges()
static func _item(t: RollTable, entry_id: String, msg: String, level: String) -> Dictionary:
return {"table_id": t.id, "entry_id": entry_id, "message": msg, "kind": "book", "level": level}