TriggerComponent - acrimi/Raven GitHub Wiki

Extends StatefulComponent

TriggerComponent is an extension of StatefulComponent that can be used to coordinate states across components and across entities. Triggers can be defined, which are entities whose own TriggerComponents and/or lifecycle will be used to determine the state of this component. Other StatefulComponents within the same entity can also be synchronized with the state of this component, using either direct or inverse relationships.

Note that the three available categories of triggers are evaluated via conjunction, and so they must all be satisfied for this component to be activated. For instance, take a case where both triggers and inverseTriggers are defined. If all entities matching the triggers filters have active TriggerComponents, but only some of the entities matching the inverseTriggers filters have inactive TriggerComponents, this component will be deactivated.

Configuration

When used inside the components block, the initial state of the component can be configured with the following parameters:

Key Type Description
triggers object[] An array of objects representing entity filters that will be used to control the state of this component. If all entities that match at least one of these filters have a TriggerComponent that has been activated, this component will be activated, otherwise this component will be deactivated. Any entity that matches one of the filters but does not have a TriggerComponent is considered to be inactive.
      type string The type of the entity to filter for
      tag string The tag of the entity to filter for
inverseTriggers object[] An array of objects representing entity filters that will be used to inversely control the state of this component. If all entities that match at least one of these filters have a TriggerComponent that is inactive, this component will be activated, otherwise this component will be deactivated. Any entity that matches one of the filters but does not have a TriggerComponent is considered to be activated.
      type string The type of the entity to filter for
      tag string The tag of the entity to filter for
destructionTriggers object[] An array of objects representing entity filters that will be used to control the state of this component according to matching entities' lifecycles. If there are no existing entities that match any of these filters, this component will be activated, otherwise it will be deactivated. This applies even if there never were any entities that matched, so it doesn't necessarily correlate to destruction events.
      type string The type of the entity to filter for
      tag string The tag of the entity to filter for
join string|string[] One or more StatefulComponents that will have their states synced with this component's state. When this component is activated, the joined components will be activated, and likewise when this component is deactivated.
invert string|string[] One or more StatefulComponents that will have their states synced with this component's state in an inverse relationship. When this component is activated, the inverted components will be deactivated, and vice versa when this component is deactivated.
duration* float The duration, in seconds, of the "active" state for this component. Defaults to -1, which is treated as infinite duration.
enterStates* (string|object)[] An array of states that will be passed through when going from the "inactive" state to the "active" state. Each state can be defined as either an object with a single key value pair corresponding the state's name and duration, or as a string representing the state name. States defined as a string will have an infinite duration. The array values can be heterogenous.
      [stateName]* float The key represents the name of this state and the value is the duration, in seconds. For infinite duration, use a value of -1
exitStates* (string|object)[] An array of states that will be passed through when going from the "active" state to the "inactive" state. Each state can be defined as either an object with a single key value pair corresponding the state's name and duration, or as a string representing the state name. States defined as a string will have an infinite duration. The array values can be heterogenous.
      [stateName]* float The key represents the name of this state and the value is the duration, in seconds. For infinite duration, use a value of -1
initialState* string The state the component will start in. Must be one of "inactive", "active", or any of the custom states provided via enterStates or exitStates. By default, the component will start in the "inactive" state. Setting a different initial state will not cause events to fire for entering that state.
isActive* boolean Equivalent to passing "active" to initialState. Defaults to false.

* from StatefulComponent

Example:

"TriggerComponent": {
  "triggers": [
    {
      "type": "switch",
      "tag": "doorSwitch"
    }
  ],
  "inverseTriggers": [
    {
      "tag": "lockLever"
    }
  ],
  "destructionTriggers": [
    {
      "type": "boss"
    },
    {
      "type": "enemy",
      "tag": "keyEnemy"
    }
  ],
  "join": [
    "OpenableComponent",
    "InvulnerabilityComponent"
  ],
  "invert": "SelfDestructComponent"
}

Properties

The following properties are readable by property accessors (eg render state and persistence definitions):

Key Type Description
isActive* boolean Whether or not the current state is "active"
isInactive* boolean Whether or not the current state is "inactive"
state* string The name of the current state
progress* float The percentage, from 0 to 1, of how much time has elapsed for the current state relative to its duration (elapsedTime / duration). If the current state has an infinite duration, this value is always 0.

* from StatefulComponent

⚠️ **GitHub.com Fallback** ⚠️