class_name LoreLevel extends RefCounted ## One level of the Lore Index, as the Lore Index panels (LoreList, ## PageEditor) see it: "This spread" (SpreadLoreLevel) or the shared ## "My library" (LibraryLoreLevel). The panels call these and never touch ## the spread or the library file themselves. const SPREAD := "spread" const LIBRARY := "library" var m: Main ## SPREAD or LIBRARY. var key := SPREAD func _init(p_main: Main) -> void: m = p_main ## The level's name on its tab and in buttons. func title() -> String: return "This spread" func pages() -> Array[BookPage]: return [] func get_page(_id: String) -> BookPage: return null ## Runs `change` as one step (one undo step for the spread) and keeps it. func edit(change: Callable) -> void: change.call() ## After the page editor changed `page`: keep it and update what shows it. func changed(_page: BookPage) -> void: pass ## A new entry in this level, as one step. func add_page(text: String, details: String = "") -> BookPage: # Lambdas copy local variables, so the result comes back in an Array. var made: Array[BookPage] = [] edit(func() -> void: made.append(_add_raw(text, details))) return made[0] ## Adds an entry without making a step (add_page and add_copy wrap it). func _add_raw(_text: String, _details: String) -> BookPage: return null func remove_page(_id: String) -> void: pass ## Goes up when the entries change, so an open list knows to refresh. func revision() -> int: return 0 ## The line under the editor: where the entry is used. func uses_note(_page: BookPage) -> String: return "" ## What a sheet link to `page` holds after "lore:" (SheetLoreLinks). func ref(page: BookPage) -> String: return page.id ## Adds a copy of `page` (from another level) here and returns it. Its item ## sheet is copied too, so the two don't share one. Pictures belong to a ## spread, so only a copy into the spread keeps one. func add_copy(page: BookPage) -> BookPage: var made: Array[BookPage] = [] edit(func() -> void: made.append(copy_raw(page))) return made[0] ## add_copy without making a step, for a caller that already has one open. func copy_raw(page: BookPage) -> BookPage: var added := _add_raw(page.text, page.details) added.name = page.name added.tags = page.tags.duplicate() added.image = page.image if key == SPREAD else "" added.sheet = SheetItems.copy_sheet(m.screens.sheets.store, page.sheet) return added