Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ Successor to [Oracle](https://github.com/script-wizards/oracle).
|---|---|
| `packages/engine` | `@scriptwizards/perhaps-engine`: parser + roller, no dependencies, no platform APIs |
| `packages/cli` | `perhaps <file.md> [table]`, `--list`, `--seed n` |
| `packages/obsidian` | Obsidian plugin (in progress) |
| `packages/obsidian` | Obsidian plugin: palette roll, insert at cursor, live code block rollers |
| `packages/web` | single-file demo page, deployed to [perhaps.sh](https://perhaps.sh) |

## Development

Expand Down
3 changes: 2 additions & 1 deletion packages/engine/src/roll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import type {

const MAX_DEPTH = 10;
const REROLL_ATTEMPTS = 5;
const REF_PATTERN = /^([A-Za-z0-9_-]+)(?:\.(selectUnique|selectMany)\((\d+)\))?$/;
const REF_PATTERN =
/^([A-Za-z0-9_-]+(?:\s+[A-Za-z0-9_-]+)*)(?:\.(selectUnique|selectMany)\((\d+)\))?$/;
const DICE_PATTERN = /\b(\d+)[dD](\d+)([+-]\d+)?\b/g;
const RANGE_PATTERN = /^(\d+)\s*-\s*(\d+)$/;
const LIST_SEPARATOR = ", ";
Expand Down
9 changes: 9 additions & 0 deletions packages/engine/test/roll.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,15 @@ describe("cross-table references", () => {
const roller = new Roller([encounters, treasure], sequence(0));
expect(roller.roll(encounters).text).toBe("wolves guarding a gem");
});

it("accepts spaces in ref names, normalized to hyphens", () => {
const encounters = table("output\n overheard: [tavern trouble]\n");
const tavern = table("title\n Tavern Trouble\noutput\n a brawl\n");
const roller = new Roller([encounters, tavern], sequence(0));
const result = roller.roll(encounters);
expect(result.text).toBe("overheard: a brawl");
expect(result.errors).toEqual([]);
});
});

describe("safety", () => {
Expand Down
27 changes: 21 additions & 6 deletions packages/obsidian/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
# perhaps (Obsidian plugin)

Not yet implemented. Planned surfaces, in build order:
Rolls perhaps/perchance tables anywhere in your vault. Three surfaces:

1. Command palette: "Roll a table" via SuggestModal over every table in the vault.
2. Reading-view code block processor: `perhaps`/`perchance` blocks render as live rollable widgets.
3. Insert-roll-at-cursor command for session logging.
4. Sidebar roller view with history.
- **Roll a table**: fuzzy picker over every table in the vault, result in a
modal. Click any underlined part to reroll just that part.
- **Roll a table into the note**: same picker, inserts the result at the
cursor. Meant for session logs.
- Reading view: ```` ```perhaps ```` and ```` ```perchance ```` code blocks
render as live rollers with reroll and copy.

The engine lives in `@scriptwizards/perhaps-engine` and has no platform dependencies.
The vault is indexed on load and kept current as files change, so tables can
reference each other across notes by title.

Syntax lives in [SPEC.md](../../SPEC.md). The engine is
`@scriptwizards/perhaps-engine`, no platform dependencies.

## Install into a vault

```bash
just plugin-install path/to/vault
```

Then enable Perhaps under Settings, Community plugins. Still to build: a
sidebar roller view with history.