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 ""])