Card threads, Morgan's welcome, and typing/scroll/wheel papercuts

- Card threads: a port on each card's bottom edge. Plain runs after any
  result (once the result's own threads finish); Otherwise runs only when
  no thread of the result ran. Saved as card_threads (LOGIC.md 3g).
- Typing on long cards no longer rebuilds the inspector or the card per
  key (~175 ms -> ~7 ms). Timing tool: tests/perf_typing.gd.
- "+ Add result" scrolls to the new row and focuses it.
- Mouse wheel zooms; Shift+wheel pans sideways; scrolling lists keep it.
- "SPREAD" caption over the switcher; Morgan's first-run welcome.
- docs/MECHANICS.md: checklist of table mechanics for planning.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
RobinFiredrake 2026-11-16 10:41:13 -06:00
parent c09cb98e8f
commit 1735ed09fd
49 changed files with 875 additions and 64 deletions

View file

@ -56,7 +56,7 @@ static func _check_table(board: TowerBoard, table: RollTable, add: Callable) ->
var init := table.initial.strip_edges()
if table.var_type == "number" and init != "" and not init.is_valid_float():
expr.call("Initial value", init)
for entry in table.entries:
for entry in table.thread_sources():
_check_braces(entry.text, func(src: String) -> void: expr.call("Text", src, entry.id))
for problem in Effects.validate(entry.effects):
add.call("effect", table, entry.id, "Change \"%s\": %s" % [problem["src"], problem["error"]])
@ -113,7 +113,7 @@ static func _check_braces(text: String, on_expr: Callable) -> void:
static func start_candidates(board: TowerBoard, last_rolled: String = "") -> Array[String]:
var used := {}
for table in board.tables:
for entry in table.entries:
for entry in table.thread_sources():
for pipe in entry.pipes:
used[pipe] = true
for ref in Roller.ref_targets(board, entry.text):

View file

@ -106,7 +106,7 @@ static func _add_table_values(table: RollTable, add: Callable, reads: Array, cha
reads.append([table.dice_mod, table.id])
for inp: Dictionary in table.inputs:
add.call(str(inp.get("name", "")), _kind_of_expr(str(inp.get("default", ""))), "input", table.id)
for entry in table.entries:
for entry in table.thread_sources():
_add_entry_values(table, entry, add, reads)

41
core/card_threads.gd Normal file
View file

@ -0,0 +1,41 @@
class_name CardThreads
extends RefCounted
## Card threads: threads that leave a card from its bottom edge rather than
## from one result (LOGIC.md §3g). They live on the card's outlet
## (RollTable.outlet), a TableEntry that is never rolled, so every thread
## option (count, Only if, save as, dice, rerolls, inputs, pause) works the
## same way as on a result's thread.
##
## When the card has given its result and that result's own threads have run
## (their whole chains), the card threads run, in order:
## - a plain card thread always runs ("Always");
## - an "Otherwise" card thread runs only if no thread of the result ran and
## no conditional card thread was true;
## - a card thread with Only if runs when its condition is true, worked out
## at that moment (after the result's chains).
## A loop card's threads run once, after its Afterwards row.
## True when card `t` has card threads to follow after `node` (a chosen row).
static func follows(t: RollTable, node: Dictionary) -> bool:
return t != null and not t.outlet.pipes.is_empty() and not node.has("pass")
## True when the pipe key belongs to a card thread.
static func is_card_key(key: String) -> bool:
return key.contains(":" + RollTable.OUTLET_ID + ">")
## Runs the card threads of frame["node"]'s card (a Roller.OP_CARD frame,
## popped once the result's own threads are done).
static func run(frame: Dictionary, ctx: RollContext, stack: Array) -> void:
var node: Dictionary = frame["node"]
var t: RollTable = node["table"]
var log: Array = []
var why: Array = []
var plan := RollPipes.pipe_plan(t.outlet, ctx, log, why, bool(frame.get("ran", false)))
for fact: Dictionary in why:
fact["card"] = true
Roller._log(node, log)
Roller._why(node, why)
RollPipes.push_plan(node, t.outlet, plan, stack, int(frame["depth"]), true)

1
core/card_threads.gd.uid Normal file
View file

@ -0,0 +1 @@
uid://c74uqepa17e6a

View file

@ -55,7 +55,7 @@ static func pipe(entry: TableEntry, target_id: String, board: TowerBoard) -> Str
if cond != "":
parts.append("only if " + Describe._condition(cond, L))
elif entry.is_otherwise(target_id):
parts.append("otherwise")
parts.append("if no thread ran" if entry.id == RollTable.OUTLET_ID else "otherwise")
var ce := entry.count_expr(target_id)
if ce != "":
parts.append("×" + Describe._expr(ce, L))

View file

@ -39,8 +39,14 @@ static func why(fact: Dictionary, board: TowerBoard, plain: bool = true) -> Stri
s = _why_when(fact, board, L, plain)
"otherwise":
var to := _table(str(fact.get("to", "")), board, plain)
var card := bool(fact.get("card", false))
if bool(fact.get("result", false)):
s = "Took %s because no condition was true" % to if plain else "%s: otherwise, ran (no condition was true)" % to
if card:
s = "Took the card thread to %s because no other thread ran" % to if plain else "%s: card otherwise, ran (no other thread ran)" % to
else:
s = "Took %s because no condition was true" % to if plain else "%s: otherwise, ran (no condition was true)" % to
elif card:
s = "Skipped the card thread to %s because another thread ran" % to if plain else "%s: card otherwise, skipped" % to
else:
s = "Skipped %s because a condition was true" % to if plain else "%s: otherwise, skipped" % to
"case":

View file

@ -38,6 +38,9 @@ static func _entry_finishes(e: TableEntry, board: TowerBoard, done: Dictionary)
static func _can_finish(t: RollTable, board: TowerBoard, done: Dictionary) -> bool:
if t.entries.is_empty() or t.kind == RollTable.KIND_VARIABLE:
return true
# A card thread that always runs follows every result (CardThreads).
if not _entry_finishes(t.outlet, board, done):
return false
if t.kind == RollTable.KIND_LOOP:
# Every entry runs (a while/until loop ends on its condition).
for e in t.entries:
@ -75,8 +78,7 @@ static func lint_pipes(board: TowerBoard) -> Array[Dictionary]:
out.append_array(lint_check(t))
out.append_array(lint_inputs(board, t))
out.append_array(RollLintBook.lint(board, t))
for i in t.entries.size():
var e := t.entries[i]
for e in t.thread_sources():
var first_other := ""
var has_when := false
var warned := false
@ -93,7 +95,9 @@ static func lint_pipes(board: TowerBoard) -> Array[Dictionary]:
"message": "The otherwise thread to %s comes before a conditional thread; put it last so it reads in order" % _table_name(board, first_other)})
elif e.is_otherwise(p) and first_other == "":
first_other = p
if first_other != "" and not has_when:
# A card's otherwise thread waits for the result's threads, so it
# needs no condition beside it (CardThreads).
if first_other != "" and not has_when and e != t.outlet:
out.append({"table_id": t.id, "entry_id": e.id,
"message": "The otherwise thread to %s always runs: no thread on this result has a condition" % _table_name(board, first_other)})
return out
@ -199,7 +203,7 @@ static func lint_inputs(board: TowerBoard, t: RollTable) -> Array[Dictionary]:
if def != "" and Expr.check(def) != "":
out.append({"table_id": t.id, "entry_id": "", "kind": "inputs", "level": "error",
"message": "Input %s default %s: %s" % [nm, def, Expr.check(def)]})
for e in t.entries:
for e in t.thread_sources():
if e.pipe_with.is_empty():
continue
for p in e.pipes:

View file

@ -8,7 +8,7 @@ extends RefCounted
static func lint(board: TowerBoard, t: RollTable) -> Array[Dictionary]:
var out: Array[Dictionary] = []
for e in t.entries:
for e in t.thread_sources():
for p in e.pipes:
var to := board.get_table(p)
if to == null:

View file

@ -20,6 +20,8 @@ static func attach(frame: Dictionary, node: Dictionary, ctx: RollContext) -> voi
node["save_as"] = frame["save"]
if frame.has("inputs"):
node["inputs"] = frame["inputs"]
if frame.get("card", false):
node["card_thread"] = true
# Facts from before the pick (inputs, a paid cost) come first.
if frame.has("pre_why"):
var facts: Array = (frame["pre_why"] as Array).duplicate()

View file

@ -19,9 +19,11 @@ extends RefCounted
## facts: {"type": "when", "to", "expr", "values": {name: value}, "result":
## bool, "error"?} per conditional pipe and {"type": "otherwise", "to",
## "result"} per otherwise pipe.
static func pipe_plan(e: TableEntry, ctx: RollContext, log: Array = [], why: Array = []) -> Array:
## `others_ran` (card threads, CardThreads): a thread of the result ran, so
## an otherwise card thread doesn't.
static func pipe_plan(e: TableEntry, ctx: RollContext, log: Array = [], why: Array = [], others_ran: bool = false) -> Array:
var plan: Array = []
var any_true := false
var any_true := others_ran
for p in e.pipes:
var w := e.when_for(p)
var run := true
@ -129,6 +131,8 @@ static func restore(f: Dictionary, ctx: RollContext) -> void:
## Snapshots a result's threads (pipe_plan) and queues the ones that run,
## last first so they run in order.
## The card's own threads (CardThreads) wait under them, so they run after
## the result's threads and their whole chains.
static func queue_pipes(node: Dictionary, ctx: RollContext, stack: Array, depth: int) -> void:
var entry: TableEntry = node["entry"]
var log: Array = []
@ -136,6 +140,17 @@ static func queue_pipes(node: Dictionary, ctx: RollContext, stack: Array, depth:
var plan := pipe_plan(entry, ctx, log, why)
Roller._log(node, log)
Roller._why(node, why)
if CardThreads.follows(node["table"], node):
var ran := false
for item: Dictionary in plan:
ran = ran or (item["run"] and int(item["count"]) > 0)
stack.append({"op": Roller.OP_CARD, "node": node, "ran": ran, "depth": depth})
push_plan(node, entry, plan, stack, depth)
## Queues the threads of `plan` that run (from `entry`, a result or the card's
## outlet), last first so they run in order. `card`: card threads.
static func push_plan(node: Dictionary, entry: TableEntry, plan: Array, stack: Array, depth: int, card: bool = false) -> void:
for k in range(plan.size() - 1, -1, -1):
var item: Dictionary = plan[k]
if not item["run"]:
@ -143,6 +158,8 @@ static func queue_pipes(node: Dictionary, ctx: RollContext, stack: Array, depth:
var target: String = item["to"]
var frame := {"op": Roller.OP_PIPE, "node": node, "entry": entry, "to": target, "left": int(item["count"]),
"save": entry.save_for(target), "depth": depth}
if card:
frame["card"] = true
if item.has("with"):
frame["with"] = item["with"]
if entry.dice_for(target) != "":
@ -191,7 +208,7 @@ static func do_pipe(board: TowerBoard, frame: Dictionary, stack: Array) -> void:
frame["left"] = int(frame["left"]) - 1
stack.append(frame)
var roll_frame := {"op": Roller.OP_ROLL, "id": frame["to"], "parent": frame["node"], "save": frame["save"], "depth": frame["depth"]}
for key in ["with", "dice", "reroll"]:
for key in ["with", "dice", "reroll", "card"]:
if frame.has(key):
roll_frame[key] = frame[key]
if frame.has("distinct_from"):

View file

@ -47,6 +47,8 @@ const COLUMNS_EACH := "each"
const CHECK_CMPS: Array[String] = ["ge", "le"]
const CHECK_DEFAULT_DICE := "2d6"
const CHECK_DEFAULT_TARGET := "8"
## The id of a card's outlet (CardThreads), so its threads have pipe keys.
const OUTLET_ID := "_card"
var id: String = ""
var name: String = ""
@ -86,6 +88,8 @@ var deck_empty: String = "reshuffle"
## What a Deck-mode card that waits for Shuffle gives once it's empty ("" = "Empty").
var deck_empty_text: String = ""
var entries: Array[TableEntry] = []
## Holds the card threads (CardThreads): a row that is never rolled or shown.
var outlet: TableEntry = TableEntry.new(OUTLET_ID, "")
## Roll cards with columns (a multi-column table): Array of {"name": String,
## "save_as": value name (optional), "when": condition (optional)}. Column 0
## is each result's own text; the others are TableEntry.cells. Empty = a
@ -345,12 +349,24 @@ func entry_index_clamped(value: int) -> int: return RollRange.index_for(self, va
func find_entry(eid: String) -> TableEntry:
if eid == OUTLET_ID:
return outlet
for e in entries:
if e.id == eid:
return e
return null
## Every row that threads leave from: the results, then the outlet when the
## card has card threads. Don't change the returned array.
func thread_sources() -> Array[TableEntry]:
if outlet.pipes.is_empty():
return entries
var out := entries.duplicate()
out.append(outlet)
return out
## The result an empty Deck-mode card gives when it waits for Shuffle.
func empty_text() -> String:
return deck_empty_text if deck_empty_text.strip_edges() != "" else "Empty"

View file

@ -11,6 +11,8 @@ static func to_dict(t: RollTable) -> Dictionary:
var d := {"id": t.id, "name": t.name, "x": roundi(t.position.x), "y": roundi(t.position.y), "entries": list}
if t.kind != RollTable.KIND_ROLL:
d["kind"] = t.kind
if not t.outlet.pipes.is_empty():
d["card_threads"] = t.outlet.to_dict()["pipes"]
if t.collapsed:
d["collapsed"] = true
if t.details != "":
@ -168,6 +170,8 @@ static func from_dict(d: Dictionary) -> RollTable:
for ed: Variant in d.get("entries", []):
if ed is Dictionary:
t.entries.append(TableEntry.from_dict(ed))
if d.get("card_threads") is Array and not (d["card_threads"] as Array).is_empty():
t.outlet = TableEntry.from_dict({"id": RollTable.OUTLET_ID, "text": "", "pipes": d["card_threads"]})
return t

View file

@ -38,7 +38,7 @@ static func step_of(n: Dictionary, depth: int = 0) -> Dictionary:
step["spread"] = n["spread"]
if n.has("effects"):
step["effects"] = (n["effects"] as Array).duplicate(true)
for k in ["answer", "passes", "pass", "after", "picked", "only_option", "random", "limit", "cancelled", "deck_empty", "dropped", "kept", "combined", "stopped_before", "case", "option", "check", "inputs", "columns"]:
for k in ["answer", "passes", "pass", "after", "picked", "only_option", "random", "limit", "cancelled", "deck_empty", "dropped", "kept", "combined", "stopped_before", "case", "option", "check", "inputs", "columns", "card_thread"]:
if n.has(k):
step[k] = n[k]
if n.has("why"):
@ -136,6 +136,8 @@ static func is_ref_key(key: String) -> bool:
## The pipe or reference-pipe key that led from an entry to child node `c`.
static func link_key(table_id: String, entry_id: String, c: Dictionary) -> String:
var to := (c["table"] as RollTable).id
if c.get("card_thread", false):
return pipe_key(table_id, RollTable.OUTLET_ID, to)
return ref_key(table_id, entry_id, to) if c.get("inline", false) else pipe_key(table_id, entry_id, to)

View file

@ -52,7 +52,7 @@ const CANCELLED := "Cancelled"
const NO_CASE := "No case matched"
const NO_OPTIONS := "No options available"
enum { OP_ROLL, OP_PIPE, OP_LOOP, OP_RESTORE, OP_COMBINE, OP_PAUSE }
enum { OP_ROLL, OP_PIPE, OP_LOOP, OP_RESTORE, OP_COMBINE, OP_PAUSE, OP_CARD }
## A paused thread the player chose not to continue.
const STOPPED_HERE := "Stopped here"
@ -201,6 +201,8 @@ static func _chain(board: TowerBoard, table_id: String, depth: int, ctx: RollCon
RollPipes.queue_pipes(keep, ctx, stack, int(f["depth"]))
OP_PAUSE:
await RollPipes.do_pause(board, f, ctx, stack)
OP_CARD:
CardThreads.run(f, ctx, stack)
# A halted roll leaves frames behind: put back any card inputs they hid.
while not stack.is_empty():
var rest: Dictionary = stack.pop_back()
@ -302,7 +304,7 @@ static func _enter(node: Dictionary, f: Dictionary, ctx: RollContext, stack: Arr
ctx.save_result(t.save_as, str(node["option"]), t.id)
else:
ctx.save_result(t.save_as, Formatter.strip_tags(str(node["summary"])).strip_edges(), t.id)
if e.pipes.is_empty():
if e.pipes.is_empty() and not CardThreads.follows(t, node):
return
# A roll that is being combined with others (RollCombine) waits: only the
# one that's kept follows its threads.

View file

@ -49,7 +49,7 @@ func remove_table(id: String) -> void:
if tables[i].id == id:
tables.remove_at(i)
for t in tables:
for e in t.entries:
for e in t.thread_sources():
e.pipes.erase(id)
for g in groups:
g.members.erase(id)

View file

@ -251,6 +251,16 @@ Each original file keeps one-line delegators, so callers are unchanged.
and the right-click menu). Spread words: `TowerBoard.dictionary` ("dictionary" in the file).
`addons/hunspell/` holds the add-on's prebuilt libraries (Windows, Linux, macOS) and the en_US dictionary.
## 3h. Modules added 2026-11-16 (papercuts, card threads, welcome)
- **Card threads:** `core/card_threads.gd` (`follows`, `run` for `Roller.OP_CARD`, `is_card_key`);
`RollTable.outlet` / `OUTLET_ID` / `thread_sources()`; `RollPipes.push_plan`. Spec: LOGIC.md §3g.
- **Welcome:** `ui/welcome_dialog.gd` (`maybe_show` once, setting `welcome_seen`; `open` any time,
for a future "Show the welcome again" button; `--welcome` flag for screenshots). The top bar's
"SPREAD" caption sits over the switcher (`MainTopBar`).
- **Typing speed:** `InspectorSync.signature` leaves out the card name and result text;
`InspectorSync.sync_texts` and `TableCardEditing.sync_text` / `text_fields` update them in
place. Timing tool: `tests/perf_typing.gd` (SPREAD=… CARD=…; not in the suite).
## 4. Data and storage
- **Collections:** `user://collections/<id>.json`, format_version 2 (`{format_version, id,
name, tables, groups?}`). On Linux that's `~/.local/share/godot/app_userdata/TableTower/`.

View file

@ -1,7 +1,7 @@
# Table Tarot (repo: TableTower) — Status and Plan
**Engine:** Godot 4.7.2 (GDScript) · **Started:** 2026-11-08 · **Last updated:** 2026-11-15 (Build UX round merged to
`main` and pushed)
**Engine:** Godot 4.7.2 (GDScript) · **Started:** 2026-11-08 · **Last updated:** 2026-11-16 (papercuts + card threads
round hand-tested, merged to `main` and pushed)
The short page to read at the start of every session. Everything else is read only when needed:
- `docs/ARCHITECTURE.md`: feature summary, file map (§3b lists the 2026-11-10 modules), storage, known gaps.
@ -113,7 +113,39 @@ underlines were checked in a screenshot. Hunspell prints "Wrote dictionary file
2026-11-15 with the user's preset edits); spellcheck is not tried in an exported build yet.
**Not hand-tested by the user yet** (only tests and screenshots): the whole round.
**Next, likely:** the user hand-tests the Build UX round; spread links; new playtest reports.
**Papercuts + card threads round (2026-11-16, merged to `main` and pushed; all 51 suites pass).** From the
user's list:
- **Typing lag** on long open cards: each key rebuilt the whole inspector (~120 ms) or, from the
inspector, the whole card (~150 ms). Now ~7 ms per key (measured with `tests/perf_typing.gd` on
Magic Wand Generator · Material, 36 results). Card renames were slow the same way; fixed too.
- **"+ Add result"** scrolls the card's list to the new row and puts the cursor in it (text selected).
The rebuild inside it scrolls to the new row, not the last-rolled one (`TableCardEditing.adding`).
- **Mouse wheel** zooms (was: scroll up/down; Ctrl+wheel zoomed). Shift+wheel moves sideways. Over a
card's list that scrolls, the wheel scrolls the list, even at its ends. Help updated.
- **Card threads** (LOGIC.md §3g): a ● on each card's bottom edge; plain = after any result,
Otherwise = only when no thread of the result ran. Every rolling kind; loops once at the end.
- **Spreads made obvious:** a "SPREAD" caption over the switcher; Morgan's welcome on first launch
(Explore the demo / Start a blank spread / Import a spread…). Replay button: not added yet
(`WelcomeDialog.open`). The user's own install will show it once, since the setting is new.
**Hand-tested by the user: works** (the add-result scroll needed one fix, now in).
Still no spellcheck on/off setting (the user looked for one; offer it if it comes up).
**Next: the table mechanics round.** The user's prompt to start it: **"Let's pick up the table
mechanics."** When they say that:
1. Read `docs/MECHANICS.md`. Ask whether they've ticked the Books column yet; if not, offer to go
through the ❌ and 🟡 rows with them instead.
2. Offer the local PDF scan (plan below), so they don't have to read their books by hand.
3. Ask for their "ten hardest tables": header, two rows and the instructions only, typed or as photos.
4. From what comes back, propose the next feature round (likely: keep highest/lowest and doubles,
exploding dice and pools, 2D grid lookups). Ask before building.
**PDF scan plan** (the user approved `pdftotext`, 2026-11-16; don't open the PDFs before they ask):
their TTRPG PDFs sit in one folder with subfolders; most have text, a few are scanned (need OCR).
A local script (in the scratchpad, not the repo) converts them to text and counts rolling phrases
("roll again", "reroll", "d66", "draw", "roll twice", "if you rolled", "cross-reference",
dice notation…), plus an "unsorted" pile: paragraphs near dice notation or numbered ranges that
match no known phrase (that catches flavourful wording). Claude reads only the short report.
Layout (grids, columns) doesn't survive text extraction; the "ten hardest tables" cover that.
Ask for the folder path when the scan starts.
## 3b. Theme slots plan (2026-11-11, user-approved order)
Mockups: "Morgan's Wardrobe" artifact (https://claude.ai/code/artifact/136b4ce8-1ef7-47ca-a39a-a75eb34d64b7):
@ -133,6 +165,8 @@ that works on any theme (solid background, stronger text, thicker borders, no ef
## 4. Open items
**Waiting on the user**
- Mechanics checklist (2026-11-16): [MECHANICS.md](MECHANICS.md). The user marks which mechanics
their books use; the ❌ rows become the next feature rounds. Start phrase and plan: §3, "Next".
- Android: export templates are installed (checksum verified); the Android SDK (build-tools,
platform-tools) is not. Ask before downloading. No Android preset yet.
- Thread string art (the user will draw it), then use it like `CardFrame` does for cards.
@ -214,7 +248,7 @@ that works on any theme (solid background, stronger text, thicker borders, no ef
## 5. Working on it
- **Godot:** `~/apps/Godot_v4.7.2-stable_linux.x86_64`. New `class_name` files need
`godot --headless --path . --import` (the test runner does this).
- **Tests:** `tools/run_tests.sh [filter]`: 47 suites in parallel, ~40 s. One line per suite; a
- **Tests:** `tools/run_tests.sh [filter]`: 51 suites in parallel, ~40 s. One line per suite; a
failing suite prints 8 lines; a compile error shared by many suites prints once. Suites extend
`TestBase` (`tests/testbase.gd`, named so the `test_*.gd` glob skips it): `start_main()`,
`require_sample()`, `_check`, `_eq`, `_frames`, `_wipe` (temp folders), `finish()`.

View file

@ -326,6 +326,34 @@ Two more thread options (stored on the thread object):
with "This thread rolls again on every result" (and the board check says so). Repeated
rolls (a count) reroll each roll separately. Code: `RollCards.pick_for()`.
## 3g. Card threads
A card may have **card threads** (`card_threads` in the file, same format as an entry's
`pipes`): threads off the card's bottom edge rather than off one result. Code:
`core/card_threads.gd`. In memory they sit on `RollTable.outlet`, a `TableEntry` with id
`RollTable.OUTLET_ID` (`"_card"`) that is never rolled or shown; `find_entry("_card")` returns
it, so pipe keys (`tid:_card>to`), the thread inspector, the pop-up and removal work unchanged.
`thread_sources()` is the results plus the outlet (when it has threads), for code that walks
every thread (lint, checks, drawing, Threads in/out).
- When the chain enters a result (`Roller._enter`) and the card has card threads,
`RollPipes.queue_pipes` pushes an `OP_CARD` frame under the result's own pipe frames, so it
pops after the result's threads and their whole subtrees.
- `CardThreads.run` takes the outlet's snapshot then: a plain card thread always runs; an
`otherwise` one runs only if no thread of the result ran (with a count above 0) and no
conditional card thread was true (`pipe_plan(..., others_ran)`); a `when` is worked out at
that moment. Then the threads queue like a result's (`push_plan`, all options apply).
- A loop card's threads run once, after Afterwards (pass nodes are skipped). Combined rolls
(RollCombine): only the kept roll follows them, like its own threads.
- Nodes reached through a card thread have `card_thread: true` (also in steps), so lighting
uses the outlet's key (`RollTree.link_key`, `MainRollingShow._light_steps`). Why facts from a
card thread's snapshot have `card: true`.
- Lint: an otherwise card thread with no condition beside it is not a hint (it needs none);
`endless_cycles` treats an always-running card thread like a thread on every result.
- UI: the port is the middle of the card's bottom edge (`TableCardGeometry.outlet_point`),
drawn in Build always and in Play when there are card threads; the curve leaves downwards.
The card's Threads out list shows "After any result" / "If no thread ran".
## 4. Expressions
Expressions appear in loop rules, pipe counts, pipe conditions, router cases, `min`/`max`,

115
docs/MECHANICS.md Normal file
View file

@ -0,0 +1,115 @@
# Table mechanics checklist
The ways printed TTRPG and story-prompt tables get rolled, and how Table Tarot handles each.
Written 2026-11-16 from general genre knowledge (no book read) and checked against LOGIC.md.
**Status:** ✅ built · 🟡 works with a workaround · ❌ missing · ❓ not sure, test it
**Books column:** put an `x` (or a book name) when one of your books uses it. Add rows for
anything not here.
## 1. Dice shapes
| # | Mechanic | Example wording | Status | Books |
|---|---|---|---|---|
| 1.1 | One die, one row per face | "Roll 1d8" | ✅ ranged or weighted card | |
| 1.2 | Ranges on a die | "d100: 01–15 Bandits, 16–30 Wolves" | ✅ ranged card | |
| 1.3 | Bell curve sums | "2d6: 2 Disaster … 12 Windfall" | ✅ | |
| 1.4 | Modifier pushes past the table | "1d20 + Luck; 21+ …" | ✅ `dice_mod`, ends clamp | |
| 1.5 | d66 / d666 (dice read as digits, not added) | "Roll d66: 11–16 …, 21–26 …" | 🟡 expression `d6*10+d6` with ranges; card shows odd chances and gaps | |
| 1.6 | d100 as two d10 with "00 = 100" | "Roll percentile dice" | ✅ `1d100` | |
| 1.7 | Keep highest / lowest | "Roll 2d6 and keep the best", advantage | ❌ | |
| 1.8 | Exploding dice | "On a 6, roll again and add" | ❌ | |
| 1.9 | Dice pool, count successes | "Roll 5d6, each 5+ is a hit" | ❌ | |
| 1.10 | Read each die on its own | "Red die = where, white die = what" | 🟡 two cards or `column_rolls: each` | |
| 1.11 | Doubles or matches mean something | "On doubles, add a twist" | ❌ no way to see the separate faces | |
| 1.12 | Step dice from a value | "Roll your Danger die (d4–d12)" | ✅ dice can be an expression | |
| 1.13 | Odd / even or high / low split | "Odd: male, even: female" | ✅ `nat % 2` in an "only if" | |
| 1.14 | Fudge / Fate dice, symbol dice | "4dF", "count the skulls" | ❌ | |
## 2. Cards and draws
| # | Mechanic | Example wording | Status | Books |
|---|---|---|---|---|
| 2.1 | Draw without repeats until reshuffled | "Draw from the deck" | ✅ Deck mode | |
| 2.2 | Playing cards: suit means one thing, rank another | "Hearts = love; Ace–10 …" | 🟡 two columns or two cards; not one real 52-card draw | |
| 2.3 | Jokers reshuffle or trigger something | "On a Joker, shuffle and add a twist" | 🟡 Joker entry with an effect; no "reshuffle" action | |
| 2.4 | Tarot upright / reversed | "Reversed: the opposite meaning" | 🟡 second column or a coin-flip thread | |
| 2.5 | Draw several, then pick one | "Draw 3, choose 1" | ✅ "roll N different results, then pick" | |
| 2.6 | Draw several and lay them out in positions | "Past / Present / Future" | 🟡 one card per position | |
| 2.7 | Shared deck across tables | "Use the same deck for both" | ❓ | |
| 2.8 | Remove a card for the session | "Once drawn, cross it out" | ✅ Deck mode keeps state | |
## 3. Flow between tables
| # | Mechanic | Example wording | Status | Books |
|---|---|---|---|---|
| 3.1 | A result sends you to another table | "Roll on the Treasure table" | ✅ thread | |
| 3.2 | Walk every table in order, whatever the result | "Then roll on table 2" | ✅ card thread | |
| 3.3 | Go there only if nothing more specific applied | "Otherwise, go to step 4" | ✅ card thread with Otherwise | |
| 3.4 | Roll N times, N rolled | "Roll 1d4 times on …" | ✅ thread count as expression | |
| 3.5 | Roll twice and combine | "Roll twice, ignore this result" | ✅ repeat on columns; thread back to card otherwise | |
| 3.6 | Reroll certain results | "Reroll 96–00" | ✅ thread rerolls | |
| 3.7 | Roll on this table with other dice | "Roll 1d6+4 on the same table" | ✅ thread dice | |
| 3.8 | Inline sub-roll in a result | "1d6 goblins and [a trinket]" | ✅ `{= 1d6}`, `[[Table]]` | |
| 3.9 | Table from another book / spread | "See Core Rules p. 40" | ✅ `[[Spread::Card]]` | |
| 3.10 | Branch on a value | "If Wealth 3+, roll on Noble" | ✅ router, "only if" threads | |
| 3.11 | Repeat until something happens | "Keep rolling until you get a Door" | ✅ loop `until` | |
| 3.12 | Player choice instead of a roll | "Choose one, or roll" | ✅ choice card, Random option | |
| 3.13 | Return to an earlier table | "Go back to step 2" | ✅ cycles allowed (action limit) | |
## 4. State and memory
| # | Mechanic | Example wording | Status | Books |
|---|---|---|---|---|
| 4.1 | Save a result for later text | "the NPC's name" | ✅ save as, `{name}` | |
| 4.2 | Counters that later tables read | "+1 Threat; at 5, …" | ✅ variables, effects | |
| 4.3 | Ordered steps | "Thin → Standard → Dense" | ✅ scales | |
| 4.4 | Collected lists | "Add each find to the hoard" | ✅ list cards | |
| 4.5 | No repeats across a whole session | "Each rumour only once" | ✅ Deck mode / "No repeats" threads | |
| 4.6 | Clock or progress track | "Fill 1 of 6 segments" | 🟡 number variable + router at full | |
| 4.7 | A later result changes an earlier one | "Shattered lowers the atmosphere" | 🟡 no clean form (DESIGN "small ideas") | |
| 4.8 | A cost to roll | "Spend 1 Supply to search" | ✅ card costs, Pay / Don't pay | |
| 4.9 | Values that last between sessions | "Chaos factor stays" | ✅ board variables are kept | |
## 5. Lookup shapes
| # | Mechanic | Example wording | Status | Books |
|---|---|---|---|---|
| 5.1 | Several result columns per row | "Size / Gravity / Moons" | ✅ columns | |
| 5.2 | 2D grid: row from one value, column from another | "Cross-reference Odds with Chaos" | ❌ needs a router per row or a card per column | |
| 5.3 | Table picked by a value | "Use the table for your terrain" | 🟡 router to one card per terrain | |
| 5.4 | Shift the result up or down rows | "Move 2 rows down if at night" | ✅ plain-table modifier moves rows | |
| 5.5 | Words that join into one phrase | "Adjective + Noun", name syllables | ✅ "Read as one phrase" | |
| 5.6 | Weighted rows with no dice shown | "Common / Uncommon / Rare" | ✅ weighted card | |
## 6. Oracles and procedures
| # | Mechanic | Example wording | Status | Books |
|---|---|---|---|---|
| 6.1 | Yes / No with a likelihood | "Likely: 1–13 Yes" | ✅ check or router on likelihood | |
| 6.2 | "Yes, and" / "No, but" grades | "Exceptional yes on 1–3" | ✅ ranged card | |
| 6.3 | Random event on doubles or a threshold | "If both dice ≤ Chaos, event" | ❌ needs 1.11 (separate faces) | |
| 6.4 | Map or hex walk (position moves on a grid) | "Hex flower: 2d6 moves you" | ❌ no grid position | |
| 6.5 | Roll under a stat | "Roll d20 under DEX" | ✅ check `le` | |
| 6.6 | Opposed rolls | "Both roll, high wins" | 🟡 two variables + router | |
| 6.7 | Timed or per-period rolls | "Roll each watch / each day" | 🟡 loop `times`; no calendar | |
| 6.8 | Pick a table by the time already spent | "After 3 turns, use table B" | ✅ variable + router | |
## 7. Text and output
| # | Mechanic | Example wording | Status | Books |
|---|---|---|---|---|
| 7.1 | Result text with blanks filled in | "A {colour} {beast}" | ✅ `[[refs]]`, `{@x}` | |
| 7.2 | A summary sheet at the end | Character sheet, NPC block | ✅ sheet card | |
| 7.3 | Grammar: a / an, plurals | "a eel" → "an eel" | ❌ | |
| 7.4 | Results with page references or notes | "(see p. 112)" | ✅ plain text | |
| 7.5 | Pictures in results | Map tile, monster portrait | ❓ (board images exist; in results?) | |
## Gaps so far (❌), roughly by how often books use them
1. Keep highest / lowest (1.7) and doubles (1.11, 6.3).
2. Exploding dice (1.8) and dice pools (1.9).
3. 2D grid lookups (5.2).
4. Real d66 notation (1.5) and playing-card / tarot decks as one draw (2.2–2.4).
5. Map or hex walks (6.4).
6. a / an grammar (7.3).

View file

@ -77,6 +77,15 @@ A thread carries the roll from a result to another card.
- [b]Otherwise[/b] runs the thread only when none of the result's Only if threads ran.
- [b]Inputs[/b] pass values to a card that declares them.
## Card threads
A card thread leaves from the ● on a card's bottom edge, not from one result. Use it to walk through tables in order ("then roll on the next table") without a thread on every result.
- In Build mode, drag from the ● on the bottom edge onto the next card.
- It runs after the card's result, and after that result's own threads have finished.
- Plain, it runs whatever the result was.
- With [b]Otherwise[/b] ticked, it runs only when no thread of the result ran. So a few results can send the roll somewhere special, and every other result goes on to the next card.
- [b]Only if[/b], [b]Count[/b], [b]Save as[/b] and the other options work as on any thread.
- Every card that rolls has one: roll tables, choices, checks, branches, repeats (once, after the last pass) and sheets.
## Rolling with other dice
A thread can roll a card with numbered ranges using different dice, just this once.
- Type the dice in [b]Roll it with … instead[/b], such as `3d10+70`. Leave it empty to use the card's own dice.
@ -287,7 +296,7 @@ Click any item in the report to jump to that card. A spread that can loop foreve
# Finding your way
- [b]Search[/b] (the magnifier, or [b]Ctrl+F[/b]) finds cards by name, result, question, value or group, opens closed groups and flashes the card.
- Drag with the middle mouse button, or hold [b]Space[/b] and drag, to move around. The mouse wheel scrolls up and down, [b]Shift+wheel[/b] scrolls sideways and [b]Ctrl+wheel[/b] zooms.
- Drag with the middle mouse button, or hold [b]Space[/b] and drag, to move around. The mouse wheel zooms in and out ([b]Shift+wheel[/b] moves sideways). Over a card's list that scrolls, the wheel scrolls the list.
- The zoom control at the top right shows the zoom. − and + step it, and the percentage opens [b]Fit spread[/b], [b]Zoom to 100%[/b] and the minimap.
- The [b]minimap[/b] (press [b]M[/b]) shows the whole spread in the corner. Click or drag on it to move there.
@ -312,7 +321,7 @@ Click any item in the report to jump to that card. A spread that can loop foreve
- [b]Right-click[/b]: the menu for what's under the mouse
- [b]Drag on empty space[/b] (Build): a selection box. Add [b]Ctrl[/b] or [b]Shift[/b] to add to the selection
- [b]Middle-drag[/b], or [b]Space[/b] + drag: move around the spread
- [b]Wheel[/b]: scroll. [b]Shift+wheel[/b]: sideways. [b]Ctrl+wheel[/b]: zoom
- [b]Wheel[/b]: zoom (over a card's scrolling list: scroll the list). [b]Shift+wheel[/b]: move sideways
- A card's bottom-right corner: drag to resize, double-click for its own size
- Double-click the edge of the tray, inspector, list or Lore Index: reset its size
## Touch

46
tests/perf_typing.gd Normal file
View file

@ -0,0 +1,46 @@
extends TestBase
## Times typing on a long card in Build mode: one key in a result's field on
## the card, in the card's name, and in the inspector's text field. Each number
## is the frame after the key (an idle frame is ~7 ms headless). Not part of
## the suite (the name doesn't start with test_). Run:
## SPREAD=/path/to/spread.json CARD=card_id \
## godot --headless --path . -s res://tests/perf_typing.gd -- --sample
func _init() -> void:
if not await start_main():
return
main.data.load_json(FileAccess.get_file_as_string(OS.get_environment("SPREAD")))
var t := main.data.get_table(OS.get_environment("CARD"))
t.collapsed = false
main.set_mode(Main.Mode.BUILD)
main._rebuild_cards()
await _frames(10)
var card: TableCard = main.card_for(t.id)
var eid := t.entries[mini(5, t.entries.size() - 1)].id
var row_edit: LineEdit = card.edit_ui.text_fields[eid]
var name_edit := _first_line_edit(card)
row_edit.grab_focus()
await _frames(5)
var insp_edit: LineEdit = (main.inspector.section_parts[eid]["fields"] as Dictionary)["text"]
for field: Array in [["card result", row_edit], ["card name", name_edit], ["inspector text", insp_edit]]:
var times: Array[String] = []
for i in 4:
var edit: LineEdit = field[1]
var started := Time.get_ticks_usec()
edit.text += "x"
edit.text_changed.emit(edit.text)
await process_frame
times.append("%.1f" % ((Time.get_ticks_usec() - started) / 1000.0))
print("PERF %s ms per key: %s" % [field[0], ", ".join(times)])
finish()
func _first_line_edit(n: Node) -> LineEdit:
for c in n.get_children():
if c is LineEdit and (c as LineEdit).editable:
return c
var found := _first_line_edit(c)
if found:
return found
return null

1
tests/perf_typing.gd.uid Normal file
View file

@ -0,0 +1 @@
uid://cqq2xdkb6jd4b

View file

@ -11,6 +11,8 @@ func _init() -> void:
await _test_compact()
await _test_play_drag_selects()
await _test_show_less()
await _test_add_scrolls_and_focuses()
await _test_wheel_zooms()
finish()
@ -105,3 +107,61 @@ func _test_show_less() -> void:
(less[0] as Button).pressed.emit()
await _frames(2)
_check(t.collapsed, "Show less collapses it again")
## "+ Add result" on a card whose list scrolls: the list scrolls to the new
## row and its text field gets the cursor, its starter text selected.
func _test_add_scrolls_and_focuses() -> void:
main.set_mode(Main.Mode.BUILD)
var t := main.data.get_table("road")
t.collapsed = false
var card := main.card_for("road")
card.set_user_size(0.0, 80.0)
# A lit result near the top: the list must still go to the new row.
main.lit_entries[Roller.entry_key("road", t.entries[0].id)] = true
await _frames(3)
var add := _button(card, "+ Add")
_check(add != null, "the card has an add button")
if add == null:
return
add.pressed.emit()
await _frames(3)
var eid := t.entries[-1].id
var edit: LineEdit = card.edit_ui.text_fields.get(eid)
_check(is_instance_valid(edit) and edit.has_focus(), "the new result's field has the cursor")
_check(is_instance_valid(edit) and edit.has_selection() and edit.get_selected_text() == edit.text, "its starter text is selected")
var bar := card.list_scroll.get_v_scroll_bar()
_check(card.list_scroll.scroll_vertical > 0 and card.list_scroll.scroll_vertical >= int(bar.max_value - bar.page) - 1, "the list is scrolled to the bottom")
card.set_user_size(0.0, 0.0)
main.set_mode(Main.Mode.PLAY)
await _frames()
## The wheel zooms the spread; Shift+wheel moves it sideways.
func _test_wheel_zooms() -> void:
main.board.set_zoom(1.0)
var wheel := InputEventMouseButton.new()
wheel.button_index = MOUSE_BUTTON_WHEEL_UP
wheel.pressed = true
wheel.position = main.board.size / 2.0
var y := main.board.world.position.y
main.board._gui_input(wheel)
_check(main.board.zoom > 1.0, "the wheel zooms in")
_check(not is_equal_approx(main.board.world.position.y - y, 60.0), "and doesn't just scroll up")
var x := main.board.world.position.x
var z := main.board.zoom
wheel.shift_pressed = true
main.board._gui_input(wheel)
_check(is_equal_approx(main.board.zoom, z) and is_equal_approx(main.board.world.position.x - x, 60.0), "Shift+wheel moves sideways")
main.board.set_zoom(1.0)
await _frames()
func _button(n: Node, prefix: String) -> Button:
for c in n.get_children():
if c is Button and (c as Button).text.begins_with(prefix):
return c
var found := _button(c, prefix)
if found:
return found
return null

114
tests/test_card_threads.gd Normal file
View file

@ -0,0 +1,114 @@
extends TestBase
## Card threads (CardThreads, LOGIC.md §3g): threads off a card's bottom edge
## that run after the card's result and that result's own threads, whatever
## the result was ("Always"), or only when no result thread ran ("Otherwise").
## Run: godot --headless --path . -s res://tests/test_card_threads.gd
func _init() -> void:
_test_always_runs_after()
_test_otherwise()
_test_card_condition()
_test_kinds()
_test_io_and_lit()
finish()
## Start (results a, b; a → Side) then card thread → Next.
func _board() -> TowerBoard:
var b := TowerBoard.new()
var start := RollTable.new("start", "Start")
var a := TableEntry.new("a", "A")
a.add_pipe("side")
start.entries.append(a)
start.entries.append(TableEntry.new("b", "B"))
start.outlet.add_pipe("next")
b.tables.append(start)
for id in ["side", "next"]:
var t := RollTable.new(id, id.capitalize())
t.entries.append(TableEntry.new(id + "1", id + " result"))
b.tables.append(t)
return b
func _roll(b: TowerBoard, seed_value: int, id: String = "start") -> Dictionary:
var rng := RandomNumberGenerator.new()
rng.seed = seed_value
return Roller.roll(b, id, rng)
func _order(tree: Dictionary) -> Array:
var out: Array = []
for step: Dictionary in Roller.flatten(tree):
out.append(str(step.get("table_id", "")))
return out
func _test_always_runs_after() -> void:
var seen := {}
for seed_value in 20:
var b := _board()
var tree := _roll(b, seed_value)
var eid := (tree["entry"] as TableEntry).id
seen[eid] = true
var order := _order(tree)
_check(order.has("next"), "the card thread runs after result %s" % eid)
if eid == "a":
_check(order.find("side") < order.find("next"), "after the result's own thread: %s" % str(order))
_check(seen.size() == 2, "both results came up")
func _test_otherwise() -> void:
for seed_value in 20:
var b := _board()
b.get_table("start").outlet.set_pipe_otherwise("next", true)
var tree := _roll(b, seed_value)
var eid := (tree["entry"] as TableEntry).id
var order := _order(tree)
_eq(order.has("next"), eid == "b", "otherwise card thread runs only when no result thread ran (got %s)" % eid)
## Only if on a card thread is read after the result's chain ran.
func _test_card_condition() -> void:
var b := _board()
var start := b.get_table("start")
start.entries[0].effects = "@hit = 1"
start.entries[1].effects = "@hit = 0"
start.outlet.set_pipe_when("next", "@hit = 1")
for seed_value in 10:
var tree := _roll(b, seed_value)
_eq(_order(tree).has("next"), (tree["entry"] as TableEntry).id == "a", "Only if on a card thread")
## Every rolled kind follows its card threads; a loop only once, at the end.
func _test_kinds() -> void:
var b := _board()
var loop := RollTable.create(RollTable.KIND_LOOP, "lp", "Loop")
loop.loop_expr = "3"
loop.outlet.add_pipe("next")
b.tables.append(loop)
var order := _order(_roll(b, 1, "lp"))
_eq(order.count("next"), 1, "a loop's card thread runs once")
_check(order.back() == "next", "after the loop's last row: %s" % str(order))
var check := RollTable.create(RollTable.KIND_CHECK, "ck", "Check")
check.outlet.add_pipe("next")
b.tables.append(check)
_check(_order(_roll(b, 2, "ck")).has("next"), "a check follows its card thread")
func _test_io_and_lit() -> void:
var b := _board()
var start := b.get_table("start")
start.outlet.set_pipe_otherwise("next", true)
var d := start.to_dict()
_check(d.has("card_threads"), "card threads are saved")
var back := RollTable.from_dict(d)
_check(back.outlet.pipes == start.outlet.pipes and back.outlet.is_otherwise("next"), "and loaded with their options")
_check(not RollTable.from_dict(b.get_table("side").to_dict()).to_dict().has("card_threads"), "no key without card threads")
_check(start.find_entry(RollTable.OUTLET_ID) == start.outlet and start.thread_sources().has(start.outlet), "the outlet is a thread source")
start.outlet.set_pipe_otherwise("next", false)
var entries := {}
var pipes := {}
Roller.collect_lit(_roll(b, 3), entries, pipes)
_check(pipes.has(Roller.pipe_key("start", RollTable.OUTLET_ID, "next")), "the card thread lights: %s" % str(pipes.keys()))
_check(CardThreads.is_card_key(Roller.pipe_key("start", RollTable.OUTLET_ID, "next")), "card keys are recognised")

View file

@ -0,0 +1 @@
uid://blmb2b7mn81ad

View file

@ -17,6 +17,7 @@ func _init() -> void:
await _test_card_menu()
await _test_help()
await _test_build_hint()
await _test_welcome()
finish()
@ -157,3 +158,18 @@ func _test_build_hint() -> void:
_check(not bar.play_add_button.visible, "Build hides the greyed button")
main.toast("Saved")
_eq(bar._toast_undo.text, "Undo", "a later toast's button is Undo again")
## Morgan's welcome: not in a session that doesn't save; open() shows it with
## its three ways to start, and Explore the demo closes it.
func _test_welcome() -> void:
WelcomeDialog.maybe_show(main)
await _frames()
_check(main.find_children("*", "ModalCard", true, false).is_empty(), "no welcome in a session that doesn't save")
var dialog := WelcomeDialog.open(main)
await _frames()
var labels: Array = dialog.footer.get_children().map(func(b: Node) -> String: return (b as Button).text)
_eq(labels, ["Import a spread…", "Start a blank spread", "Explore the demo"], "the welcome's buttons")
(dialog.footer.get_child(2) as Button).pressed.emit()
await _frames(20)
_check(not is_instance_valid(dialog) or dialog.is_queued_for_deletion(), "Explore the demo closes it")

View file

@ -11,6 +11,7 @@ func _init() -> void:
await _test_ranged_target()
await _test_plain_target()
await _test_ports_under_cards()
await _test_card_thread_port()
finish()
@ -31,6 +32,48 @@ func _test_ports_under_cards() -> void:
_check(not ports._covered(low.inlet_point(), low.get_index()), "raised again, its inlet shows")
## Build mode: each card has a port on its bottom edge; a thread laid from it
## is a card thread, drawn from there, listed on the card and undoable.
func _test_card_thread_port() -> void:
main.set_mode(Main.Mode.BUILD)
await _frames(10)
var road := main.data.get_table("road")
var card := main.card_for("road")
main.board.set_zoom(1.0)
main.board.ports.queue_redraw()
await _frames(3)
var grabs: Array = main.board.ports._grab.filter(func(g: Dictionary) -> bool:
return g["tid"] == "road" and g["eid"] == RollTable.OUTLET_ID)
var bottom := card.position + Vector2(card.size.x / 2.0, card.size.y)
_check(grabs.size() == 1 and (grabs[0]["pos"] as Vector2).is_equal_approx(bottom), "a card-thread port on the card's bottom edge")
var target := main.card_for("monsters")
main.start_link("road", RollTable.OUTLET_ID)
main.editing._card_under_mouse_override = target
main.finish_link()
main.editing._card_under_mouse_override = null
_check(road.outlet.pipes.has("monsters"), "the drag made a card thread")
await _frames(3)
var key := Roller.pipe_key("road", RollTable.OUTLET_ID, "monsters")
_check(main.board.pipes._paths.has(key), "it is drawn")
main.inspector.select({"kind": "card", "tid": "road"})
await _frames(2)
_check(_find_text(main.inspector, "After any result → "), "the card section lists it")
main.undo_redo.undo()
await _frames(2)
_check(main.data.get_table("road").outlet.pipes.is_empty(), "undo takes it away")
main.set_mode(Main.Mode.PLAY)
await _frames()
func _find_text(n: Node, prefix: String) -> bool:
if n is Button and (n as Button).text.begins_with(prefix):
return true
for c in n.get_children():
if _find_text(c, prefix):
return true
return false
func _parts(to: String) -> Dictionary:
return main.inspector.pipe_parts.get(to, {})

View file

@ -2,7 +2,7 @@ class_name BoardView
extends Control
## The felt board. Holds a scaled "world" with three layers: pipes behind the
## cards, the cards, and the ports (pipe ends) on top. Drag the felt to pan,
## Ctrl+wheel or pinch to zoom.
## wheel or pinch to zoom (Shift+wheel pans sideways).
## Low enough that Fit shows a whole board of several hundred cards.
const MIN_ZOOM := 0.08
@ -351,12 +351,10 @@ func _gui_input(ev: InputEvent) -> void:
MOUSE_BUTTON_WHEEL_UP, MOUSE_BUTTON_WHEEL_DOWN:
if mb.pressed:
var up := mb.button_index == MOUSE_BUTTON_WHEEL_UP
if mb.ctrl_pressed:
set_zoom(zoom * (1.1 if up else 1.0 / 1.1), mb.position)
elif mb.shift_pressed:
if mb.shift_pressed:
world.position.x += 60.0 if up else -60.0
else:
world.position.y += 60.0 if up else -60.0
set_zoom(zoom * (1.1 if up else 1.0 / 1.1), mb.position)
accept_event()
MOUSE_BUTTON_WHEEL_LEFT, MOUSE_BUTTON_WHEEL_RIGHT:
if mb.pressed:

View file

@ -163,6 +163,8 @@ func _do_sync() -> void:
_sync_queued = false
if _signature() != _sig:
rebuild()
else:
InspectorSync.sync_texts(self)
func _signature() -> String:
@ -188,6 +190,26 @@ func wrote(t: RollTable, all_cards: bool = false, rebuild_panel: bool = false) -
rebuild()
## After the inspector changed one result's text: the card's inline field
## takes the text in place (a rebuild of a long card took ~150 ms per key);
## otherwise as wrote().
func wrote_text(t: RollTable, eid: String) -> void:
var card := main.card_for(t.id)
if card == null or not card.edit_ui.sync_text(eid):
wrote(t)
return
_writing = true
main.local_state._ref_cache.clear()
main.mark_dirty()
_writing = false
_sig = _signature()
card.update_warning()
for f in _live:
if f.is_valid():
f.call()
InspectorFrame.refresh_title(self)
## Applies table settings through TableSettingsDialog.apply_settings (the
## same rules as the settings dialog). Returns "" or the problem.
func apply_settings(over: Dictionary, rebuild_panel: bool = false) -> String:

View file

@ -128,7 +128,7 @@ static func set_entry_text(insp: Inspector, s: String) -> void:
if e and e.text != s:
e.text = s
e.page = ""
insp.wrote(insp.selected_table())
insp.wrote_text(insp.selected_table(), e.id)
static func set_entry_details(insp: Inspector, s: String) -> void:

View file

@ -24,8 +24,15 @@ static func signature(insp: Inspector) -> String:
if t == null or (insp.selection.has("eid") and insp.selected_entry() == null):
return "gone"
var d := t.to_dict()
for k in ["x", "y", "collapsed"]:
for k in ["x", "y", "collapsed", "name"]:
d.erase(k)
# The name and result text change on every key typed on the card; sync_texts() shows it
# without a rebuild (a rebuild of a long card took ~120 ms per key).
if t.kind != RollTable.KIND_ROUTER:
for ed: Variant in d.get("entries", []):
if ed is Dictionary:
(ed as Dictionary).erase("text")
(ed as Dictionary).erase("page")
var parts := PackedStringArray([JSON.stringify(d), insp.main.rules_view(), str(insp.main.mode)])
for x in insp.main.data.tables:
if x.kind == RollTable.KIND_VARIABLE:
@ -39,3 +46,25 @@ static func signature(insp: Inspector) -> String:
if t.is_collection():
parts.append(JSON.stringify(members(insp, t)))
return str(hash("\n".join(parts)))
## Puts the card's name and each result's text into the headings and fields
## (unless a field is being typed in), so the page needs no rebuild for them.
static func sync_texts(insp: Inspector) -> void:
var t := insp.selected_table()
if t == null:
return
if is_instance_valid(insp._title_label):
insp._title_label.text = Inspector._title_of(t.name, "(no name)")
_sync_field(insp.section_parts.get(InspectorList.CARD, {}), "name", t.name)
if t.kind == RollTable.KIND_VARIABLE:
return
for e in t.entries:
InspectorList.refresh_title(insp, e)
_sync_field(insp.section_parts.get(e.id, {}), "text", e.text)
static func _sync_field(parts: Dictionary, key: String, value: String) -> void:
var le: Variant = (parts.get("fields", {}) as Dictionary).get(key)
if le is LineEdit and is_instance_valid(le) and not (le as LineEdit).has_focus() and (le as LineEdit).text != value:
(le as LineEdit).text = value

View file

@ -109,10 +109,11 @@ static func section(insp: Inspector, t: RollTable, e: TableEntry, to: String) ->
InspectorResult.section(insp, t, e)
return
var target := insp.main.data.get_table(to)
insp._content.add_child(insp._head("Selected thread", "%s → %s" % [Inspector._title_of(e.text, "(no text)"), Inspector._title_of(target.name, to) if target else to]))
var back := InspectorKit.link("Edit the whole result", "Show the result this thread leaves from")
var card := e == t.outlet
insp._content.add_child(insp._head("Selected card thread" if card else "Selected thread", "%s → %s" % [source_title(t, e), Inspector._title_of(target.name, to) if target else to]))
var back := InspectorKit.link("Edit the whole card" if card else "Edit the whole result", "Show the card" if card else "Show the result this thread leaves from")
back.add_theme_color_override("font_color", Style.MUTED)
back.pressed.connect(func() -> void: insp.select({"kind": "result", "tid": t.id, "eid": e.id}))
back.pressed.connect(func() -> void: insp.select({"kind": "card", "tid": t.id} if card else {"kind": "result", "tid": t.id, "eid": e.id}))
insp._content.add_child(back)
insp._content.add_child(box(insp, t, e, to))
insp._content.add_child(InspectorKit.field("Thread colour", ColorChoice.new(str(e.pipe_color.get(to, "")), func(h: String) -> void: set_color(insp, h, to))))
@ -205,7 +206,7 @@ static func box(insp: Inspector, t: RollTable, e: TableEntry, to: String) -> Con
when_box.add_child(cond)
v.add_child(when_box)
var other := InspectorKit.check_box("Otherwise", e.is_otherwise(to))
other.tooltip_text = "Runs only when none of this result's \"Only if\" threads is true"
other.tooltip_text = otherwise_tip(t, e)
other.toggled.connect(func(on: bool) -> void: set_otherwise(insp, to, on))
parts["otherwise"] = other
v.add_child(other)
@ -274,6 +275,19 @@ static func box(insp: Inspector, t: RollTable, e: TableEntry, to: String) -> Con
return panel
## What a thread leaves from: the result's text, or "<card> (card thread)".
static func source_title(t: RollTable, e: TableEntry) -> String:
if t != null and e == t.outlet:
return "%s (card thread)" % Inspector._title_of(t.name, "(no name)")
return Inspector._title_of(e.text, "(no text)")
static func otherwise_tip(t: RollTable, e: TableEntry) -> String:
if t != null and e == t.outlet:
return "Runs only when no thread of the card's result ran (and no \"Only if\" card thread was true). Off: runs after every result"
return "Runs only when none of this result's \"Only if\" threads is true"
## Otherwise is off and disabled while the pipe has an Only if.
static func refresh_otherwise(insp: Inspector, to: String) -> void:
var parts: Dictionary = insp.pipe_parts.get(to, {})
@ -285,7 +299,7 @@ static func refresh_otherwise(insp: Inspector, to: String) -> void:
cb.disabled = has_when
cb.set_pressed_no_signal(e.is_otherwise(to))
cb.tooltip_text = "Turn off \"Only if\" first: a thread with a condition isn't an otherwise thread" if has_when \
else "Runs only when none of this result's \"Only if\" threads is true"
else otherwise_tip(insp.selected_table(), e)
static func _chip(text: String, fg: Color, bg: Color) -> Control:

View file

@ -2,26 +2,29 @@ class_name InspectorThreads
extends RefCounted
## The card inspector's "Threads in" and "Threads out" lists: every thread
## leading into the card (from which card and result) and out of it (from
## which result, to which card). Clicking one selects that thread.
## which result, to which card). Card threads (CardThreads) list as "After any
## result" or "If no thread ran". Clicking one selects that thread.
static func build(insp: Inspector, box: VBoxContainer, t: RollTable) -> void:
var board := insp.main.data
var ins := VBoxContainer.new()
for src in board.tables:
for e in src.entries:
for e in src.thread_sources():
if e.pipes.has(t.id):
ins.add_child(_link(insp, src, e, t.id, "%s · %s" % [_name(src.name), _result(e)]))
ins.add_child(_link(insp, src, e, t.id, "%s · %s" % [_name(src.name), _result(src, e, t.id)]))
var outs := VBoxContainer.new()
for e in t.entries:
for e in t.thread_sources():
for to in e.pipes:
var target := board.get_table(to)
outs.add_child(_link(insp, t, e, to, "%s → %s" % [_result(e), _name(target.name) if target else to + " (missing)"]))
outs.add_child(_link(insp, t, e, to, "%s → %s" % [_result(t, e, to), _name(target.name) if target else to + " (missing)"]))
if ins.get_child_count() == 0:
ins.add_child(InspectorKit.note("Nothing leads here yet."))
if outs.get_child_count() == 0:
outs.add_child(InspectorKit.note("No threads leave this card."))
box.add_child(InspectorKit.field("Threads in (%d)" % _count(ins), ins))
if t.outlet.pipes.is_empty():
outs.add_child(InspectorKit.note("To roll another card after any result, drag from the dot on this card's bottom edge (a card thread)."))
box.add_child(InspectorKit.field("Threads out (%d)" % _count(outs), outs))
@ -46,5 +49,9 @@ static func _name(s: String) -> String:
return Inspector._title_of(s, "(no name)")
static func _result(e: TableEntry) -> String:
static func _result(t: RollTable, e: TableEntry, to: String) -> String:
if e == t.outlet:
if e.when_for(to) != "":
return "After any result, if…"
return "If no thread ran" if e.is_otherwise(to) else "After any result"
return Inspector._title_of(e.text, "(no text)")

View file

@ -112,18 +112,18 @@ func _card_row(parent: TreeItem, t: RollTable) -> void:
func _threads_in(tid: String) -> PackedStringArray:
var out := PackedStringArray()
for src in m.data.tables:
for e in src.entries:
for e in src.thread_sources():
if e.pipes.has(tid):
out.append("from %s · %s" % [Formatter.strip_tags(src.name), Formatter.strip_tags(e.text).left(40)])
out.append("from %s · %s" % [Formatter.strip_tags(src.name), "card thread" if e == src.outlet else Formatter.strip_tags(e.text).left(40)])
return out
func _threads_out(t: RollTable) -> PackedStringArray:
var out := PackedStringArray()
for e in t.entries:
for e in t.thread_sources():
for to in e.pipes:
var target := m.data.get_table(to)
out.append("%s → %s" % [Formatter.strip_tags(e.text).left(40), Formatter.strip_tags(target.name) if target else to])
out.append("%s → %s" % ["After any result" if e == t.outlet else Formatter.strip_tags(e.text).left(40), Formatter.strip_tags(target.name) if target else to])
return out

View file

@ -145,6 +145,7 @@ func _ready() -> void:
await get_tree().process_frame
board.fit()
cli._run_cli(args)
WelcomeDialog.maybe_show(self)
func _exit_tree() -> void:
_save_now()

View file

@ -109,6 +109,8 @@ func _run_shell_cli(args: PackedStringArray) -> void:
var more := card.find_children("*", "MenuButton", true, false) if card else []
if not more.is_empty():
(more[0] as MenuButton).show_popup()
if args.has("--welcome"):
WelcomeDialog.open(m)
if args.has("--help") or _arg_value(args, "--help") != "":
m.top_bar.help_menu.open(_arg_value(args, "--help"))
if menu == "add":

View file

@ -6,6 +6,8 @@ extends RefCounted
var m: Main
var _link_from: Dictionary = {}
## Tests only: the card a link drop lands on, instead of the one under the mouse.
var _card_under_mouse_override: TableCard = null
var _drop_card: TableCard
var _add_menu: MenuButton
var _sel_bar: PanelContainer
@ -234,7 +236,10 @@ func remove_pipe(key: String) -> void:
if card:
card.rebuild()
m.undo_redo._end_edit()
m.toast("Deleted thread from “%s” to %s" % [e.text, target.name if target else to], true)
if e == t.outlet:
m.toast("Deleted card thread from %s to %s" % [t.name, target.name if target else to], true)
else:
m.toast("Deleted thread from “%s” to %s" % [e.text, target.name if target else to], true)
func start_link(tid: String, eid: String) -> void:
@ -272,10 +277,15 @@ func finish_link() -> void:
e.add_pipe(over.table.id)
m.card_for(t.id).rebuild()
m.undo_redo._end_edit()
m.toast("“%s” now rolls on %s" % [e.text, over.table.name], true)
if e == t.outlet:
m.toast("After any result of %s, %s rolls" % [t.name, over.table.name], true)
else:
m.toast("“%s” now rolls on %s" % [e.text, over.table.name], true)
func _card_under_mouse() -> TableCard:
if _card_under_mouse_override:
return _card_under_mouse_override
var gp := m.get_global_mouse_position()
var kids := m.board.cards.get_children()
for i in range(kids.size() - 1, -1, -1):

View file

@ -79,5 +79,5 @@ func _light_steps(steps: Array) -> void:
if d > 0 and not (s.has("pass") or s.has("after")) and stack[d - 1] is Dictionary and (stack[d - 1] as Dictionary).has("entry_id"):
var p: Dictionary = stack[d - 1]
var ptid := str(p.get("table_id", ""))
var peid := str(p["entry_id"])
var peid := RollTable.OUTLET_ID if s.get("card_thread", false) else str(p["entry_id"])
m.lit_pipes[Roller.ref_key(ptid, peid, tid) if s.get("inline", false) else Roller.pipe_key(ptid, peid, tid)] = true

View file

@ -94,10 +94,18 @@ func _build_top_bar() -> Control:
seg_row.add_child(_build_button)
h.add_child(seg)
# "SPREAD" over the switcher says what the name is and that it can change.
var spread_box := VBoxContainer.new()
spread_box.size_flags_vertical = Control.SIZE_SHRINK_CENTER
spread_box.add_theme_constant_override("separation", 0)
var caption := Style.make_label("SPREAD", Style.caps(), 10, Style.ON_BG_MUTED)
caption.tooltip_text = "A spread is a set of cards laid out together. Click its name to switch spreads or make a new one."
caption.mouse_filter = Control.MOUSE_FILTER_PASS
spread_box.add_child(caption)
_switcher = CollectionSwitcher.new()
_switcher.size_flags_vertical = Control.SIZE_SHRINK_CENTER
_switcher.setup(m)
h.add_child(_switcher)
spread_box.add_child(_switcher)
h.add_child(spread_box)
_hint = Style.make_label(Main.HINTS[m.mode], Style.body(), 15, Style.ON_BG_MUTED)
_hint.size_flags_horizontal = Control.SIZE_EXPAND_FILL

View file

@ -8,10 +8,11 @@ extends RefCounted
const SAMPLES := 40
## A smooth S-curve from `start` to `end`, as SAMPLES + 1 points.
static func curve(start: Vector2, end: Vector2) -> PackedVector2Array:
## A smooth S-curve from `start` to `end`, as SAMPLES + 1 points. `down`:
## it leaves `start` downwards (a card thread, off a card's bottom edge).
static func curve(start: Vector2, end: Vector2, down: bool = false) -> PackedVector2Array:
var dx := maxf(70.0, absf(end.x - start.x) / 2.0)
var control1 := start + Vector2(dx, 0)
var control1 := start + (Vector2(0, maxf(70.0, absf(end.y - start.y) / 2.0)) if down else Vector2(dx, 0))
var control2 := end - Vector2(dx, 0)
var pts := PackedVector2Array()
for i in SAMPLES + 1:

View file

@ -83,8 +83,8 @@ func _notification(what: int) -> void:
## A smooth curve between two points (PipeGeometry.curve).
static func curve(start: Vector2, end: Vector2) -> PackedVector2Array:
return PipeGeometry.curve(start, end)
static func curve(start: Vector2, end: Vector2, down: bool = false) -> PackedVector2Array:
return PipeGeometry.curve(start, end, down)
func _draw() -> void:
@ -109,7 +109,7 @@ func _draw() -> void:
var src_g: GroupCard = hidden.get(t.id)
if card == null and src_g == null:
continue
for e in t.entries:
for e in t.thread_sources():
var refs := main.ref_targets_for(e)
if e.pipes.is_empty() and refs.is_empty():
continue
@ -131,7 +131,7 @@ func _draw() -> void:
continue # inside one collapsed group
var key := Roller.ref_key(t.id, e.id, to) if is_ref else Roller.pipe_key(t.id, e.id, to)
var end: Vector2 = dst_g.inlet_point() if dst_g else target.inlet_point()
var pts := curve(a["pos"], end)
var pts := curve(a["pos"], end, e == t.outlet and src_g == null)
_paths[key] = pts
var lit := main.lit_pipes.has(key)
var rerouted := src_g != null or dst_g != null

View file

@ -199,7 +199,9 @@ func open(pipe_key: String, at: Vector2) -> void:
return
key = pipe_key
var target := main.data.get_table(_to)
_title.text = "%s [color=#%s]→[/color] [b]%s[/b]" % [RichText.preview(_entry.text, main.data), Style.THREAD.to_html(false), RichText.plain(Formatter.strip_tags(target.name)) if target else _to]
var source := RichText.plain(InspectorThread.source_title(t, _entry)) if _entry == t.outlet else RichText.preview(_entry.text, main.data)
_title.text = "%s [color=#%s]→[/color] [b]%s[/b]" % [source, Style.THREAD.to_html(false), RichText.plain(Formatter.strip_tags(target.name)) if target else _to]
_otherwise.tooltip_text = InspectorThread.otherwise_tip(t, _entry)
_count.text = _entry.count_text(_to)
_count.add_theme_stylebox_override("normal", _save_ok)
_count_msg.hide()

View file

@ -1,7 +1,8 @@
class_name PortLayer
extends Control
## Draws pipe ends on top of the cards: an inlet on each card and an outlet on
## each result. In Build mode, dragging from an outlet lays a new pipe.
## Draws pipe ends on top of the cards: an inlet on each card, an outlet on
## each result and one on each card's bottom edge (card threads). In Build
## mode, dragging from an outlet lays a new pipe.
## Only the ports themselves take mouse input; everything else passes through.
const GRAB_RADIUS := 10.0
@ -11,6 +12,7 @@ var _grab: Array = [] # [{pos, tid, eid}] outlets that can start a pipe
var _linking := false
var _ghost_from := Vector2.ZERO
var _ghost_to := Vector2.ZERO
var _ghost_down := false
var _drawn_rev := -1
var _drawn_hover := -1
var _drawn_mode := -1
@ -103,6 +105,8 @@ func _draw() -> void:
_port(pos, fill, ring, s)
if build:
_grab.append({"pos": pos, "tid": t.id, "eid": e.id})
if t.kind != RollTable.KIND_VARIABLE:
_outlet_port(t, card, build, mouse, below)
if card.more_row != null:
var m := card.anchor_for("")
var on_hidden := card.hidden_has_pipes()
@ -121,7 +125,29 @@ func _draw() -> void:
else:
_port(Vector2(p), Style.THREAD, Style.THREAD_DARK, 1.0)
if _linking:
_draw_ghost(PipeLayer.curve(_ghost_from, _ghost_to))
_draw_ghost(PipeLayer.curve(_ghost_from, _ghost_to, _ghost_down))
## The port on a card's bottom edge for card threads (CardThreads): in Build
## always (drag from it to add one), in Play only when the card has some.
func _outlet_port(t: RollTable, card: TableCard, build: bool, mouse: Vector2, below: int) -> void:
var on := not t.outlet.pipes.is_empty()
var pos: Vector2 = card.anchor_for(RollTable.OUTLET_ID)["pos"]
if not (build or on) or _covered(pos - Vector2(0, 2), below):
return
var fill := Style.THREAD if on else Style.CARD
var ring := Style.THREAD_DARK
var s := 1.0
for to in t.outlet.pipes:
if main.lit_pipes.has(Roller.pipe_key(t.id, RollTable.OUTLET_ID, to)):
fill = Style.ACCENT
ring = Style.ACCENT_DARK
if build and pos.distance_to(mouse) <= GRAB_RADIUS and not _linking:
fill = Style.ACCENT
s = 1.2
_port(pos, fill, ring, s)
if build:
_grab.append({"pos": pos, "tid": t.id, "eid": RollTable.OUTLET_ID})
## Remembers where each visible card sits and how high it is stacked.
@ -167,6 +193,7 @@ func _gui_input(ev: InputEvent) -> void:
if mb.position.distance_to(g["pos"]) <= GRAB_RADIUS:
_linking = true
_ghost_from = g["pos"]
_ghost_down = g["eid"] == RollTable.OUTLET_ID
_ghost_to = mb.position
main.start_link(g["tid"], g["eid"])
accept_event()

View file

@ -8,6 +8,11 @@ extends RefCounted
var card: TableCard
## Build mode: each result's inline text field by result id (refilled on rebuild).
var text_fields: Dictionary = {}
## True while "+ Add result" rebuilds the card: it scrolls to the new (last)
## row instead of the last-rolled one (TableCardRebuild).
var adding := false
func _init(p_card: TableCard) -> void:
@ -44,9 +49,39 @@ func text_edit(e: TableEntry, index: int, chosen: bool) -> LineEdit:
card.main.mark_dirty()
)
edit.focus_entered.connect(func() -> void: card.select_entry(e.id))
text_fields[e.id] = edit
return edit
## After "+ Add result": scrolls the list to the new row and puts the cursor
## in its text field, with the starter text selected so typing replaces it.
func focus_new(eid: String) -> void:
await card.get_tree().process_frame
if not is_instance_valid(card):
return
var edit: LineEdit = text_fields.get(eid)
if is_instance_valid(edit):
edit.grab_focus()
edit.select_all()
## Puts a result's text into its inline field without a rebuild. False when
## the card has no such field (Play mode, or a kind without one).
func sync_text(eid: String) -> bool:
var edit: LineEdit = text_fields.get(eid)
var e := card.table.find_entry(eid)
if not is_instance_valid(edit) or e == null:
return false
if edit.text != e.text:
var caret := edit.caret_column
edit.text = e.text
edit.caret_column = caret
var spell: Variant = edit.get_meta("spell", null)
if spell is SpellUnderline:
(spell as SpellUnderline).recheck()
return true
## Build mode: a click on a row (outside its fields) selects the result for
## the inspector.
func hook_select(row: Control, eid: String) -> void:
@ -243,7 +278,13 @@ func make_footer(ranged: bool) -> Control:
if table.kind == RollTable.KIND_ROLL or (table.kind == RollTable.KIND_CHOICE and table.choice == "pick"):
var label := "+ Add range" if ranged and not RangeWeights.uses_weights(table) else ("+ Add option" if table.kind == RollTable.KIND_CHOICE else "+ Add result")
var add := footer_button(label, Style.INK)
add.pressed.connect(func() -> void: main.add_entry(table.id))
add.pressed.connect(func() -> void:
# The rebuild inside add_entry scrolls to the new row, not the lit one.
adding = true
main.add_entry(table.id)
adding = false
if not table.entries.is_empty():
focus_new(table.entries[-1].id))
h.add_child(add)
elif table.kind == RollTable.KIND_ROUTER:
var addc := footer_button("+ Add case", Style.INK)

View file

@ -13,10 +13,17 @@ func inlet_point() -> Vector2:
return Vector2(card.position.x, card.position.y + TableCard.INLET_Y)
## Where card threads leave (CardThreads): the middle of the bottom edge.
func outlet_point() -> Vector2:
return card.position + Vector2(card.size.x / 2.0, card.size.y)
## Where a pipe leaves this card for an entry: its row, or the "more" row when the
## entry is hidden in a collapsed card. Rows scrolled out of a long list clamp to
## its edge. Returns {} if there's nowhere to anchor.
func anchor_for(eid: String) -> Dictionary:
if eid == RollTable.OUTLET_ID:
return {"pos": outlet_point(), "visible": true}
var row: Control = card.rows.get(eid, card.more_row)
if row == null or not row.is_inside_tree():
return {}

View file

@ -10,14 +10,27 @@ func _init(p_card: TableCard) -> void:
func gui_input(ev: InputEvent) -> void:
# Clicks on the card body shouldn't pan the board; the wheel still passes through.
# Clicks on the card body shouldn't pan the board. The wheel zooms the
# board, except over a list that scrolls: that list keeps it, even at its
# ends, so scrolling past the last result doesn't start zooming.
var mb := ev as InputEventMouseButton
if mb and mb.button_index == MOUSE_BUTTON_LEFT:
card.accept_event()
elif mb and _wheel_in_list(mb):
card.accept_event()
elif open_menu_on(mb):
card.accept_event()
func _wheel_in_list(mb: InputEventMouseButton) -> bool:
if mb.button_index != MOUSE_BUTTON_WHEEL_UP and mb.button_index != MOUSE_BUTTON_WHEEL_DOWN:
return false
var list := card.list_scroll
if mb.ctrl_pressed or mb.shift_pressed or not is_instance_valid(list) or not list.get_v_scroll_bar().visible:
return false
return list.get_global_rect().has_point(card.get_global_mouse_position())
## The grip, then the zoomed-out shield, stay on top of the rebuilt content.
func raise_covers() -> void:
card.move_child(card.grip, -1)

View file

@ -23,6 +23,7 @@ func run() -> void:
card.skin.sync_frame()
card.rows.clear()
card.rows_ui.clear()
card.edit_ui.text_fields.clear()
card.more_row = null
card.list_scroll = null
card.header_ui.clear()
@ -50,7 +51,9 @@ func run() -> void:
card.list_ui.fill(column, build, ranged, collapsed)
_finish(column, build, ranged)
card.skin.dim_drawn()
if card.list_scroll != null:
if card.list_scroll != null and card.edit_ui.adding and not table.entries.is_empty():
card._reveal_when_laid_out.call_deferred(table.entries[-1].id)
elif card.list_scroll != null:
for eid in card.rows:
if main.is_entry_lit(table.id, eid):
card._reveal_when_laid_out.call_deferred(eid)

53
ui/welcome_dialog.gd Normal file
View file

@ -0,0 +1,53 @@
class_name WelcomeDialog
extends RefCounted
## Morgan's welcome on the first launch: what a spread is, where the spread
## switcher is, and three ways to start (explore the demo, a blank spread,
## import one). maybe_show() shows it once (the "welcome_seen" setting);
## open() shows it any time, for a later "Show the welcome again" button.
const SETTING := "welcome_seen"
const MASCOT_PIXELS := 96
## Shows the welcome if it hasn't been seen, then remembers that it has.
## Not in sessions that don't save (tests, screenshots).
static func maybe_show(main: Main) -> void:
if not main._saving_enabled or main.state == null or main.state.get_setting(SETTING, false):
return
main.state.set_setting(SETTING, true)
main.state.save()
open(main)
static func open(main: Main) -> ModalCard:
var dialog := ModalCard.new("Welcome to Table Tarot", 560.0)
var row := HBoxContainer.new()
row.add_theme_constant_override("separation", 18)
var art := MascotArt.texture(ThemeStore.current, MASCOT_PIXELS)
if art:
var picture := TextureRect.new()
picture.texture = art
picture.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
picture.custom_minimum_size = Vector2(MASCOT_PIXELS, MASCOT_PIXELS)
picture.size_flags_vertical = Control.SIZE_SHRINK_BEGIN
row.add_child(picture)
var text := VBoxContainer.new()
text.add_theme_constant_override("separation", 10)
text.size_flags_horizontal = Control.SIZE_EXPAND_FILL
for line in [
"I'm Morgan. Let me show you around.",
"A spread is a set of table cards laid out together, like cards in a tarot reading. Each card is a random table. Threads carry a roll from one card to the next.",
"You're looking at a demo spread. Your own spreads live in the Spread ▾ menu at the top left. Switch between them, or make a new one, there at any time.",
]:
text.add_child(ModalCard.note(line, Style.INK))
row.add_child(text)
dialog.body.add_child(row)
dialog.add_button("Import a spread…", "plain", func() -> void:
dialog.close()
main.collections.import_collection())
dialog.add_button("Start a blank spread", "plain", func() -> void:
dialog.close()
main.new_collection())
dialog.add_button("Explore the demo", "primary", dialog.close)
main._add_modal(dialog)
return dialog

1
ui/welcome_dialog.gd.uid Normal file
View file

@ -0,0 +1 @@
uid://b7fhk4566u234