Specs specify how to retrieve and update components and singletons. They are initialized using the Ecs.ComponentsN and Ecs.SingletonsN modules.
type alias Specs =
{ allComponents : AllComponentsSpec EntityId Components
, position : ComponentSpec EntityId Position Components
, velocity : ComponentSpec EntityId Velocity Components
, nextEntityId : SingletonSpec EntityId Singletons
}
specs : Specs
specs =
Specs |> Ecs.Components2.specs |> Ecs.Singletons1.specs
Internal.AllComponentsSpec comparable components
Used for operations on multiple component types.
Internal.ComponentSpec comparable a components
Used for operations on a single component type.
Internal.SingletonSpec a singletons
Used for operations on a single singleton type.
The world contains all your entities, components and singletons.
Internal.World comparable components singletons
The world that contains all you data.
emptyWorld : AllComponentsSpec comparable components -> singletons -> World comparable components singletons
Create an empty world without entities or components. Singletons need an intial value.
isEmptyWorld : World comparable components singletons -> Basics.Bool
Determine if the world is empty, without entities or components.
worldEntities : World comparable components singletons -> Set comparable
Get all entity ids in the world.
worldEntityCount : World comparable components singletons -> Basics.Int
Determine the total number of entities in the world.
worldComponentCount : AllComponentsSpec comparable components -> World comparable components singletons -> Basics.Int
Determine the total number of components in the world.
Entities are represented by an id.
An entity id can be any comparable
type.
Operations on entities usually apply to the active entity in the world. You can make an entity active with the onEntiy function. Also when you insert a new entity that entity will be active.
insertEntity : comparable -> World comparable components singletons -> World comparable components singletons
Add a new entity id to the world and make the entity active.
onEntity : comparable -> World comparable components singletons -> World comparable components singletons
Make an entity active if it is part of the world, otherwise no entity will be active.
removeEntity : AllComponentsSpec comparable components -> World comparable components singletons -> World comparable components singletons
Remove the active entity from the world. All component associated with the entity will also be removed.
clearEntity : AllComponentsSpec comparable components -> World comparable components singletons -> World comparable components singletons
Remove all components of the active entity. The entity will remain part of the world.
hasEntity : World comparable components singletons -> Basics.Bool
Determine if there is an active entity.
getEntity : World comparable components singletons -> Maybe comparable
Get the active entity id.
Components contain all the entity data in the world. Every component is associated with an entity.
insertComponent : ComponentSpec comparable a components -> a -> World comparable components singletons -> World comparable components singletons
Insert a component with the specified component type in the active entity.
updateComponent : ComponentSpec comparable a components -> (Maybe a -> Maybe a) -> World comparable components singletons -> World comparable components singletons
Update a component with the specified component type in the active entity.
removeComponent : ComponentSpec comparable a components -> World comparable components singletons -> World comparable components singletons
Remove a component with the specified component type from the active entity.
hasComponent : ComponentSpec comparable a components -> World comparable components singletons -> Basics.Bool
Determine if the active entity has the specified component type.
getComponent : ComponentSpec comparable a components -> World comparable components singletons -> Maybe a
Get a component with the specified component type of the active entity.
componentEntities : ComponentSpec comparable a components -> World comparable components singletons -> Set comparable
Get all entities that contain the specified component type.
componentCount : ComponentSpec comparable a components -> World comparable components singletons -> Basics.Int
Determine the total number of components of the specified component type.
setComponents : ComponentSpec comparable a components -> Dict comparable a -> World comparable components singletons -> World comparable components singletons
Replace all components for the specified component type. All provided entities are added to the world.
clearComponents : ComponentSpec comparable a components -> World comparable components singletons -> World comparable components singletons
Clear all components for the specified component type.
getComponents : ComponentSpec comparable a components -> World comparable components singletons -> Dict comparable a
Get all components for the specified component type.
Singletons contain data where there should only be one instance of. Singletons are optional. They are added to the package for convenience and to create a consistent way to deal with data (singletons and components). You can also just keep the singleton data in your model next to the ecs world just like you do in any Elm program.
setSingleton : SingletonSpec a singletons -> a -> World comparable components singletons -> World comparable components singletons
Set the data for the specified singleton type.
updateSingleton : SingletonSpec a singletons -> (a -> a) -> World comparable components singletons -> World comparable components singletons
Update the data for the specified singleton type.
getSingleton : SingletonSpec a singletons -> World comparable components singletons -> a
Get the data for the specified singleton type.