Implements docs/PLAIN.md sections 1-5 (the engine half of the usability pass): - core/describe.gd (Describe): rules in plain words, labelled from variable cards, collections and card inputs, falling back to the original text. - core/builder.gd (Builder): effect and condition models that round-trip with the rule text, a rule tokenizer, and known_values(board). - Collections: variable cards with var_type "collection" label their members and don't declare their stem. - Check cards (kind "check"): dice + modifier vs target, Success/Failure, chain values nat/total/effect, node "check" info, lint and static checks. - Card inputs and pipe "with" values, scoped over the pipe's subtree on the explicit work stack (OP_RESTORE frames), with defaults and snapshot evaluation. - nat on every roll-table roll; dice faces recorded through ctx.faces. - Why trace: facts on nodes and steps (input, roll, check, case, show_if, options_where, effect, when, otherwise). - StateStore rules_view setting; JSON for the new keys; LOGIC.md and PLAIN.md updated (deviations in PLAIN.md 5a). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
143 lines
9.7 KiB
Markdown
143 lines
9.7 KiB
Markdown
# TableTower: Plain Build (usability pass)
|
||
|
||
**Status:** Spec · **Branch:** `plain-build` · **Mockup:** https://claude.ai/code/artifact/caad5536-59a0-4b74-9c0d-b3024a9767c1
|
||
|
||
**Goal:** a person can build logic boards without learning the rule language, and anyone
|
||
can read a board and see why a roll went the way it did.
|
||
|
||
**Constraint:** the stored format stays the rule text from `docs/LOGIC.md`, so old boards
|
||
open unchanged and power users can always edit as text. Everything here is a layer in
|
||
front of it. New keys are additive.
|
||
|
||
## 1. Describe: rules in plain words (`core/describe.gd`, class `Describe`)
|
||
Pure functions that turn stored rules into short phrases. They use value labels
|
||
(§3) and fall back to the original text for anything they can't parse.
|
||
|
||
| Function | Input | Example output |
|
||
|---|---|---|
|
||
| `effect(stmt, board) -> String` | one effect statement | `@luck -= 1` → "Luck −1"; `@skill_pilot += 1` → "Pilot +1"; `@town = "Millbrook"` → "Town = Millbrook"; `reset @skill_*` → "Clear all Skills"; `@[option] += 1` → "Chosen skill +1" (or "Chosen value +1" outside a skills collection) |
|
||
| `effects(text, board) -> Array[String]` | effects field | one phrase per statement |
|
||
| `condition(expr, board) -> String` | a `when` / `show_if` / `options_where` / loop rule | `@str >= 8` → "Strength is 8 or more"; `@x = 0 and @soc >= 9` → "X is 0 and Social Standing is 9 or more"; `has(@traits, "Psionic")` → "Traits include Psionic" |
|
||
| `dice(expr, board) -> String` | dice / count expression | `2d6 + dm(@str)` → "2D + Strength modifier"; `1d6 + tier` → "1D + Tier" |
|
||
| `options(table, board) -> String` | dynamic pick source | "your Skills, level 1 or more" |
|
||
| `pipe(entry, target_id, board) -> String` | a pipe's label | "Tier 3 · only if Luck is 2 or more", "otherwise", "×2 · saves Weapon" |
|
||
| `check(table, board) -> String` | a Check card | "Roll 2D + Strength modifier, need 8 or more" |
|
||
| `why(fact, board, plain := true) -> String` | one trace fact (§5) | "Skipped Tier 3 because Luck was 1 (needs 2 or more)" |
|
||
|
||
Comparisons read as "is", "is not", "is at least", "is at most", "is more than" and "is less
|
||
than". `>= N` reads "is N or more" when it sits after a value name.
|
||
|
||
## 2. Builders: structured models that round-trip with text (`core/builder.gd`, class `Builder`)
|
||
- `parse_effect(stmt) -> {ok, op, var, amount}`
|
||
- `op` is one of `set`, `add`, `subtract`, `multiply`, `divide`, `reset`, `append` or `remove`.
|
||
- `var` may be `@name`, `@prefix_*` (reset only) or `@[option]`.
|
||
- `ok: false` means the statement doesn't fit the builder, so the UI shows it as text.
|
||
- `effect_text(model) -> String` is the inverse. `parse_effect(effect_text(m))` must equal `m`.
|
||
- `parse_condition(expr) -> {ok, join: "and"|"or", clauses: [{var, cmp, value}]}`
|
||
- `cmp` is one of `eq`, `ne`, `ge`, `le`, `gt`, `lt`, `has` (list contains), `set` or `unset`.
|
||
- `value` is a number, quoted text, or another `@name`.
|
||
- Mixed and/or, function calls other than `has`, and dice give `ok: false`.
|
||
- `condition_text(model) -> String` is the inverse.
|
||
- `known_values(board) -> Array[{name, label, kind, source}]`: every value the board uses.
|
||
- `kind` is `number`, `text`, `list` or `collection`.
|
||
- Sources: variable cards, collections, effect targets, `save_as`, card inputs, and chain names (`answer`, `option`, `i`, `total`, `nat`, `effect`).
|
||
- It's used by value pickers, with variable-card labels first.
|
||
|
||
## 3. Value labels and collections
|
||
- **Labels.** A value's label comes from its variable card's name, then from the collection
|
||
it belongs to (`skill_gun_combat` in the Skills collection reads "Gun Combat"), and otherwise
|
||
from a pretty form of its name (`soc` → "Soc"). A label table for common short names
|
||
(`str` → "Strength") isn't built in; variable cards are how boards name things.
|
||
- **Collection** is a variable card with `var_type: "collection"`. Its `var_name` is the stem
|
||
(e.g. `skill`), its name is the label ("Skills"), and its members are the board values
|
||
`@<stem>_<item>`.
|
||
- On the board it shows a list editor: members with their values, plus "+ Add".
|
||
- `options_from: "@skill_*"` reads "your Skills".
|
||
- `count("skill_")` and `{@skill_*}` work as before.
|
||
- `Describe` uses the collection to label its members.
|
||
|
||
## 4. New engine features
|
||
1. **Check card** (`kind: "check"`).
|
||
- Fields: `check_dice` (default `"2d6"`), `check_mod` (an expression, default `""`, e.g.
|
||
`dm(@str)`), `check_cmp` (`ge`, the default, or `le`) and `check_target` (an expression,
|
||
default `"8"`).
|
||
- Two fixed entries: **Success** (index 0) and **Failure** (index 1), each with effects and pipes.
|
||
- Rolling sets the chain variables `nat` (the dice alone), `total` (dice plus modifier) and
|
||
`effect` (total minus target).
|
||
- The node gets `check: {nat, mod, total, target, success}`. It counts as one action.
|
||
2. **Card inputs (pipe parameters).**
|
||
- A table may declare `inputs: [{name, label, default}]`.
|
||
- A pipe object may carry `with: {name: "<expr>"}`. The expressions are evaluated in the
|
||
entry's snapshot (LOGIC §3a), with the other pipe values.
|
||
- While that pipe's subtree runs, each input is a chain value (`tier`, `{tier}` in text).
|
||
When the subtree ends, the previous values come back. Two pipes to the same card can pass
|
||
different values.
|
||
- Missing inputs use their default. A roll that starts on the card uses the defaults.
|
||
- JSON: `inputs` on tables and `with` on pipe objects.
|
||
3. **`nat`** is also set on every dice roll of a roll table (the dice part only), so
|
||
"natural 2" rules can test `nat = 2`.
|
||
4. **Why trace.** Every node gets `why: Array[Dictionary]` facts, recorded by the roller:
|
||
- `roll`: dice faces, modifier and total.
|
||
- `check`.
|
||
- `when`: the pipe, the expression, the values it read, and the result.
|
||
- `otherwise`.
|
||
- `case` (router): the case tried, its values and its result.
|
||
- `show_if` / `options_where` (summarized).
|
||
- `effect`: before and after.
|
||
- `input`: name and value.
|
||
|
||
`Describe.why` turns each fact into a sentence. Steps from `Roller.flatten` carry the facts.
|
||
Facts are plain data and survive JSON (history).
|
||
|
||
## 5. Display preference
|
||
`state` setting `rules_view`: `"plain"` (default) or `"text"`. Everywhere a rule is shown,
|
||
the UI uses `Describe` in plain mode and the stored text in text mode.
|
||
|
||
## 5a. Engine notes and deviations (phase 1)
|
||
The engine half (§1–§5) is built; LOGIC.md §3c, §3d, §5.1 (collections), §9 and §10 have the
|
||
details. Where it settles something the spec left open, or differs:
|
||
- **Builder models.** `amount` is the expression text as written (`"2d6"`, `"\"Millbrook\""`),
|
||
except for `append`/`remove`, where it is the item text without quotes (`"Psionic"`);
|
||
`append`/`remove` are `+=`/`-=` with one quoted text. Condition `value`s are the token as
|
||
written (a String: `"8"`, `"-2"`, `"\"Aslan\""`, `"@soc"`, a chain name, `true`/`false`).
|
||
Both models also accept chain names as `var` (`option_value >= 1`, `tier = 3`), which dynamic
|
||
options and inputs need. An empty condition parses to `{ok: true, join: "and", clauses: []}`.
|
||
- **`known_values`** items also have `table_id`, and members of a collection `collection`
|
||
(`"@skill_*"`); a value that is only read by some rule has source `read`. Chain names are
|
||
listed only when the board has a card that sets them.
|
||
- **Labels.** `le` reads "is at most N" and `ge` "is N or more" (as specified); a check card
|
||
reads "need N or more" / "need N or less". `Describe.effect()`/`effects()` take an optional
|
||
card, so `@[option] += 1` on a pick card taking options from a collection reads "Chosen
|
||
skill +1". `Describe.label(name, board)` is public.
|
||
- **Check cards.** `effect` is total minus target for both comparisons (negative on a roll-under
|
||
success). A dice, modifier or target expression that fails stops the node ("Can't roll the
|
||
check: …") rather than counting as a failure.
|
||
- **`nat`** on weighted and card-mode tables is the die value; an expression with no dice leaves
|
||
`nat` alone.
|
||
- **Inputs.** Defaults are expressions (quote text; empty means 0). Inputs are bound however the
|
||
card is reached (pipe, inline reference, start of the roll), and a `with` name the card
|
||
doesn't declare is still passed (and linted as a hint).
|
||
- **Why facts** are described in LOGIC.md §10. `show_if` and `options_where` are one summary
|
||
fact each; a node without facts has no `why` key.
|
||
- **Collections.** `RollTable.create("variable", …, "collection")` takes the stem from the name
|
||
without a final "s" ("Skills" → `skill`). A collection card doesn't declare `@skill` itself.
|
||
The settings dialog's Type switch gained a "Collection" choice so such cards stay editable.
|
||
- **Display preference.** `StateStore.rules_view()` / `rules_plain()` / `set_rules_view()` read
|
||
and write the `rules_view` setting.
|
||
|
||
## 6. UI (phase 2)
|
||
- **Inspector** (Build mode): a panel docked right that edits the selected card, result or pipe.
|
||
- **Results:** text, details, and a **When this comes up** effects builder (rows of
|
||
`[op] [amount] [to/from] [value ▾]`).
|
||
- **Then go to:** one box per pipe with inputs, **Only if** (condition builder rows of
|
||
`[value ▾] [comparison ▾] [amount]`, plus and/or), **Otherwise**, count and save as.
|
||
- **Cards:** kind-specific fields (check dice, modifier picker and target; collection members;
|
||
declared inputs; options source as "from [collection ▾] where [condition]"; and so on).
|
||
- A value picker lists `known_values` with search and "+ New value…".
|
||
- "Edit as text" on any builder switches it to the text field, and back when it parses.
|
||
- **Display:**
|
||
- Plain chips for effects, plain pipe labels, router cases, choice option sources and loop rules.
|
||
- Check, collection and input visuals on the cards.
|
||
- "Why this?" on tray chips and in step hover.
|
||
- Plain previews in the choice pop-up.
|
||
- A **Plain words / Text** switch.
|