event

Event system API functions.

Description

Warp Gate includes a hook-like event system that can be used to respond to stages of the spawning and mutation process. Additionally, the event system is exposed so that users and module authors can create custom events in any context.

Methods


<static> notify( name [, payload [, onBehalf ] ] ) → {Object}

Description

Allow custom events to be fired using the Warp Gate event system. Is broadcast to all users, including the initiator. Like Hooks, these functions cannot be awaited for a response, but all event functions executing on a given client will be evaluated in order of initial registration and the processing of the event functions will respect (and await) returned Promises.

Parameters
Name Type Attributes Default Description
name string

Name of this event. Watches and triggers use this name to register themselves. Like Hooks, any string can be used and it is dependent upon the watch or trigger registration to monitor the correct event name.

payload object <optional>
{sceneId: canvas.scene.id, userId: game.user.id}

eventData {Object} The data that will be provided to watches and triggers and their condition functions.

onBehalf string <optional>
game.user.id

User ID that will be used in place of the current user in the cases of a relayed request to the GM (e.g. dismissal).

Returns

Data object containing the event's payload (execution details), and identifying metadata about this event, sent to all watching and triggering clients.

Details

<static> remove( id )

Description

Removes a watch or trigger by its provided id -- obtained by the return value of watch and trigger.

Parameters
Name Type Description
id number

Numerical ID of the event function to remove.


<static> trigger()

Description

Identical to warpgate.event.watch, except that this function will only be called once, after the condition is met.


<static> watch( name, fn [, condition ] ) → {number}

Description

Similar in operation to Hooks.on, with two exceptions. First, the provided function can be asynchronous and will be awaited. Second, an optional conditionFn parameter is added to help compartmentalize logic between detecting the desired event and responding to said event.

Parameters
Name Type Attributes Default Description
name String

Event name to watch for; It is recommended to use the enums found in warpgate.EVENT

fn function

Function to execute when this event has passed the condition function. Will be awaited

condition function <optional>
()=>true

Optional. Function to determine if the event function should be executed. While not strictly required, as the fn function could simply return as a NOOP, providing this parameter may help compartmentalize "detection" vs "action" processing.

Returns

Function id assigned to this event, for use with warpgate.event.remove

Details