new MutationStack()

Description

The following class and its utility methods allows safer and more direct modification of the mutation stack, which is stored on a token's actor. This mutation stack stores the information needed to revert the changes made by a mutation. This could be used, for example, to deal with rollover damage where the hit point value being reverted to is lower than when the mutation was first applied.

Searching and querying a given mutation is a quick, read-only process. When the mutation stack is modified via one of its class methods, the actor's mutation data at that point in time will be copied for fast, local updates.

No changes will be made to the actor's serialized data until the changes have been commited (MutationStack#commit). The MutationStack object will then be locked back into a read-only state sourced with this newly updated data.

Details

Classes


new MutationStack()

Members


last :MutationData

Description

Retrieves that last mutation added to the mutation stack (i.e. the "newest"), or undefined if none present


stack :Array.<MutationData>

Description

Mutation stack according to its lock state.

Details
Array.<MutationData>

Methods


<async> commit() → {Promise.<MutationStack>}

Description

Updates the owning actor with the mutation stack changes made. Will not commit a locked buffer.

Returns

self, locked for writing

Details

deleteAll( [ filterFn ] ) → {MutationStack}

Description

Deletes all mutations from this actor's stack, effectively making the current changes permanent.

Parameters
Name Type Attributes Default Description
filterFn function <optional>
() => true

Optional function returning a boolean indicating if this element should be delete. By default, deletes all elements of the mutation stack.

Returns

self, unlocked for writing and updates staged.

Details

find( predicate ) → {MutationData|undefined}

Description

Searches for an element of the mutation stack that satisfies the provided predicate

Parameters
Name Type Description
predicate FilterFn

Receives the argments of Array.prototype.find and should return a boolean indicating if the current element satisfies the predicate condition

Returns

Element of the mutation stack that matches the predicate, or undefined if none.

Details

getName( name ) → {MutationData|undefined}

Description

Retrieves an element of the mutation stack that matches the provided name

Parameters
Name Type Description
name String

Name of mutation (serves as a unique identifier)

Returns

Element of the mutation stack matching the provided name, or undefined if none

Details

update( name, data, options ) → {MutationStack}

Description

Updates the mutation matching the provided name with the provided mutation info. The mutation info can be a subset of the full object if (and only if) overwrite is false.

Parameters
Name Type Description
name string

name of mutation to update

data MutationData

New information, can include 'name'.

options object
Name Type Attributes Default Description
overwrite boolean <optional>
false

default will merge the provided info with the current values. True will replace the entire entry and requires at least the 'name' field.

Returns

self, unlocked for writing and updates staged if update successful

Details

updateAll( transform [, filterFn ] ) → {MutationStack}

Description

Applies a given change or tranform function to the current buffer, unlocking if needed.

Parameters
Name Type Attributes Default Description
transform MutationData | function

Object to merge or function to generate an object to merge from provided MutationData

filterFn FilterFn <optional>
() => true

Optional function returning a boolean indicating if this element should be modified. By default, affects all elements of the mutation stack.

Returns

self, unlocked for writing and updates staged.

Details

Type Definitions


FilterFn( mutation ) → {boolean}

Parameters
Name Type Description
mutation MutationData
Returns

provided mutation meets criteria

Details
function