wolfadex / elm-ecs / Ecs.Entity

Creation

create : Ecs.Config.Spec world -> world -> ( Ecs.Internal.Entity, world )

Creates a new

Ecs.Entity.create ecsConfigSpec world

Build

with : ( Ecs.Component.Spec comp world, comp ) -> ( Ecs.Internal.Entity, world ) -> ( Ecs.Internal.Entity, world )

Adds a component to an entity

Ecs.Entity.create ecsConfigSpec world
    |> Ecs.Entity.with ( positionSpec, positionComponent )
    |> Ecs.Entity.with ( velocitySpec, velocityComponent )

remove : Ecs.Component.Spec comp world -> ( Ecs.Internal.Entity, world ) -> ( Ecs.Internal.Entity, world )

For creating Entity destruction functions, should pipe in all possible component specs. It also can be used to remove some/select components from an entity.

deleteEntity : ( EntityId, World ) -> ( EntityId, World )
deleteEntity =
    Ecs.Entity.remove positionSpec
        >> Ecs.Entity.remove velocitySpec
        >> Ecs.Entity.delete ecsConfigSpec

newWorld : World
newWorld =
    deleteEntity ( id, world )

delete : Ecs.Config.Spec world -> ( Ecs.Internal.Entity, world ) -> ( Ecs.Internal.Entity, world )

Finalizes the deletion of an Entity from the world. This should be used after remove.