49 lines
2.1 KiB
GDScript3
49 lines
2.1 KiB
GDScript3
|
|
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}
|