- 25 palette items over 23 kinds: basics, trackers (bars, ticks, clocks, dots, step/usage dice, ladders), formulas and dice buttons (rule language with sheet @names), lists (rows, mini table, chips, point pool that may go negative, bonds), slots, conditions, spell slots, XP, currency, heading, divider, picture. - Per-kind settings in the inspector; hover excerpts and an in-app details panel for list entries; live redraw of dependent boxes. - Canvas: the page stays put after edits (boxes can go anywhere), a screen of room past the boxes, drag-to-pan and edge scrolling. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
175 lines
11 KiB
GDScript
175 lines
11 KiB
GDScript
class_name SheetKinds
|
||
extends RefCounted
|
||
## Every kind of box you can put on a sheet, in one list: the field palette,
|
||
## new boxes' starting size, title, settings (config) and value all read it
|
||
## (the sheet's version of CardCatalog). Several palette items can share a
|
||
## kind with different start settings (a Mini table and a Point pool are
|
||
## both a "list"). How each kind looks: SheetFieldViews; its settings:
|
||
## SheetKindSettings; its value for formulas and tables: SheetValues.
|
||
|
||
## The snap grid's step, in canvas pixels.
|
||
const GRID := 16.0
|
||
|
||
const NUMBER := "number"
|
||
const SHORT_TEXT := "short_text"
|
||
const TEXT := "text"
|
||
const CHECKBOX := "checkbox"
|
||
const DROPDOWN := "dropdown"
|
||
const RESOURCE := "resource"
|
||
const TICKS := "ticks"
|
||
const CLOCK := "clock"
|
||
const DOTS := "dots"
|
||
const STEP_DIE := "step_die"
|
||
const USAGE_DIE := "usage_die"
|
||
const LADDER := "ladder"
|
||
const FORMULA := "formula"
|
||
const DICE := "dice"
|
||
const LIST := "list"
|
||
const SLOTS := "slots"
|
||
const CONDITIONS := "conditions"
|
||
const SPELL_SLOTS := "spell_slots"
|
||
const XP := "xp"
|
||
const CURRENCY := "currency"
|
||
const HEADING := "heading"
|
||
const DIVIDER := "divider"
|
||
const PICTURE := "picture"
|
||
|
||
const GROUP_BASICS := "Basics"
|
||
const GROUP_TRACKERS := "Trackers"
|
||
const GROUP_SMART := "Smart"
|
||
const GROUP_LISTS := "Lists"
|
||
const GROUP_LAYOUT := "Layout"
|
||
|
||
const DIE_STEPS := ["d4", "d6", "d8", "d10", "d12"]
|
||
const FATE_LADDER := ["Terrible", "Poor", "Mediocre", "Average", "Fair", "Good", "Great", "Superb", "Fantastic", "Epic", "Legendary"]
|
||
|
||
## Each item: id, kind, label, group, tip, search words, start size (w, h in
|
||
## grid steps), title, config and value.
|
||
const ITEMS := [
|
||
{"id": "number", "kind": NUMBER, "label": "Number", "group": GROUP_BASICS, "tip": "A stat or count, like Strength 14",
|
||
"words": "stat score value count", "w": 8, "h": 5, "title": "Number", "config": {}, "value": 0},
|
||
{"id": "short_text", "kind": SHORT_TEXT, "label": "Short text", "group": GROUP_BASICS, "tip": "One line: a name, a class, a word",
|
||
"words": "name word line", "w": 12, "h": 4, "title": "Name", "config": {}, "value": ""},
|
||
{"id": "text", "kind": TEXT, "label": "Long notes", "group": GROUP_BASICS, "tip": "Notes or a description, with formatting and live values like {@str}",
|
||
"words": "notes description bbcode text paragraph", "w": 14, "h": 8, "title": "Notes", "config": {}, "value": ""},
|
||
{"id": "checkbox", "kind": CHECKBOX, "label": "Checkbox", "group": GROUP_BASICS, "tip": "Yes or no, like Inspired",
|
||
"words": "tick yes no toggle", "w": 10, "h": 4, "title": "Inspired", "config": {}, "value": false},
|
||
{"id": "dropdown", "kind": DROPDOWN, "label": "Dropdown", "group": GROUP_BASICS, "tip": "Pick one from a list you write",
|
||
"words": "choice pick list select", "w": 12, "h": 4, "title": "Alignment",
|
||
"config": {"options": ["Lawful", "Neutral", "Chaotic"]}, "value": "Neutral"},
|
||
{"id": "resource", "kind": RESOURCE, "label": "Current / max", "group": GROUP_TRACKERS, "tip": "A bar like HP 6 / 10",
|
||
"words": "hp bar health resource mana", "w": 14, "h": 4, "title": "HP", "config": {"color": "#a33a2c"}, "value": {"cur": 10, "max": 10}},
|
||
{"id": "ticks", "kind": TICKS, "label": "Tick boxes", "group": GROUP_TRACKERS, "tip": "A row of boxes to mark, like stress or ammo",
|
||
"words": "stress ammo boxes marks", "w": 12, "h": 4, "title": "Stress", "config": {"count": 5}, "value": 0},
|
||
{"id": "clock", "kind": CLOCK, "label": "Clock", "group": GROUP_TRACKERS, "tip": "A progress clock you fill in segments",
|
||
"words": "progress segments countdown", "w": 8, "h": 7, "title": "Clock", "config": {"segments": 6}, "value": 0},
|
||
{"id": "dots", "kind": DOTS, "label": "Dot rating", "group": GROUP_TRACKERS, "tip": "A rating in dots like ●●●○○",
|
||
"words": "dots stars rating", "w": 12, "h": 4, "title": "Rating", "config": {"max": 5}, "value": 2},
|
||
{"id": "step_die", "kind": STEP_DIE, "label": "Step die", "group": GROUP_TRACKERS, "tip": "A die that steps up or down, d4 to d12",
|
||
"words": "d4 d6 d8 d10 d12 dice trait", "w": 8, "h": 5, "title": "Trait", "config": {}, "value": "d6"},
|
||
{"id": "usage_die", "kind": USAGE_DIE, "label": "Usage die", "group": GROUP_TRACKERS, "tip": "Roll it when used; on a 1–2 it shrinks (torches, rations)",
|
||
"words": "dice shrink torches rations supply", "w": 10, "h": 5, "title": "Torches", "config": {}, "value": "d8"},
|
||
{"id": "ladder", "kind": LADDER, "label": "Word ladder", "group": GROUP_TRACKERS, "tip": "A rating in words, like the Fate ladder",
|
||
"words": "fate rating scale words", "w": 12, "h": 5, "title": "Rating", "config": {"steps": FATE_LADDER}, "value": 4},
|
||
{"id": "formula", "kind": FORMULA, "label": "Formula", "group": GROUP_SMART, "tip": "Worked out from other values, like (@str - 10) / 2",
|
||
"words": "computed modifier math calculate", "w": 8, "h": 5, "title": "Modifier", "config": {"expr": "floor((@str - 10) / 2)"}, "value": null},
|
||
{"id": "dice", "kind": DICE, "label": "Dice button", "group": GROUP_SMART, "tip": "Rolls dice with sheet values, like 1d20 + @str",
|
||
"words": "roll attack damage", "w": 10, "h": 5, "title": "Attack", "config": {"dice": "1d20 + @str"}, "value": null},
|
||
{"id": "rows", "kind": LIST, "label": "Rows box", "group": GROUP_LISTS, "tip": "Many entries in one box: a name and a value per row",
|
||
"words": "multi entry stats skills list", "w": 13, "h": 12, "title": "Skills",
|
||
"config": {"style": "rows", "columns": [{"name": "Name", "type": "text"}, {"name": "Value", "type": "number"}]},
|
||
"value": [{"Name": "Climb", "Value": 2}, {"Name": "Sneak", "Value": 1}]},
|
||
{"id": "table", "kind": LIST, "label": "Mini table", "group": GROUP_LISTS, "tip": "Entries with columns you choose",
|
||
"words": "columns table list", "w": 18, "h": 10, "title": "Gear",
|
||
"config": {"style": "table", "columns": [{"name": "Name", "type": "text"}, {"name": "Qty", "type": "number"}, {"name": "Notes", "type": "text"}]},
|
||
"value": [{"Name": "Rope", "Qty": 1, "Notes": "50 ft"}]},
|
||
{"id": "chips", "kind": LIST, "label": "Chips", "group": GROUP_LISTS, "tip": "Short entries side by side, like tags",
|
||
"words": "inline tags aspects", "w": 16, "h": 6, "title": "Aspects",
|
||
"config": {"style": "chips", "columns": [{"name": "Name", "type": "text"}]}, "value": [{"Name": "Hedge knight"}, {"Name": "Owes the ferryman"}]},
|
||
{"id": "pool", "kind": LIST, "label": "Point pool", "group": GROUP_LISTS, "tip": "A stock of points; each entry's cost comes off it",
|
||
"words": "points buy spend cost talents", "w": 20, "h": 12, "title": "Talents",
|
||
"config": {"style": "table", "pool": 20, "cost_column": "Cost",
|
||
"columns": [{"name": "Name", "type": "text"}, {"name": "Cost", "type": "number"}, {"name": "Effect", "type": "text"}]},
|
||
"value": [{"Name": "Shield Wall", "Cost": 6, "Effect": "+2 Armour beside allies", "details": "When an ally stands beside you, both of you gain +2 Armour until one of you moves."}]},
|
||
{"id": "bonds", "kind": LIST, "label": "Bonds", "group": GROUP_LISTS, "tip": "People and ties, each with a rating",
|
||
"words": "relationships bonds contacts ties", "w": 14, "h": 9, "title": "Bonds",
|
||
"config": {"style": "rows", "columns": [{"name": "Name", "type": "text"}, {"name": "Bond", "type": "number"}]},
|
||
"value": [{"Name": "Mother Ilse", "Bond": 2}]},
|
||
{"id": "slots", "kind": SLOTS, "label": "Slots", "group": GROUP_LISTS, "tip": "Slot inventory: items take slots; a full pack warns",
|
||
"words": "inventory encumbrance gear pack", "w": 16, "h": 11, "title": "Inventory", "config": {"slots": 10},
|
||
"value": [{"name": "Longsword", "size": 2}, {"name": "Rations", "size": 1}]},
|
||
{"id": "conditions", "kind": CONDITIONS, "label": "Conditions", "group": GROUP_LISTS, "tip": "Toggle chips like Poisoned or Exhausted",
|
||
"words": "tags status poisoned exhausted", "w": 16, "h": 6, "title": "Conditions",
|
||
"config": {"options": ["Poisoned", "Exhausted", "Frightened", "Wounded"]}, "value": []},
|
||
{"id": "spell_slots", "kind": SPELL_SLOTS, "label": "Spell slots", "group": GROUP_LISTS, "tip": "Slots per spell level to mark as used",
|
||
"words": "magic spells levels slots", "w": 14, "h": 8, "title": "Spell slots",
|
||
"config": {"levels": [{"name": "1st", "max": 4}, {"name": "2nd", "max": 2}]}, "value": [0, 0]},
|
||
{"id": "xp", "kind": XP, "label": "XP", "group": GROUP_LISTS, "tip": "Experience with the level it reaches and how far to the next",
|
||
"words": "experience level advancement", "w": 14, "h": 5, "title": "XP", "config": {"levels": [0, 2000, 4000, 8000, 16000]}, "value": 0},
|
||
{"id": "currency", "kind": CURRENCY, "label": "Currency", "group": GROUP_LISTS, "tip": "Coins with exchange rates and a total",
|
||
"words": "money coins gold silver copper", "w": 14, "h": 7, "title": "Purse",
|
||
"config": {"coins": [{"name": "gp", "rate": 1.0}, {"name": "sp", "rate": 0.1}, {"name": "cp", "rate": 0.01}]}, "value": {"gp": 0, "sp": 0, "cp": 0}},
|
||
{"id": "heading", "kind": HEADING, "label": "Heading", "group": GROUP_LAYOUT, "tip": "A title to label part of the sheet",
|
||
"words": "title label section", "w": 14, "h": 4, "title": "Heading", "config": {}, "value": null},
|
||
{"id": "divider", "kind": DIVIDER, "label": "Divider", "group": GROUP_LAYOUT, "tip": "A line between parts of the sheet",
|
||
"words": "line rule separator", "w": 20, "h": 2, "title": "", "config": {}, "value": null},
|
||
{"id": "picture", "kind": PICTURE, "label": "Picture", "group": GROUP_LAYOUT, "tip": "A portrait or picture from a file",
|
||
"words": "image portrait art", "w": 10, "h": 10, "title": "Portrait", "config": {}, "value": ""},
|
||
]
|
||
|
||
|
||
## The palette item with `id` ({} if none).
|
||
static func item(id: String) -> Dictionary:
|
||
for it: Dictionary in ITEMS:
|
||
if it["id"] == id:
|
||
return it
|
||
return {}
|
||
|
||
|
||
## The first palette item of `kind` ({} if none).
|
||
static func find(kind: String) -> Dictionary:
|
||
for it: Dictionary in ITEMS:
|
||
if it["kind"] == kind:
|
||
return it
|
||
return {}
|
||
|
||
|
||
## The name to show for a box's kind: its palette item's label.
|
||
static func label_of(box: SheetBox) -> String:
|
||
var it := item(str(box.config.get("preset", "")))
|
||
if it.is_empty():
|
||
it = find(box.kind)
|
||
return str(it.get("label", box.kind))
|
||
|
||
|
||
static func groups() -> Array[String]:
|
||
var out: Array[String] = []
|
||
for it: Dictionary in ITEMS:
|
||
if not out.has(it["group"]):
|
||
out.append(it["group"])
|
||
return out
|
||
|
||
|
||
## A new box from palette item `item_id` (or the first item of that kind) with
|
||
## its start size, title, settings and value, top-left at `at`.
|
||
static func make_box(item_id: String, id: String, at: Vector2) -> SheetBox:
|
||
var it := item(item_id)
|
||
if it.is_empty():
|
||
it = find(item_id)
|
||
var box := SheetBox.new(id, str(it.get("kind", TEXT)))
|
||
box.title = str(it.get("title", ""))
|
||
box.x = snap(at.x)
|
||
box.y = snap(at.y)
|
||
box.w = float(it.get("w", 12)) * GRID
|
||
box.h = float(it.get("h", 6)) * GRID
|
||
box.config = (it.get("config", {}) as Dictionary).duplicate(true)
|
||
if str(it.get("id", "")) != str(it.get("kind", "")):
|
||
box.config["preset"] = it["id"]
|
||
var start: Variant = it.get("value", null)
|
||
box.value = start.duplicate(true) if start is Array or start is Dictionary else start
|
||
return box
|
||
|
||
|
||
## Rounds to the nearest grid step.
|
||
static func snap(v: float) -> float:
|
||
return roundf(v / GRID) * GRID
|