Group cards and templates
Groups: an optional groups list on a collection (frame rect, collapsed,
members, details), saved by TowerBoard and kept by JsonIO. Expanded groups
draw a frame behind their cards with a title bar; collapsed ones become one
compact card that lists the members' lit results, with pipes re-routed to
its inlet and right edge. Build mode adds multi-select (Ctrl/Shift-click,
Ctrl-drag), Group (Ctrl+G), drop in/out of frames, rename, ungroup, delete
with undo and a details editor.
Templates: TemplateKit saves cards, groups or selections with relative
positions, internal pipes and outside pipes by name, detects {$name}
parameters and inserts with fresh ids. TemplateLibrary keeps user templates
in user://templates and lists the built-in ones in templates/.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 17:01:34 -06:00
class_name TemplateForms
extends RefCounted
## Card-styled dialogs for templates: saving one (name, description and the
## detected {$parameters}), filling in parameters before an insert, and the
## small board preview the template list shows.
## The "Save as template" dialog. `on_save` gets the template with the name,
## description and parameter labels and defaults the user typed.
static func save_dialog ( tpl : Dictionary , on_save : Callable ) - > ModalCard :
var d : = ModalCard . new ( " Save as template " , 580.0 )
var top : = HBoxContainer . new ( )
top . add_theme_constant_override ( " separation " , 16 )
var pv : = preview ( tpl , Vector2 ( 150 , 92 ) )
pv . size_flags_vertical = Control . SIZE_SHRINK_BEGIN
top . add_child ( pv )
var fields : = VBoxContainer . new ( )
fields . add_theme_constant_override ( " separation " , 10 )
fields . size_flags_horizontal = Control . SIZE_EXPAND_FILL
top . add_child ( fields )
var name_edit : = LineEdit . new ( )
name_edit . text = str ( tpl . get ( " name " , " " ) )
ModalCard . style_line_edit ( name_edit )
fields . add_child ( ModalCard . field ( " Name " , name_edit ) )
fields . add_child ( ModalCard . note ( TemplateKit . summary ( tpl ) ) )
d . body . add_child ( top )
var desc : = TextEdit . new ( )
desc . text = str ( tpl . get ( " description " , " " ) )
desc . placeholder_text = " What it ' s for, and what to fill in (shown in the template list) "
desc . wrap_mode = TextEdit . LINE_WRAPPING_BOUNDARY
desc . custom_minimum_size = Vector2 ( 0 , 64 )
desc . scroll_fit_content_height = true
ModalCard . style_text_edit ( desc )
d . body . add_child ( ModalCard . field ( " Description " , desc ) )
var outside : = 0
for t : Dictionary in tpl . get ( " tables " , [ ] ) :
for e : Dictionary in t . get ( " entries " , [ ] ) :
for p : Variant in e . get ( " pipes " , [ ] ) :
if p is Dictionary and bool ( ( p as Dictionary ) . get ( " outside " , false ) ) :
outside += 1
if outside > 0 :
2026-11-10 18:24:23 -06:00
d . body . add_child ( ModalCard . note ( " %d %s to cards outside the template. When it ' s inserted they relink to a card with the same name, if there is one. " % [ outside , " thread leads " if outside == 1 else " threads lead " ] ) )
Group cards and templates
Groups: an optional groups list on a collection (frame rect, collapsed,
members, details), saved by TowerBoard and kept by JsonIO. Expanded groups
draw a frame behind their cards with a title bar; collapsed ones become one
compact card that lists the members' lit results, with pipes re-routed to
its inlet and right edge. Build mode adds multi-select (Ctrl/Shift-click,
Ctrl-drag), Group (Ctrl+G), drop in/out of frames, rename, ungroup, delete
with undo and a details editor.
Templates: TemplateKit saves cards, groups or selections with relative
positions, internal pipes and outside pipes by name, detects {$name}
parameters and inserts with fresh ids. TemplateLibrary keeps user templates
in user://templates and lists the built-in ones in templates/.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 17:01:34 -06:00
d . body . add_child ( ModalCard . section ( " Parameters " ) )
var rows : Array = [ ]
var params : Array = tpl . get ( " params " , [ ] )
if params . is_empty ( ) :
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
d . body . add_child ( ModalCard . note ( " None found. Write {$name} in any text (card names, results, changes, expressions, prompts, variable names) and it becomes a parameter you fill in when inserting. " ) )
Group cards and templates
Groups: an optional groups list on a collection (frame rect, collapsed,
members, details), saved by TowerBoard and kept by JsonIO. Expanded groups
draw a frame behind their cards with a title bar; collapsed ones become one
compact card that lists the members' lit results, with pipes re-routed to
its inlet and right edge. Build mode adds multi-select (Ctrl/Shift-click,
Ctrl-drag), Group (Ctrl+G), drop in/out of frames, rename, ungroup, delete
with undo and a details editor.
Templates: TemplateKit saves cards, groups or selections with relative
positions, internal pipes and outside pipes by name, detects {$name}
parameters and inserts with fresh ids. TemplateLibrary keeps user templates
in user://templates and lists the built-in ones in templates/.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 17:01:34 -06:00
else :
d . body . add_child ( ModalCard . note ( " Found in the cards ' text. Give each a label and a default for the insert form. " ) )
for p : Dictionary in params :
var row : = HBoxContainer . new ( )
row . add_theme_constant_override ( " separation " , 8 )
var chip : = 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
chip . add_theme_stylebox_override ( " panel " , Style . bordered ( Style . box ( Color ( Style . ACCENT , 0.18 ) , 6 , [ 8 , 4 , 8 , 4 ] ) , 1 , Color ( Style . ACCENT_DARK , 0.4 ) ) )
Group cards and templates
Groups: an optional groups list on a collection (frame rect, collapsed,
members, details), saved by TowerBoard and kept by JsonIO. Expanded groups
draw a frame behind their cards with a title bar; collapsed ones become one
compact card that lists the members' lit results, with pipes re-routed to
its inlet and right edge. Build mode adds multi-select (Ctrl/Shift-click,
Ctrl-drag), Group (Ctrl+G), drop in/out of frames, rename, ungroup, delete
with undo and a details editor.
Templates: TemplateKit saves cards, groups or selections with relative
positions, internal pipes and outside pipes by name, detects {$name}
parameters and inserts with fresh ids. TemplateLibrary keeps user templates
in user://templates and lists the built-in ones in templates/.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 17:01:34 -06:00
chip . custom_minimum_size = Vector2 ( 120 , 0 )
chip . size_flags_vertical = Control . SIZE_SHRINK_CENTER
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
chip . add_child ( Style . make_label ( " {$ %s } " % p [ " name " ] , Style . body_bold ( ) , 14 , Style . TRIM_DARK ) )
Group cards and templates
Groups: an optional groups list on a collection (frame rect, collapsed,
members, details), saved by TowerBoard and kept by JsonIO. Expanded groups
draw a frame behind their cards with a title bar; collapsed ones become one
compact card that lists the members' lit results, with pipes re-routed to
its inlet and right edge. Build mode adds multi-select (Ctrl/Shift-click,
Ctrl-drag), Group (Ctrl+G), drop in/out of frames, rename, ungroup, delete
with undo and a details editor.
Templates: TemplateKit saves cards, groups or selections with relative
positions, internal pipes and outside pipes by name, detects {$name}
parameters and inserts with fresh ids. TemplateLibrary keeps user templates
in user://templates and lists the built-in ones in templates/.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 17:01:34 -06:00
row . add_child ( chip )
var label : = LineEdit . new ( )
label . text = str ( p . get ( " label " , " " ) )
label . placeholder_text = " Label "
ModalCard . style_line_edit ( label )
row . add_child ( label )
var def : = LineEdit . new ( )
def . text = str ( p . get ( " default " , " " ) )
def . placeholder_text = " Default "
ModalCard . style_line_edit ( def )
row . add_child ( def )
d . body . add_child ( row )
rows . append ( [ p , label , def ] )
d . add_button ( " Cancel " , " plain " , d . close )
d . add_button ( " Save template " , " primary " , func ( ) - > void :
var out : = tpl . duplicate ( true )
out [ " name " ] = name_edit . text . strip_edges ( ) if name_edit . text . strip_edges ( ) != " " else " Untitled template "
out [ " description " ] = desc . text . strip_edges ( )
var plist : Array = [ ]
for r : Array in rows :
var p : Dictionary = r [ 0 ]
plist . append ( { " name " : p [ " name " ] , " label " : ( r [ 1 ] as LineEdit ) . text . strip_edges ( ) , " default " : ( r [ 2 ] as LineEdit ) . text } )
out [ " params " ] = plist
d . close ( )
on_save . call ( out )
)
d . ready . connect ( func ( ) - > void :
name_edit . grab_focus ( )
name_edit . select_all ( )
)
return d
## Asks for the template's parameter values; `on_ok` gets {name: value}.
static func params_dialog ( tpl : Dictionary , on_ok : Callable ) - > ModalCard :
var d : = ModalCard . new ( " Insert “ %s ” " % str ( tpl . get ( " name " , " template " ) ) , 480.0 )
if str ( tpl . get ( " description " , " " ) ) != " " :
d . body . add_child ( ModalCard . note ( str ( tpl [ " description " ] ) ) )
var edits : Array = [ ]
for p : Dictionary in tpl . get ( " params " , [ ] ) :
var le : = LineEdit . new ( )
le . text = str ( p . get ( " default " , " " ) )
le . placeholder_text = " {$ %s } " % p [ " name " ]
ModalCard . style_line_edit ( le )
var label : = str ( p . get ( " label " , " " ) )
d . body . add_child ( ModalCard . field ( label if label != " " else str ( p [ " name " ] ) . capitalize ( ) , le ) )
edits . append ( [ str ( p [ " name " ] ) , le ] )
var accept : = func ( ) - > void :
var values : = { }
for pair : Array in edits :
values [ pair [ 0 ] ] = ( pair [ 1 ] as LineEdit ) . text
d . close ( )
on_ok . call ( values )
for pair : Array in edits :
( pair [ 1 ] as LineEdit ) . text_submitted . connect ( func ( _t : String ) - > void : accept . call ( ) )
d . add_button ( " Cancel " , " plain " , d . close )
d . add_button ( " Insert " , " primary " , accept )
d . ready . connect ( func ( ) - > void :
if not edits . is_empty ( ) :
( edits [ 0 ] [ 1 ] as LineEdit ) . grab_focus ( )
( edits [ 0 ] [ 1 ] as LineEdit ) . select_all ( )
)
return d
## A small picture of the template's layout: group frames on a felt tile and
## each card as a little paper rectangle (choice cards brass, loops copper,
## variables and sheets outlined).
static func preview ( tpl : Dictionary , box : Vector2 = Vector2 ( 120 , 74 ) ) - > Control :
var c : = Control . new ( )
c . custom_minimum_size = box
c . mouse_filter = Control . MOUSE_FILTER_IGNORE
c . draw . connect ( func ( ) - > void :
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
c . draw_style_box ( Style . box ( Style . BG , 8 ) , Rect2 ( Vector2 . ZERO , box ) )
Group cards and templates
Groups: an optional groups list on a collection (frame rect, collapsed,
members, details), saved by TowerBoard and kept by JsonIO. Expanded groups
draw a frame behind their cards with a title bar; collapsed ones become one
compact card that lists the members' lit results, with pipes re-routed to
its inlet and right edge. Build mode adds multi-select (Ctrl/Shift-click,
Ctrl-drag), Group (Ctrl+G), drop in/out of frames, rename, ungroup, delete
with undo and a details editor.
Templates: TemplateKit saves cards, groups or selections with relative
positions, internal pipes and outside pipes by name, detects {$name}
parameters and inserts with fresh ids. TemplateLibrary keeps user templates
in user://templates and lists the built-in ones in templates/.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 17:01:34 -06:00
var ext : = TemplateKit . extent ( tpl )
if ext . x < = 0.0 or ext . y < = 0.0 :
return
var inner : = box - Vector2 ( 16 , 16 )
var s : = minf ( inner . x / ext . x , inner . y / ext . y )
var off : = Vector2 ( 8 , 8 ) + ( inner - ext * s ) / 2.0
for g : Dictionary in tpl . get ( " groups " , [ ] ) :
var gr : = Rect2 ( off + Vector2 ( float ( g . get ( " x " , 0 ) ) , float ( g . get ( " y " , 0 ) ) ) * s ,
Vector2 ( float ( g . get ( " w " , 0 ) ) , float ( g . get ( " h " , 0 ) ) ) * s )
c . draw_style_box ( Style . box ( Color ( 0 , 0 , 0 , 0.22 ) , 4 ) , gr )
for t : Dictionary in tpl . get ( " tables " , [ ] ) :
var r : = Rect2 ( off + Vector2 ( float ( t . get ( " x " , 0 ) ) , float ( t . get ( " y " , 0 ) ) ) * s , TemplateKit . CARD_SIZE * s * Vector2 ( 1.0 , 0.8 ) )
var kind : = str ( t . get ( " kind " , " roll " ) )
var fill : = Style . CARD
if kind == " choice " :
fill = Style . LIT
c . draw_style_box ( Style . box ( fill , 3 ) , r )
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 band : = Color ( Style . TRIM , 0.9 ) if kind == " loop " else ( Style . BG_HOVER if kind == " variable " else Style . RULE )
Group cards and templates
Groups: an optional groups list on a collection (frame rect, collapsed,
members, details), saved by TowerBoard and kept by JsonIO. Expanded groups
draw a frame behind their cards with a title bar; collapsed ones become one
compact card that lists the members' lit results, with pipes re-routed to
its inlet and right edge. Build mode adds multi-select (Ctrl/Shift-click,
Ctrl-drag), Group (Ctrl+G), drop in/out of frames, rename, ungroup, delete
with undo and a details editor.
Templates: TemplateKit saves cards, groups or selections with relative
positions, internal pipes and outside pipes by name, detects {$name}
parameters and inserts with fresh ids. TemplateLibrary keeps user templates
in user://templates and lists the built-in ones in templates/.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 17:01:34 -06:00
if kind == " sheet " :
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
band = Style . ACCENT_DARK
Group cards and templates
Groups: an optional groups list on a collection (frame rect, collapsed,
members, details), saved by TowerBoard and kept by JsonIO. Expanded groups
draw a frame behind their cards with a title bar; collapsed ones become one
compact card that lists the members' lit results, with pipes re-routed to
its inlet and right edge. Build mode adds multi-select (Ctrl/Shift-click,
Ctrl-drag), Group (Ctrl+G), drop in/out of frames, rename, ungroup, delete
with undo and a details editor.
Templates: TemplateKit saves cards, groups or selections with relative
positions, internal pipes and outside pipes by name, detects {$name}
parameters and inserts with fresh ids. TemplateLibrary keeps user templates
in user://templates and lists the built-in ones in templates/.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 17:01:34 -06:00
c . draw_rect ( Rect2 ( r . position + Vector2 ( 0 , 2 ) , Vector2 ( r . size . x , maxf ( 2.0 , r . size . y * 0.16 ) ) ) , band )
)
return c