2026-11-08 21:24:25 -06:00
class_name InspectorCard
extends RefCounted
## The card section of the inspector: name, details, tags and inputs for
## every card, then the kind's own fields (roll dice, check, choice, loop,
## router cases, variable, collection members, sheet template). Writes go
## through Inspector (apply_settings / wrote), so the settings dialog's rules
2026-11-14 13:18:17 -06:00
## and the undo history apply. The roll section is InspectorRoll; choice,
## router and ledger cards are InspectorChoice, InspectorRouter and
## InspectorCollection.
2026-11-08 21:24:25 -06:00
static func build ( insp : Inspector , box : VBoxContainer , t : RollTable ) - > void :
Terminology pass: one set of kind and choice names, 2d6, result/change wording
- Describe.kind_label / choice_label / choice_labels replace six drifting
label tables. Search no longer calls Check and Router cards "Table", and
a Check card's dialog is titled "Check settings".
- Choice types read "Which option / How many / Open ended" everywhere
(menu, settings, inspector, card, preview, details).
- Plain dice read "2d6" / "d6" instead of the 2D-game "2D" / "1D".
- The built-in "2D skill check" template becomes "Skill check (2d6 vs
target)" (builtin:skill-check), a real Check card with Success and Failure.
- User text says "result" and "change" instead of "entry", "row" and "effect"
(Test board, settings dialog, lint, variables panel, pipe options).
- Pipes are deleted (link, toast, undo label), like cards and results; the
reset statement reads "Reset" in the builder and "Reset all X" for
prefixes. "Clear" stays for a value that really was erased.
- The template-saved toast points at "+ Card ▾".
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 09:14:30 -06:00
box . add_child ( insp . _head ( " Selected card · " + Describe . kind_label ( t ) , Inspector . _title_of ( t . name , " (no name) " ) ) )
2026-11-08 21:24:25 -06:00
var plain : = insp . main . rules_plain ( )
var name : = InspectorKit . line ( t . name , " Name " )
InspectorKit . tag ( name , " card.name " )
name . text_changed . connect ( func ( s : String ) - > void :
if s . strip_edges ( ) != " " :
insp . apply_settings ( { " name " : s } )
)
insp . fields [ " name " ] = name
box . add_child ( InspectorKit . field ( " Label " if t . kind == RollTable . KIND_VARIABLE else " Name " , name ) )
match t . kind :
RollTable . KIND_ROLL :
2026-11-09 10:01:10 -06:00
InspectorRoll . build ( insp , box , t , plain )
2026-11-10 18:43:16 -06:00
InspectorRoll . deck ( insp , box , t )
UI for cards with columns: header and cells, inspector Columns section, help
- TableCardColumns: the column-name header, each row's cells after its text
(Play: wrapping text; Build: a field per cell, edited inline), cards widen
per column, and in "each" mode the cell each column landed on is lit
(Main.lit_columns, from the rolled node's columns).
- InspectorColumns: Add columns, add/rename/move/remove (cells kept in step),
one roll vs each column, Save as (value picker) and Only if (condition
builder); the result inspector gets a field per extra column.
- Help: a Columns topic after Ranged tables and dice.
- tests/test_ui_columns.gd.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 21:24:35 -06:00
InspectorColumns . build ( insp , box , t )
2026-11-08 21:24:25 -06:00
RollTable . KIND_CHECK :
_check ( insp , box , t , plain )
RollTable . KIND_CHOICE :
2026-11-14 13:18:17 -06:00
InspectorChoice . build ( insp , box , t , plain )
2026-11-08 21:24:25 -06:00
RollTable . KIND_LOOP :
_loop ( insp , box , t , plain )
RollTable . KIND_ROUTER :
2026-11-14 13:18:17 -06:00
InspectorRouter . build ( insp , box , t )
2026-11-08 21:24:25 -06:00
RollTable . KIND_VARIABLE :
if t . is_collection ( ) :
2026-11-14 13:18:17 -06:00
InspectorCollection . build ( insp , box , t )
2026-11-08 21:24:25 -06:00
else :
_variable ( insp , box , t )
RollTable . KIND_SHEET :
_sheet ( insp , box , t )
2026-11-08 21:29:59 -06:00
var det : = InspectorKit . text_box ( t . details , " Notes about this card (optional) " , 36.0 )
2026-11-08 21:24:25 -06:00
InspectorKit . tag ( det , " card.details " )
det . text_changed . connect ( func ( ) - > void : insp . apply_settings ( { " details " : det . text } ) )
insp . fields [ " details " ] = det
box . add_child ( InspectorKit . field ( " Details " , det ) )
var tags : = InspectorKit . line ( " , " . join ( t . tags ) , " e.g. loot, town " )
InspectorKit . tag ( tags , " card.tags " )
tags . text_changed . connect ( func ( s : String ) - > void : insp . apply_settings ( { " tags " : s } ) )
insp . fields [ " tags " ] = tags
box . add_child ( InspectorKit . field ( " Tags " , tags ) )
2026-11-10 18:20:46 -06:00
box . add_child ( InspectorKit . field ( " Colour " , ColorChoice . new ( t . color , func ( hex : String ) - > void :
t . color = hex
insp . wrote ( t ) ) ) )
2026-11-08 21:24:25 -06:00
if t . kind != RollTable . KIND_VARIABLE :
2026-11-14 14:23:07 -06:00
box . add_child ( InspectorKit . field ( " Costs to roll " , InspectorResult . cost_row ( insp , t , t ,
" Its roll button is greyed out when there isn ' t enough; a thread that reaches it asks first. " ) ) )
2026-11-08 21:24:25 -06:00
box . add_child ( _inputs ( insp , t ) )
2026-11-10 18:40:53 -06:00
InspectorThreads . build ( insp , box , t )
2026-11-08 21:24:25 -06:00
2026-11-10 18:43:16 -06:00
var more : = InspectorKit . link ( " More settings… " , " Deck mode and the other settings " )
2026-11-08 21:24:25 -06:00
more . pressed . connect ( func ( ) - > void : insp . main . open_table_settings ( t . id ) )
box . add_child ( more )
# ---------- Inputs (every rollable card) ----------
static func _inputs ( insp : Inspector , t : RollTable ) - > Control :
var v : = InspectorKit . vbox ( 5 )
v . add_child ( InspectorKit . flabel ( " Inputs " ) )
2026-11-10 18:24:23 -06:00
v . add_child ( InspectorKit . note ( " Values a thread into this card can pass, like a Tier. Each one has a starting value. " , Style . MUTED , 13 ) )
2026-11-08 21:24:25 -06:00
var rows : Array = [ ]
for inp : Dictionary in t . inputs :
rows . append ( inp . duplicate ( ) )
insp . fields [ " inputs_rows " ] = rows
var grid : = GridContainer . new ( )
grid . columns = 4
grid . add_theme_constant_override ( " h_separation " , 5 )
grid . add_theme_constant_override ( " v_separation " , 5 )
v . add_child ( grid )
var err : = InspectorKit . error_label ( )
var write : = func ( ) - > void :
t . inputs = RollTable . clean_inputs ( rows )
insp . wrote ( t )
var lint : = func ( ) - > void :
var msgs : = PackedStringArray ( )
for it : Dictionary in Roller . lint_inputs ( insp . main . data , t ) :
if str ( it [ " entry_id " ] ) == " " :
msgs . append ( str ( it [ " message " ] ) + " . " )
InspectorKit . show_error ( err , " \n " . join ( msgs ) )
if not rows . is_empty ( ) :
for h in [ " Name " , " Label " , " Default " , " " ] :
grid . add_child ( InspectorKit . flabel ( h ) )
for i in rows . size ( ) :
var r : Dictionary = rows [ i ]
for k in [ " name " , " label " , " default " ] :
var le : = InspectorKit . line ( str ( r . get ( k , " " ) ) , { " name " : " tier " , " label " : " Tier " , " default " : " 1 " } [ k ] , 0.0 )
le . custom_minimum_size = Vector2 ( 70 , 0 )
InspectorKit . tag ( le , " card.in. %d . %s " % [ i , k ] )
var key : String = k
le . text_changed . connect ( func ( s : String ) - > void :
r [ key ] = s . strip_edges ( ) . trim_prefix ( " @ " ) . to_lower ( ) if key == " name " else s
write . call ( )
)
grid . add_child ( le )
var x : = InspectorKit . xbutton ( " Remove this input " )
x . pressed . connect ( func ( ) - > void :
rows . remove_at ( i )
t . inputs = RollTable . clean_inputs ( rows )
insp . wrote ( t , false , true )
)
grid . add_child ( x )
var add : = InspectorKit . link ( " + Add input " )
add . pressed . connect ( func ( ) - > void :
var used : = t . input_names ( )
var nm : = " tier "
var k : = 2
while used . has ( nm ) :
nm = " input_ %d " % k
k += 1
t . inputs . append ( { " name " : nm , " label " : RollContext . pretty_name ( nm ) , " default " : " 1 " } )
insp . wrote ( t , false , true )
)
v . add_child ( add )
v . add_child ( err )
lint . call ( )
insp . _live . append ( lint )
return v
# ---------- Check ----------
static func _check ( insp : Inspector , box : VBoxContainer , t : RollTable , plain : bool ) - > void :
var main : = insp . main
var sentence : = InspectorKit . note ( " " , Style . INK , 15 )
sentence . add_theme_font_override ( " font " , Style . body_bold ( ) )
var sp : = PanelContainer . new ( )
Theme system: runtime colour tokens, theme sets and a Theme dialog
Style's colours become static vars named by role (BG, PANEL, CARD, THREAD,
ACCENT, TRIM, GLOW…) instead of materials (felt, copper, brass), so a theme
can replace them. Stray hard-coded colours moved into tokens.
ThemeStore applies built-in sets (Tarot, the new default: jewel-purple
cloth with a shine; Felt, the old look) and the user's own sets from
user://themes/. Fills for the background and panels can be gradients; the
background pattern (dots, stars, none) and logo are per set. View ▾ →
Theme… edits a set; changes to a built-in save as a new set. Using a theme
reloads the UI and keeps the open spread.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 18:10:16 -06:00
sp . add_theme_stylebox_override ( " panel " , Style . bordered ( Style . box ( Style . VALUE_BG , 8 , [ 10 , 7 , 10 , 8 ] ) , 1 , Style . ACCENT ) )
2026-11-08 21:24:25 -06:00
sp . add_child ( sentence )
box . add_child ( sp )
insp . fields [ " sentence " ] = sentence
var errs : = InspectorKit . error_label ( )
var refresh : = func ( ) - > void :
sentence . text = Describe . check ( t , main . data ) if plain else " Roll %s %s , need %s %s " % [ t . check_dice , ( " + " + t . check_mod ) if t . check_mod != " " else " " , t . check_target , " or more " if t . check_cmp == " ge " else " or less " ]
var msgs : = PackedStringArray ( )
for it : Dictionary in Roller . lint_check ( t ) :
msgs . append ( str ( it [ " message " ] ) + " . " )
InspectorKit . show_error ( errs , " \n " . join ( msgs ) )
insp . _live . append ( refresh )
var dice : = InspectorKit . line ( t . check_dice , " 2d6 " , 80.0 )
InspectorKit . tag ( dice , " card.check_dice " )
insp . fields [ " check_dice " ] = dice
dice . text_changed . connect ( func ( s : String ) - > void : set_check ( insp , " check_dice " , s ) )
var r1 : = InspectorKit . flow ( )
r1 . add_child ( InspectorKit . word ( " Roll " ) )
r1 . add_child ( dice )
box . add_child ( InspectorKit . field ( " Dice " , r1 ) )
2026-11-09 10:01:10 -06:00
var mod : = ModifierEditor . new ( main , t . check_mod , plain , " card.check_mod " )
insp . fields [ " check_mod " ] = mod
mod . changed . connect ( func ( s : String ) - > void : set_check ( insp , " check_mod " , s ) )
box . add_child ( InspectorKit . field ( " Modifier " , mod ) )
2026-11-08 21:24:25 -06:00
var r3 : = InspectorKit . flow ( )
r3 . add_child ( InspectorKit . word ( " Need " ) )
var target : = InspectorKit . amount ( t . check_target , " 8 " )
InspectorKit . tag ( target , " card.check_target " )
insp . fields [ " check_target " ] = target
target . text_changed . connect ( func ( s : String ) - > void : set_check ( insp , " check_target " , s ) )
r3 . add_child ( target )
var cmp : = InspectorKit . dropdown ( [ " or more " , " or less " ] , 0 if t . check_cmp == " ge " else 1 )
cmp . item_selected . connect ( func ( k : int ) - > void : set_check ( insp , " check_cmp " , " ge " if k == 0 else " le " ) )
insp . fields [ " check_cmp " ] = cmp
r3 . add_child ( cmp )
box . add_child ( InspectorKit . field ( " Target " , r3 ) )
box . add_child ( errs )
2026-11-10 18:24:23 -06:00
box . add_child ( InspectorKit . note ( " Success and Failure are the card ' s two results; select one to give it changes and threads. " , Style . MUTED , 13 ) )
2026-11-08 21:24:25 -06:00
refresh . call ( )
## Sets a check field (check_dice, check_mod, check_target, check_cmp).
static func set_check ( insp : Inspector , key : String , value : String ) - > void :
var t : = insp . selected_table ( )
if t == null or t . kind != RollTable . KIND_CHECK :
return
var s : = value . strip_edges ( )
if key == " check_cmp " :
if not RollTable . CHECK_CMPS . has ( s ) :
return
elif key != " check_mod " and s == " " :
return
if str ( t . get ( key ) ) == s :
return
t . set ( key , s )
insp . wrote ( t )
2026-11-14 13:18:17 -06:00
# ---------- Choice (InspectorChoice) ----------
2026-11-08 21:24:25 -06:00
## Options from `from` where `where` (a pick card). Returns "" or the problem.
static func set_options ( insp : Inspector , from : String , where : String ) - > String :
2026-11-14 13:18:17 -06:00
return InspectorChoice . set_options ( insp , from , where )
2026-11-08 21:24:25 -06:00
# ---------- Loop ----------
static func _loop ( insp : Inspector , box : VBoxContainer , t : RollTable , plain : bool ) - > void :
var labels : = [ " Times " , " While " , " Until " ]
var err : = InspectorKit . error_label ( )
var seg : = ModalCard . segmented ( labels , maxi ( 0 , RollTable . LOOPS . find ( t . loop_mode ) ) , func ( i : int ) - > void :
set_loop_mode ( insp , RollTable . LOOPS [ i ] )
)
box . add_child ( InspectorKit . field ( " Repeat " , seg ) )
if t . loop_mode == " times " :
var r : = InspectorKit . flow ( )
r . add_child ( InspectorKit . word ( " Run Each time " ) )
var n : = InspectorKit . amount ( t . loop_expr , " 3 " )
InspectorKit . tag ( n , " card.loop_expr " )
insp . fields [ " loop_expr " ] = n
n . text_changed . connect ( func ( s : String ) - > void :
var msg : = " Fill in how many times. " if s . strip_edges ( ) == " " else InspectorKit . expr_error ( s , " The count " )
InspectorKit . show_error ( err , msg )
InspectorKit . mark ( n , msg == " " )
if msg == " " and s . strip_edges ( ) != t . loop_expr :
t . loop_expr = s . strip_edges ( )
insp . wrote ( t )
)
r . add_child ( n )
r . add_child ( InspectorKit . word ( " times, then Afterwards. " ) )
box . add_child ( r )
else :
var cond : = ConditionBuilder . new ( )
cond . setup ( insp . main , t . loop_expr , not plain , " card.loop_cond " , { } )
cond . changed . connect ( func ( s : String ) - > void :
if s . strip_edges ( ) != " " and TableSettingsDialog . when_error ( s ) == " " and s . strip_edges ( ) != t . loop_expr :
t . loop_expr = s . strip_edges ( )
insp . wrote ( t )
)
insp . fields [ " loop_cond " ] = cond
var cap : = " Keep going while " if t . loop_mode == " while " else " Stop once "
box . add_child ( InspectorKit . field ( cap , cond ) )
box . add_child ( InspectorKit . note ( TableSettingsDialog . LOOP_NOTES . get ( t . loop_mode , " " ) , Style . MUTED , 13 ) )
box . add_child ( err )
static func set_loop_mode ( insp : Inspector , m : String ) - > void :
var t : = insp . selected_table ( )
if t == null or m == t . loop_mode or not RollTable . LOOPS . has ( m ) :
return
var cond_like : = Builder . parse_condition ( t . loop_expr )
var is_cond : bool = cond_like [ " ok " ] and not ( cond_like [ " clauses " ] as Array ) . is_empty ( ) \
and str ( ( cond_like [ " clauses " ] as Array ) [ 0 ] [ " cmp " ] ) != " set "
if m == " times " and is_cond :
t . loop_expr = " 3 "
elif m != " times " and not is_cond :
t . loop_expr = " i < 3 "
t . loop_mode = m
insp . wrote ( t , false , true )
2026-11-14 13:18:17 -06:00
# ---------- Router (InspectorRouter) ----------
2026-11-08 21:24:25 -06:00
## One router case: its condition, or Otherwise for the last case.
static func case_block ( insp : Inspector , t : RollTable , e : TableEntry , framed : bool = false ) - > Control :
2026-11-14 13:18:17 -06:00
return InspectorRouter . case_block ( insp , t , e , framed )
2026-11-08 21:24:25 -06:00
## Adds a case before a final Otherwise case (or at the end).
static func add_case ( insp : Inspector ) - > void :
2026-11-14 13:18:17 -06:00
InspectorRouter . add_case ( insp )
2026-11-08 21:24:25 -06:00
# ---------- Variable ----------
2026-11-09 08:21:26 -06:00
## A field for one card setting: applied as you type, marked and explained in `err` when refused.
2026-11-14 13:18:17 -06:00
static func setting_line ( insp : Inspector , key : String , text : String , placeholder : String , err : Label ) - > LineEdit :
2026-11-09 08:21:26 -06:00
var le : = InspectorKit . line ( text , placeholder )
InspectorKit . tag ( le , " card. " + key )
insp . fields [ key ] = le
le . text_changed . connect ( func ( s : String ) - > void :
var msg : = insp . apply_settings ( { key : s } )
InspectorKit . mark ( le , msg == " " )
InspectorKit . show_error ( err , msg )
)
return le
2026-11-08 21:24:25 -06:00
static func _variable ( insp : Inspector , box : VBoxContainer , t : RollTable ) - > void :
var err : = InspectorKit . error_label ( )
2026-11-14 13:18:17 -06:00
var vn : = setting_line ( insp , " var_name " , t . var_name , " luck " , err )
2026-11-08 21:24:25 -06:00
InspectorKit . code ( vn )
box . add_child ( InspectorKit . field ( " Name in rules (@name) " , vn ) )
UI for scales: make, show and edit ordered-step values
- Making one: Scale (ordered steps) in + Card, the inspector's Type switch
and the settings dialog; steps one per line and a starting step dropdown
(InspectorScale); new scales get Low, Medium, High.
- Showing one: the variable card shows the current step and the steps in a
row with the current one marked; the Variables tab stores a typed step
number or name as the step.
- Plain words: Builder ops step_up, step_down, toward, at_least, at_most
(BuilderScales; step_up/down need the board), DescribeScales phrases,
scale effect rows (EffectsScaleRow) and step dropdowns in conditions.
- Help: a Scales topic after Values and changes.
- Tests: test_ui_scales, plus builder and describe cases.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 21:25:30 -06:00
var types : = [ " number " , " text " , " list " , RollTable . VAR_SCALE ]
var seg : = ModalCard . segmented ( [ " Number " , " Text " , " List " , " Scale " ] , maxi ( 0 , types . find ( t . var_type ) ) , func ( i : int ) - > void :
InspectorKit . show_error ( err , insp . apply_settings ( { " var_type " : types [ i ] , " initial " : " " if t . is_scale ( ) else t . initial } , true ) )
2026-11-08 21:24:25 -06:00
)
box . add_child ( InspectorKit . field ( " Type " , seg ) )
UI for scales: make, show and edit ordered-step values
- Making one: Scale (ordered steps) in + Card, the inspector's Type switch
and the settings dialog; steps one per line and a starting step dropdown
(InspectorScale); new scales get Low, Medium, High.
- Showing one: the variable card shows the current step and the steps in a
row with the current one marked; the Variables tab stores a typed step
number or name as the step.
- Plain words: Builder ops step_up, step_down, toward, at_least, at_most
(BuilderScales; step_up/down need the board), DescribeScales phrases,
scale effect rows (EffectsScaleRow) and step dropdowns in conditions.
- Help: a Scales topic after Values and changes.
- Tests: test_ui_scales, plus builder and describe cases.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 21:25:30 -06:00
if t . is_scale ( ) :
InspectorScale . build ( insp , box , t , err )
else :
2026-11-14 13:18:17 -06:00
box . add_child ( InspectorKit . field ( " Starting value " , setting_line ( insp , " initial " , t . initial , " 0 " if t . var_type == " number " else " nothing " , err ) ) )
2026-11-14 13:40:20 -06:00
if t . var_type == " list " :
var repeats : = InspectorKit . check_box ( " Allow repeats " , t . list_repeats )
repeats . tooltip_text = " On: an item is added every time, in order. Off: only if it isn ' t on the list yet. "
InspectorKit . tag ( repeats , " card.repeats " )
repeats . toggled . connect ( func ( on : bool ) - > void :
t . list_repeats = on
insp . wrote ( t ) )
box . add_child ( repeats )
2026-11-08 21:24:25 -06:00
box . add_child ( err )
2026-11-14 13:18:17 -06:00
# ---------- Collection (InspectorCollection) ----------
2026-11-08 21:24:25 -06:00
static func set_member ( insp : Inspector , t : RollTable , item : String , value : String ) - > void :
2026-11-14 13:18:17 -06:00
InspectorCollection . set_member ( insp , t , item , value )
2026-11-08 21:24:25 -06:00
static func rename_member ( insp : Inspector , t : RollTable , old_item : String , new_item : String ) - > void :
2026-11-14 13:18:17 -06:00
InspectorCollection . rename_member ( insp , t , old_item , new_item )
2026-11-08 21:24:25 -06:00
static func remove_member ( insp : Inspector , t : RollTable , item : String ) - > void :
2026-11-14 13:18:17 -06:00
InspectorCollection . remove_member ( insp , t , item )
2026-11-08 21:24:25 -06:00
static func add_member ( insp : Inspector , t : RollTable ) - > String :
2026-11-14 13:18:17 -06:00
return InspectorCollection . add_member ( insp , t )
2026-11-08 21:24:25 -06:00
# ---------- Sheet ----------
static func _sheet ( insp : Inspector , box : VBoxContainer , t : RollTable ) - > void :
var tpl : = InspectorKit . text_box ( t . entries [ 0 ] . text if not t . entries . is_empty ( ) else " " , " [b]{@name}[/b] \n Strength {@str} " , 120.0 )
InspectorKit . code ( tpl )
InspectorKit . tag ( tpl , " card.template " )
insp . fields [ " template " ] = tpl
tpl . text_changed . connect ( func ( ) - > void : insp . apply_settings ( { " template " : tpl . text } ) )
box . add_child ( InspectorKit . field ( " Template " , tpl ) )
box . add_child ( InspectorKit . note ( " Write {@value} where a value goes. The sheet shows the values as they are now. " , Style . MUTED , 13 ) )
2026-11-10 19:17:27 -06:00
# The easy way: pick a value and get a "Label: value" line.
var row : = InspectorKit . flow ( )
row . add_child ( InspectorKit . word ( " + Add a line for " ) )
var pick : = ValuePicker . new ( insp . main , " " )
pick . value_chosen . connect ( func ( n : String ) - > void :
var name : = n . trim_prefix ( " @ " )
var line : = " [b] %s :[/b] {@ %s } " % [ Describe . label ( name , insp . main . data ) , name ]
tpl . text = ( tpl . text . strip_edges ( ) + " \n " + line ) . strip_edges ( )
insp . apply_settings ( { " template " : tpl . text } ) )
row . add_child ( pick )
box . add_child ( row )
box . add_child ( InspectorKit . note ( " Save a finished sheet from the tray: Copy ▾ → Save as a file (text, Markdown, or a web page to print as PDF). " , Style . MUTED , 12 ) )