TableTower/ui/card_catalog.gd
RobinFiredrake 2661744b06 Sheets phase B: main menu, Sheets list, sheet editor
- Main menu (Spreads, Sheets, Settings, Quit) on the theme background,
  with recent spreads and sheets; logo or ☰ returns to it.
- Sheets: data model, store, templates, snapshot undo; New sheet dialog
  (blank or a template); editor with folder tabs, snap-grid canvas on the
  spread background, field palette, inspector, Play/Build, status strip.
- Field kinds: Number, Text box (BBCode, live {@name}), Heading.
- PaletteList shared by the card and field palettes; shared top bar brand.
- Keys go to the screen that shows; theme reloads keep the screen.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 15:53:56 -06:00

84 lines
4.6 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

class_name CardCatalog
extends RefCounted
## Every kind of card you can add, in one list: the card palette (CardPalette),
## right-click › New card (Actions.background) and the new card's starting name
## (MainEditing.add_table) all read it.
## `variant` gives the same kind different start settings: "dice" makes a
## ranged dice table, "deck" turns on Deck mode.
const GROUP_TABLES := "Tables"
const GROUP_ASK := "Ask the player"
const GROUP_LOGIC := "Logic"
const GROUP_VALUES := "Values"
const GROUP_SHEETS := "Sheets"
const GROUP_TEMPLATES := "Templates"
const GROUP_OTHER := "Other"
const VARIANT_DICE := "dice"
const VARIANT_DECK := "deck"
## Each item: label, group, kind, sub, variant, the new card's name, a tip and
## extra search words.
const ITEMS := [
{"label": "Roll table", "group": GROUP_TABLES, "kind": RollTable.KIND_ROLL, "sub": "", "variant": "",
"name": "New table", "tip": "Pick a result at random, by weight", "words": "random weight results"},
{"label": "Dice table", "group": GROUP_TABLES, "kind": RollTable.KIND_ROLL, "sub": "", "variant": VARIANT_DICE,
"name": "New dice table", "tip": "Results on number ranges, rolled with dice (1d100)", "words": "ranged d100 d20 d6 range"},
{"label": "Deck", "group": GROUP_TABLES, "kind": RollTable.KIND_ROLL, "sub": "", "variant": VARIANT_DECK,
"name": "New deck", "tip": "Draw results like cards: each comes up once until you shuffle", "words": "draw shuffle cards no repeats"},
{"label": "Check", "group": GROUP_TABLES, "kind": RollTable.KIND_CHECK, "sub": "", "variant": "",
"name": "Check", "tip": "Roll against a target: success or failure", "words": "target skill test success failure"},
{"label": "Which option", "group": GROUP_ASK, "kind": RollTable.KIND_CHOICE, "sub": "pick", "variant": "",
"name": "New choice", "tip": "The player picks one of a few options", "words": "choice pick question"},
{"label": "How many", "group": GROUP_ASK, "kind": RollTable.KIND_CHOICE, "sub": "number", "variant": "",
"name": "How many?", "tip": "The player types a number", "words": "choice number question count"},
{"label": "Open answer", "group": GROUP_ASK, "kind": RollTable.KIND_CHOICE, "sub": "text", "variant": "",
"name": "What is it?", "tip": "The player types any answer, like a name", "words": "choice text question name"},
{"label": "Branch", "group": GROUP_LOGIC, "kind": RollTable.KIND_ROUTER, "sub": "", "variant": "",
"name": "Branch", "tip": "If / else if / otherwise: go one way or another", "words": "if else condition router"},
{"label": "Repeat", "group": GROUP_LOGIC, "kind": RollTable.KIND_LOOP, "sub": "times", "variant": "",
"name": "Repeat", "tip": "Do the next cards several times", "words": "loop times while"},
{"label": "Variable", "group": GROUP_VALUES, "kind": RollTable.KIND_VARIABLE, "sub": "number", "variant": "",
"name": "New variable", "tip": "A value that rolls can read and change, like @gold", "words": "value number text @"},
{"label": "Ledger", "group": GROUP_VALUES, "kind": RollTable.KIND_VARIABLE, "sub": RollTable.VAR_COLLECTION, "variant": "",
"name": "Skills", "tip": "A named list of values: skills, contacts…", "words": "collection list skills contacts"},
{"label": "Scale", "group": GROUP_VALUES, "kind": RollTable.KIND_VARIABLE, "sub": RollTable.VAR_SCALE, "variant": "",
"name": "New scale", "tip": "Ordered steps that move up or down", "words": "steps ladder ordered"},
{"label": "Sheet", "group": GROUP_SHEETS, "kind": RollTable.KIND_SHEET, "sub": "", "variant": "",
"name": "Sheet", "tip": "Shows values as formatted text that stays up to date", "words": "character summary text"},
]
## The item for a kind, sub and variant: an exact match first, then the first
## item of that kind (a choice card also needs its sub to match). {} if none.
static func find(kind: String, sub: String = "", variant: String = "") -> Dictionary:
for item: Dictionary in ITEMS:
if item["kind"] == kind and item["sub"] == sub and item["variant"] == variant:
return item
for item: Dictionary in ITEMS:
if item["kind"] != kind or item["variant"] != variant:
continue
if kind == RollTable.KIND_CHOICE and sub != "":
continue
if item["sub"] == RollTable.VAR_COLLECTION:
continue
return item
return {}
## The group names in palette order (the templates group sits before Other).
static func groups() -> Array[String]:
var out: Array[String] = []
for item: Dictionary in ITEMS:
if not out.has(item["group"]):
out.append(item["group"])
return out
## Gives a new card its variant's start settings.
static func apply_variant(t: RollTable, variant: String) -> void:
match variant:
VARIANT_DICE:
TableSettingsRules.assign_ranges(t)
VARIANT_DECK:
t.card_mode = true