@dice-roller/rpg-dice-roller / modifiers / ModifierHandler
Interface: ModifierHandler<N> โ
Defined in: src/modifiers/types.ts:60
The behaviour of a modifier.
Handlers are registered by name in the ModifierRegistry, and run in ascending order regardless of notation order; equal orders retain notation order. Implementations should not mutate their input: return a new array, copying changed items with the result helpers. Unchanged items may be reused.
Type Parameters โ
N โ
N extends ModifierNode = ModifierNode
Properties โ
appliesTo โ
readonlyappliesTo: readonlyModifierTarget[]
Defined in: src/modifiers/types.ts:66
Targets on which the evaluator permits this handler.
groupHandling? โ
readonlyoptionalgroupHandling?:"flatten"|"each-pool"
Defined in: src/modifiers/types.ts:82
How the handler treats the dice inside a roll group. By default it only gets the members.
flatten: a group with a single expression gets the dice of every pool in it, flattened, instead of its member (keep, drop:{4d6+2d8}k2keeps the 2 highest dice)each-pool: gets the members of each group, then the dice of each pool, separately (sort: nested members are sorted by total, and the dice within each pool)
Pools in a pool's quantity or die arguments aren't included. Flattening stops at nested groups; with multiple expressions it operates on members instead. Flattened dice are written back to their original pools, so returned dice must retain their pool association (e.g. by copying an input item with object spread). New, unassociated dice cause an EvaluationError. The matching-batch modifier treats every item supplied to it as its initial batch, so earlier modifiers can change its batch size.
name โ
readonlyname:N["name"]
Defined in: src/modifiers/types.ts:62
The existing AST modifier name this handler implements.
order โ
readonlyorder:number
Defined in: src/modifiers/types.ts:64
Execution order; lower runs first.
Methods โ
apply() โ
apply<
T>(items,input):T[] |Generator<EvaluationDrawRequest,T[],number>
Defined in: src/modifiers/types.ts:92
Applies the modifier.
items are die results for a pool, or group members for a group (or die results, as set by groupHandling). Group calls, including calls for their pool dice, do not supply die, rollDie or rollBatch. The evaluator requires an array result. A generator handler may yield die requests through those helpers and resumes with the externally supplied face.
Type Parameters โ
T โ
T extends ScoredItem
Parameters โ
items โ
readonly T[]
input โ
Returns โ
T[] | Generator<EvaluationDrawRequest, T[], number>