justgook/elm-game-logic/1.0.0

NOTE: the latest version is 3.0.0

Logic.Entity

type alias EntityID =
Int
create : EntityID -> world -> ( EntityID, world )

Start point for spawning entity

Entity.create ( id, world )
    |> Entity.with ( positionSpec, positionComponent )
    |> Entity.with ( velocitySpec, velocityComponent )
( Spec comp world, comp )
-> ( EntityID, world )
-> ( EntityID, world )

Setting components to spawn with new entity

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

List

fromList : List ( EntityID, a ) -> Set a
toList : Set a -> List ( EntityID, a )

Dict

fromDict : Dict EntityID a -> Set a
toDict : Set a -> Dict EntityID a

Manipulations

getComponent : Int -> Set comp -> Maybe comp
mapComponent : (Maybe comp -> Maybe comp) -> EntityID -> Set comp -> Set comp
mapComponentSet : (comp -> comp) -> EntityID -> Set comp -> Set comp
removeComponent : EntityID -> Set a -> Set a

Remove component from Component.Set by EntityID return new Component.Set, or return unchanged if component not in set

removeFor : Spec comp world -> ( EntityID, world ) -> ( EntityID, world )

Way to create Entity destruction functions, should pipe in all possible component sets, from what Entity should be removed. Also can be used to just disable (remove) some components from entity

remove =
    Entity.removeFor positionSpec
        >> Entity.removeFor velocitySpec


newWorld =
    remove ( id, world )
setComponent : EntityID -> a -> Set a -> Set a

Set the component at a particular index. Returns an updated component Set. If the index is out of range, the Set is unaltered.

spawnComponent : EntityID -> a -> Set a -> Set a

Safe way to create component, same as setComponent, only if index is out of range Component.Set will be stretched\