TableTower/ui/sheet_lore_drop.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

56 lines
2.5 KiB
GDScript

class_name SheetLoreDrop
extends RefCounted
## A Lore Entry dropped on a sheet box (from SheetLoreDock), as one undo step:
## onto a list box it adds a row (the entry's name, its text as "details");
## onto a Slots box an item; onto a Long notes box a link (SheetLoreLinks).
## A drop copies: its item sheet is copied too (SheetItems). With Shift held
## the row stays linked: "lore" holds the link ref and "sheet" the entry's
## own sheet. Linked rows show § (SheetFieldsList.link_mark).
const TAKES := [SheetKinds.LIST, SheetKinds.SLOTS, SheetKinds.TEXT]
## Drops `page` at screen point `at`. True when a box took it.
static func drop(ed: SheetEditor, page: BookPage, level: LoreLevel, at: Vector2, linked: bool) -> bool:
var box := box_at(ed, at)
if box == null:
return false
if not box.kind in TAKES:
ed.m.toast("Drop a Lore Entry on a list, Slots or Long notes box")
return false
add(ed, box, page, level.ref(page), linked)
return true
## The box whose view is under screen point `at`, or null.
static func box_at(ed: SheetEditor, at: Vector2) -> SheetBox:
for view: SheetBoxView in ed.canvas.views.values():
if is_instance_valid(view) and view.is_visible_in_tree() and view.get_global_rect().has_point(at):
return view.box
return null
## Adds `page` to `box` (a list, Slots or Long notes box) as one undo step.
static func add(ed: SheetEditor, box: SheetBox, page: BookPage, link_ref: String, linked: bool) -> void:
var name := Formatter.strip_tags(page.label()).strip_edges()
var value: Variant
match box.kind:
SheetKinds.TEXT:
var text := str(box.value if box.value != null else "")
value = text + (" " if text != "" and not text.ends_with("\n") else "") + SheetLoreLinks.tag_for(link_ref) + SheetLoreLinks.shown_name(page) + "[/url]"
SheetKinds.SLOTS:
value = SheetFieldsList.entries(box)
value.append(SheetItems.with_links({"name": name, "size": 1}, page, link_ref, linked, ed.screen.store))
_:
var row := {}
var cols := SheetFieldsList.columns(box)
for col: Dictionary in cols:
row[col["name"]] = 0 if col.get("type", "text") == "number" else ""
row[str(cols[0]["name"])] = name
var details := SheetItems.plain_text(page)
if details != "":
row["details"] = details
value = SheetFieldsList.entries(box)
value.append(SheetItems.with_links(row, page, link_ref, linked, ed.screen.store))
ed.set_value(box, value)
ed.m.toast("Added “%s” to %s%s" % [name, box.title if box.title != "" else "the box", " (linked)" if linked else ""])