Skip to content

EntityState

ctreffs edited this page Oct 8, 2020 · 1 revision

EntityState

Represents a state for an EntityStateMachine. The state contains any number of ComponentProviders which are used to add components to the entity when this state is entered.

public class EntityState

Initializers

init()

public init()

Methods

addMapping(for:)

Add a new StateComponentMapping to this state. The mapping is a utility class that is used to map a component type to the provider that provides the component.

@discardableResult public func addMapping(for type: ComponentInitializable.Type) -> StateComponentMapping

Parameters

  • type: The type of component to be mapped

Returns

The component mapping to use when setting the provider for the component

provider(for:)

Get the ComponentProvider for a particular component type.

public func provider(for type: ComponentInitializable.Type) -> ComponentProvider?

Parameters

  • type: The type of component to get the provider for

Returns

The ComponentProvider

hasProvider(for:)

To determine whether this state has a provider for a specific component type.

public func hasProvider(for type: ComponentInitializable.Type) -> Bool

Parameters

  • type: The type of component to look for a provider for

Returns

true if there is a provider for the given type, false otherwise

addInstance(_:)

Creates a mapping for the component type to a specific component instance. ComponentInstanceProvider is used for the mapping.

@discardableResult @inline(__always) public func addInstance<C: ComponentInitializable>(_ component: C) -> Self

Parameters

  • component: The component instance to use for the mapping

Returns

This EntityState, so more modifications can be applied

addType(_:)

Creates a mapping for the component type to new instances of the provided type. A ComponentTypeProvider is used for the mapping.

@inline(__always) @discardableResult public func addType(_ type: ComponentInitializable.Type) -> Self

Parameters

  • type: The type of components to be created by this mapping

Returns

This EntityState, so more modifications can be applied

addSingleton(_:)

Creates a mapping for the component type to a single instance of the provided type. The instance is not created until it is first requested. A ComponentSingletonProvider is used for the mapping.

@inline(__always) @discardableResult public func addSingleton(_ type: ComponentInitializable.Type) -> Self

Parameters

  • type: The type of the single instance to be created.

Returns

This EntityState, so more modifications can be applied

addMethod(closure:)

Creates a mapping for the component type to a method call. A DynamicComponentProvider is used for the mapping.

@inline(__always) @discardableResult public func addMethod<C: ComponentInitializable>(closure: DynamicComponentProvider<C>.Closure) -> Self

Parameters

  • closure: The Closure instance to return the component instance

Returns

This EntityState, so more modifications can be applied

addProvider(type:provider:)

Creates a mapping for the component type to any ComponentProvider.

@inline(__always) @discardableResult public func addProvider<C: ComponentInitializable>(type: C.Type, provider: ComponentProvider) -> Self

Parameters

  • type: The type of component to be mapped
  • provider: The component provider to use.

Returns

This EntityState, so more modifications can be applied.

Clone this wiki locally