TableTower/core/roll_lint_book.gd
RobinFiredrake 200edfd67e Book tables: columns as one phrase, roll twice and combine, results saved into lists, one-option picks answer themselves
- column_join: a card with columns reads as one phrase ("Ash Canyons"), which threads save
- TableEntry.repeat: a result that rolls its column again N times and combines them
- Saving a result into a declared list value adds an item (RollContext.save_result)
- A pick with only one available option picks it without asking
- Lint, why facts, inspector controls, tests, LOGIC.md

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 09:06:55 -06:00

60 lines
2.7 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 their "roll twice and
## combine" rows), 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 Dice.roll_problem(dice) != "":
out.append(_item(t, e.id, "The thread to %s rolls with %s: %s" % [_n(to), dice, Dice.roll_problem(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"))
for e in t.entries:
if e.repeat.is_empty():
continue
if not t.has_columns():
out.append(_item(t, e.id, "%s rolls its column again, but this card has no columns, so it does nothing. Use a thread back to the card instead." % _q(e), "hint"))
elif t.entries.all(func(x: TableEntry) -> bool: return not x.repeat.is_empty() or (e.repeat.get("reroll", []) as Array).has(x.id)):
out.append(_item(t, e.id, "%s rolls its column again, but every result rolls again too, so it can never finish." % _q(e), "error"))
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 _q(e: TableEntry) -> String:
return "“%s”" % Formatter.strip_tags(e.text).strip_edges()
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}