2026-11-08 12:23:21 -06:00
class_name IoMenu
extends MenuButton
2026-11-29 14:58:56 -06:00
## The Build-mode "Spread ▾" menu (test, reset, arrange, import, export) plus the import and
2026-11-08 12:23:21 -06:00
## export logic as static functions, so it can be tested without a window.
const ID_RESET : = 1
const ID_IMPORT : = 2
2026-11-08 17:49:35 -06:00
const ID_TEST : = 3
UI pass: striped rows, View/Help menus, zoom control, card ⋯ menu, fuller sample
- Striped result rows (parchment tint, on by default, `striped_rows` setting).
- Top bar: View ▾ (Plain words / Rule text, Collapse/Expand all, Striped rows,
Minimap) and a "− 90% ▾ +" zoom control replace the Plain|Text switch,
Collapse all, −/Fit/+ and Map. Arrange ▾ folds into Board ▾; Search is an icon.
- Help ▾ and F1 open a Help window; the 17 topics live in help/topics.txt.
- Build cards get a ⋯ menu (settings, template, collapse, delete) instead of
the gear and footer Delete, sharing Style.overflow_button with group cards.
Row × buttons show only on hover, focus or selection.
- Sample: Luck value card, Make Camp (pick card) and Search the Ruins
(1d6 + Luck, with results only a modifier reaches).
- New test suite test_top_bar; Canvas/GraphML round-trip tests compare plain
tables only, since logic keys are JSON-only.
- DESIGN.md: open items, including the Card Mode UI redesign.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 10:36:38 -06:00
const ID_PACK : = 4
2026-11-08 12:23:21 -06:00
const ID_EXPORT : = 100
## Export formats: label, file extension, FileDialog filter.
const EXPORTS : = [
2026-11-10 18:24:23 -06:00
{ " key " : " json " , " label " : " Table Tarot JSON " , " ext " : " json " , " filter " : " *.json ; Table Tarot JSON " } ,
2026-11-08 12:23:21 -06:00
{ " key " : " canvas " , " label " : " JSON Canvas " , " ext " : " canvas " , " filter " : " *.canvas ; JSON Canvas " } ,
{ " key " : " mermaid " , " label " : " Mermaid diagram (.mmd) " , " ext " : " mmd " , " filter " : " *.mmd ; Mermaid " } ,
{ " key " : " mermaid_md " , " label " : " Mermaid in Markdown (.md) " , " ext " : " md " , " filter " : " *.md ; Markdown " } ,
{ " key " : " dot " , " label " : " Graphviz DOT " , " ext " : " dot " , " filter " : " *.dot, *.gv ; Graphviz DOT " } ,
{ " key " : " graphml " , " label " : " GraphML " , " ext " : " graphml " , " filter " : " *.graphml, *.xml ; GraphML " } ,
]
const IMPORT_FILTERS : Array [ String ] = [
2026-11-10 18:24:23 -06:00
" *.json, *.canvas, *.graphml, *.xml ; Table Tarot, JSON Canvas or GraphML " ,
" *.json ; Table Tarot JSON " ,
2026-11-08 12:23:21 -06:00
" *.canvas ; JSON Canvas " ,
" *.graphml, *.xml ; GraphML " ,
]
signal reset_requested
signal import_requested
signal export_requested ( format : Dictionary )
2026-11-08 17:49:35 -06:00
signal test_requested
UI pass: striped rows, View/Help menus, zoom control, card ⋯ menu, fuller sample
- Striped result rows (parchment tint, on by default, `striped_rows` setting).
- Top bar: View ▾ (Plain words / Rule text, Collapse/Expand all, Striped rows,
Minimap) and a "− 90% ▾ +" zoom control replace the Plain|Text switch,
Collapse all, −/Fit/+ and Map. Arrange ▾ folds into Board ▾; Search is an icon.
- Help ▾ and F1 open a Help window; the 17 topics live in help/topics.txt.
- Build cards get a ⋯ menu (settings, template, collapse, delete) instead of
the gear and footer Delete, sharing Style.overflow_button with group cards.
Row × buttons show only on hover, focus or selection.
- Sample: Luck value card, Make Camp (pick card) and Search the Ruins
(1d6 + Luck, with results only a modifier reaches).
- New test suite test_top_bar; Canvas/GraphML round-trip tests compare plain
tables only, since logic keys are JSON-only.
- DESIGN.md: open items, including the Card Mode UI redesign.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 10:36:38 -06:00
signal pack_requested
2026-11-08 12:23:21 -06:00
func setup ( can_reset : bool , can_import : bool ) - > void :
2026-11-10 18:24:23 -06:00
Style . menu_button ( " Spread ▾ " , false , self )
tooltip_text = " Test, arrange, import and export the spread "
2026-11-08 12:23:21 -06:00
var pm : = get_popup ( )
ModalCard . style_popup ( pm )
2026-11-10 18:24:23 -06:00
pm . add_item ( " Test spread… " , ID_TEST )
UI pass: striped rows, View/Help menus, zoom control, card ⋯ menu, fuller sample
- Striped result rows (parchment tint, on by default, `striped_rows` setting).
- Top bar: View ▾ (Plain words / Rule text, Collapse/Expand all, Striped rows,
Minimap) and a "− 90% ▾ +" zoom control replace the Plain|Text switch,
Collapse all, −/Fit/+ and Map. Arrange ▾ folds into Board ▾; Search is an icon.
- Help ▾ and F1 open a Help window; the 17 topics live in help/topics.txt.
- Build cards get a ⋯ menu (settings, template, collapse, delete) instead of
the gear and footer Delete, sharing Style.overflow_button with group cards.
Row × buttons show only on hover, focus or selection.
- Sample: Luck value card, Make Camp (pick card) and Search the Ruins
(1d6 + Luck, with results only a modifier reaches).
- New test suite test_top_bar; Canvas/GraphML round-trip tests compare plain
tables only, since logic keys are JSON-only.
- DESIGN.md: open items, including the Card Mode UI redesign.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 10:36:38 -06:00
pm . add_item ( " Reset sample " , ID_RESET )
pm . add_separator ( " Arrange " )
pm . add_item ( " Pack collapsed groups " , ID_PACK )
pm . set_item_tooltip ( pm . get_item_index ( ID_PACK ) , " Move collapsed groups and the cards between them together, closing the gaps, in reading order " )
2026-11-08 12:23:21 -06:00
pm . add_separator ( " Import " )
2026-11-10 18:24:23 -06:00
pm . add_item ( " Import as new spread… " , ID_IMPORT )
2026-11-08 12:23:21 -06:00
pm . set_item_disabled ( pm . get_item_index ( ID_IMPORT ) , not can_import )
2026-11-10 18:24:23 -06:00
pm . add_separator ( " Export this spread " )
2026-11-14 14:35:35 -06:00
pm . add_item ( " Export as " + str ( EXPORTS [ 0 ] [ " label " ] ) + " … (full copy) " , ID_EXPORT )
pm . set_item_tooltip ( pm . get_item_index ( ID_EXPORT ) , " Everything on the spread, ready to import again or share " )
2026-11-10 18:40:53 -06:00
# Formats for other tools (diagram and graph programs) sit one level down.
var other : = PopupMenu . new ( )
ModalCard . style_popup ( other )
for i in range ( 1 , EXPORTS . size ( ) ) :
other . add_item ( str ( EXPORTS [ i ] [ " label " ] ) + " … " , ID_EXPORT + i )
pm . add_child ( other )
2026-11-14 14:35:35 -06:00
pm . add_submenu_node_item ( " Export as a diagram (cards and threads only) " , other )
pm . set_item_tooltip ( pm . item_count - 1 , " For diagram and mind-map tools. Settings, values, groups and pictures are left out, so importing one back is not a full copy. " )
2026-11-10 18:40:53 -06:00
var on_id : = func ( id : int ) - > void :
2026-11-08 12:23:21 -06:00
if id == ID_RESET :
reset_requested . emit ( )
2026-11-08 17:49:35 -06:00
elif id == ID_TEST :
test_requested . emit ( )
UI pass: striped rows, View/Help menus, zoom control, card ⋯ menu, fuller sample
- Striped result rows (parchment tint, on by default, `striped_rows` setting).
- Top bar: View ▾ (Plain words / Rule text, Collapse/Expand all, Striped rows,
Minimap) and a "− 90% ▾ +" zoom control replace the Plain|Text switch,
Collapse all, −/Fit/+ and Map. Arrange ▾ folds into Board ▾; Search is an icon.
- Help ▾ and F1 open a Help window; the 17 topics live in help/topics.txt.
- Build cards get a ⋯ menu (settings, template, collapse, delete) instead of
the gear and footer Delete, sharing Style.overflow_button with group cards.
Row × buttons show only on hover, focus or selection.
- Sample: Luck value card, Make Camp (pick card) and Search the Ruins
(1d6 + Luck, with results only a modifier reaches).
- New test suite test_top_bar; Canvas/GraphML round-trip tests compare plain
tables only, since logic keys are JSON-only.
- DESIGN.md: open items, including the Card Mode UI redesign.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 10:36:38 -06:00
elif id == ID_PACK :
pack_requested . emit ( )
2026-11-08 12:23:21 -06:00
elif id == ID_IMPORT :
import_requested . emit ( )
elif id > = ID_EXPORT and id < ID_EXPORT + EXPORTS . size ( ) :
export_requested . emit ( EXPORTS [ id - ID_EXPORT ] )
2026-11-10 18:40:53 -06:00
pm . id_pressed . connect ( on_id )
other . id_pressed . connect ( on_id )
2026-11-08 12:23:21 -06:00
# ---------- Export ----------
## Text for one export format. Works from the board's saved form only, so local
## state (decks, variables, history) can never end up in an export.
static func export_text ( format_key : String , board : TowerBoard ) - > String :
var c : = board . to_dict ( )
match format_key :
" canvas " : return CanvasIO . export_canvas ( c )
" mermaid " : return MermaidExporter . export_mermaid ( c )
" mermaid_md " : return " # %s \n \n ```mermaid \n %s \n ``` \n " % [ board . name , MermaidExporter . export_mermaid ( c ) . strip_edges ( ) ]
" dot " : return DotExporter . export_dot ( c )
" graphml " : return GraphMLIO . export_graphml ( c )
_ : return JsonIO . export_json ( c )
static func default_file_name ( board : TowerBoard , format : Dictionary ) - > String :
return " %s . %s " % [ LibraryStore . slugify ( board . name ) , format [ " ext " ] ]
# ---------- Import ----------
## Guesses the format from the file name, then from the text.
static func detect_format ( file_name : String , text : String ) - > String :
match file_name . get_extension ( ) . to_lower ( ) :
" canvas " : return " canvas "
" graphml " , " xml " : return " graphml "
" json " : return " json "
var t : = text . strip_edges ( )
if t . begins_with ( " < " ) :
return " graphml "
if t . begins_with ( " { " ) and t . contains ( " \" nodes \" " ) and not t . contains ( " \" tables \" " ) :
return " canvas "
return " json "
## Parses text with the right importer. Same result shape as the importers:
## {ok, collection, errors, warnings, guesses}.
static func parse_import ( text : String , format_key : String ) - > Dictionary :
var sanitize : Callable = Formatter . sanitize_import
var r : Dictionary
match format_key :
" canvas " : r = CanvasIO . import_canvas ( text , sanitize )
" graphml " : r = GraphMLIO . import_graphml ( text , sanitize )
_ : r = JsonIO . import_json ( text , sanitize )
for k in [ " errors " , " warnings " , " guesses " ] :
if not r . has ( k ) :
r [ k ] = [ ]
return r
## Imports text as a NEW collection in the library: sanitized, converted with
## TowerBoard.load_dict and saved under a fresh id. Result: {ok, board, errors,
## warnings, guesses}; board is null on failure. Nothing existing is touched.
static func import_as_collection ( library : LibraryStore , text : String , file_name : String ) - > Dictionary :
var r : = parse_import ( text , detect_format ( file_name , text ) )
var out : = { " ok " : false , " board " : null , " errors " : r [ " errors " ] , " warnings " : r [ " warnings " ] , " guesses " : r [ " guesses " ] }
if not r [ " ok " ] :
return out
var b : = TowerBoard . new ( )
if not b . load_dict ( r [ " collection " ] ) :
( out [ " errors " ] as Array ) . append ( " The file didn ' t contain any tables. " )
return out
if b . name . strip_edges ( ) == " " :
b . name = file_name . get_file ( ) . get_basename ( )
if b . name . strip_edges ( ) == " " :
2026-11-10 18:24:23 -06:00
b . name = " Imported spread "
2026-11-08 12:23:21 -06:00
b . id = library . unique_id ( LibraryStore . slugify ( b . name ) )
if not library . save ( b ) :
2026-11-10 18:24:23 -06:00
( out [ " errors " ] as Array ) . append ( " Couldn ' t save the imported spread. " )
2026-11-08 12:23:21 -06:00
return out
out [ " ok " ] = true
out [ " board " ] = b
return out
## Card-styled report of an import: errors, warnings and guesses.
static func report_dialog ( title : String , result : Dictionary ) - > ModalCard :
var d : = ModalCard . new ( title , 540.0 )
var any : = false
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
for spec in [ [ " errors " , " Problems " , Style . WARN_INK ] , [ " warnings " , " Warnings " , Style . TRIM_DARK ] ,
2026-11-08 12:23:21 -06:00
[ " guesses " , " Guesses made " , Style . INK ] ] :
var items : Array = result . get ( spec [ 0 ] , [ ] )
if items . is_empty ( ) :
continue
any = true
d . body . add_child ( ModalCard . section ( " %s ( %d ) " % [ spec [ 1 ] , items . size ( ) ] ) )
for m in items :
var row : = HBoxContainer . new ( )
row . add_theme_constant_override ( " separation " , 8 )
var dot : = Style . make_label ( " • " , Style . body_bold ( ) , 16 , spec [ 2 ] )
dot . size_flags_vertical = SIZE_SHRINK_BEGIN
row . add_child ( dot )
row . add_child ( ModalCard . note ( str ( m ) , Style . INK ) )
d . body . add_child ( row )
if not any :
d . body . add_child ( ModalCard . note ( " Nothing to report. " ) )
d . add_button ( " Done " , " primary " , d . close )
return d