TableTower/ui/card_catalog.gd

90 lines
4.9 KiB
GDScript3
Raw Normal View History

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": "New sheet", "group": GROUP_SHEETS, "kind": RollTable.KIND_SHEET, "sub": "", "variant": "",
"name": "Sheet", "tip": "A new sheet on the spread (open it to add fields)", "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
# "sheet:<sheet id>:<prefix>": a Sheet card showing that sheet (MainSheetLinks.add_card).
if variant.begins_with("sheet:"):
t.sheet_id = variant.get_slice(":", 1)
t.sheet_prefix = variant.get_slice(":", 2)
t.width = 340