TableTower/core/book_page.gd
RobinFiredrake 193794a9e0 The Book: reusable results (Pages) to drag onto tables
BookPage (text with BBCode, details, tags, a name) lives in the spread file
under "book"; a result linked to a page (TableEntry.page) follows its
text and details, so one edit reaches every copy. The Book panel (View ▾,
☰ or right-click) lists pages with search over names, text and tags, and
edits the selected page with a live preview. Drag a page onto a result to
link it, or onto a card to add it as a new result. The inspector offers
Save to the Book, or shows the page with Unlink; editing a result's own
text unlinks it; linked rows show a §. Undo covers the Book.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 19:02:46 -06:00

39 lines
1.1 KiB
GDScript

class_name BookPage
extends RefCounted
## A Page in the spread's Book: a reusable result (its text with any BBCode,
## its details tooltip and tags). Results linked to a page (TableEntry.page)
## show its text and details; editing the page updates every linked result
## (TowerBoard.sync_page). Saved in the spread file under "book".
var id: String = ""
## The page's name in the Book's list ("" = its text without formatting).
var name: String = ""
var text: String = ""
var details: String = ""
var tags: Array[String] = []
func label() -> String:
return name if name.strip_edges() != "" else Formatter.strip_tags(text).strip_edges()
func to_dict() -> Dictionary:
var d := {"id": id, "text": text}
if name != "":
d["name"] = name
if details != "":
d["details"] = details
if not tags.is_empty():
d["tags"] = tags.duplicate()
return d
static func from_dict(d: Dictionary) -> BookPage:
var p := BookPage.new()
p.id = str(d.get("id", ""))
p.name = str(d.get("name", ""))
p.text = str(d.get("text", ""))
p.details = str(d.get("details", ""))
for t: Variant in d.get("tags", []):
p.tags.append(str(t))
return p