ActionState

platypus. ActionState

new ActionState(event, states, trigger) → {ActionState}

This class defines an action state based on one or more inputs. This is used by EntityController to produce event messages listing whether a particular action is "triggered", "pressed", and/or "released".

Properties:
Name Type Attributes Description
event string <optional>

The name of the event to trigger on the Entity.

trigger function <optional>

The function to call if the ActionState is active.

active boolean <optional>

Whether any of the ActionState's inputs are active.

wasActive boolean <optional>

Whether any of the ActionState's inputs were active last update.

valid boolean <optional>

Whether the Entity's state is valid for this ActionState.

wasValid boolean <optional>

Whether the Entity's state was valid for this ActionState last update.

states platypus.StateMap <optional>

The state of the Entity that is valid for this ActionState.

inputs Array <optional>

The list of input toggles to track control input.

stateSummary platypus.Data <optional>

The message that is passed to the Entity if the ActionState is active.

Source:
Parameters:
Name Type Description
event string

The name of the event to trigger on the Entity.

states Object

A list of key/value pairs describing what states should be true or false on the Entity for this action to be triggered.

trigger function

The function to be called if one or more inputs are active and the current state of the Entity is valid.

Returns:
Type:
ActionState

Returns the new ActionState object.

Methods

(static) recycle(actionState)

Returns an ActionState back to the cache. Prefer the ActionState's recycle method since it recycles property objects as well.

Source:
Parameters:
Name Type Description
actionState platypus.ActionState

The ActionState to be recycled.

(static) setUp() → {platypus.ActionState}

Returns an ActionState from cache or creates a new one if none are available.

Source:
Returns:
Type:
platypus.ActionState

The instantiated ActionState.

recycle()

Relinquishes properties of the ActionState and recycles it.

Source:

resolve()

Triggers events on the Entity related to the ActionState's state. This is necessarily separate from the update method since triggered events could affect entity state. The messages have the following form and are only triggered if one of the values is true:

{
    "triggered": true,
    "pressed": true,
    "released": false
}

Here is a mapping of the various event messages depending on the ActionState's state.

ActionState State:
     wasValid:  0 0 0 0  0 0 0 0  1 1 1 1  1 1 1 1
        valid:  0 0 0 0  1 1 1 1  0 0 0 0  1 1 1 1
    wasActive:  0 0 1 1  0 0 1 1  0 0 1 1  0 0 1 1
       active:  0 1 0 1  0 1 0 1  0 1 0 1  0 1 0 1
Events:
    triggered:  0 0 0 0  0 1 0 0  0 0 0 0  0 1 0 0
      pressed:  0 0 0 0  0 1 0 1  0 0 0 0  0 1 0 1
     released:  0 0 0 0  0 0 1 0  0 0 1 1  0 0 1 0
Source:

update(state) → {Boolean}

Updates the state of the action by checking the state of the Entity and whether any inputs are active.

Source:
Parameters:
Name Type Description
state Object

The Entity's state property to compare against the ActionState's valid state.

Returns:
Type:
Boolean

Whether the ActionState is triggered, pressed, or released.