wolfadex / elm-ecs / Ecs.Component
import Ecs.Component

type alias Velocity =
    { x : Float, y : Float }

velocitySpec : Ecs.Component.Spec Velocity { world | velocityComponent : Ecs.Component Velocity }
velocitySpec =
    { get = .velocityComponent
    , set = \component world -> { world | velocityComponent = component }
    }

initVelocity : Ecs.Component.Component Velocity
initVelocity =
    Ecs.Component.empty

Create


type alias Spec comp world =
{ get : world -> Ecs.Internal.Component comp
, set : Ecs.Internal.Component comp -> world -> world 
}

Component specification, how to get a Component from the world and set it back into the world. Used when creating new entities and when running systems.

Build

empty : Ecs.Internal.Component comp

Create an empty Component - mostly used to init components in the world.

set : Ecs.Internal.Entity -> a -> Ecs.Internal.Component a -> Ecs.Internal.Component a

Set the value of a component for an Entity.

update : Ecs.Internal.Entity -> (comp -> comp) -> Ecs.Internal.Component comp -> Ecs.Internal.Component comp

Update Component by Entity.

remove : Ecs.Internal.Entity -> Ecs.Internal.Component a -> Ecs.Internal.Component a

Remove Component from an entity by Entity, or return unchanged if the entity never had a Component.

Query

get : Ecs.Internal.Entity -> Ecs.Internal.Component comp -> Maybe comp

Get component for Entity.

get2 : Ecs.Internal.Entity -> Ecs.Internal.Component comp -> Ecs.Internal.Component comp2 -> Maybe ( comp, comp2 )

Get components Tuple for Entity.

Transform

map : (comp -> comp) -> Ecs.Internal.Component comp -> Ecs.Internal.Component comp

Apply a function on every entity with a Component.

Ecs.Component.fromList [ ( 0, 1 ), ( 1, 14 ), ( 2, 89 ) ]
    |> Ecs.Component.map (\age -> age + 1)
    |> (==) (Ecs.Component.fromList [ ( 0, 2 ), ( 1, 15 ), ( 2, 90 ) ])

filter : (comp -> Basics.Bool) -> Ecs.Internal.Component comp -> Ecs.Internal.Component comp

Removes a component from an Entity

indexedFilter : (Ecs.Internal.Entity -> comp -> Basics.Bool) -> Ecs.Internal.Component comp -> Ecs.Internal.Component comp

Removes a component from an Entity

List

fromList : List ( ( Basics.Int, Basics.Int ), a ) -> Ecs.Internal.Component a

Create a Component from a List.

Note: Useful for data serialization.

toList : Ecs.Internal.Component a -> List ( ( Basics.Int, Basics.Int ), a )

Convert a Component into an association list of id-component pairs, sorted by id.

Note: Useful for data deserialization.

Dict

fromDict : Dict ( Basics.Int, Basics.Int ) a -> Ecs.Internal.Component a

Create a Component from a Dict.

Note: Useful for data serialization.

toDict : Ecs.Internal.Component a -> Dict ( Basics.Int, Basics.Int ) a

Create a Dict from a Component.

Note: Useful for data deserialization.