TableTower/core/sheet_items.gd
RobinFiredrake 317cac7a78 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

60 lines
2.5 KiB
GDScript

class_name SheetItems
extends RefCounted
## Item sheets: a Lore Entry (BookPage) can carry a small sheet of its own,
## e.g. the Ashen Blade with Damage, Charges and Notes (BookPage.sheet holds
## its SheetStore id). Dropped into a sheet box, an entry becomes a row or an
## item; a copy gets its own copy of the item sheet (copy_sheet), a linked one
## (Shift) points at the entry's sheet. The rows' keys: "lore" (a link ref,
## SheetLoreLinks) and "sheet" (a sheet id).
## A new item sheet for `page`, saved in `store`; the page now links to it.
static func make_sheet(store: SheetStore, page: BookPage) -> SheetDoc:
var name := Formatter.strip_tags(page.label()).strip_edges()
var doc := SheetDoc.new("", name if name != "" else "Item")
var boxes: Array = doc.tabs[0]["boxes"]
SheetKinds.place(doc, boxes, SheetKinds.HEADING, doc.name, Rect2i(1, 1, 24, 3)).frameless = true
SheetKinds.place(doc, boxes, SheetKinds.SHORT_TEXT, "Damage", Rect2i(1, 5, 11, 4))
SheetKinds.place(doc, boxes, SheetKinds.NUMBER, "Charges", Rect2i(13, 5, 8, 5))
var notes := SheetKinds.place(doc, boxes, SheetKinds.TEXT, "Notes", Rect2i(1, 11, 24, 8))
notes.value = (page.text + "\n\n" + page.details).strip_edges()
doc.id = store.free_id(doc.name)
store.save(doc)
page.sheet = doc.id
return doc
## Saves a copy of sheet `id` under a new id; returns it ("" when `id` is gone).
static func copy_sheet(store: SheetStore, id: String) -> String:
var doc := store.load_sheet(id) if id != "" else null
if doc == null:
return ""
var copied := doc.copy()
copied.id = store.free_id(doc.name)
store.save(copied)
return copied.id
## The row or item a dropped entry becomes. `fields` holds the box's own
## keys (name, details or size); "lore" and "sheet" are added here.
static func with_links(fields: Dictionary, page: BookPage, ref: String, linked: bool, store: SheetStore) -> Dictionary:
var out := fields.duplicate()
if linked:
out["lore"] = ref
if page.sheet != "":
out["sheet"] = page.sheet
elif page.sheet != "":
var copied := copy_sheet(store, page.sheet)
if copied != "":
out["sheet"] = copied
return out
## The entry's text and details without formatting, for a row's details.
static func plain_text(page: BookPage) -> String:
var parts := PackedStringArray()
for part in [page.text, page.details]:
var plain := Formatter.strip_tags(part).strip_edges()
if plain != "" and plain != Formatter.strip_tags(page.label()).strip_edges():
parts.append(plain)
return "\n\n".join(parts)