2026-11-10 21:12:47 -06:00
class_name RollLintBook
extends RefCounted
## Board checks for the book-table features: threads that roll with other dice
2026-11-11 09:06:55 -06:00
## or roll again on some results, cards with columns (and their "roll twice and
## combine" rows), and scale values.
2026-11-10 21:12:47 -06:00
## 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 " ) )
2026-11-10 21:19:36 -06:00
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 " ) )
2026-11-10 21:12:47 -06:00
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 " ) )
2026-11-11 09:06:55 -06:00
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 " ) )
2026-11-10 21:12:47 -06:00
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
2026-11-11 09:06:55 -06:00
static func _q ( e : TableEntry ) - > String :
return " “ %s ” " % Formatter . strip_tags ( e . text ) . strip_edges ( )
2026-11-10 21:12:47 -06:00
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 }