TableTower/core/sheet_kinds.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

61 lines
2.1 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 and value, and search all read it (the
## sheet's version of CardCatalog). More kinds come in later phases
## (docs/SHEETS.md §4 C).
## The snap grid's step, in canvas pixels.
const GRID := 16.0
const HEADING := "heading"
const TEXT := "text"
const NUMBER := "number"
const GROUP_BASICS := "Basics"
const GROUP_LAYOUT := "Layout"
## Each item: kind, label, group, tip, search words, start size (w, h in grid
## steps), title and value.
const ITEMS := [
{"kind": NUMBER, "label": "Number", "group": GROUP_BASICS, "tip": "A stat or count, like Strength 14 or Gold 30",
"words": "stat score value count", "w": 8, "h": 4, "title": "Number", "value": 0},
{"kind": TEXT, "label": "Text box", "group": GROUP_BASICS, "tip": "Notes or a description, with formatting and live values like {@str}",
"words": "notes description bbcode long", "w": 14, "h": 8, "title": "Notes", "value": ""},
{"kind": HEADING, "label": "Heading", "group": GROUP_LAYOUT, "tip": "A title to label part of the sheet",
"words": "title label section", "w": 14, "h": 3, "title": "Heading", "value": null},
]
static func find(kind: String) -> Dictionary:
for item: Dictionary in ITEMS:
if item["kind"] == kind:
return item
return {}
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
## A new box of `kind` with its start size, title and value, top-left at `at`.
static func make_box(kind: String, id: String, at: Vector2) -> SheetBox:
var item := find(kind)
var box := SheetBox.new(id, kind)
box.title = str(item.get("title", ""))
box.x = snap(at.x)
box.y = snap(at.y)
box.w = float(item.get("w", 12)) * GRID
box.h = float(item.get("h", 6)) * GRID
var start: Variant = item.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