TableTower/core/book_page.gd
RobinFiredrake 57041d41b3 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

44 lines
1.2 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] = []
## A picture (BoardImages id). "" = none.
var image: 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()
if image != "":
d["image"] = image
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", ""))
p.image = str(d.get("image", ""))
for t: Variant in d.get("tags", []):
p.tags.append(str(t))
return p