@dice-roller/rpg-dice-roller / Roller
Class: Roller<T, Options> โ
Defined in: src/Roller.ts:80
Rolls notation and keeps a history of the rolls.
For a single roll without a history, use new Roll(notation) instead.
Example โ
const roller = new Roller();
roller.roll("4d6");
roller.roll("2d10+3");
roller.history.total; // e.g. 27
`${roller}`; // e.g. "4d6: [3, 5, 2, 2] = 12; 2d10+3: [4, 8]+3 = 15"Type Parameters โ
T โ
T = string
the output type of the configured presenter
Options โ
Options extends RollerOptions<T> = SyncRollOptions<T>
Constructors โ
Constructor โ
new Roller<
T,Options>(options?):Roller<T,Options>
Defined in: src/Roller.ts:89
Parameters โ
options? โ
Options & RollerOptions<T> = ...
Returns โ
Roller<T, Options>
Properties โ
history โ
readonlyhistory:RollHistory
Defined in: src/Roller.ts:85
Mutable history of rolls made or imported by this roller.
settings โ
readonlysettings:RollSettings<T,ConfiguredDrawMode<Options>>
Defined in: src/Roller.ts:87
Shared by every roll of this roller (and their re-rolls).
Accessors โ
dice โ
Get Signature โ
get dice():
DieRegistry
Defined in: src/Roller.ts:105
Returns โ
generator โ
Get Signature โ
get generator():
NumberGenerator
Defined in: src/Roller.ts:101
Returns โ
limits โ
Get Signature โ
get limits():
RollLimits
Defined in: src/Roller.ts:113
Returns โ
modifiers โ
Get Signature โ
get modifiers():
ModifierRegistry
Defined in: src/Roller.ts:109
Returns โ
presenter โ
Get Signature โ
get presenter():
Presenter<T>
Defined in: src/Roller.ts:97
Returns โ
Presenter<T>
Methods โ
export() โ
Call Signature โ
export(
format?):object
Defined in: src/Roller.ts:180
Exports the history as a JSON-safe object (default), JSON, or UTF-8 base64 JSON. May evaluate uncached min/max totals.
Parameters โ
format? โ
"object"
Returns โ
rolls โ
readonlyrolls: readonlyobject[]
total โ
readonlytotal:EncodedNumber
Can be NaN, e.g. for a history of 1/0 and -1/0.
type โ
readonlytype:"history"
version โ
readonlyversion:1
Call Signature โ
export(
format):string
Defined in: src/Roller.ts:181
Exports the history as a JSON-safe object (default), JSON, or UTF-8 base64 JSON. May evaluate uncached min/max totals.
Parameters โ
format โ
"json" | "base64"
Returns โ
string
Call Signature โ
export(
format):string| {rolls: readonlyobject[];total:EncodedNumber;type:"history";version:1; }
Defined in: src/Roller.ts:182
Exports the history as a JSON-safe object (default), JSON, or UTF-8 base64 JSON. May evaluate uncached min/max totals.
Parameters โ
format โ
"object" | "json" | "base64"
Returns โ
string
Type Literal โ
{ rolls: readonly object[]; total: EncodedNumber; type: "history"; version: 1; }
rolls โ
readonlyrolls: readonlyobject[]
total โ
readonlytotal:EncodedNumber
Can be NaN, e.g. for a history of 1/0 and -1/0.
type โ
readonlytype:"history"
version โ
readonlyversion:1
import() โ
import(
data):Roll<T,ConfiguredDrawMode<Options>>[]
Defined in: src/Roller.ts:197
Imports a roll, a whole history or concise finished results (an object, JSON or base64), and adds the rolls to the history, without rolling.
The data is validated first, so nothing is added if any of it is invalid. Imported rolls share this roller's settings for later re-rolls; re-rolling does not add the new roll to the history.
Parameters โ
data โ
string | ConciseRollData | EncodedExportData
Returns โ
Roll<T, ConfiguredDrawMode<Options>>[]
the imported rolls
Throws โ
the data is invalid
parse() โ
parse(
notation):ExpressionNode
Defined in: src/Roller.ts:118
Parses notation into the AST, without rolling.
Parameters โ
notation โ
string
Returns โ
present() โ
Call Signature โ
present():
T
Defined in: src/Roller.ts:173
Presents the history with the presenter, or the one from the options (default TextPresenter).
Returns โ
T
Call Signature โ
present<
U>(presenter):U
Defined in: src/Roller.ts:174
Presents the history with the presenter, or the one from the options (default TextPresenter).
Type Parameters โ
U โ
U
Parameters โ
presenter โ
Presenter<U>
Returns โ
U
roll() โ
Call Signature โ
roll(
input,options):Promise<Roll<T,"async">>
Defined in: src/Roller.ts:123
Rolls notation (or an AST), and adds the roll to the history only if it succeeds. Async rolls are appended in completion order. Per-roll data replaces the roller's defaults and is snapshotted for the roll.
Parameters โ
input โ
string | ExpressionNode
options โ
AsyncRollCallOptions
Returns โ
Promise<Roll<T, "async">>
Call Signature โ
roll(
input,options):Roll<T,"sync">
Defined in: src/Roller.ts:127
Rolls notation (or an AST), and adds the roll to the history only if it succeeds. Async rolls are appended in completion order. Per-roll data replaces the roller's defaults and is snapshotted for the roll.
Parameters โ
input โ
string | ExpressionNode
options โ
SyncRollCallOptions
Returns โ
Roll<T, "sync">
Call Signature โ
roll(
this,input,options?):RollResultForMode<T,ConfiguredDrawMode<Options>>
Defined in: src/Roller.ts:131
Rolls notation (or an AST), and adds the roll to the history only if it succeeds. Async rolls are appended in completion order. Per-roll data replaces the roller's defaults and is snapshotted for the roll.
Parameters โ
this โ
Roller<T, Options>
input โ
string | ExpressionNode
options? โ
Omit<RollCallOptions, "drawDie">
Returns โ
RollResultForMode<T, ConfiguredDrawMode<Options>>
Call Signature โ
roll(
input,options):Promise<Roll<T,"async">> |Roll<T,"sync">
Defined in: src/Roller.ts:136
Rolls notation (or an AST), and adds the roll to the history only if it succeeds. Async rolls are appended in completion order. Per-roll data replaces the roller's defaults and is snapshotted for the roll.
Parameters โ
input โ
string | ExpressionNode
options โ
RollCallOptions
Returns โ
Promise<Roll<T, "async">> | Roll<T, "sync">
toString() โ
toString():
string
Defined in: src/Roller.ts:211
Always the default TextPresenter output of the history.
Returns โ
string