new TrappedRoomManager()

Manages access to the trapped rooms, storing handlers and properties for each plugin.

Description

Manages access to the trapped rooms, storing handlers and properties for each plugin.

Properties
Name Type Description
eventStateValidators Object.<string, Object.<number, Array.<function()>>>

Array of event state validators for each plugin and handler.

functionReflector FunctionReflector

FunctionReflector used to analyze event handler functions.

handlerExecutionOrders Object.<string, Array.<number>>

Array of plugin IDs in execution order for each handler.

handlerNames Set.<string>

Known event handler names.

handlers Object.<number, Object.<string, function()>>

Event handlers for each plugin.

handlersDirty boolean

Whether handlers have been changed since the last call to TrappedRoomManager#determineExecutionOrders.

postEventHandlerHooks Object.<string, Object.<number, Array.<function()>>>

Array of post-event handler hooks for each plugin and handler.

preEventHandlerHooks Object.<string, Object.<number, Array.<function()>>>

Array of pre-event handler hooks for each plugin and handler.

properties Object.<number, Object.<string, *>>

Properties for each plugin.

room HhmRoomObject

Associated room object.

Details

document where certain events are triggered

Methods


constructor( room )

Creates a trapped room manager for the given room.

Description

Creates a trapped room manager for the given room.

Parameters
Name Type Description
room HhmRoomObject

Room object.


<private> _addVertices( vertices, pluginId, handlerName, orderProperty )

Helper function to add vertices for execution orders.

Description

Helper function to add vertices for execution orders.

This function adds one vertex for each plugin name in the execution order Array for the given plugin ID, handler name and order property.

Parameters
Name Type Description
vertices Array.<Array.<number, number>>

Array of vertices which will be extended in this function. A vertex is an array of two plugin IDs: [pluginToBeExecutedBefore, pluginToBeExecutedAfter].

pluginId number

Plugin ID.

handlerName string

Handler name.

orderProperty string

One of "before" or "after".


<private> _executeHandler( handler, pluginName, metadata, ...args )

Executes the given handler.

Description

Executes the given handler.

Parameters
Name Type Attributes Description
handler function | Object | Array

The handler function, or collection of functions in an iterable object.

pluginName string

Name of the plugin.

metadata EventHandlerExecutionMetadata

Event metadata.

args * <repeatable>

Event arguments.


<private> _isPluginEnabledAndLoaded( pluginId ) → {boolean}

Returns whether the plugin with the given ID is both enabled and loaded.

Description

Returns whether the plugin with the given ID is both enabled and loaded.

Parameters
Name Type Description
pluginId number

Plugin ID.

Returns

Whether the plugin is enabled.

TODO remove


<private> _isValidEventState( handlerName, metadata, ...args ) → {boolean}

Checks event state validity.

Description

Checks event state validity.

An event state is valid unless one of the event state validators returns false, in which case further event handler execution is aborted for the given event.

Parameters
Name Type Attributes Description
handlerName string

Event handler name.

metadata EventHandlerExecutionMetadata

Event metadata.

args * <repeatable>

Event arguments.

Returns

false if one of the event state validators returned false, true otherwise.


<private> _provideHandler( pluginId, handlerName )

Makes sure the given handler name is registered so that pre- and post-event handler hooks for that handler are executed.

Description

Makes sure the given handler name is registered so that pre- and post-event handler hooks for that handler are executed.

Parameters
Name Type Description
pluginId number

Plugin ID.

handlerName string

Event handler name.


<private> _provideHandlerObjectForIdentifier( pluginId )

Helper function to make sure there's a handler for each plugin ID.

Description

Helper function to make sure there's a handler for each plugin ID.

This is not done once for all plugins but instead every time the handlers are accessed to make it possible to load additional plugins at runtime later on.

Parameters
Name Type Description
pluginId number

Plugin ID.


<private> _providePropertyObjectForIdentifier( pluginId )

Helper function to make sure there's a property holder for each plugin ID.

Description

Helper function to make sure there's a property holder for each plugin ID.

This is not done once for all plugins but instead every time the properties are accessed to make it possible to load additional plugins at runtime later on.

Parameters
Name Type Description
pluginId number

Plugin ID.


determineExecutionOrders( pluginIds, handlerName ) → {Array.<number>}

Determine execution order for the given plugins and handler name.

Description

Determine execution order for the given plugins and handler name.

Parameters
Name Type Description
pluginIds Array.<number>

Array of plugin IDs for which the execution order is to be determined.

handlerName string

Name of the event handler.

Returns

Given plugin IDs sorted for proper execution order.


determineExecutionOrders()

Determines the execution order for all plugins and handlers.

Description

Determines the execution order for all plugins and handlers.


getEventHandlerNames( _, pluginId ) → {Array.<string>}

Returns the event handler names for the given plugin.

Description

Returns the event handler names for the given plugin.

Parameters
Name Type Description
_ *

Unused.

pluginId number

Plugin ID.

Returns

Event handler names for the given plugin.


getPropertyNames( _, pluginId ) → {Array.<string>}

Returns the properties (not event handlers) registered for the given plugin.

Description

Returns the properties (not event handlers) registered for the given plugin.

To get both properties and event handlers, use Object.getOwnPropertyNames.

Parameters
Name Type Description
_ *

Unused.

pluginId number

Plugin ID.

Returns

Property names for the given plugin.


hasEventHandlers( _, pluginId ) → {boolean}

Returns whether there are event handlers registered for the given plugin.

Description

Returns whether there are event handlers registered for the given plugin.

Parameters
Name Type Description
_ *

Unused.

pluginId number

Plugin ID.

Returns

Whether there are event handlers registered for the given plugin.


hasProperties( _, pluginId ) → {boolean}

Returns whether there are properties registered for the given plugin.

Description

Returns whether there are properties registered for the given plugin.

Note that global properties of the proxied room are NOT taken into account, as are properties starting with an underscore.

Parameters
Name Type Description
_ *

Unused.

pluginId number

Plugin ID.

Returns

Whether there are properties registered for the given plugin


onEventHandlerGet( _, handlerName, pluginId ) → {function|undefined}

Returns the event handler registered for the given handler and plugin ID, or undefined if none is registered.

Description

Returns the event handler registered for the given handler and plugin ID, or undefined if none is registered.

Parameters
Name Type Description
_ *

Unused.

handlerName string

Name of the event handler.

pluginId number

Plugin ID.

Returns

Event handler function or undefined if no such function is registered for the given plugin.


onEventHandlerHas( _, handlerName, pluginId ) → {boolean}

Returns whether there is an event handler registered for the given handler and plugin.

Description

Returns whether there is an event handler registered for the given handler and plugin.

Parameters
Name Type Description
_ *

Unused.

handlerName string

Event handler name.

pluginId number

Plugin ID.

Returns

whether there is an event handler registered for the given handler and plugin.


onEventHandlerSet( _, handlerName, handler, pluginId )

Registers the given handler function for the given handler name and plugin ID.

Description

Registers the given handler function for the given handler name and plugin ID.

Parameters
Name Type Description
_ *

Unused.

handlerName string

Event handler name.

handler *

Event handler function or object

pluginId number

Plugin ID.

Details

handle onGameTick differently


onEventHandlerUnset( _, handlerName, pluginId )

Removes the registered event handler for the given handler and plugin name.

Description

Removes the registered event handler for the given handler and plugin name.

Parameters
Name Type Description
_ *

Unused.

handlerName string

Event handler name.

pluginId number

Plugin ID.


onPropertyHas( _, propertyName, pluginId ) → {boolean}

Returns whether the given property exists for the given plugin.

Description

Returns whether the given property exists for the given plugin.

Note that global properties of the proxied room are taken into account as well so long as they don't start with an underscore.

Parameters
Name Type Description
_ *

Unused.

propertyName string

Name of the property.

pluginId number

Plugin ID.

Returns

Whether the given property exists for the given plugin.


onOwnHandlerNamesGet( _, pluginId ) → {Array.<string>}

Returns an array of handlers registered for the given plugin ID.

Description

Returns an array of handlers registered for the given plugin ID.

Parameters
Name Type Description
_ *

Unused.

pluginId number

Plugin ID.

Returns

Names of the registered handlers for the given plugin.


onOwnPropertyNamesGet( _, pluginId ) → {Array.<string>}

Returns an array of properties (including event handlers) registered for the given plugin ID.

Description

Returns an array of properties (including event handlers) registered for the given plugin ID.

Properties are the object properties in the JavaScript sense here:

  • properties of the proxied room (except ones starting with "_"), excluding event handlers
  • properties registered for the given plugin
  • handlers registered for the given plugin
Parameters
Name Type Description
_ *

Unused.

pluginId number

Plugin ID.

Returns

Names of the visible properties on the room proxy of the given plugin.


onOwnHandlerDescriptorGet( _, handlerName, pluginId ) → {Object|undefined}

Returns a property descriptor for the given handler and plugin ID.

Description

Returns a property descriptor for the given handler and plugin ID.

Parameters
Name Type Description
_ *

Unused.

handlerName string

Event handler name.

pluginId number

Plugin ID.

Returns

Property descriptor or undefined if the handler is not defined.


onOwnPropertyDescriptorGet( _, propertyName, pluginId ) → {Object|undefined}

Returns a property descriptor for the given property and plugin ID.

Description

Returns a property descriptor for the given property and plugin ID.

This will first look for a property on the given plugin, then for global properties on the room object.

Parameters
Name Type Description
_ *

Unused.

propertyName string

Property name.

pluginId number

Plugin ID.

Returns

Property descriptor or undefined.


onExecuteEventHandlers( _, handlerName, ...args ) → {boolean}

Executes the event handlers registered for the given handler.

Description

Executes the event handlers registered for the given handler.

Parameters
Name Type Attributes Description
_ *

Unused.

handlerName string

Event handler name.

args * <repeatable>

Event arguments.

Returns

false if one of the event handlers returned false, true otherwise.

Details

handle onGameTick differently


onPropertyGet( _, propertyName, pluginId ) → {*|undefined}

Returns the given property for the given plugin ID.

Description

Returns the given property for the given plugin ID.

Note that global properties of the proxied room are taken into account as well so long as they don't start with an underscore and only if there is not a property with the given name set for the plugin.

Parameters
Name Type Description
_ *

Unused.

propertyName string

Property name.

pluginId number

Plugin ID.

Returns

Property value or undefined.


onPropertySet( _, propertyName, value, pluginId )

Sets the given property to the given value for the given plugin ID.

Description

Sets the given property to the given value for the given plugin ID.

Parameters
Name Type Description
_ *

Unused.

propertyName string

Property name.

value *

New value for the property.

pluginId number

Plugin ID.


onPropertyUnset( _, propertyName, pluginId )

Unset the given property for the given plugin ID.

Description

Unset the given property for the given plugin ID.

Parameters
Name Type Description
_ *

Unused.

propertyName string

Property name.

pluginId number

Plugin ID.


removePluginHandlersAndProperties( pluginId )

Removes the handlers and properties for the given plugin ID.

Description

Removes the handlers and properties for the given plugin ID.

Must be called by PluginManager#_removePlugin to ensure overall consistency.

Parameters
Name Type Description
pluginId number

Plugin ID.


addEventStateValidator( pluginId, handlerNames, validator ) → {TrappedRoomManager}

Add an event state validator function for the given handler names.

Description

Add an event state validator function for the given handler names.

The validator function should return false if the event state is no longer valid and further event handlers should not be executed.

Parameters
Name Type Description
pluginId number

Plugin ID.

handlerNames string

Event handler name(s).

validator function

Validator function.

Returns

The trapped room manager, enables method chaining.


addPostEventHandlerHook( pluginId, handlerNames, hook ) → {TrappedRoomManager}

Add a hook for the given handler names that is executed before plugin event handlers.

Description

Add a hook for the given handler names that is executed before plugin event handlers.

Hooks are passed the room object and the event arguments. If the hook returns an Array it will be used to overwrite the event arguments.

Parameters
Name Type Description
pluginId number

Plugin ID.

handlerNames string | Array.<string>

Event handler name(s).

hook function

Function hook.

Returns

The trapped room manager, enables method chaining.


addPostEventHandlerHook( pluginId, handlerNames, hook ) → {TrappedRoomManager}

Add a hook for the given handler names that is executed after plugin event handlers.

Description

Add a hook for the given handler names that is executed after plugin event handlers.

It is executed regardless of event state validity.

Hooks are passed the room object, a metadata object, and the event arguments.

Parameters
Name Type Description
pluginId number

Plugin ID.

handlerNames string | Array.<string>

Event handler name(s).

hook function

Function hook.

Returns

The trapped room manager, enables method chaining.