Spread folders (Move to folder…, submenus), useful switcher tooltip, clearer export names

A spread can be listed under a folder (saved in its file, kept by copies);
the switcher shows each folder as a submenu. The switcher's tooltip now
gives the card count, folder and what it does. Export menu: "Table Tarot
JSON… (full copy)" and "Export as a diagram (cards and threads only)".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
RobinFiredrake 2026-11-14 14:35:35 -06:00
parent bd077ebadc
commit 0ec50cc1fc
9 changed files with 85 additions and 17 deletions

View file

@ -66,7 +66,7 @@ func list() -> Array[Dictionary]:
continue continue
var b := load_collection(id) var b := load_collection(id)
if b: if b:
out.append({"id": id, "name": b.name}) out.append({"id": id, "name": b.name, "folder": b.folder})
out.sort_custom(func(a: Dictionary, b: Dictionary) -> bool: out.sort_custom(func(a: Dictionary, b: Dictionary) -> bool:
return str(a["name"]).naturalnocasecmp_to(str(b["name"])) < 0) return str(a["name"]).naturalnocasecmp_to(str(b["name"])) < 0)
return out return out

View file

@ -13,6 +13,8 @@ static var _salt: String = ""
var id: String = "" var id: String = ""
## Display name; free to change. ## Display name; free to change.
var name: String = "" var name: String = ""
## The folder it's listed under in the spread switcher ("" = none).
var folder: String = ""
var tables: Array[RollTable] = [] var tables: Array[RollTable] = []
## Group cards (frames around blocks of tables). Optional; a table is in at ## Group cards (frames around blocks of tables). Optional; a table is in at
## most one group. See TableGroup. ## most one group. See TableGroup.
@ -201,6 +203,8 @@ func to_dict() -> Dictionary:
for t in tables: for t in tables:
list.append(t.to_dict()) list.append(t.to_dict())
var d := {"format_version": FORMAT_VERSION, "id": id, "name": name, "tables": list} var d := {"format_version": FORMAT_VERSION, "id": id, "name": name, "tables": list}
if folder != "":
d["folder"] = folder
if not groups.is_empty(): if not groups.is_empty():
var gl: Array = [] var gl: Array = []
for g in groups: for g in groups:
@ -253,6 +257,8 @@ func load_dict(src: Dictionary) -> bool:
id = str(d["id"]) id = str(d["id"])
if str(d.get("name", "")) != "": if str(d.get("name", "")) != "":
name = str(d["name"]) name = str(d["name"])
if d.has("folder"):
folder = str(d["folder"]).strip_edges()
return true return true

View file

@ -261,11 +261,12 @@ A result or a Book page can have a picture: [b]Picture → Choose…[/b] in its
- View, Help and Play/Build are in the [b]☰[/b] menu. - View, Help and Play/Build are in the [b]☰[/b] menu.
# Spreads, import and export # Spreads, import and export
A [b]spread[/b] is one layout of cards, saved under its own name. Use the switcher beside Play | Build (it shows the spread's name) to switch, or to make a new spread, rename, duplicate or delete one. A [b]spread[/b] is one layout of cards, saved under its own name. Use the switcher beside Play | Build (it shows the spread's name) to switch, or to make a new spread, rename, duplicate, delete one, or [b]Move to folder…[/b] to sort spreads into folders (the switcher lists each folder as a submenu).
In Build mode, [b]Spread ▾[/b] has: In Build mode, [b]Spread ▾[/b] has:
- [b]Import as new spread…[/b] for Table Tarot JSON, JSON Canvas and GraphML files. - [b]Import as new spread…[/b] for Table Tarot JSON, JSON Canvas and GraphML files.
- [b]Export as…[/b] Table Tarot JSON, JSON Canvas, GraphML, a Mermaid diagram or Graphviz DOT. - [b]Export as Table Tarot JSON… (full copy)[/b]: everything on the spread, to import again or share.
- [b]Export as a diagram[/b]: JSON Canvas, GraphML, a Mermaid diagram or Graphviz DOT, for diagram and mind-map tools. These hold cards and threads only; importing one back is not a full copy.
Exports hold the tables only. Your roll history, decks and remembered values stay on this computer. Exports hold the tables only. Your roll history, decks and remembered values stay on this computer.

View file

@ -15,6 +15,8 @@ static func canonical(src: Dictionary) -> Dictionary:
tables.append(_canon_table(t)) tables.append(_canon_table(t))
var cname := str(src.get("name", src.get("collection", ""))) var cname := str(src.get("name", src.get("collection", "")))
var out := {"format_version": JsonIO.FORMAT_VERSION, "id": str(src.get("id", "")), "name": cname, "tables": tables} var out := {"format_version": JsonIO.FORMAT_VERSION, "id": str(src.get("id", "")), "name": cname, "tables": tables}
if str(src.get("folder", "")).strip_edges() != "":
out["folder"] = str(src["folder"]).strip_edges()
var groups: Array = [] var groups: Array = []
var src_groups: Variant = src.get("groups", []) var src_groups: Variant = src.get("groups", [])
if src_groups is Array: if src_groups is Array:
@ -129,7 +131,7 @@ static func _canon_table(td: Dictionary) -> Dictionary:
for e in src_entries: for e in src_entries:
entries.append(_canon_entry(e)) entries.append(_canon_entry(e))
t["entries"] = entries t["entries"] = entries
_keep(td, t, ["color", "w", "list_h", "roll_floor", "roll_ceiling", "deck_empty_text", "columns", "column_rolls", "steps", "members", "repeats"]) _keep(td, t, ["color", "w", "list_h", "roll_floor", "roll_ceiling", "deck_empty_text", "columns", "column_rolls", "steps", "members", "repeats", "cost"])
# A separator may be just a space, so it isn't trimmed. # A separator may be just a space, so it isn't trimmed.
if td.get("column_join") is String and td["column_join"] != "": if td.get("column_join") is String and td["column_join"] != "":
t["column_join"] = td["column_join"] t["column_join"] = td["column_join"]

View file

@ -1,7 +1,7 @@
extends TestBase extends TestBase
## Small UI items: backwards ranges warn and block rolling (no auto-swap), the ## Small UI items: backwards ranges warn and block rolling (no auto-swap), the
## inspector's thread lists, replacing a template, the tray chip's bold source ## inspector's thread lists, replacing a template, the tray chip's bold source
## name, and the export menu's Other formats. ## name, and the export menu's diagram formats.
## Run: godot --headless --path . -s res://tests/test_small_ui.gd -- --sample ## Run: godot --headless --path . -s res://tests/test_small_ui.gd -- --sample
@ -81,7 +81,7 @@ func _test_chip_and_export() -> void:
_check(bold, "the chip names its card in bold") _check(bold, "the chip names its card in bold")
var pm := main.top_bar._board_menu.get_popup() var pm := main.top_bar._board_menu.get_popup()
var subs := pm.find_children("*", "PopupMenu", false, false) var subs := pm.find_children("*", "PopupMenu", false, false)
_check(subs.size() == 1 and (subs[0] as PopupMenu).item_count == IoMenu.EXPORTS.size() - 1, "rare formats sit under Other formats") _check(subs.size() == 1 and (subs[0] as PopupMenu).item_count == IoMenu.EXPORTS.size() - 1, "diagram formats sit under Export as a diagram")
## Deck mode: drawn results fade, an empty deck that waits for Shuffle gives ## Deck mode: drawn results fade, an empty deck that waits for Shuffle gives

View file

@ -55,8 +55,15 @@ func _test_library() -> void:
_check(lib.rename("fantasy-loot", "Dark Loot"), "rename succeeds") _check(lib.rename("fantasy-loot", "Dark Loot"), "rename succeeds")
_check(lib.load_collection("fantasy-loot").name == "Dark Loot", "rename keeps id, changes name") _check(lib.load_collection("fantasy-loot").name == "Dark Loot", "rename keeps id, changes name")
var dark := lib.load_collection("fantasy-loot")
CollectionSwitcher.set_folder(lib, dark, " Campaign ")
_eq(lib.load_collection("fantasy-loot").folder, "Campaign", "a spread can be put in a folder (saved, trimmed)")
_check(lib.list().any(func(entry: Dictionary) -> bool: return entry["folder"] == "Campaign"), "the library lists its folder")
var copy := lib.duplicate("fantasy-loot", "Dark Loot Copy") var copy := lib.duplicate("fantasy-loot", "Dark Loot Copy")
_check(copy != null and copy.id == "dark-loot-copy" and copy.tables.size() == a.tables.size(), "duplicate copies tables") _check(copy != null and copy.id == "dark-loot-copy" and copy.tables.size() == a.tables.size(), "duplicate copies tables")
_eq(copy.folder, "Campaign", "a copy stays in the same folder")
CollectionSwitcher.set_folder(lib, copy, "")
_eq(lib.load_collection("dark-loot-copy").folder, "", "an empty folder takes it out again")
var names: Array = [] var names: Array = []
for e in lib.list(): for e in lib.list():
names.append(e["name"]) names.append(e["name"])

View file

@ -1,7 +1,8 @@
class_name CollectionSwitcher class_name CollectionSwitcher
extends MenuButton extends MenuButton
## Top-bar dropdown that names the current collection and offers switching, ## Top-bar dropdown that names the current collection and offers switching,
## New, Rename, Duplicate and Delete. The storage rules are static functions ## New, Rename, Duplicate, Move to folder and Delete. Spreads in a folder are
## listed in that folder's submenu. The storage rules are static functions
## (create_collection and friends) so tests can run them on a temporary ## (create_collection and friends) so tests can run them on a temporary
## LibraryStore; Main does the UI side (rebuilding cards, dialogs). ## LibraryStore; Main does the UI side (rebuilding cards, dialogs).
@ -9,6 +10,7 @@ const ID_NEW := 1000
const ID_RENAME := 1001 const ID_RENAME := 1001
const ID_DUPLICATE := 1002 const ID_DUPLICATE := 1002
const ID_DELETE := 1003 const ID_DELETE := 1003
const ID_FOLDER := 1004
const MAX_LABEL := 22 const MAX_LABEL := 22
var main: Main var main: Main
@ -30,7 +32,8 @@ func setup(p_main: Main) -> void:
func refresh() -> void: func refresh() -> void:
var n := main.data.name if main.data.name != "" else "Untitled" var n := main.data.name if main.data.name != "" else "Untitled"
text = "%s ▾" % (n if n.length() <= MAX_LABEL else n.substr(0, MAX_LABEL - 1) + "…") text = "%s ▾" % (n if n.length() <= MAX_LABEL else n.substr(0, MAX_LABEL - 1) + "…")
tooltip_text = "Spread: %s" % n var where := " (in %s)" % main.data.folder if main.data.folder != "" else ""
tooltip_text = "%s%s · %d cards\nSwitch spreads, or make, rename, copy, sort into folders or delete one" % [n, where, main.data.tables.size()]
func _fill() -> void: func _fill() -> void:
@ -38,12 +41,31 @@ func _fill() -> void:
pm.clear() pm.clear()
_ids.clear() _ids.clear()
var can := main.collections_enabled() var can := main.collections_enabled()
for child in pm.get_children():
if child is PopupMenu:
pm.remove_child(child)
child.queue_free()
if can: if can:
var folders := {}
for entry in main.library.list(): for entry in main.library.list():
var id := str(entry["id"]) var folder := str(entry.get("folder", ""))
var current := id == main.data.id if folder != "":
pm.add_item(("● " if current else " ") + str(entry["name"]), _ids.size()) if not folders.has(folder):
_ids.append(id) folders[folder] = []
(folders[folder] as Array).append(entry)
continue
_add_spread(pm, entry)
var names: Array = folders.keys()
names.sort_custom(func(left: String, right: String) -> bool: return left.naturalnocasecmp_to(right) < 0)
for folder: String in names:
var sub := PopupMenu.new()
ModalCard.style_popup(sub)
sub.id_pressed.connect(_on_id)
var holds_current := false
for entry: Dictionary in folders[folder]:
_add_spread(sub, entry)
holds_current = holds_current or str(entry["id"]) == main.data.id
pm.add_submenu_node_item(("● " if holds_current else " ") + folder, sub)
else: else:
pm.add_item("● " + main.data.name, 0) pm.add_item("● " + main.data.name, 0)
pm.set_item_disabled(0, true) pm.set_item_disabled(0, true)
@ -52,9 +74,10 @@ func _fill() -> void:
pm.add_item("New spread…", ID_NEW) pm.add_item("New spread…", ID_NEW)
pm.add_item("Rename…", ID_RENAME) pm.add_item("Rename…", ID_RENAME)
pm.add_item("Duplicate", ID_DUPLICATE) pm.add_item("Duplicate", ID_DUPLICATE)
pm.add_item("Move to folder…", ID_FOLDER)
pm.add_item("Delete…", ID_DELETE) pm.add_item("Delete…", ID_DELETE)
if not can: if not can:
for id in [ID_NEW, ID_RENAME, ID_DUPLICATE, ID_DELETE]: for id in [ID_NEW, ID_RENAME, ID_DUPLICATE, ID_FOLDER, ID_DELETE]:
pm.set_item_disabled(pm.get_item_index(id), true) pm.set_item_disabled(pm.get_item_index(id), true)
pm.add_separator() pm.add_separator()
pm.add_item("Saving is off in this session", -1) pm.add_item("Saving is off in this session", -1)
@ -67,13 +90,39 @@ func _on_id(id: int) -> void:
ID_RENAME: main.rename_collection() ID_RENAME: main.rename_collection()
ID_DUPLICATE: main.duplicate_collection() ID_DUPLICATE: main.duplicate_collection()
ID_DELETE: main.delete_collection() ID_DELETE: main.delete_collection()
ID_FOLDER: _ask_folder()
_: _:
if id >= 0 and id < _ids.size() and _ids[id] != main.data.id: if id >= 0 and id < _ids.size() and _ids[id] != main.data.id:
main.switch_collection(_ids[id]) main.switch_collection(_ids[id])
func _add_spread(menu: PopupMenu, entry: Dictionary) -> void:
var id := str(entry["id"])
menu.add_item(("● " if id == main.data.id else " ") + str(entry["name"]), _ids.size())
_ids.append(id)
## Asks for the folder to list the current spread under (empty = none).
func _ask_folder() -> void:
var known := {}
for entry in main.library.list():
if str(entry.get("folder", "")) != "":
known[str(entry["folder"])] = true
var prompt := "Folder (leave empty for none)"
if not known.is_empty():
prompt += ". Folders so far: " + ", ".join(known.keys())
main._add_modal(ModalCard.ask_text("Move to folder", prompt, main.data.folder, "Move", func(folder: String) -> void:
set_folder(main.library, main.data, folder)
refresh(), true))
# ---------- Storage rules (no UI) ---------- # ---------- Storage rules (no UI) ----------
## Lists `current` under `folder` ("" = none) and saves it.
static func set_folder(library: LibraryStore, current: TowerBoard, folder: String) -> void:
current.folder = folder.strip_edges()
library.save(current)
## Saves `current`, then makes and returns a new empty collection. ## Saves `current`, then makes and returns a new empty collection.
static func create_collection(library: LibraryStore, current: TowerBoard, coll_name: String) -> TowerBoard: static func create_collection(library: LibraryStore, current: TowerBoard, coll_name: String) -> TowerBoard:
if current: if current:

View file

@ -47,14 +47,16 @@ func setup(can_reset: bool, can_import: bool) -> void:
pm.add_item("Import as new spread…", ID_IMPORT) pm.add_item("Import as new spread…", ID_IMPORT)
pm.set_item_disabled(pm.get_item_index(ID_IMPORT), not can_import) pm.set_item_disabled(pm.get_item_index(ID_IMPORT), not can_import)
pm.add_separator("Export this spread") pm.add_separator("Export this spread")
pm.add_item("Export as " + str(EXPORTS[0]["label"]) + "…", ID_EXPORT) pm.add_item("Export as " + str(EXPORTS[0]["label"]) + "… (full copy)", ID_EXPORT)
pm.set_item_tooltip(pm.get_item_index(ID_EXPORT), "Everything on the spread, ready to import again or share")
# Formats for other tools (diagram and graph programs) sit one level down. # Formats for other tools (diagram and graph programs) sit one level down.
var other := PopupMenu.new() var other := PopupMenu.new()
ModalCard.style_popup(other) ModalCard.style_popup(other)
for i in range(1, EXPORTS.size()): for i in range(1, EXPORTS.size()):
other.add_item(str(EXPORTS[i]["label"]) + "…", ID_EXPORT + i) other.add_item(str(EXPORTS[i]["label"]) + "…", ID_EXPORT + i)
pm.add_child(other) pm.add_child(other)
pm.add_submenu_node_item("Other formats", other) pm.add_submenu_node_item("Export as a diagram (cards and threads only)", other)
pm.set_item_tooltip(pm.item_count - 1, "For diagram and mind-map tools. Settings, values, groups and pictures are left out, so importing one back is not a full copy.")
var on_id := func(id: int) -> void: var on_id := func(id: int) -> void:
if id == ID_RESET: if id == ID_RESET:
reset_requested.emit() reset_requested.emit()

View file

@ -226,7 +226,8 @@ static func make_theme() -> Theme:
# ---------- Ready-made dialogs ---------- # ---------- Ready-made dialogs ----------
## Asks for one line of text; calls on_ok(text) with non-blank text. ## Asks for one line of text; calls on_ok(text) with non-blank text.
static func ask_text(title: String, prompt: String, initial: String, ok_text: String, on_ok: Callable) -> ModalCard: ## Asks for one line of text. `allow_empty` accepts an empty answer.
static func ask_text(title: String, prompt: String, initial: String, ok_text: String, on_ok: Callable, allow_empty: bool = false) -> ModalCard:
var d := ModalCard.new(title, 420.0) var d := ModalCard.new(title, 420.0)
var le := LineEdit.new() var le := LineEdit.new()
le.text = initial le.text = initial
@ -234,7 +235,7 @@ static func ask_text(title: String, prompt: String, initial: String, ok_text: St
d.body.add_child(field(prompt, le)) d.body.add_child(field(prompt, le))
var accept := func() -> void: var accept := func() -> void:
var t := le.text.strip_edges() var t := le.text.strip_edges()
if t == "": if t == "" and not allow_empty:
return return
d.close() d.close()
on_ok.call(t) on_ok.call(t)