2026-11-08 21:24:25 -06:00
class_name Inspector
extends PanelContainer
## The Build-mode inspector (docs/PLAIN.md §6): a panel docked right of the
## board that edits the selected card, result or pipe with fill-in builders.
## Plain words mode shows builders; Text mode shows the rule text.
##
## Every change goes through Main (mark_dirty), so it is saved and is an undo
## step; typing is one step once it pauses. The panel rebuilds when the
## selected card changes from outside (an undo, an edit on the card), and
## keeps focus in the field being typed in.
2026-11-09 10:01:10 -06:00
## The default and smallest widths (the player can drag it wider) and the
## collapsed strip's width.
2026-11-08 21:24:25 -06:00
const WIDTH : = 340.0
2026-11-09 10:01:10 -06:00
const MIN_WIDTH : = 280.0
2026-11-08 21:24:25 -06:00
const STRIP : = 30.0
2026-11-09 10:01:10 -06:00
var width : = WIDTH
## The drag handle on the inspector's left edge, shown with it when open.
var splitter : PanelSplitter
2026-11-08 21:24:25 -06:00
var main : Main
## {kind: "card" | "result" | "pipe", tid, eid?, to?}, or {} for nothing.
var selection : Dictionary = { }
var collapsed : = false
var _body : VBoxContainer
var _scroll : ScrollContainer
var _content : VBoxContainer
var _strip : PanelContainer
var _sig : = " "
var _sync_queued : = false
var _writing : = false
## Run after every write, to refresh live sentences and problem lines.
var _live : Array [ Callable ] = [ ]
2026-11-08 21:29:59 -06:00
var _title_label : Label
2026-11-08 21:24:25 -06:00
# Parts the tests drive (rebuilt with the panel).
var effects : EffectsBuilder
var show_if_builder : ConditionBuilder
var case_builder : ConditionBuilder
## target id -> {box, when (ConditionBuilder), otherwise (CheckBox), count, save, inputs: {name: LineEdit}, taken}
var pipe_parts : Dictionary = { }
## Named fields of the card section ("name", "dice", "check_mod", ...).
var fields : Dictionary = { }
func setup ( p_main : Main ) - > void :
main = p_main
theme = Style . card_theme ( )
custom_minimum_size = Vector2 ( WIDTH , 0 )
size_flags_vertical = Control . SIZE_EXPAND_FILL
2026-11-09 10:01:10 -06:00
visibility_changed . connect ( _sync_splitter )
2026-11-08 21:24:25 -06:00
var sb : = Style . box ( Style . CARD , 0 , [ 0 , 0 , 0 , 0 ] )
sb . border_width_left = 1
sb . border_color = Color ( 0 , 0 , 0 , 0.25 )
add_theme_stylebox_override ( " panel " , sb )
var stack : = Control . new ( )
stack . size_flags_vertical = Control . SIZE_EXPAND_FILL
add_child ( stack )
_body = VBoxContainer . new ( )
_body . set_anchors_and_offsets_preset ( Control . PRESET_FULL_RECT )
_body . add_theme_constant_override ( " separation " , 0 )
stack . add_child ( _body )
_scroll = ScrollContainer . new ( )
_scroll . horizontal_scroll_mode = ScrollContainer . SCROLL_MODE_DISABLED
_scroll . size_flags_vertical = Control . SIZE_EXPAND_FILL
_body . add_child ( _scroll )
var pad : = MarginContainer . new ( )
pad . size_flags_horizontal = Control . SIZE_EXPAND_FILL
for k in [ " margin_left " , " margin_right " ] :
pad . add_theme_constant_override ( k , 16 )
pad . add_theme_constant_override ( " margin_top " , 14 )
pad . add_theme_constant_override ( " margin_bottom " , 18 )
_scroll . add_child ( pad )
_content = InspectorKit . vbox ( 14 )
pad . add_child ( _content )
_strip = PanelContainer . new ( )
_strip . set_anchors_and_offsets_preset ( Control . PRESET_FULL_RECT )
_strip . add_theme_stylebox_override ( " panel " , Style . box ( Style . CARD , 0 , [ 2 , 8 , 2 , 8 ] ) )
var open : = Button . new ( )
open . text = " « "
open . tooltip_text = " Show the inspector "
open . size_flags_vertical = Control . SIZE_SHRINK_BEGIN
Style . skin_button ( open , Style . box ( Color ( 0 , 0 , 0 , 0 ) , 5 , [ 4 , 2 , 4 , 2 ] ) , Style . box ( Style . HOVER_ROW , 5 , [ 4 , 2 , 4 , 2 ] ) ,
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
Style . box ( Style . HOVER_ROW , 5 , [ 4 , 2 , 4 , 2 ] ) , Style . TRIM_DARK )
2026-11-08 21:24:25 -06:00
open . add_theme_font_size_override ( " font_size " , 18 )
open . pressed . connect ( func ( ) - > void : set_collapsed ( false ) )
_strip . add_child ( open )
_strip . hide ( )
stack . add_child ( _strip )
rebuild ( )
# ---------- Selection ----------
func select ( sel : Dictionary ) - > void :
if collapsed :
set_collapsed ( false )
selection = sel
rebuild ( )
2026-11-08 21:36:29 -06:00
_mark_cards ( )
2026-11-08 21:24:25 -06:00
func clear ( ) - > void :
selection = { }
rebuild ( )
2026-11-08 21:36:29 -06:00
_mark_cards ( )
## Puts the copper selection bar on the selected result's row, and clears it
## everywhere else.
func _mark_cards ( ) - > void :
if main == null :
return
var tid : = str ( selection . get ( " tid " , " " ) )
var eid : = str ( selection . get ( " eid " , " " ) ) if str ( selection . get ( " kind " , " " ) ) == " result " else " "
for c in main . cards . values ( ) :
var card : = c as TableCard
if card and card . has_method ( " set_selected_entry " ) :
card . set_selected_entry ( eid if card . table . id == tid else " " )
2026-11-08 21:24:25 -06:00
func set_collapsed ( on : bool ) - > void :
collapsed = on
2026-11-09 10:01:10 -06:00
custom_minimum_size . x = STRIP if on else width
2026-11-08 21:24:25 -06:00
_body . visible = not on
_strip . visible = on
2026-11-09 10:01:10 -06:00
_sync_splitter ( )
2026-11-08 21:24:25 -06:00
if main and main . state :
main . state . set_setting ( " inspector_collapsed " , on )
2026-11-09 10:01:10 -06:00
## Sets the open width (from the PanelSplitter).
func set_width ( px : float ) - > void :
width = px
if not collapsed :
custom_minimum_size . x = px
func _sync_splitter ( ) - > void :
if splitter :
splitter . visible = visible and not collapsed
2026-11-08 21:24:25 -06:00
func selected_table ( ) - > RollTable :
if selection . is_empty ( ) or main == null :
return null
return main . data . get_table ( str ( selection . get ( " tid " , " " ) ) )
func selected_entry ( ) - > TableEntry :
var t : = selected_table ( )
if t == null or not selection . has ( " eid " ) :
return null
return t . find_entry ( str ( selection [ " eid " ] ) )
## Rebuilds once, at the end of the frame, if the selection changed from outside.
func sync ( ) - > void :
if _writing or _sync_queued :
return
_sync_queued = true
_do_sync . call_deferred ( )
func _do_sync ( ) - > void :
_sync_queued = false
if _signature ( ) != _sig :
rebuild ( )
func _signature ( ) - > String :
var t : = selected_table ( )
if selection . is_empty ( ) :
return " "
if t == null or ( selection . has ( " eid " ) and selected_entry ( ) == null ) :
return " gone "
var d : = t . to_dict ( )
for k in [ " x " , " y " , " collapsed " ] :
d . erase ( k )
var parts : = PackedStringArray ( [ JSON . stringify ( d ) , main . rules_view ( ) , str ( main . mode ) ] )
for x in main . data . tables :
if x . kind == RollTable . KIND_VARIABLE :
parts . append ( " %s | %s | %s " % [ x . name , x . var_name , x . var_type ] )
for e in t . entries :
for p in e . pipes :
var target : = main . data . get_table ( p )
parts . append ( ( " %s | %s " % [ target . name , JSON . stringify ( target . inputs ) ] ) if target else " - " )
parts . append ( str ( main . lit_pipes . has ( Roller . pipe_key ( t . id , e . id , p ) ) ) )
parts . append ( str ( main . is_entry_lit ( t . id , e . id ) ) )
if t . is_collection ( ) :
parts . append ( JSON . stringify ( members ( t ) ) )
return str ( hash ( " \n " . join ( parts ) ) )
# ---------- Writing ----------
## After the inspector changed table `t`: Main refreshes the card(s) and
## records the undo step. `rebuild_panel` redraws the inspector too (for
## changes that add or remove rows).
func wrote ( t : RollTable , all_cards : bool = false , rebuild_panel : bool = false ) - > void :
_writing = true
main . inspector_edited ( t . id , all_cards )
main . mark_dirty ( )
_writing = false
_sig = _signature ( )
for f in _live :
if f . is_valid ( ) :
f . call ( )
2026-11-08 21:29:59 -06:00
_refresh_title ( )
2026-11-08 21:24:25 -06:00
if rebuild_panel :
rebuild ( )
## Applies table settings through TableSettingsDialog.apply_settings (the
## same rules as the settings dialog). Returns "" or the problem.
func apply_settings ( over : Dictionary , rebuild_panel : bool = false ) - > String :
var t : = selected_table ( )
if t == null :
return " Nothing selected "
var s : = { " name " : t . name , " details " : t . details , " tags " : " , " . join ( t . tags ) , " ranged " : t . is_ranged ( ) ,
2026-11-09 10:01:10 -06:00
" dice " : t . dice , " dice_mod " : t . dice_mod , " card_mode " : t . card_mode , " deck_empty " : t . deck_empty }
2026-11-08 21:24:25 -06:00
s . merge ( over , true )
var r : = TableSettingsDialog . apply_settings ( t , s )
if not r [ " ok " ] :
return str ( r [ " error " ] )
if r . get ( " deck_reset " , false ) and main . state and main . data . id != " " :
main . state . clear_deck ( main . data . id , t . id )
wrote ( t , t . kind == RollTable . KIND_VARIABLE , rebuild_panel )
return " "
func set_entry_text ( s : String ) - > void :
var e : = selected_entry ( )
if e and e . text != s :
e . text = s
2026-11-10 19:02:46 -06:00
e . page = " "
2026-11-08 21:24:25 -06:00
wrote ( selected_table ( ) )
func set_entry_details ( s : String ) - > void :
var e : = selected_entry ( )
if e and e . details != s :
e . details = s
2026-11-10 19:02:46 -06:00
e . page = " "
2026-11-08 21:24:25 -06:00
wrote ( selected_table ( ) )
func set_entry_effects ( s : String ) - > void :
var e : = selected_entry ( )
if e and e . effects != s :
e . effects = s
wrote ( selected_table ( ) )
func set_entry_show_if ( s : String ) - > void :
var e : = selected_entry ( )
if e and e . show_if != s . strip_edges ( ) and TableSettingsDialog . when_error ( s ) == " " :
e . show_if = s . strip_edges ( )
wrote ( selected_table ( ) )
## A router case's condition ("" makes it the Otherwise case).
func set_case_when ( eid : String , s : String ) - > void :
var t : = selected_table ( )
var e : = t . find_entry ( eid ) if t else null
if e and e . when != s . strip_edges ( ) and TableSettingsDialog . when_error ( s ) == " " :
e . when = s . strip_edges ( )
wrote ( t )
func _pipe_entry ( ) - > TableEntry :
return selected_entry ( )
func set_pipe_when ( to : String , s : String ) - > void :
var e : = _pipe_entry ( )
if e == null or PipePopover . when_error ( s ) != " " or s . strip_edges ( ) == e . when_for ( to ) :
return
e . set_pipe_when ( to , s )
wrote ( selected_table ( ) )
_refresh_otherwise ( to )
func set_pipe_otherwise ( to : String , on : bool ) - > void :
var e : = _pipe_entry ( )
if e == null or on == e . is_otherwise ( to ) :
return
e . set_pipe_otherwise ( to , on )
wrote ( selected_table ( ) )
_refresh_otherwise ( to )
## Sets one input value passed down the pipe ("" uses the card's default).
func set_pipe_input ( to : String , input_name : String , expr : String ) - > void :
var e : = _pipe_entry ( )
if e == null :
return
var w : = e . with_for ( to )
var s : = expr . strip_edges ( )
if s != " " and InspectorKit . expr_error ( s ) != " " :
return
if s == " " :
w . erase ( input_name )
else :
w [ input_name ] = s
if w == e . with_for ( to ) :
return
e . set_pipe_with ( to , w )
wrote ( selected_table ( ) )
func set_pipe_count ( to : String , s : String ) - > void :
var e : = _pipe_entry ( )
if e == null or PipePopover . _count_error ( s ) != " " :
return
var before : = e . count_text ( to )
e . set_pipe_count ( to , s . strip_edges ( ) if s . strip_edges ( ) != " " else " 1 " )
if e . count_text ( to ) != before :
wrote ( selected_table ( ) )
2026-11-10 19:10:11 -06:00
func set_pipe_pause ( to : String , on : bool ) - > void :
var e : = _pipe_entry ( )
if e == null or e . pipe_pause . has ( to ) == on :
return
if on :
e . pipe_pause [ to ] = true
else :
e . pipe_pause . erase ( to )
wrote ( selected_table ( ) )
2026-11-10 19:06:55 -06:00
func set_pipe_combine ( to : String , mode : String ) - > void :
var e : = _pipe_entry ( )
if e == null or e . combine_for ( to ) == mode :
return
if mode == " all " :
e . pipe_combine . erase ( to )
else :
e . pipe_combine [ to ] = mode
wrote ( selected_table ( ) )
2026-11-08 21:24:25 -06:00
func set_pipe_save ( to : String , s : String ) - > void :
var e : = _pipe_entry ( )
if e == null or _save_error ( s ) != " " or s . strip_edges ( ) == e . save_for ( to ) :
return
e . set_pipe_save ( to , s )
wrote ( selected_table ( ) )
2026-11-10 18:20:46 -06:00
func set_pipe_color ( hex : String , to : String ) - > void :
var e : = _pipe_entry ( )
if e == null :
return
if hex == " " :
e . pipe_color . erase ( to )
else :
e . pipe_color [ to ] = hex
wrote ( selected_table ( ) )
main . board . geometry_rev += 1
2026-11-08 21:24:25 -06:00
func remove_pipe ( to : String ) - > void :
var t : = selected_table ( )
var e : = selected_entry ( )
if t == null or e == null :
return
var was_pipe : = str ( selection . get ( " kind " , " " ) ) == " pipe "
main . remove_pipe ( Roller . pipe_key ( t . id , e . id , to ) )
if was_pipe :
select ( { " kind " : " result " , " tid " : t . id , " eid " : e . id } )
else :
rebuild ( )
static func _save_error ( s : String ) - > String :
var t : = TemplateKit . probe ( s . strip_edges ( ) )
if t == " " or RegEx . create_from_string ( PipePopover . SAVE_PATTERN ) . search ( t ) != null :
return " "
return " Use a name like weapon, or @weapon to keep it between rolls. "
# ---------- Collections ----------
## A collection card's members: Array of [item, value] (item without the stem).
func members ( t : RollTable ) - > Array :
var out : Array = [ ]
var pre : = t . var_name + " _ "
var names : Array = main . persistent_vars . keys ( )
names . sort_custom ( func ( a : String , b : String ) - > bool : return a . naturalnocasecmp_to ( b ) < 0 )
for n : String in names :
if n . begins_with ( pre ) and n . length ( ) > pre . length ( ) :
var v : Variant = main . persistent_vars [ n ]
out . append ( [ n . substr ( pre . length ( ) ) , Expr . format_value ( v . get ( " value " ) if v is Dictionary else v ) ] )
return out
# ---------- Building ----------
func rebuild ( ) - > void :
var focus_key : = " "
var caret : = - 1
var f : = get_viewport ( ) . gui_get_focus_owner ( ) if is_inside_tree ( ) else null
if f and is_ancestor_of ( f ) and f . has_meta ( InspectorKit . KEY ) :
focus_key = str ( f . get_meta ( InspectorKit . KEY ) )
if f is LineEdit :
caret = ( f as LineEdit ) . caret_column
for c in _content . get_children ( ) :
_content . remove_child ( c )
c . queue_free ( )
_live . clear ( )
effects = null
show_if_builder = null
case_builder = null
pipe_parts . clear ( )
fields . clear ( )
var t : = selected_table ( )
var e : = selected_entry ( )
if selection . has ( " eid " ) and e == null :
t = null
if t == null :
selection = { }
_empty ( )
else :
match str ( selection . get ( " kind " , " card " ) ) :
" result " :
_result_section ( t , e )
" pipe " :
_pipe_section ( t , e , str ( selection . get ( " to " , " " ) ) )
_ :
InspectorCard . build ( self , _content , t )
_sig = _signature ( )
if main and main . board and main . board . pipes :
main . board . pipes . select_key = Roller . pipe_key ( t . id , e . id , str ( selection [ " to " ] ) ) if t and str ( selection . get ( " kind " , " " ) ) == " pipe " else " "
if focus_key != " " :
var c : = InspectorKit . find_tagged ( _content , focus_key )
if c :
c . grab_focus ( )
if c is LineEdit and caret > = 0 :
( c as LineEdit ) . caret_column = caret
func _head ( kind : String , title : String ) - > Control :
var h : = InspectorKit . hbox ( 6 )
var v : = InspectorKit . vbox ( 2 )
v . size_flags_horizontal = Control . SIZE_EXPAND_FILL
v . add_child ( InspectorKit . flabel ( kind ) )
var tl : = Style . make_label ( title , Style . display ( ) , 22 , Style . INK )
2026-11-08 21:29:59 -06:00
_title_label = tl
2026-11-08 21:24:25 -06:00
tl . autowrap_mode = TextServer . AUTOWRAP_WORD_SMART
tl . custom_minimum_size = Vector2 ( 120 , 0 )
v . add_child ( tl )
h . add_child ( v )
var hide_b : = Button . new ( )
hide_b . text = " » "
hide_b . tooltip_text = " Hide the inspector "
hide_b . size_flags_vertical = Control . SIZE_SHRINK_BEGIN
Style . skin_button ( hide_b , Style . box ( Color ( 0 , 0 , 0 , 0 ) , 5 , [ 6 , 0 , 6 , 2 ] ) , Style . box ( Style . HOVER_ROW , 5 , [ 6 , 0 , 6 , 2 ] ) ,
Style . box ( Style . HOVER_ROW , 5 , [ 6 , 0 , 6 , 2 ] ) , Style . MUTED , Style . INK )
hide_b . add_theme_font_size_override ( " font_size " , 18 )
hide_b . focus_mode = Control . FOCUS_NONE
hide_b . pressed . connect ( func ( ) - > void : set_collapsed ( true ) )
h . add_child ( hide_b )
return h
2026-11-08 21:29:59 -06:00
## Keeps the heading in step with the name or text being typed.
func _refresh_title ( ) - > void :
if not is_instance_valid ( _title_label ) :
return
var t : = selected_table ( )
match str ( selection . get ( " kind " , " " ) ) :
" card " :
if t :
_title_label . text = _title_of ( t . name , " (no name) " )
" result " :
var e : = selected_entry ( )
if e :
_title_label . text = _title_of ( e . text , " (no text) " )
2026-11-08 21:24:25 -06:00
func _empty ( ) - > void :
_content . add_child ( _head ( " Inspector " , " Nothing selected " ) )
2026-11-10 18:24:23 -06:00
_content . add_child ( InspectorKit . note ( " Select a card, a result or a thread to edit it. " , Style . MUTED , 15 ) )
_content . add_child ( InspectorKit . note ( " Click a card ' s title for the card, a result ' s text for the result, or a thread on the felt for its options. " , Style . MUTED , 13 ) )
2026-11-08 21:24:25 -06:00
static func _title_of ( s : String , fallback : String ) - > String :
var t : = Formatter . strip_tags ( s ) . strip_edges ( )
return t if t != " " else fallback
## A link back to the card the result or pipe belongs to.
2026-11-10 19:02:46 -06:00
## "From the Book page X · unlink" for a linked result, else "Save to the Book".
func _book_line ( t : RollTable , e : TableEntry ) - > Control :
var p : = main . data . get_page ( e . page )
if p == null :
var save : = InspectorKit . link ( " Save to the Book " , " Keep this result as a Page to reuse on other tables " )
save . pressed . connect ( func ( ) - > void : main . book . save_result ( t , e ) )
return save
var row : = InspectorKit . hbox ( 8 )
var open : = InspectorKit . link ( " § From the Book: %s " % p . label ( ) , " Edit the page; every result using it changes " )
open . pressed . connect ( func ( ) - > void :
main . book . set_shown ( true )
main . book . refresh ( )
main . book . select_page ( p . id ) )
row . add_child ( open )
var unlink : = InspectorKit . link ( " Unlink " , " Keep the text here but stop following the page " )
unlink . pressed . connect ( func ( ) - > void :
e . page = " "
wrote ( t , false , true ) )
row . add_child ( unlink )
return row
2026-11-10 19:12:06 -06:00
## "[1] of [Points ▾]": what picking this option costs (RollCosts).
func _cost_row ( t : RollTable , e : TableEntry ) - > Control :
var row : = InspectorKit . flow ( )
var amount : = InspectorKit . amount ( e . cost_amount , " 0 " )
amount . tooltip_text = " How much picking this takes away (0 or empty: free) "
row . add_child ( amount )
row . add_child ( InspectorKit . word ( " of " ) )
var picker : = ValuePicker . new ( main , e . cost_value . trim_prefix ( " @ " ) )
row . add_child ( picker )
var apply : = func ( ) - > void :
var a : = amount . text . strip_edges ( )
e . cost_amount = " " if a == " " or a == " 0 " else a
if e . cost_amount == " " :
e . cost_value = " "
wrote ( t )
amount . text_changed . connect ( func ( _s : String ) - > void : apply . call ( ) )
picker . value_chosen . connect ( func ( n : String ) - > void :
e . cost_value = " @ " + n . trim_prefix ( " @ " )
if amount . text . strip_edges ( ) == " " :
amount . text = " 1 "
apply . call ( ) )
row . add_child ( InspectorKit . note ( " Greyed out in the pop-up when there isn ' t enough. " , Style . MUTED , 12 ) )
return row
2026-11-08 21:24:25 -06:00
func _card_link ( t : RollTable ) - > Button :
var b : = InspectorKit . link ( " On %s · edit the card " % _title_of ( t . name , " this card " ) , " Show the card ' s settings " )
b . add_theme_color_override ( " font_color " , Style . MUTED )
b . pressed . connect ( func ( ) - > void : select ( { " kind " : " card " , " tid " : t . id } ) )
return b
func _result_section ( t : RollTable , e : TableEntry ) - > void :
_content . add_child ( _head ( " Selected result " , _title_of ( e . text , " (no text) " ) ) )
_content . add_child ( _card_link ( t ) )
var plain : = main . rules_plain ( )
if t . kind != RollTable . KIND_SHEET :
var le : = InspectorKit . line ( e . text , " What this result says " )
InspectorKit . tag ( le , " res.text " )
le . text_changed . connect ( set_entry_text )
fields [ " text " ] = le
_content . add_child ( InspectorKit . field ( " Text " , le ) )
2026-11-08 21:29:59 -06:00
var det : = InspectorKit . text_box ( e . details , " Shown on hover (optional) " , 36.0 )
2026-11-08 21:24:25 -06:00
InspectorKit . tag ( det , " res.details " )
det . text_changed . connect ( func ( ) - > void : set_entry_details ( det . text ) )
fields [ " details " ] = det
_content . add_child ( InspectorKit . field ( " Details " , det ) )
Pictures on results and Book pages; export/import keeps everything new
A result or page can have a picture (TableEntry.image, BookPage.image),
chosen from a file, shrunk to 512 px and kept in the spread file as WebP
under "images" (BoardImages; only used pictures are saved). It shows as
a thumbnail on the card row and in the details pop-up, and comes with a
page. Imported BBCode still can't point at files.
Fix: the Table Tarot JSON export and import (JsonIO.canonical) dropped
every key it didn't know, losing the Book, pictures, card colours and
sizes, limits, nesting, costs and thread options. They now pass through;
a round-trip test covers them.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 19:21:05 -06:00
_content . add_child ( InspectorKit . field ( " Picture " , ImageField . new ( main , e . image , func ( id : String ) - > void :
e . image = id
e . page = " "
wrote ( t ) ) ) )
2026-11-10 19:02:46 -06:00
_content . add_child ( _book_line ( t , e ) )
2026-11-08 21:24:25 -06:00
if t . kind == RollTable . KIND_CHOICE and t . choice == " pick " and not ( t . is_dynamic ( ) and t . entries . find ( e ) == 0 ) :
show_if_builder = ConditionBuilder . new ( )
show_if_builder . setup ( main , e . show_if , not plain , " res.show_if " , { " empty_note " : " Always offered. " } )
show_if_builder . changed . connect ( set_entry_show_if )
_content . add_child ( InspectorKit . field ( " Offer only if " , show_if_builder ) )
2026-11-10 19:12:06 -06:00
_content . add_child ( InspectorKit . field ( " Costs " , _cost_row ( t , e ) ) )
2026-11-08 21:24:25 -06:00
if t . kind == RollTable . KIND_ROUTER :
_content . add_child ( InspectorCard . case_block ( self , t , e ) )
effects = EffectsBuilder . new ( )
effects . setup ( main , e . effects , t , not plain , " res.fx " )
effects . changed . connect ( set_entry_effects )
_content . add_child ( InspectorKit . field ( " When this comes up " , effects ) )
var go : = InspectorKit . vbox ( 8 )
if e . pipes . is_empty ( ) :
2026-11-10 18:24:23 -06:00
go . add_child ( InspectorKit . note ( " No threads yet. Drag from the ● at the end of this result to a card. " , Style . MUTED , 14 ) )
2026-11-08 21:24:25 -06:00
for p in e . pipes :
go . add_child ( _pipe_box ( t , e , p ) )
_content . add_child ( InspectorKit . field ( " Then go to " , go ) )
_lint_lines ( t , e )
func _pipe_section ( t : RollTable , e : TableEntry , to : String ) - > void :
if not e . pipes . has ( to ) :
_result_section ( t , e )
return
var target : = main . data . get_table ( to )
2026-11-10 18:24:23 -06:00
_content . add_child ( _head ( " Selected thread " , " %s → %s " % [ _title_of ( e . text , " (no text) " ) , _title_of ( target . name , to ) if target else to ] ) )
var back : = InspectorKit . link ( " Edit the whole result " , " Show the result this thread leaves from " )
2026-11-08 21:24:25 -06:00
back . add_theme_color_override ( " font_color " , Style . MUTED )
back . pressed . connect ( func ( ) - > void : select ( { " kind " : " result " , " tid " : t . id , " eid " : e . id } ) )
_content . add_child ( back )
_content . add_child ( _pipe_box ( t , e , to ) )
2026-11-10 18:20:46 -06:00
_content . add_child ( InspectorKit . field ( " Thread colour " , ColorChoice . new ( str ( e . pipe_color . get ( to , " " ) ) , set_pipe_color . bind ( to ) ) ) )
2026-11-08 21:24:25 -06:00
_lint_lines ( t , e )
## Problems and hints the board check finds on this result's pipes.
func _lint_lines ( t : RollTable , e : TableEntry ) - > void :
var box : = InspectorKit . vbox ( 3 )
var fill : = func ( ) - > void :
for c in box . get_children ( ) :
box . remove_child ( c )
c . queue_free ( )
for it : Dictionary in Roller . lint_pipes ( main . data ) :
if str ( it [ " table_id " ] ) == t . id and str ( it [ " entry_id " ] ) == e . id :
var hint : = str ( it . get ( " level " , " error " ) ) == " hint " or str ( it [ " message " ] ) . contains ( " otherwise " )
box . add_child ( InspectorKit . note ( ( " Note: " if hint else " Problem: " ) + str ( it [ " message " ] ) + " . " ,
Style . MUTED if hint else Style . DANGER_INK , 13 ) )
box . visible = box . get_child_count ( ) > 0
fill . call ( )
_live . append ( fill )
_content . add_child ( box )
func _pipe_box ( t : RollTable , e : TableEntry , to : String ) - > Control :
var target : = main . data . get_table ( to )
var parts : = { " inputs " : { } }
var taken : = main . lit_pipes . has ( Roller . pipe_key ( t . id , e . id , to ) )
var panel : = 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
var sb : = Style . bordered ( Style . box ( Style . VALUE_BG if taken else Style . CARD_SOFT , 8 , [ 10 , 9 , 10 , 10 ] ) , 1 , Style . ACCENT if taken else Style . RULE )
2026-11-08 21:24:25 -06:00
panel . add_theme_stylebox_override ( " panel " , sb )
var v : = InspectorKit . vbox ( 8 )
panel . add_child ( v )
parts [ " box " ] = panel
parts [ " taken " ] = taken
var head : = InspectorKit . hbox ( 8 )
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
head . add_child ( InspectorKit . word ( " → " , Style . TRIM , true ) )
2026-11-08 21:24:25 -06:00
var tn : = Style . make_label ( _title_of ( target . name , to ) if target else to + " (missing) " , Style . display ( ) , 19 , Style . INK )
tn . size_flags_horizontal = Control . SIZE_EXPAND_FILL
tn . clip_text = true
head . add_child ( tn )
if taken :
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
head . add_child ( _chip ( " taken last roll " , Style . ACCENT_DARK , Style . LIT ) )
2026-11-08 21:24:25 -06:00
elif main . is_entry_lit ( t . id , e . id ) :
head . add_child ( Style . make_label ( " not taken " , Style . body_bold ( ) , 12 , Style . MUTED ) )
v . add_child ( head )
# Inputs the target declares (and any extra names the pipe passes).
var w : = e . with_for ( to )
var names : Array = target . input_names ( ) if target else [ ]
for nm : String in w :
if not names . has ( nm ) :
names . append ( nm )
for nm : String in names :
var decl : Dictionary = target . find_input ( nm ) if target else { }
var row : = InspectorKit . hbox ( 6 )
var lab : = str ( decl . get ( " label " , " " ) ) if not decl . is_empty ( ) else " "
var cap : = InspectorKit . word ( lab if lab != " " else RollContext . pretty_name ( nm ) )
cap . custom_minimum_size = Vector2 ( 64 , 0 )
cap . tooltip_text = " Input %s of %s " % [ nm , target . name if target else to ]
row . add_child ( cap )
var def : = str ( decl . get ( " default " , " " ) )
var le : = InspectorKit . amount ( str ( w . get ( nm , " " ) ) , def if def != " " else " 0 " )
le . tooltip_text = " An expression passed as %s . Empty uses the card ' s default %s . " % [ nm , ( " ( " + def + " ) " ) if def != " " else " " ]
InspectorKit . tag ( le , " pipe. %s .in. %s " % [ to , nm ] )
var err : = InspectorKit . error_label ( )
var nm_c : = nm
le . text_changed . connect ( func ( s : String ) - > void :
var msg : = InspectorKit . expr_error ( s , " This value " )
InspectorKit . show_error ( err , msg )
InspectorKit . mark ( le , msg == " " )
set_pipe_input ( to , nm_c , s )
)
row . add_child ( le )
if decl . is_empty ( ) :
row . add_child ( InspectorKit . word ( " (not an input of this card) " , Style . MUTED ) )
( parts [ " inputs " ] as Dictionary ) [ nm ] = le
v . add_child ( row )
v . add_child ( err )
# Only if / Otherwise.
var cond : = ConditionBuilder . new ( )
cond . setup ( main , e . when_for ( to ) , not main . rules_plain ( ) , " pipe. %s .when " % to ,
{ " add_label " : " + Only if… " if e . when_for ( to ) == " " else " + Add condition " } )
cond . changed . connect ( func ( s : String ) - > void : set_pipe_when ( to , s ) )
parts [ " when " ] = cond
var when_box : = InspectorKit . vbox ( 4 )
when_box . add_child ( InspectorKit . flabel ( " Only if " ) )
when_box . add_child ( cond )
v . add_child ( when_box )
var other : = InspectorKit . check_box ( " Otherwise " , e . is_otherwise ( to ) )
2026-11-10 18:24:23 -06:00
other . tooltip_text = " Runs only when none of this result ' s \" Only if \" threads is true "
2026-11-08 21:24:25 -06:00
other . toggled . connect ( func ( on : bool ) - > void : set_pipe_otherwise ( to , on ) )
parts [ " otherwise " ] = other
v . add_child ( other )
2026-11-10 19:10:11 -06:00
var pause : = InspectorKit . check_box ( " Wait for me first " , e . pipe_pause . has ( to ) )
pause . tooltip_text = " The roll stops here with Continue ▸ in the tray, so you can reveal the next part when you ' re ready "
pause . toggled . connect ( func ( on : bool ) - > void : set_pipe_pause ( to , on ) )
parts [ " pause " ] = pause
v . add_child ( pause )
2026-11-08 21:24:25 -06:00
# Count and saves as.
var cr : = InspectorKit . flow ( )
cr . add_child ( InspectorKit . word ( " Rolls " ) )
var count : = InspectorKit . amount ( e . count_text ( to ) , " 1 " )
2026-11-10 18:24:23 -06:00
count . tooltip_text = " A number, or an expression such as @terms, answer or 1d3 (worked out when the thread runs) "
2026-11-08 21:24:25 -06:00
InspectorKit . tag ( count , " pipe. %s .count " % to )
var cerr : = InspectorKit . error_label ( )
count . text_changed . connect ( func ( s : String ) - > void :
var msg : = PipePopover . _count_error ( s )
InspectorKit . show_error ( cerr , msg )
InspectorKit . mark ( count , msg == " " )
set_pipe_count ( to , s )
)
cr . add_child ( count )
2026-11-10 19:06:55 -06:00
cr . add_child ( InspectorKit . word ( " times, then " ) )
var then : = OptionButton . new ( )
ModalCard . style_popup ( then . get_popup ( ) )
for i in RollCombine . LABELS . size ( ) :
then . add_item ( RollCombine . LABELS [ i ] , i )
then . select ( maxi ( 0 , RollCombine . MODES . find ( e . combine_for ( to ) ) ) )
then . tooltip_text = " What to do with the rolls when there ' s more than one (rerolls, best of two, totals…) "
then . item_selected . connect ( func ( i : int ) - > void : set_pipe_combine ( to , RollCombine . MODES [ i ] ) )
cr . add_child ( then )
parts [ " combine " ] = then
2026-11-08 21:29:59 -06:00
var sr : = InspectorKit . hbox ( 6 )
sr . add_child ( InspectorKit . word ( " Saves as " ) )
var save : = InspectorKit . line ( e . save_for ( to ) , " nothing (or a name) " )
2026-11-08 21:24:25 -06:00
save . tooltip_text = " Keep the result as a value: a name lasts one roll, @name is kept between rolls "
InspectorKit . tag ( save , " pipe. %s .save " % to )
save . text_changed . connect ( func ( s : String ) - > void :
var msg : = _save_error ( s )
InspectorKit . show_error ( cerr , msg )
InspectorKit . mark ( save , msg == " " )
set_pipe_save ( to , s )
)
2026-11-08 21:29:59 -06:00
sr . add_child ( save )
2026-11-08 21:24:25 -06:00
parts [ " count " ] = count
parts [ " save " ] = save
v . add_child ( cr )
2026-11-08 21:29:59 -06:00
v . add_child ( sr )
2026-11-08 21:24:25 -06:00
v . add_child ( cerr )
2026-11-10 18:24:23 -06:00
var rm : = InspectorKit . link ( " Delete thread " , " Delete this thread " )
2026-11-08 21:24:25 -06:00
rm . add_theme_color_override ( " font_color " , Style . DANGER_INK )
rm . add_theme_color_override ( " font_hover_color " , Style . DANGER_INK )
rm . pressed . connect ( func ( ) - > void : remove_pipe ( to ) )
v . add_child ( rm )
pipe_parts [ to ] = parts
_refresh_otherwise ( to )
return panel
## Otherwise is off and disabled while the pipe has an Only if.
func _refresh_otherwise ( to : String ) - > void :
var parts : Dictionary = pipe_parts . get ( to , { } )
var e : = _pipe_entry ( )
if parts . is_empty ( ) or e == null :
return
var cb : = parts [ " otherwise " ] as CheckBox
var has_when : = e . when_for ( to ) != " "
cb . disabled = has_when
cb . set_pressed_no_signal ( e . is_otherwise ( to ) )
2026-11-10 18:24:23 -06:00
cb . tooltip_text = " Turn off \" Only if \" first: a thread with a condition isn ' t an otherwise thread " if has_when \
else " Runs only when none of this result ' s \" Only if \" threads is true "
2026-11-08 21:24:25 -06:00
static func _chip ( text : String , fg : Color , bg : Color ) - > Control :
var p : = 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
p . add_theme_stylebox_override ( " panel " , Style . bordered ( Style . box ( bg , 9 , [ 7 , 1 , 7 , 2 ] ) , 1 , Style . ACCENT ) )
2026-11-08 21:24:25 -06:00
p . add_child ( Style . make_label ( text , Style . body_bold ( ) , 12 , fg ) )
p . size_flags_vertical = Control . SIZE_SHRINK_CENTER
return p
## Closes any open value-picker menu (before an undo rebuilds the board).
func close_menus ( ) - > void :
_close_pickers ( self )
func _close_pickers ( n : Node ) - > void :
for c in n . get_children ( ) :
if c is ValuePicker :
( c as ValuePicker ) . close_menu ( )
_close_pickers ( c )