Global

Members

dirty :Boolean

Whether the handler list requires resorting.

Properties:
Name Type Description
dirty
Default Value:
  • false
Source:
Type:
  • Boolean

handlers :Array

The ordered list of EventHandler objects.

Properties:
Name Type Description
handlers
Source:
Type:
  • Array

orderIndex :Number

Incrementing insertion index used to preserve deterministic ordering between equal priorities.

Properties:
Name Type Description
orderIndex
Default Value:
  • 0
Source:
Type:
  • Number

Methods

#sortPriority()

Comparator used for sorting event handlers.

Returns a negative number if this handler should run before the other. Returns a positive number if it should run after. Returns 0 when equivalent.

Sorting rule:

  1. higher priority runs first
  2. if equal, lower order runs first
Source:

add(callback, contextopt, priorityopt) → {platypus.EventHandler}

Adds a new handler to the list.

Handlers are not immediately sorted. Sorting occurs lazily during the next dispatch.

Source:
Parameters:
Name Type Attributes Default Description
callback function

The listener callback function.

context Object <optional>
null

The callback execution context.

priority Number <optional>
0

Lower numbers execute first.

Returns:
Type:
platypus.EventHandler

Returns the created EventHandler instance.

addComponent(component) → {platypus.Component}

Attaches the provided component to the entity.

Source:
Parameters:
Name Type Description
component platypus.Component

Must be an object that functions as a Component.

Fires:
Returns:
Type:
platypus.Component

Returns the same object that was submitted.

destroy()

This method removes all components from the entity.

Source:

get(path) → {*}

Allows lookup for components or child entities and their properties.

For example, "component-id.sprite" will return an entity component's sprite property value.

Source:
Parameters:
Name Type Description
path String
Returns:
Type:
*

getAssetList(definition, properties, data) → {Array}

Returns all of the assets required for this Entity. This method calls the corresponding method on all components to determine the list of assets.

Source:
Parameters:
Name Type Description
definition Object

The definition for the Entity.

properties Object

Properties for this instance of the Entity.

data Object

Layer data that affects asset list.

Returns:
Type:
Array

A list of the necessary assets to load.

getComponentById(componentId) → {Component}

This method gets a component by its id.

Source:
Parameters:
Name Type Description
componentId String
Returns:
Type:
Component

A component

getComponentsByType(componentType) → {Array}

This method gets all components by their type.

Source:
Parameters:
Name Type Description
componentType String
Returns:
Type:
Array

An array of components

greenSlice(array)

Slices, but uses a recycled array. Note that this slice does not accept parameters and makes a shallow copy of the original array.

Source:
Parameters:
Name Type Description
array Array

The array to copy.

Returns:

Array

greenSplice(array, index) → {any}

Splices, but only removes a single item and returns the item itself, not an array.

Source:
Parameters:
Name Type Description
array Array

The array from which an item is to be extracted.

index Number

The index of the item to extract.

Returns:
Type:
any

greenSplit(text, splitteropt)

Splits a string, but populates an array from the array cache instead of creating a new one.

Source:
Parameters:
Name Type Attributes Description
text String

String to split.

splitter String <optional>

String demarking where to split. If not provided, each character in the split string becomes an array item.

Returns:

Array

off(nameopt, callbackopt)

Removes listeners.

Calling without arguments removes all listeners.

Calling with only an event name removes all listeners for that event.

Calling with both name and callback removes matching listeners for that callback.

Source:
Parameters:
Name Type Attributes Description
name String <optional>

Event name.

callback function <optional>

Listener callback.

on(name, callback, contextopt, onceopt, priorityopt)

Registers an event listener.

Listeners are executed in ascending priority order. Lower priority values execute first.

When priorities match, listeners execute in registration order.

If no context is supplied, the Messenger instance becomes the callback context.

Source:
Parameters:
Name Type Attributes Default Description
name String

Event name.

callback function

Function invoked when the event fires.

context Object <optional>
this

Callback execution context.

once Boolean <optional>
false

Whether the listener should automatically remove itself after its first execution.

priority Number <optional>
MAX_SAFE_INTEGER

Listener execution priority.

Lower numbers execute first.

remove(callback, context)

Removes all handlers matching the supplied callback.

Source:
Parameters:
Name Type Description
callback function
context Object

The callback function to remove.

removeComponent(component) → {Component}

Removes the mentioned component from the entity.

Source:
Parameters:
Name Type Description
component Component

Must be a [[Component]] attached to the entity.

Fires:
Returns:
Type:
Component

Returns the same object that was submitted if removal was successful; otherwise returns false (the component was not found attached to the entity).

setProperty(properties)

This method sets one or more properties on the entity.

Source:
Parameters:
Name Type Description
properties Object

A list of key/value pairs to set as properties on the entity.

toJSON(includeComponents) → {Object}

Returns a JSON object describing the entity.

Source:
Parameters:
Name Type Description
includeComponents Boolean

Whether the returned JSON should list components. Defaults to false to condense output since components are generally defined in platypus.game.settings.entities, but may be needed for custom-constructed entities not so defined.

Returns:
Type:
Object

Returns a JSON definition that can be used to recreate the entity.

toJSON() → {Object}

Returns a JSON structure describing this componet. This can be overridden by a "toJSON" method in the component definition. This is by design.

Source:
Returns:
Type:
Object

toString() → {String}

Returns a string describing the entity.

Source:
Returns:
Type:
String

Returns the entity type as a string of the form "[Entity entity-type]".

trigger(argsopt) → {Number}

Dispatches the event to all registered handlers.

The handler list is shallow-copied before iteration so listeners may safely remove themselves during dispatch.

Source:
Parameters:
Name Type Attributes Description
args Array <optional>

The arguments passed to listener callbacks.

Returns:
Type:
Number

Returns the number of handlers triggered.

trigger(events, messageopt, debugopt) → {Number}

Dispatches one or more events.

Supported formats:

String: trigger('jump', value)

Array: trigger(['jump', 'land'], value)

Object: trigger({ event: 'jump', message: value, debug: true })

Source:
Parameters:
Name Type Attributes Description
events String | Array | Object

Event descriptor.

message * <optional>

Event payload.

debug Boolean <optional>

Enables debug logging for this dispatch.

Returns:
Type:
Number

Total number of listeners triggered.

triggerEvent(type, …args) → {Number}

Dispatches a single event directly.

This bypasses trigger-format normalization and is the fastest dispatch path.

Source:
Parameters:
Name Type Attributes Description
type String

Event name.

args * <repeatable>

Arguments forwarded to listeners.

Returns:
Type:
Number

Number of listeners triggered.

union(arrayTo)

Merges items from one array into the other, making sure to not duplicate identical entries.

Source:
Parameters:
Name Type Description
arrayTo Array

The array into which items will be inserted.

...arrayFrom Array

The array(s) containing items to be merged.

Returns:

Array