new PluginLoader()

PluginLoader class, responsible for loading plugins via repositories or via code.

Description

PluginLoader class, responsible for loading plugins via repositories or via code.

Properties
Name Type Description
room HhmRoomObject

Room object.

repositoryTypeHandlers Object.<string, function()>

Handler functions for different repository types, see module:src/repositories.

Methods


<private> _executePlugin( pluginCode, pluginRoom [, pluginName ] )

Create and execute the plugin in a function context, passing a single argument 'HBInit', which is a function returning the trapped room

.

Description

Create and execute the plugin in a function context, passing a single argument 'HBInit', which is a function returning the trapped room

Parameters
Name Type Attributes Description
pluginCode function | string

Plugin code as either a function or a string.

pluginRoom external:haxball-room-trapper.TrappedRoom

Trapped room for the plugin.

pluginName string <optional>

Default plugin name, will be overwritten by the name property of the pluginSpec if given.


<private> _loadPlugin( pluginUrl [, pluginName ] ) → {number}

Loads a plugin with the given name from the given URL.

Description

Loads a plugin with the given name from the given URL.

The plugin will be loaded as plain text from the given URL and then executed in a function context.

Parameters
Name Type Attributes Description
pluginUrl string

Plugin URL.

pluginName string <optional>

Optional default plugin name.

Returns

Plugin ID if it was loaded or -1 otherwise


<private> _prepareRepositoryConfigurations( repositories )

Prepare the repository configurations.

Description

Prepare the repository configurations.

Adds the given repositories using PluginLoader#addRepository.

Parameters
Name Type Description
repositories Array.<(string|Object)>

Array of repositories, as strings or objects.


addRepository( repository [, append ] ) → {boolean}

Adds a repository.

Description

Adds a repository.

The repository can be specified as a string, then it is interpreted as the URL of a plain type repository, or as an Object.

If append is set to true, the new repository will be added with the lowest priority, i.e. plugins will only be loaded from it they can't be found in any other repository. Otherwise the repository will be added with the highest priority.

For more control over repository order, feel free to directly change the repositories Array.

The following default values are set if the given repository does not include them:

  • type: plain
  • suffix: .js
Parameters
Name Type Attributes Description
repository string | Object

The repository to be added, as string or Object.

append boolean <optional>

Whether to append or prepend the repository to the Array of repositories.

Returns

Whether the repository was successfully added.


registerRepositoryTypeHandler( repositoryType, handler ) → {boolean}

Adds a function which generates a URL based on the repository configuration and a plugin name.

Description

Adds a function which generates a URL based on the repository configuration and a plugin name.

Parameters
Name Type Description
repositoryType

String identifying the repository type.

handler

Function which will receive two arguments (repository object and plugin name) and is expected to return an HTTPs URL which can be used to load the plugin, or false in case of errors.

Returns

Whether the repository type handler was successfully registered.


tryToLoadPluginByCode( pluginCode [, pluginName ] ) → {number}

Tries to load a plugin from the plugin code.

Description

Tries to load a plugin from the plugin code.

Parameters
Name Type Attributes Description
pluginCode string | function

Plugin code as string or Function.

pluginName string <optional>

Optional default plugin name, used only if the plugin code does not set a name.

Returns

the ID of the plugin or -1 if it couldn't be loaded.


tryToLoadPluginByName( pluginName ) → {number}

Tries to load the given plugin from the configured repositories.

Description

Tries to load the given plugin from the configured repositories.

Parameters
Name Type Description
pluginName string

Name of the plugin to be loaded.

Returns

The ID of the plugin or -1 if it couldn't be loaded.


tryToLoadPluginByUrl( url [, pluginName ] ) → {number}

Tries to load a plugin from the given URL.

Description

Tries to load a plugin from the given URL.

Parameters
Name Type Attributes Description
url string

Plugin must be served as plain text at this URL.

pluginName string <optional>

Optional default plugin name, which may be overwritten by the plugin code.

Returns

The ID of the plugin or -1 if it couldn't be loaded.