TableTower/ui/card_catalog.gd
RobinFiredrake 16b34c40f6 Card palette: left dock Cards | List, search, click or drag to add
- CardCatalog: one list of card kinds for the palette, right-click New card
  and new-card names; Dice table and Deck are their own items.
- LeftDock holds the palette and List view in the shared dock tab style.
- Play greys the palette under a Switch to Build notice (replaces the
  greyed + Card button); + Card menu removed; Card palette button in Build.
- Templates dropped from the palette land where they are let go.
- Phones: + opens the palette full screen.
- docs/SHEETS.md: the Sheets and unified editor plan.

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

96 lines
5 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
## True when `query` (lower case, may be "") matches the item's label, tip,
## group or search words.
static func matches(item: Dictionary, query: String) -> bool:
if query == "":
return true
var hay := " ".join([item.get("label", ""), item.get("tip", ""), item.get("group", ""), item.get("words", "")]).to_lower()
for word in query.split(" ", false):
if not hay.contains(word):
return false
return true
## 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