Split ui/main.gd into area helpers (no behaviour change)
Main (3679 lines) becomes a shell: shared state, start-up, cards, input,
rules view and one-line delegators for the methods other files call. Each
area moves with its state into a RefCounted helper holding a back-reference
(m: Main):
main_cli.gd command-line and screenshot flags
main_top_bar.gd top bar, toast, endless-loop chip
main_editing.gd add/delete cards, results and pipes, selection bar
main_groups.gd groups and card drags
main_templates.gd templates
main_rolling.gd rolling, choice questions, playback, session seed, copy
main_collections.gd collections, import/export, table settings, test board
main_state.gd decks, variables, roll history (local state)
main_navigation.gd search, focus, minimap, arrange/pack
main_history.gd undo/redo and mark_dirty
main_inspector.gd inspector selection and refresh
Tests that reached moved private members now go through the helper
(main.undo_redo.edits, main.rolling.pending_choice(), ...).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 08:14:19 -06:00
class_name MainTemplates
extends RefCounted
## Main's templates: saving cards as templates, inserting, import and export.
## Saved in user://templates (TemplateLibrary), shared by every collection.
## --sample runs keep them in memory only.
2026-11-10 18:24:23 -06:00
const TEMPLATE_FILTER : = " *.json ; Table Tarot template "
2026-11-09 08:21:26 -06:00
Split ui/main.gd into area helpers (no behaviour change)
Main (3679 lines) becomes a shell: shared state, start-up, cards, input,
rules view and one-line delegators for the methods other files call. Each
area moves with its state into a RefCounted helper holding a back-reference
(m: Main):
main_cli.gd command-line and screenshot flags
main_top_bar.gd top bar, toast, endless-loop chip
main_editing.gd add/delete cards, results and pipes, selection bar
main_groups.gd groups and card drags
main_templates.gd templates
main_rolling.gd rolling, choice questions, playback, session seed, copy
main_collections.gd collections, import/export, table settings, test board
main_state.gd decks, variables, roll history (local state)
main_navigation.gd search, focus, minimap, arrange/pack
main_history.gd undo/redo and mark_dirty
main_inspector.gd inspector selection and refresh
Tests that reached moved private members now go through the helper
(main.undo_redo.edits, main.rolling.pending_choice(), ...).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 08:14:19 -06:00
var m : Main
var _templates : TemplateLibrary
func _init ( p_main : Main ) - > void :
m = p_main
func templates ( ) - > TemplateLibrary :
if _templates == null :
_templates = TemplateLibrary . new ( " user:// " if m . _saving_enabled else " " )
return _templates
## Opens the save dialog for a template of these tables (and groups).
func save_template_from ( table_ids : Array , kind : String , group_ids : Array = [ ] ) - > void :
var tname : = " Template "
if kind == " card " and table_ids . size ( ) == 1 and m . data . get_table ( str ( table_ids [ 0 ] ) ) :
tname = Formatter . strip_tags ( m . data . get_table ( str ( table_ids [ 0 ] ) ) . name )
elif kind == " group " and group_ids . size ( ) == 1 and m . data . get_group ( str ( group_ids [ 0 ] ) ) :
tname = Formatter . strip_tags ( m . data . get_group ( str ( group_ids [ 0 ] ) ) . name )
var tpl : = TemplateKit . make ( m . data , table_ids , kind , tname , " " , group_ids )
if ( tpl [ " tables " ] as Array ) . is_empty ( ) :
m . toast ( " Nothing to save: the template would have no cards " )
return
if kind == " selection " :
tpl [ " name " ] = " %d cards " % ( tpl [ " tables " ] as Array ) . size ( )
m . _add_modal ( TemplateForms . save_dialog ( tpl , func ( out : Dictionary ) - > void :
var id : = templates ( ) . add ( out )
if id == " " :
m . toast ( " Couldn ' t save the template " )
else :
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
m . toast ( " Saved template “ %s ”. Insert it from + Card ▾ → From template… " % out [ " name " ] )
Split ui/main.gd into area helpers (no behaviour change)
Main (3679 lines) becomes a shell: shared state, start-up, cards, input,
rules view and one-line delegators for the methods other files call. Each
area moves with its state into a RefCounted helper holding a back-reference
(m: Main):
main_cli.gd command-line and screenshot flags
main_top_bar.gd top bar, toast, endless-loop chip
main_editing.gd add/delete cards, results and pipes, selection bar
main_groups.gd groups and card drags
main_templates.gd templates
main_rolling.gd rolling, choice questions, playback, session seed, copy
main_collections.gd collections, import/export, table settings, test board
main_state.gd decks, variables, roll history (local state)
main_navigation.gd search, focus, minimap, arrange/pack
main_history.gd undo/redo and mark_dirty
main_inspector.gd inspector selection and refresh
Tests that reached moved private members now go through the helper
(main.undo_redo.edits, main.rolling.pending_choice(), ...).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 08:14:19 -06:00
) )
## The selection as a template; groups whose cards are all selected come along.
func save_selection_as_template ( ) - > void :
if m . selection . is_empty ( ) :
m . toast ( " Select some cards first " )
return
var gids : Array = [ ]
for g in m . data . groups :
if g . members . is_empty ( ) :
continue
var all : = true
for member in g . members :
if not m . selection . has ( member ) :
all = false
break
if all :
gids . append ( g . id )
save_template_from ( m . selection . keys ( ) , " selection " , gids )
func open_template_picker ( ) - > TemplatePicker :
var p : = TemplatePicker . new ( m , templates ( ) )
m . _add_modal ( p )
return p
## Asks for the template's parameters (if it has any), then inserts it.
func begin_template_insert ( tpl : Dictionary ) - > void :
if ( tpl . get ( " params " , [ ] ) as Array ) . is_empty ( ) :
insert_template ( tpl , { } )
return
m . _add_modal ( TemplateForms . params_dialog ( tpl , func ( values : Dictionary ) - > void : insert_template ( tpl , values ) ) )
## Inserts a template at the view centre: parameters substituted, fresh ids,
## outside pipes relinked by name (or dropped and reported). Returns
## TemplateKit.instantiate's result.
func insert_template ( tpl : Dictionary , values : Dictionary ) - > Dictionary :
m . undo_redo . _begin_edit ( )
var ext : = TemplateKit . extent ( tpl )
var center : = m . board . screen_to_world ( m . board . size / 2.0 )
var origin : = ( center - ext / 2.0 ) . round ( )
var r : = TemplateKit . insert ( tpl , values , m . data , origin )
for t : RollTable in r [ " tables " ] :
if t . kind == RollTable . KIND_VARIABLE and t . var_name == " " :
t . var_name = m . editing . _free_var_name ( " var " )
var card : = TableCard . new ( )
m . board . cards . add_child ( card )
card . setup ( m , t )
m . cards [ t . id ] = card
m . grouping . _groups_changed ( )
m . undo_redo . _end_edit ( " Insert template %s " % Formatter . strip_tags ( str ( tpl . get ( " name " , " template " ) ) ) )
var n : = ( r [ " tables " ] as Array ) . size ( )
var msg : = " Inserted “ %s ” ( %d %s ) " % [ str ( tpl . get ( " name " , " template " ) ) , n , " card " if n == 1 else " cards " ]
var relinked : Array = r [ " relinked " ]
if not relinked . is_empty ( ) :
msg += " · %d %s relinked by name " % [ relinked . size ( ) , " pipe " if relinked . size ( ) == 1 else " pipes " ]
var dropped : Array = r [ " dropped " ]
if dropped . is_empty ( ) :
m . toast ( msg , true )
else :
m . toast ( msg + " · %d left out " % dropped . size ( ) , true )
var d : = ModalCard . new ( " Inserted “ %s ” " % str ( tpl . get ( " name " , " template " ) ) , 540.0 )
2026-11-10 18:24:23 -06:00
d . body . add_child ( ModalCard . note ( " These threads led to cards outside the template, and this spread has no card with that name, so they were left out. Lay them again by hand, or rename a card and insert again. " , Style . INK ) )
Split ui/main.gd into area helpers (no behaviour change)
Main (3679 lines) becomes a shell: shared state, start-up, cards, input,
rules view and one-line delegators for the methods other files call. Each
area moves with its state into a RefCounted helper holding a back-reference
(m: Main):
main_cli.gd command-line and screenshot flags
main_top_bar.gd top bar, toast, endless-loop chip
main_editing.gd add/delete cards, results and pipes, selection bar
main_groups.gd groups and card drags
main_templates.gd templates
main_rolling.gd rolling, choice questions, playback, session seed, copy
main_collections.gd collections, import/export, table settings, test board
main_state.gd decks, variables, roll history (local state)
main_navigation.gd search, focus, minimap, arrange/pack
main_history.gd undo/redo and mark_dirty
main_inspector.gd inspector selection and refresh
Tests that reached moved private members now go through the helper
(main.undo_redo.edits, main.rolling.pending_choice(), ...).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 08:14:19 -06:00
d . body . add_child ( ModalCard . section ( " Left out ( %d ) " % dropped . size ( ) ) )
for what : String in dropped :
d . body . add_child ( ModalCard . note ( " • " + what , Style . INK ) )
if not relinked . is_empty ( ) :
d . body . add_child ( ModalCard . section ( " Relinked ( %d ) " % relinked . size ( ) ) )
for what : String in relinked :
d . body . add_child ( ModalCard . note ( " • " + what ) )
d . add_button ( " Done " , " primary " , d . close )
m . _add_modal ( d )
return r
func export_template ( id : String ) - > void :
var text : = templates ( ) . export_text ( id )
if text == " " :
m . toast ( " Couldn ' t read that template " )
return
2026-11-09 08:21:26 -06:00
m . export_dialog ( " Export template " , TEMPLATE_FILTER ,
id . trim_prefix ( TemplateLibrary . BUILTIN_PREFIX ) + " .template.json " , func ( ) - > String : return text )
Split ui/main.gd into area helpers (no behaviour change)
Main (3679 lines) becomes a shell: shared state, start-up, cards, input,
rules view and one-line delegators for the methods other files call. Each
area moves with its state into a RefCounted helper holding a back-reference
(m: Main):
main_cli.gd command-line and screenshot flags
main_top_bar.gd top bar, toast, endless-loop chip
main_editing.gd add/delete cards, results and pipes, selection bar
main_groups.gd groups and card drags
main_templates.gd templates
main_rolling.gd rolling, choice questions, playback, session seed, copy
main_collections.gd collections, import/export, table settings, test board
main_state.gd decks, variables, roll history (local state)
main_navigation.gd search, focus, minimap, arrange/pack
main_history.gd undo/redo and mark_dirty
main_inspector.gd inspector selection and refresh
Tests that reached moved private members now go through the helper
(main.undo_redo.edits, main.rolling.pending_choice(), ...).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 08:14:19 -06:00
func import_template_file ( picker : TemplatePicker = null ) - > void :
2026-11-09 08:21:26 -06:00
m . file_dialog ( " Import a template " , [ TEMPLATE_FILTER ] , FileDialog . FILE_MODE_OPEN_FILE , func ( path : String ) - > void :
Split ui/main.gd into area helpers (no behaviour change)
Main (3679 lines) becomes a shell: shared state, start-up, cards, input,
rules view and one-line delegators for the methods other files call. Each
area moves with its state into a RefCounted helper holding a back-reference
(m: Main):
main_cli.gd command-line and screenshot flags
main_top_bar.gd top bar, toast, endless-loop chip
main_editing.gd add/delete cards, results and pipes, selection bar
main_groups.gd groups and card drags
main_templates.gd templates
main_rolling.gd rolling, choice questions, playback, session seed, copy
main_collections.gd collections, import/export, table settings, test board
main_state.gd decks, variables, roll history (local state)
main_navigation.gd search, focus, minimap, arrange/pack
main_history.gd undo/redo and mark_dirty
main_inspector.gd inspector selection and refresh
Tests that reached moved private members now go through the helper
(main.undo_redo.edits, main.rolling.pending_choice(), ...).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 08:14:19 -06:00
var r : = templates ( ) . import_text ( FileAccess . get_file_as_string ( path ) )
if r [ " ok " ] :
m . toast ( " Imported template “ %s ” " % r [ " name " ] )
if is_instance_valid ( picker ) :
picker . refresh ( )
picker . select ( r [ " id " ] )
else :
m . _add_modal ( IoMenu . report_dialog ( " Couldn ' t import %s " % path . get_file ( ) , { " errors " : r [ " errors " ] } ) )
)