@dice-roller/rpg-dice-roller / dice / DieRegistry
Class: DieRegistry โ
Defined in: src/dice/DieRegistry.ts:36
Die factories by name.
A pool's die is a DieNode ({ name, args }), and the evaluator creates the die with registry.create(name, ...args). The grammar uses the built-in names (d6 -> standard(6), d% -> percentile(), dF.1 -> fudge(1)), so registering a factory with a built-in name changes what that notation rolls, for every roll using this registry.
Pass a registry as the dice option to a Roll or Roller. Registering a new name does not extend the notation grammar: use an AST such as ast.pool(1, ast.die("fib")) for custom names. The AST stores the name and arguments, not the factory; provide the same registration when re-rolling an imported expression that uses a custom name.
Constructors โ
Constructor โ
new DieRegistry():
DieRegistry
Defined in: src/dice/DieRegistry.ts:40
A registry with the built-in factories: standard, percentile, fudge, range, face.
Returns โ
DieRegistry
Accessors โ
names โ
Get Signature โ
get names(): readonly
string[]
Defined in: src/dice/DieRegistry.ts:56
The registered names, in alphabetical order.
Returns โ
readonly string[]
Methods โ
create() โ
create(
name, ...args):DieLike
Defined in: src/dice/DieRegistry.ts:120
Creates a die with the named factory, e.g. registry.create("standard", 6).
Parameters โ
name โ
string
args โ
...number[]
Returns โ
Throws โ
no factory is registered with the name
Throws โ
any error raised by the factory is propagated
get() โ
get(
name):DieFactory|undefined
Defined in: src/dice/DieRegistry.ts:80
The factory registered with the name, e.g. registry.get("standard")?.(6).
Parameters โ
name โ
string
Returns โ
DieFactory | undefined
getOrThrow() โ
getOrThrow(
name):DieFactory
Defined in: src/dice/DieRegistry.ts:89
Returns the factory registered with the name.
Parameters โ
name โ
string
Returns โ
Throws โ
no factory is registered with the name
has() โ
has(
name):boolean
Defined in: src/dice/DieRegistry.ts:100
Whether a factory is registered with the name.
Parameters โ
name โ
string
Returns โ
boolean
register() โ
register(
name,factory):this
Defined in: src/dice/DieRegistry.ts:65
Registers a factory, replacing any already registered with the same name.
Parameters โ
name โ
string
factory โ
Returns โ
this
Throws โ
the name isn't a string or is empty, or the factory isn't a function
remove() โ
remove(
name):boolean
Defined in: src/dice/DieRegistry.ts:110
Removes the factory registered with the name. Notation that uses a removed built-in (e.g. d6 after removing standard) then throws when it's rolled.
Parameters โ
name โ
string
Returns โ
boolean
whether a factory was registered with the name
empty() โ
staticempty():DieRegistry
Defined in: src/dice/DieRegistry.ts:47
A registry with no factories, not even the built-ins.
Returns โ
DieRegistry