API Documentation for: 0.11.8
Show:

platypus.ActionState Class

Module: platypus

Available since 0.6.8

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".

Constructor

platypus.ActionState

(
  • event
  • states
  • trigger
)
ActionState

Defined in platypus.ActionState:1

Available since 0.6.8

Parameters:

  • 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:

ActionState:

Returns the new ActionState object.

Methods

ActionState.recycle

(
  • The
)

Defined in ActionState.recycle:158

Available since 0.7.1

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

Parameters:

ActionState.setUp

() platypus.ActionState

Defined in ActionState.setUp:151

Available since 0.7.1

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

Returns:

platypus.ActionState:

The instantiated ActionState.

recycle

()

Defined in recycle:165

Available since 0.7.1

Relinquishes properties of the ActionState and recycles it.

resolve

()

Defined in resolve:124

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

update

(
  • state
)
Boolean

Defined in update:101

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

Parameters:

  • state Object

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

Returns:

Boolean:

Whether the ActionState is triggered, pressed, or released.

Properties

active

Boolean

Defined in active:36

Whether any of the ActionState's inputs are active.

event

String

Defined in event:20

The name of the event to trigger on the Entity.

inputs

Array

Defined in inputs:76

The list of input toggles to track control input.

states

platypus.StateMap

Defined in states:68

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

stateSummary

platypus.Data

Defined in stateSummary:84

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

trigger

Function

Defined in trigger:28

The function to call if the ActionState is active.

valid

Boolean

Defined in valid:52

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

wasActive

Boolean

Defined in wasActive:44

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

wasValid

Boolean

Defined in wasValid:60

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