TableTower/docs/SHEETS.md
RobinFiredrake 160848f881 Sheet canvas: page starts at the left edge so boxes can go left; docs
The page was placed in the middle of the canvas, so boxes could not be
dragged left of it. Design doc: Sheets status, open items, review list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 17:37:39 -06:00

14 KiB
Raw Blame History

Sheets and the unified editor: spec and plan

Agreed with the user 2026-11-29. Mockup canvas (design only, not code): https://claude.ai/code/artifact/4311ebce-47e0-479c-bc1b-40800339b50b

1. Goal

A sheet builder for any TTRPG: odd OSR stats, point buy, a vehicle with only description boxes. Sheets can be used on their own or as a node in a spread, and tables can read and write them. The new Sheets replace today's Sheet card kind (RollTable.KIND_SHEET, a BBCode template): an old sheet card becomes a sheet with one text box.

2. Decisions

  • Main menu: Spreads / Sheets / Settings / Quit, titles only (no descriptions). Room for more.
  • Sheets standalone or in a spread. On a spread the node shows a preview of the sheet's first tab. Double-click opens it in an in-app tab (view only in Play).
  • Layout: free placement with a snap grid; Alt places freely. A sheet has tabs, each its own canvas. One Play/Build toggle; in a spread, the spread's toggle.
  • Multi-entry boxes ("repeating section" elsewhere): each box picks rows, mini table or chips.
  • Point pools: may go negative, shown red. Reuse the result cost {value, amount} variable.
  • Details: hover tooltip (short, cut with "…"); click opens an in-app side panel.
  • Field types: number, text, notes, checkbox, dropdown; current/max bars, tick rows, clocks; computed fields, dice buttons; image, heading, divider; dots, step dice, usage dice, ladders; slot inventory with encumbrance; tag/condition chips, aspects, bonds; spell slots, XP, currency.
  • Tables ↔ sheets: tables write and read fields. A field gets an @variable only when "Use in tables" is on. Each field has a lock: locked fields ignore roll writes. Later: a sheet event triggers a table roll (fumble → critical-failure table).
  • Templates and one-off sheets. New sheet = blank canvas or one of your templates.
  • Look: app theme, plus per-box colour and per-sheet tint; frameless boxes.
  • Text: all BBCode, buttons for common tags, live {@var}, links to Lore Entries.
  • Lore Index: opens in Play and Build, in spreads and sheets. Holds sheet entries and whole sheets as items (a rolled sword → a character's inventory). Gains a shared "My library" level beside "This spread". Drop copies; Shift keeps it linked.
  • Undo/redo for values and layout. Export: share file, PDF/print, PNG.
  • Phone: Play stacks boxes full width in reading order (top-down, then left-right), with a manual "Phone order" per box; a Canvas switch shows the real layout with pan/zoom.

3. Unified editor (spreads and sheets look alike)

  • Card palette replaces "+ Card ▾": a left dock with tabs Cards | List. Cards has a search box at the top, grouped kinds, templates as a group; drag onto the spread (click adds at the view centre). Roll table, Dice table and Deck are separate items (same kind, different start settings). Right-click › New card stays.
  • Play mode: the Cards tab stays, greyed, with "Cards are added in Build mode" and a Switch to Build button. This replaces the greyed "+ Card" button.
  • Right dock: Inspector | Lore Index (as today), same tab style as the left dock.
  • Top bar: "Board ▾" is renamed "Spread ▾". Later one shared top bar for spreads and sheets.
  • Open documents as tabs (needed for sheets opened from a spread node).
  • Sheet editor uses the same palette (with search) for fields.

4. Phases

  • A. Card palette — done 2026-11-29 (commit 16b34c4 on card-palette): left dock Cards | List, search, drag/click to add, Play-mode notice, remove "+ Card ▾", rename Board ▾ → Spread ▾. Phone: "+" opens a searchable list.
  • B. Sheets core — base built 2026-11-29 (branch sheets): main menu, Sheets list, New sheet dialog, sheet editor with tabs, snap canvas (Alt = free), field palette (shared PaletteList), inspector, Play/Build, snapshot undo, saving. Kinds so far: Number, Text box, Heading. Theme changes keep the screen (MainScreens.resume). Was planned as: data model + storage (sheets and templates), main menu, Sheets list, New sheet dialog, sheet editor (tabs, snap canvas, palette, inspector, Play/Build, undo).
  • C. Field types — built 2026-11-29 (branch sheets): every kind in §2 (SheetKinds.ITEMS, 25 palette items over 23 kinds). Values for formulas/dice/live text: core/sheet_values.gd (rule language with sheet @names; loops are errors). Views: ui/sheet_field_views.gd (basics, dispatch), sheet_fields_trackers/smart/list/niche.gd; settings: ui/sheet_kind_settings.gd; details side panel: ui/sheet_detail_panel.gd. Pictures are copied to sheets/pictures/. Not yet: per-entry variables in lists (phase D), BBCode buttons and Lore links in text (done in E2).
  • D. Sheets on spreads — built 2026-11-29: a sheet on a spread is a Sheet card linked to a sheet file (RollTable.sheet_id, sheet_prefix; JSON sheet, prefix), so threads, groups, undo, List view and the tray headline work as for any card. The card shows SheetPreview (first tab, values, gold outline on boxes the last roll changed; double-click / "Open sheet" opens it with "← spread"; the sheet editor then uses the spread's Play/Build). A roll reaching the card rolls SheetText.summary (boxes as "Title: value", linked ones as {@prefix_name}) through Roller.sheet_text. Bridge core/sheet_links.gd + ui/main_sheet_links.gd: before a roll "Use in tables" boxes become @name / @prefix_name; after it changed values go back unless locked or not writable. Text boxes on a sheet that is on the open spread also show spread values ({@answer}). Migration: an old template Sheet card gets a sheet file (id <spread>-<card>, one text box with its template) when the spread loads or the card arrives (not inside Help demos). The user's picks: prefix per card (blank allowed; the second sheet gets one from its name), only "Use in tables" boxes. Card palette › Sheets: "New sheet" + your sheets. Sheet canvas: grid is one tiled texture (smooth panning); boxes don't overlap (new ones take the nearest free spot, drags stop short; Alt = free).
  • E. Lore Index library + items, export (PDF, PNG, share file), phone stacked view.
    • E1. Export and import — built 2026-11-29: sheet top bar Export ▾ (Play and Build): "Share file…" (*.sheet.json: {"tabletarot_sheet": 1, "sheet", "pictures"}, picture boxes' files inside as base64; no template link), "Print / PDF (web page)…" (Godot has no PDF writer: an HTML page, one <section> per tab printed on its own page, boxes as "Title: value" lines from SheetText.tab_text with values, through the tray's SheetExport.to_html), "Image (PNG)…" (the window's pixels under the canvas: this tab as you see it). Import… on the Sheets list and "Import a sheet file…" in the New sheet dialog: a new id, pictures written to sheets/pictures/, saved and opened (from the card palette: placed on the spread).
    • E2. Text tools and Lore links — built 2026-11-29: editing a Long notes box (Play) shows SheetTextToolbar above it: B I U S, Colour ▾ / Size ▾ / Effect ▾ (the tags of FormatMenu, which the TextEdit also gets as its right-click menu), {@} ▾ (the sheet's @names as live values) and "§ Link…" (Link a Lore Entry…, LoreLinkPicker with search). Link syntax: plain BBCode [url=lore:ENTRY_ID]words[/url] (no selection: the entry's name is added). RichText.decorate draws it in REF_INK on REF_BG; hover (DetailsPopup "lore:") shows the name and an excerpt cut with "…"; a click opens it in the side panel (SheetDetailPanel.open_lore, read only). "lore:" is an internal meta (Copy as BBCode drops the link, keeps the words). Which Lore Index: the open spread's, even for a sheet not on a spread; the one lookup is SheetLoreLinks.entries (E3 adds "My library" there).
    • E3. Lore Index everywhere, My library, sheet items — built 2026-11-29: the Lore Index panel is LoreList (title, + Lore Entry, ×, This spread | My library tabs, search, list, PageEditor), shown by BookPanel (spread, Play and Build) and SheetLoreDock (sheet editor: the inspector's Lore tab in Build, top bar Lore Index toggle in both modes). Levels are LoreLevel objects (SpreadLoreLevel: spread undo, sync_page; LibraryLoreLevel: saved at once, no undo). My library is LoreLibrary, <store root>/lore_library.json ({"book": [BookPage dicts]}; user:// when saving, the sheets' scratch folder otherwise). Link refs: lore:ID = this spread, lore:lib:ID = My library (SheetLoreLinks.ref/find). Under an entry: "Copy to My library / This spread" (a new id; its item sheet copied; pictures only stay in the spread) and "Make a sheet for this entry" / "Open its sheet": BookPage.sheet (JSON sheet, a SheetStore id) → SheetItems.make_sheet (Heading, Damage, Charges, Notes). A library entry dropped on a spread card is copied into the spread first. Drops into a sheet (SheetLoreDrop, one set_value undo step): list box → a row (first column = name, details = plain text), Slots → an item {name, size: 1}, Long notes → a link appended. A drop copies (the item sheet too, SheetItems.copy_sheet); Shift links: lore = ref and sheet = the entry's own sheet. Marks: § before a linked row/item, ▤ opens a row's sheet (Slots: the item's menu); ⓘ on such a row has "Read the Lore Entry" / "Open its sheet". Opening a sheet from a sheet uses SheetItemNav ("← previous sheet", then back to the spread). A linked row keeps its own copy of the text (it doesn't follow later edits of the entry); deleting an entry leaves its item sheet in Sheets.
    • E4. Phones and tablets — built 2026-11-29: in the phone layout (MobileLayout, also --mobile) the sheet editor uses SheetPhoneLayout. Play shows the stacked view (SheetStackView): the open tab's boxes in one full-width column, each the same SheetBoxView at its own height or taller if its content needs it. Phone order rule (SheetStackView.order_of): boxes with a Phone order number (> 0) come first, smallest first; then the automatic ones (0) in reading order (y, then x); equal numbers also fall back to reading order. Touch size: while the stack builds a box, SheetFieldViews.touch is on and tap_size grows step buttons, ticks, dots and slot cells to 44 px (no second set of views). A bottom bar replaces the status strip: Undo, Stacked | Canvas (Play; Canvas is the real layout, drag to pan, no pinch zoom yet), and "+ Field" (Build, which always uses the canvas) that opens the field palette full screen; a pick goes back to the canvas. The inspector (only while a box is selected), the Lore Index and the details panel open as bottom panels. The top bar drops the brand words, hint, Lore Index and Export ▾ (both move into ☰). Not done: narrow desktop windows keep the desktop layout; a stats list in Rows style stays rows (no big tiles); Lore drops onto stacked boxes don't land.

5. Code map (phase B)

  • Data: core/sheet_doc.gd (tabs of boxes), core/sheet_box.gd, core/sheet_kinds.gd (the kinds list, grid step, make_box), core/sheet_store.gd (user://sheets, user://sheet_templates; a scratch folder when not saving), core/snapshot_history.gd, core/sheet_demo.gd.
  • Screens: ui/main_screens.gd (menu / spread / sheets; start screen; resume after a theme change), ui/main_menu.gd, ui/sheets_screen.gd, ui/new_sheet_dialog.gd.
  • Editor: ui/sheet_editor.gd (mode, tab, selection, edit/undo/save), ui/sheet_top_bar.gd, ui/sheet_tabs_bar.gd, ui/sheet_canvas.gd, ui/sheet_box_view.gd, ui/sheet_field_views.gd, ui/sheet_inspector.gd, ui/field_palette.gd; ui/palette_list.gd is shared with the card palette.
  • Look (2026-11-29, matched to the mockup): ui/menu_icons.gd (drawn icons), MainTopBar.make_brand (shared brand), SheetBoxView.look (tinted card, band, border), canvas and menu draw the theme's spread background (BoardBackdrop). Sheets in Play keep the greyed palette (user's rule).
  • Keys: MainLayout._shortcut_input sends keys to the screen that shows.
  • Export/import (E1): core/sheet_file.gd (share file), ui/sheet_export_menu.gd (Export ▾, PNG capture), SheetExport.sheet_html, SheetStore.keep_picture_bytes, SheetsScreen.import_sheet.
  • Text tools and Lore links (E2): ui/sheet_text_box.gd (the Long notes view), ui/sheet_text_toolbar.gd, ui/sheet_lore_links.gd (lookup, excerpt, hover), ui/lore_link_picker.gd; FormatMenu.colours/selection.
  • Lore Index everywhere (E3): ui/lore_list.gd, ui/lore_level*.gd, core/lore_library.gd, ui/lore_entry_actions.gd, ui/sheet_lore_dock.gd, ui/sheet_lore_drop.gd, ui/sheet_item_nav.gd, core/sheet_items.gd; SheetKinds.place (a box on the grid; SheetDemo uses it too).
  • Phones (E4): ui/sheet_phone_layout.gd (bottom bar, bottom panels, full-screen palette), ui/sheet_stack_view.gd (stacked view, order_of); SheetFieldViews.touch/tap_size. Suite: test_mobile.
  • CLI (ui/main_cli_sheets.gd): --menu, --sheets, --sheet-demo (+ --sheet-build, --sheet-lore (a linked Lore Entry in the panel), --sheet-edit=TITLE (that text box open with its toolbar), --sheet-lore-index (the Lore Index beside it, with a My library item dropped in)), --new-sheet. Suites: test_sheets, test_sheet_editor.

6. Review list (decisions made during phase E, for the user)

  • My library has no undo (saved at once); copying an entry into it drops its picture.
  • A linked list row keeps its own copy of the entry's text; deleting an entry leaves its item sheet.
  • A Lore drop on notes appends the link (not at the cursor); the print page leaves out pictures; no "import as template".
  • Phones: no pinch zoom on the sheet canvas; Rows-style stats stay rows (no big tiles); no Lore drops onto stacked boxes; narrow desktop windows keep the desktop layout.
  • Sheet canvas (2026-11-29 fix): the page starts at the left edge, not centred, so boxes can be dragged anywhere, left included.