API Docs for: 1.4.0
Show:

Kiwi.PluginManager Class

Module: Kiwi

The plugin manager registers plugins, checks plugin dependencies, and calls designated functions on each registered plugin at boot time, and during the update loop if required. Plugins are registered on the global Kiwi instance. Once a plugin in registered it is allocated a place on the Kiwi.Plugins name space. Eg. FooPlugin will be accessible at Kiwi.Plugins.FooPlugin. When a game instance is created, it can contain a list of required plugins in the configuration object. At this point the plugin manager will validate that the plugins exist, and that dependencies are met (both Kiwi version and versions of other required plugins). If the plugin has a "create" function, the plugin manager instance will call that function as part of the boot process. The create function may do anything, but usually it would create an instance of an object. The plugin manager update function is called every update loop. If an object was created by the "create" function and it has an "update" function, that function will be called in turn.

Constructor

Kiwi.PluginManager

(
  • game
  • plugins
)
Kiwi.PluginManager

Parameters:

  • game Kiwi.Game

    The state that this entity belongs to. Used to generate the Unique ID and for garbage collection.

  • plugins String

    The entities position on the x axis.

Returns:

Kiwi.PluginManager:

This PluginManager.

Methods

_createPlugins

() private

Called after all other core objects and services created by the Kiwi.Game constructor are created. Attempts to find a "create" function on each plugin and calls it if it exists. The create function may return an object on which a boot function exists - to be called during boot process.

boot

() public

Calls the boot functions on any objects that plugins used by the game instance have designated during creation.

pluginIsRegistered

(
  • pluginName
)
public

Returns true if a plugin identified by the supplied pluginName is registered.

Parameters:

  • pluginName String

register

(
  • plugin
)
public static

Registers a plugin object as available. Any game instance can choose to use the plugin. Plugins need only be registered once per webpage. If registered a second time it will be ignored. Two plugins with the same names cannot be reigstered simultaneously, even if different versions.

Parameters:

  • plugin Object

update

() public

Calls the update functions on any objects that plugins used by the game instance have designated during creation.

validatePlugins

() public

Builds a list of valid plugins used by the game instance. Each plugin name that is supplied in the Kiwi.Game constructor configuration object
is checked against the Kiwi.Plugins namespace to ensure that a property of the same name exists. This will ignore plugin that are registered but not used by the game instance.

validMinimumPluginVersionExists

(
  • name
  • version
)
public

Returns whether a valid minimum version of a plugin exists.

Parameters:

  • name String

    Name of plugin

  • version String

    Minimum version

Returns:

boolean

Properties

_availablePlugins

Array private static

An array of plugins which have been included in the webpage and registered successfully.

_bootObjects

Array private

An array of objects that contain a boot function, each of which will be called when PluginManager.boot is invoked.

_plugins

Array private

An array of plugin names which the game instance has been configured to use. Each name must match the constructor function for the plugin.

getAvailablePlugins

Array private static

An array of objects represetning all available plugins, each containing the name and version number of an available plugin

objType

String "PluginManager" public

Identifies the object as a PluginManager.

objType

Kiwi.Game private

A reference to the game instance that owns the PluginManager.