TableTower/core/sample_board.gd
RobinFiredrake 8f16d337cf UI pass: striped rows, View/Help menus, zoom control, card ⋯ menu, fuller sample
- Striped result rows (parchment tint, on by default, `striped_rows` setting).
- Top bar: View ▾ (Plain words / Rule text, Collapse/Expand all, Striped rows,
  Minimap) and a "− 90% ▾ +" zoom control replace the Plain|Text switch,
  Collapse all, −/Fit/+ and Map. Arrange ▾ folds into Board ▾; Search is an icon.
- Help ▾ and F1 open a Help window; the 17 topics live in help/topics.txt.
- Build cards get a ⋯ menu (settings, template, collapse, delete) instead of
  the gear and footer Delete, sharing Style.overflow_button with group cards.
  Row × buttons show only on hover, focus or selection.
- Sample: Luck value card, Make Camp (pick card) and Search the Ruins
  (1d6 + Luck, with results only a modifier reaches).
- New test suite test_top_bar; Canvas/GraphML round-trip tests compare plain
  tables only, since logic keys are JSON-only.
- DESIGN.md: open items, including the Card Mode UI redesign.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 10:36:38 -06:00

162 lines
10 KiB
GDScript

class_name SampleBoard
extends RefCounted
## The example board: road encounters, loot chains, a d100 ranged travel table,
## a d100 table of 100 unique trinkets, a card-mode deck (Party Roles), and a
## camp corner showing a pick choice (Make Camp), a value card (Luck) and a
## table whose end results only a roll modifier reaches (Search the Ruins).
const TRINKETS := [
"A brass key that's warm to the touch", "A glass eye that follows movement", "A tin whistle only dogs can hear", "A pressed flower that never wilts",
"A tiny portrait of a stranger", "A compass that points to the nearest well", "A wooden die with seven sides", "A silver spoon bent into a ring",
"A sealed letter addressed to you", "A bell with no clapper that still rings", "A jar of buttons from a hundred coats", "A dragon scale the size of a coin",
"A candle that burns cold", "A deck of cards missing every queen", "A bird skull painted gold", "A map of a city that doesn't exist",
"A thimble of sand that never spills", "A ribbon embroidered with your name", "A clockwork beetle that wants winding", "A pebble that is always wet",
"A fishhook carved from bone", "A coin from a kingdom that fell", "A lock of silver hair tied with string", "A broken hourglass, sand still falling",
"A soup recipe written in blood", "A doll with one button eye", "A chess piece shaped like a crow", "A vial of fog",
"A tooth with a tiny keyhole", "A feather that falls upward", "An empty locket that hums", "A spool of thread that never runs out",
"A ring too small for any finger", "A wax seal of a three-eyed owl", "A shell that whispers in a strange tongue", "A rusted crown sized for a cat",
"A knot no blade can cut", "A page torn from a spellbook", "A marble with a storm inside", "A tiny saddle for a mouse",
"A mirror shard that shows yesterday", "A reed flute that plays by itself", "A holed stone that shows stars at noon", "A child's drawing of you",
"A spice tin of dried fireflies", "A wooden sword notched for every win", "A pair of dice that always roll the same", "An acorn that grows back each night",
"A tarnished medal for bravery", "A bottle with a ship of bones inside", "A glove that's always warm", "A bookmark from a library that burned",
"A walnut that rattles", "A copper ring stamped with a moon", "A lantern wick that relights itself", "A painted egg that is far too heavy",
"A bag of salt from a distant sea", "A wanted poster with no face", "A spinning top that never falls", "A snuff box full of teeth",
"A crystal that glows near goblins", "A riddle carved into a spoon handle", "A scarf that smells of summer rain", "A key with no teeth",
"A thumb-sized statue of a sleeping god", "A bone flute with one hole", "An inkwell that refills with black water", "A quill that writes only in red",
"A pocket watch running backwards", "A wedding ring with both names scratched out", "An eggshell painted with a map", "A pouch of mismatched dice",
"A tinderbox that sparks blue", "A prayer bead from an unknown faith", "A playing card with your face on it", "A cracked monocle",
"A tiny cage with the door open", "A pressed four-leaf clover", "A seashell found far inland", "A gold tooth",
"A badge from the city watch", "A charm bracelet with one charm missing", "A bundle of letters tied with twine", "A chip of a giant's fingernail",
"A rope that ties itself", "A stone that floats", "A song trapped in a bottle", "A carved wooden fish",
"A toy soldier missing an arm", "A coin that always lands on its edge", "A candle stub that smells of home", "A brooch shaped like a spider",
"A sliver of moonlight in a vial", "An arrowhead made of glass", "A dried rose from a grave", "A bone die marked with runes",
"A tiny shield with an unknown crest", "A horseshoe for a six-legged horse", "A note: “Don't trust the innkeeper”", "An egg that is warm and ticking",
]
static func create() -> TowerBoard:
var trinket_rows: Array = []
for s in TRINKETS:
trinket_rows.append([s])
# [id, name, position, entries: [text, pipes?, range?, {details?, weight?}?], options?]
# options: dice, collapsed, details, tags, card_mode
var spec: Array = [
["wilderness", "Wilderness Travel", Vector2(40, 180), [
["Travelers on the road", ["road"], [1, 30], {"details": "Most days the road is just the road. Roll on the Road Encounter table to see who is on it."}],
["Beasts on the hunt", ["monsters"], [31, 50]],
["A peddler's cart", ["wares"], [51, 65]],
["Something glints in the grass", ["loot"], [66, 80]],
["A stranger at the campfire", ["names"], [81, 95]],
["An odd find", ["trinkets"], [96, 100]],
], {"dice": "1d100", "details": "Roll once per [b]travel day[/b]. Each result sends you to a table for the details of what the party meets.", "tags": ["travel"]}],
["road", "Road Encounter", Vector2(390, 40), [
["Bandits ambush the party", ["loot"]], ["A merchant caravan", ["wares"]],
["Something big in the trees", ["monsters"]], ["A quiet stretch of road"],
["A sudden storm rolls in"], ["A lost traveler", ["names"]],
]],
["trinkets", "Curious Trinkets", Vector2(390, 420), trinket_rows, {"collapsed": true}],
["monsters", "Monsters", Vector2(740, 20), [
["Owlbear", ["loot"], null, {"details": "[b]Owlbear[/b]: AC 13, 59 HP. Multiattack: beak and claws. Grabs and crushes anything that comes close to its nest."}],
["Giant spider"],
["Troll", ["loot"], null, {"details": "[b]Troll[/b]: AC 15, 84 HP. Regenerates 10 HP each turn unless hit by [i]fire[/i] or [i]acid[/i]."}],
["Wyvern"],
], {"tags": ["combat"]}],
["wares", "Merchant Wares", Vector2(740, 300), [["Bolts of silk"], ["Rare spices"], ["Lamp oil"], ["A crate of strange eggs"]]],
["loot", "Loot", Vector2(1090, 60), [
["A pouch of gold", [], null, {"weight": 3}], ["A weapon", ["weapons"]], ["A healing potion"],
["A torn map"], ["A gemstone"], ["Nothing but lint"],
], {"tags": ["treasure"]}],
["names", "Traveler Names", Vector2(1090, 400), [["Aldric"], ["Brenna"], ["Corvin"], ["Dagny"], ["Elowen"], ["Fenn"]]],
["weapons", "Weapons", Vector2(1440, 60), [["Dagger"], ["Sword", ["quality"]], ["Hand axe"], ["Shortbow"]]],
["quality", "Sword Quality", Vector2(1790, 130), [["Rusty"], ["Notched"], ["Fine"], ["Elven-forged"]]],
["party_roles", "Party Roles", Vector2(1440, 330), [
["Scout"], ["Map keeper"], ["Quartermaster"], ["Lookout"], ["Cook"], ["Diplomat"],
], {"card_mode": true, "details": "Hand out one role per player. Each role is dealt once until everyone has had one, then the deck is reshuffled."}],
["weather", "Weather", Vector2(1790, 380), [
["Storm", [], [2, 3]], ["Rain", [], [4, 5]], ["Overcast", [], [6, 8]],
["Clear skies", [], [9, 10]], ["Heat wave", [], [11, 12]],
], {"dice": "2d6", "details": "Roll [b]2d6[/b]. Middling weather is the most common."}],
# Shows inline [[references]], a chain variable and a persistent {@town}.
["quest_hooks", "Quest Hooks", Vector2(40, 560), [
["[[Traveler Names -> patron]] begs you to recover [[Loot]] from the ruins near {@town|Towns}. {patron} pays well."],
["The mayor of {@town|Towns} posts a bounty: [i]bring back [[Monsters]] alive[/i]."],
["[[Traveler Names]] swears the [[Curious Trinkets]] they found is cursed."],
], {"details": "Opening hooks for a session. [b]{@town}[/b] is the party's current town; it's rolled once, then reused until you clear it."}],
["towns", "Towns", Vector2(740, 560), [["Millbrook"], ["Saltmere"], ["Grey Harrow"], ["Kettle Ford"]]],
]
var board := TowerBoard.new()
for s in spec:
var t := RollTable.new(s[0], s[1])
t.position = s[2]
var opts: Dictionary = s[4] if s.size() > 4 else {}
t.dice = str(opts.get("dice", RollTable.DEFAULT_DICE))
t.collapsed = bool(opts.get("collapsed", false))
t.details = str(opts.get("details", ""))
for tag in opts.get("tags", []):
t.tags.append(tag)
t.card_mode = bool(opts.get("card_mode", false))
for row in s[3]:
var e := TableEntry.new(TowerBoard.new_id("e"), row[0])
if row.size() > 1:
for p in row[1]:
e.add_pipe(p)
if row.size() > 2 and row[2] != null:
e.has_range = true
e.range_lo = row[2][0]
e.range_hi = row[2][1]
if row.size() > 3:
e.details = str(row[3].get("details", ""))
e.weight = int(row[3].get("weight", 1))
t.entries.append(e)
board.tables.append(t)
_add_camp(board)
return board
## Make Camp (a pick choice that changes Luck or goes searching), the Luck value
## card, and Search the Ruins: 1d6 + Luck, whose first and last results the
## dice alone can't reach.
static func _add_camp(board: TowerBoard) -> void:
var luck := RollTable.create(RollTable.KIND_VARIABLE, "luck", "Luck")
luck.position = Vector2(1090, 800)
luck.details = "The party's luck. Make Camp raises or lowers it, and Search the Ruins adds it to the roll."
board.tables.append(luck)
var camp := RollTable.create(RollTable.KIND_CHOICE, "make_camp", "Make Camp", "pick")
camp.position = Vector2(1440, 800)
camp.prompt = "Night falls. Your Luck is {@luck}. How does the party spend the evening?"
camp.details = "A [b]pick[/b] card: the roll stops and asks which option, or picks one at Random."
camp.entries.clear()
for row in [
["Pray at the roadside shrine", "@luck += 1", ""],
["Gamble with the caravan guards", "@luck -= 1", ""],
["Search the old ruins", "", "ruins"],
["Keep watch and rest", "", ""],
]:
var e := TableEntry.new(TowerBoard.new_id("e"), row[0])
e.effects = row[1]
if row[2] != "":
e.add_pipe(row[2])
camp.entries.append(e)
board.tables.append(camp)
var ruins := RollTable.new("ruins", "Search the Ruins")
ruins.position = Vector2(1790, 800)
ruins.dice = "1d6"
ruins.dice_mod = "@luck"
ruins.details = "Roll [b]1d6 + Luck[/b]. Only bad luck reaches the cave-in, and only good luck finds the vault."
# Inline [[references]] rather than pipes: Loot and the trinkets are far
# away on the board.
for row in [
["A tunnel caves in behind you", -1, 0],
["Dust and old bones", 1, 2],
["A few tarnished coins", 3, 4],
["Something glints in the rubble: [[Loot]]", 5, 6],
["A hidden vault holding [[Curious Trinkets]]", 7, 8],
]:
var e := TableEntry.new(TowerBoard.new_id("e"), row[0])
e.has_range = true
e.range_lo = row[1]
e.range_hi = row[2]
ruins.entries.append(e)
board.tables.append(ruins)