2026-11-25 15:36:55 -06:00
extends AppTestBase
2026-11-10 19:02:46 -06:00
## The Book: pages saved from results, linked results following a page's edits,
Sheets phase E: export/import, text toolbar and Lore links, Lore library and items, phone view
- E1: Export ▾ (share file with embedded pictures, print/PDF web page,
PNG of the tab); Import a sheet file from Sheets and New sheet.
- E2: formatting toolbar (FormatMenu) in sheet text boxes; Lore links
([url=lore:ID]) with hover excerpt and the details panel.
- E3: Lore Index in Play and in sheets (shared LoreList); This spread |
My library; item sheets on Lore Entries; drag entries into lists,
slots and notes (copy, Shift keeps linked).
- E4: phone stacked view in phone order, Stacked | Canvas switch, 44 px
touch sizes, bottom panels; sheet CLI flags split out.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 17:25:09 -06:00
## dropping a page onto a result or a card, unlinking, saving and undo; the
## two levels (This spread | My library) and Lore Entries in sheets (items).
2026-11-25 15:36:55 -06:00
## Run: tools/run_tests.sh book
2026-11-10 19:02:46 -06:00
2026-11-25 15:36:55 -06:00
func run ( ) - > void :
2026-11-10 19:53:07 -06:00
if not await start_main ( ) :
2026-11-10 19:02:46 -06:00
return
main . set_mode ( Main . Mode . BUILD )
await _frames ( )
await _test_book ( )
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
_test_pictures ( )
Sheets phase E: export/import, text toolbar and Lore links, Lore library and items, phone view
- E1: Export ▾ (share file with embedded pictures, print/PDF web page,
PNG of the tab); Import a sheet file from Sheets and New sheet.
- E2: formatting toolbar (FormatMenu) in sheet text boxes; Lore links
([url=lore:ID]) with hover excerpt and the details panel.
- E3: Lore Index in Play and in sheets (shared LoreList); This spread |
My library; item sheets on Lore Entries; drag entries into lists,
slots and notes (copy, Shift keeps linked).
- E4: phone stacked view in phone order, Stacked | Canvas switch, 44 px
touch sizes, bottom panels; sheet CLI flags split out.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 17:25:09 -06:00
await _test_levels ( )
await _test_sheet_items ( )
2026-11-10 19:53:07 -06:00
finish ( )
2026-11-10 19:02:46 -06:00
func _test_book ( ) - > void :
var weapons : = main . data . get_table ( " weapons " )
var sword : = weapons . entries [ 1 ]
var p : = main . book . save_result ( weapons , sword )
await _frames ( )
_check ( main . book . visible and sword . page == p . id and p . text == sword . text , " Save to the Book makes a page and links the result " )
main . book . editor . show_page ( p )
p . text = " [b]The Sword of Holy Light[/b] "
p . details = " Glows near the undead. "
main . book . editor . _changed ( )
_check ( sword . text == p . text and sword . details == p . details , " editing the page changes the linked result " )
var loot : = main . data . get_table ( " loot " )
var target : = loot . entries [ 0 ]
await _frames ( 2 )
var row : Control = main . card_for ( " loot " ) . rows [ target . id ]
_check ( main . book . drop_page ( p . id , row . get_global_rect ( ) . get_center ( ) ) , " dropping a page on a result lands " )
_check ( target . page == p . id and target . text == p . text , " and links that result " )
var n : = loot . entries . size ( )
var card : = main . card_for ( " loot " )
main . book . drop_page ( p . id , card . get_global_rect ( ) . position + Vector2 ( 20 , 12 ) )
_check ( loot . entries . size ( ) == n + 1 and loot . entries [ n ] . page == p . id , " dropping on the card ' s header adds a new linked result " )
p . text = " Holy Sword "
main . book . editor . _changed ( )
_check ( target . text == " Holy Sword " and loot . entries [ n ] . text == " Holy Sword " , " one edit reaches every copy " )
_check ( main . data . page_uses ( p . id ) == 3 , " the page counts its uses " )
main . select_result ( " loot " , target . id )
await _frames ( )
main . inspector . set_entry_text ( " A plain sword " )
_check ( target . page == " " , " editing a result ' s own text unlinks it " )
var d : = main . data . to_dict ( )
var back : = TowerBoard . new ( )
back . load_dict ( d )
_check ( back . book . size ( ) == 1 and back . get_page ( p . id ) . text == " Holy Sword " , " the Book is saved in the spread " )
main . book . list . clear ( )
main . book . refresh ( )
main . book . _search . text = " nothing like it "
main . book . refresh ( )
_check ( main . book . list . item_count == 0 , " search filters pages " )
main . book . _search . text = " "
main . undo_redo . _begin_edit ( )
main . data . remove_page ( p . id )
main . mark_dirty ( )
main . undo_redo . _end_edit ( )
_check ( sword . page == " " and main . data . book . is_empty ( ) , " deleting a page leaves its results as plain text " )
main . undo_redo . undo ( )
await _frames ( )
_check ( main . data . book . size ( ) == 1 , " undo brings the page back " )
2026-11-14 14:39:26 -06:00
# Undo of a text edit shows in the open page editor at once.
var page : = main . data . book [ 0 ]
main . book . editor . show_page ( page )
var typed : TextEdit = main . book . editor . find_children ( " * " , " TextEdit " , true , false ) [ 0 ]
typed . text = " Rusty Sword "
typed . text_changed . emit ( )
await _frames ( )
main . undo_redo . undo ( )
await _frames ( )
var shown : Array = main . book . editor . find_children ( " * " , " TextEdit " , true , false ) . map ( func ( edit : TextEdit ) - > String : return edit . text )
_check ( shown . has ( " Holy Sword " ) , " the page editor shows the undone text without reselecting: %s " % str ( shown ) )
2026-11-10 19:02:46 -06:00
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
func _test_pictures ( ) - > void :
var img : = Image . create ( 900 , 600 , false , Image . FORMAT_RGBA8 )
img . fill ( Color . MEDIUM_PURPLE )
var r : = BoardImages . from_image ( img )
_check ( r . has ( " id " ) and not r . has ( " error " ) , " a picture is stored " )
main . data . images [ r [ " id " ] ] = r [ " data " ]
var tex : = main . data . picture ( r [ " id " ] )
_check ( tex != null and maxi ( tex . get_width ( ) , tex . get_height ( ) ) == BoardImages . MAX_SIDE , " and shrunk to %d px " % BoardImages . MAX_SIDE )
main . data . images [ " img_unused " ] = r [ " data " ]
var e : = main . data . get_table ( " weapons " ) . entries [ 0 ]
e . image = r [ " id " ]
var d : = main . data . to_dict ( )
_check ( ( d . get ( " images " , { } ) as Dictionary ) . has ( r [ " id " ] ) and not ( d [ " images " ] as Dictionary ) . has ( " img_unused " ) , " only used pictures are saved " )
var back : = TowerBoard . new ( )
back . load_dict ( d )
_check ( back . picture ( back . get_table ( " weapons " ) . entries [ 0 ] . image ) != null , " pictures load with the spread " )
var p : = main . data . add_page ( " Pic page " )
p . image = r [ " id " ]
var e2 : = main . data . get_table ( " weapons " ) . entries [ 2 ]
main . data . link_page ( e2 , p . id )
_check ( e2 . image == r [ " id " ] , " a page ' s picture comes with it " )
# Everything new survives an export and import of the spread file.
var t : = main . data . get_table ( " weapons " )
t . color = " #2f8a4f "
t . width = 300
t . roll_floor = " 2 "
e2 . cost_value = " @gold "
e2 . cost_amount = " 3 "
e2 . add_pipe ( " loot " )
e2 . pipe_combine [ " loot " ] = " max "
e2 . pipe_pause [ " loot " ] = true
e2 . pipe_color [ " loot " ] = " #c04a86 "
var g : = main . data . add_group ( " Outer " , [ ] )
var g2 : = main . data . add_group ( " Inner " , [ ] )
g2 . parent = g . id
var canon : = JsonIO . canonical ( JSON . parse_string ( JSON . stringify ( main . data . to_dict ( ) ) ) )
var b2 : = TowerBoard . new ( )
b2 . load_dict ( canon )
var t2 : = b2 . get_table ( " weapons " )
var e3 : = t2 . entries [ 2 ]
_check ( t2 . color == " #2f8a4f " and t2 . width == 300.0 and t2 . roll_floor == " 2 " , " card colour, size and limits import " )
_check ( e3 . page == p . id and e3 . image == r [ " id " ] and e3 . cost_amount == " 3 " , " page links, pictures and costs import " )
_check ( e3 . combine_for ( " loot " ) == " max " and e3 . pipe_pause . has ( " loot " ) and e3 . pipe_color . get ( " loot " ) == " #c04a86 " , " thread options import " )
_check ( b2 . get_group ( g2 . id ) . parent == g . id and b2 . book . size ( ) == main . data . book . size ( ) and b2 . images . has ( r [ " id " ] ) , " nesting, the Book and pictures import " )
Sheets phase E: export/import, text toolbar and Lore links, Lore library and items, phone view
- E1: Export ▾ (share file with embedded pictures, print/PDF web page,
PNG of the tab); Import a sheet file from Sheets and New sheet.
- E2: formatting toolbar (FormatMenu) in sheet text boxes; Lore links
([url=lore:ID]) with hover excerpt and the details panel.
- E3: Lore Index in Play and in sheets (shared LoreList); This spread |
My library; item sheets on Lore Entries; drag entries into lists,
slots and notes (copy, Shift keeps linked).
- E4: phone stacked view in phone order, Stacked | Canvas switch, 44 px
touch sizes, bottom panels; sheet CLI flags split out.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 17:25:09 -06:00
## My library beside This spread: new entries go to the level shown, Copy to
## moves a copy across, and a library entry dropped on a card is copied in.
func _test_levels ( ) - > void :
var lore : = main . book . lore
var library : = SheetLoreLinks . library ( main )
var before : = library . pages . size ( )
lore . set_level ( LoreLevel . LIBRARY )
var shared : = lore . new_page ( )
_eq ( library . pages . size ( ) , before + 1 , " + Lore Entry in My library adds it there " )
_eq ( lore . list . item_count , library . pages . size ( ) , " the list shows My library " )
lore . set_level ( LoreLevel . SPREAD )
_eq ( lore . list . item_count , main . data . book . size ( ) , " This spread shows the spread ' s entries again " )
var spread_count : = main . data . book . size ( )
var copied : = LoreEntryActions . copy_to ( lore , shared , lore . levels [ LoreLevel . SPREAD ] )
_check ( main . data . book . size ( ) == spread_count + 1 and copied . id != shared . id , " Copy to This spread adds a copy " )
_check ( SheetLoreLinks . find ( main , " lib: " + shared . id ) == shared and SheetLoreLinks . find ( main , copied . id ) == copied , " links name their level: lore:lib:ID or lore:ID " )
await _frames ( )
var card : = main . card_for ( " loot " )
_check ( main . book . drop_page ( shared . id , card . get_global_rect ( ) . position + Vector2 ( 20 , 12 ) , lore . levels [ LoreLevel . LIBRARY ] ) , " a My library entry drops onto a card " )
_eq ( main . data . book . size ( ) , spread_count + 2 , " and is copied into the spread first " )
library . remove_page ( shared . id )
## The Lore Index in a sheet: an entry with an item sheet dropped on a Slots
## box (a copy with its own sheet) and on a list box with Shift (linked), one
## undo step each; its sheet opens with a way back.
func _test_sheet_items ( ) - > void :
var sheets : = main . screens . sheets
var doc : = SheetDemo . create ( " lore-items " )
sheets . store . save ( doc )
main . screens . show ( MainScreens . SHEETS )
sheets . open_doc ( doc )
var ed : = sheets . editor
ed . set_mode ( Main . Mode . PLAY )
ed . set_lore_shown ( true )
_check ( ed . lore_dock . visible and not ed . inspector . visible , " Play: the Lore Index opens beside the sheet " )
var level : LoreLevel = ed . lore_dock . lore . levels [ LoreLevel . LIBRARY ]
var blade : = level . add_page ( " Ashen Blade " , " Burns what it cuts. " )
LoreEntryActions . open_or_make_sheet ( ed . lore_dock . lore , blade )
_check ( blade . sheet != " " and ed . doc . id == blade . sheet , " Make a sheet for this entry opens its new sheet " )
_eq ( ed . top_bar . back_button . text , " ← Brin Hollowmere " , " with a way back " )
ed . nav . back ( )
_eq ( ed . doc . id , doc . id , " back returns to the character " )
await _frames ( )
var inventory : = MainCliSheets . box_titled ( ed . doc , " Inventory " )
var at : Vector2 = ed . canvas . views [ inventory . id ] . get_global_rect ( ) . get_center ( )
_check ( SheetLoreDrop . drop ( ed , blade , level , at , false ) , " an entry drops onto a Slots box " )
var item : Dictionary = ( MainCliSheets . box_titled ( ed . doc , " Inventory " ) . value as Array ) . back ( )
_check ( item [ " name " ] == " Ashen Blade " and str ( item . get ( " sheet " , " " ) ) not in [ " " , blade . sheet ] and not item . has ( " lore " ) , " as an item with its own copy of the sheet " )
await _frames ( )
var talents : = MainCliSheets . box_titled ( ed . doc , " Talents " )
var rows : = ( talents . value as Array ) . size ( )
SheetLoreDrop . drop ( ed , blade , level , ed . canvas . views [ talents . id ] . get_global_rect ( ) . get_center ( ) , true )
var row : Dictionary = ( MainCliSheets . box_titled ( ed . doc , " Talents " ) . value as Array ) . back ( )
_check ( row [ " Name " ] == " Ashen Blade " and row [ " details " ] == " Burns what it cuts. " and row [ " lore " ] == " lib: " + blade . id and row [ " sheet " ] == blade . sheet , " Shift: a list row stays linked " )
_check ( ed . canvas . views [ talents . id ] . find_child ( " LoreMark " , true , false ) != null , " and shows § " )
ed . undo ( )
_eq ( ( MainCliSheets . box_titled ( ed . doc , " Talents " ) . value as Array ) . size ( ) , rows , " undo takes the row out again " )
ed . set_lore_shown ( false )
level . remove_page ( blade . id )
sheets . show_list ( )
main . screens . show ( MainScreens . SPREAD )