Skip to content

EntityStateMachine

ctreffs edited this page Oct 8, 2020 · 1 revision

EntityStateMachine

This is a state machine for an entity. The state machine manages a set of states, each of which has a set of component providers. When the state machine changes the state, it removes components associated with the previous state and adds components associated with the new state.

public class EntityStateMachine<StateIdentifier: Hashable>

Parameters

  • StateIdentifier: Generic hashable state name type

Initializers

init(entity:)

Initializer. Creates an EntityStateMachine.

public init(entity: Entity)

Properties

entity

The entity whose state machine this is

var entity: Entity

Methods

addState(name:state:)

Add a state to this state machine.

@discardableResult public func addState(name: StateIdentifier, state: EntityState) -> Self

Parameters

  • name: The name of this state - used to identify it later in the changeState method call.
  • state: The state.

Returns

This state machine, so methods can be chained.

createState(name:)

Create a new state in this state machine.

public func createState(name: StateIdentifier) -> EntityState

Parameters

  • name: The name of the new state - used to identify it later in the changeState method call.

Returns

The new EntityState object that is the state. This will need to be configured with the appropriate component providers.

changeState(name:)

Change to a new state. The components from the old state will be removed and the components for the new state will be added.

public func changeState(name: StateIdentifier)

Parameters

  • name: The name of the state to change to.
Clone this wiki locally