@anvil-and-loom/the-weave-core
v1.0.0
Published
Core engine for The Weave random table generator
Maintainers
Readme
@the-weave/core
Core engine for The Weave random table generator.
Installation
npm install @the-weave/coreUsage
import { WeaveEngine } from '@the-weave/core';
// Create an engine instance
const engine = new WeaveEngine();
// Load tables
engine.loadTables([
{
id: 'uuid-here',
name: 'Encounters',
tags: ['encounter', 'd20'],
maxRoll: 20,
headers: ['ROLL', 'RESULT'],
tableData: [
{ floor: 1, ceiling: 5, resultType: 'text', result: 'Goblin' },
{ floor: 6, ceiling: 15, resultType: 'text', result: 'Orc' },
{ floor: 16, ceiling: 20, resultType: 'text', result: 'Dragon' },
],
// ... other required fields
}
]);
// Roll on a table (internal RNG)
const result = engine.roll('encounter');
console.log(result.result); // "Goblin", "Orc", or "Dragon"
// Roll with external dice value
const info = engine.getTableInfo('encounter');
console.log(info.diceNotation); // "d20"
// Your dice engine rolls...
const myRoll = 17;
const result2 = engine.roll('encounter', myRoll);
console.log(result2.result); // "Dragon"API
WeaveEngine
| Method | Description |
|--------|-------------|
| loadTables(tables) | Load tables from array |
| getAllTables(filter?) | Get all tables, optionally filtered |
| getTable(idOrTag) | Get table by ID or tag |
| saveTable(table) | Save a table (async) |
| deleteTable(id) | Delete a table (async) |
| duplicateTable(id, newName) | Clone a table |
| getTableInfo(idOrTag) | Get table metadata |
| getAllTags() | Get all unique tags |
| getTablesByTag(tag) | Get tables with tag |
| roll(idOrTag, rollValue?) | Roll on a table |
| rollByTag(tag, rollValue?) | Roll by tag |
| validate(table) | Validate a table |
| parseImport(text, options) | Parse import text |
| exportTable(id, format) | Export as JSON or CSV |
| exportTableToMarkdown(id) | Export table as Markdown |
| exportAllTables() | Export all tables as JSON |
| exportAllTablesToMarkdown() | Export all tables as Markdown |
| onRoll(callback) | Subscribe to roll events |
| onTableSaved(callback) | Subscribe to save events |
| onTableDeleted(callback) | Subscribe to delete events |
| onError(callback) | Subscribe to error events |
Storage Adapters
import { WeaveEngine, FileSystemStorage } from '@the-weave/core';
// Use file system storage (Node.js only)
const engine = new WeaveEngine({
storage: new FileSystemStorage('./data/tables')
});
await engine.initialize(); // Loads tables from diskLicense
MIT
