justgook/elm-game-logic/1.0.0

NOTE: the latest version is 3.0.0

Logic.System

Main logic driver is System that is what used to step each game-loop and update World

type alias System world =
world -> world
step : (comp -> comp) -> Spec comp world -> world -> world

single component mapping, same as List.map - only for Component.Set inside World

SetsReducer2
a
b
{ a : Set a
, b : Set b
}
-> Spec a world
-> Spec b world
-> world
-> world

Example:

system : Logic.Component.Spec Velocity world -> Logic.Component.Spec Position world -> System world
   system =
       Logic.System.step2
           (\( velocity, _ ) ( pos, setPos ) -> setPos (Vec2.add velocity pos))
SetsReducer3
a
b
c
{ a : Set a
, b : Set b
, c : Set c
}
-> Spec a world
-> Spec b world
-> Spec c world
-> world
-> world

same as step2 only with 3 components

SetsReducer4
a
b
c
d
{ a : Set a
, b : Set b
, c : Set c
, d : Set d
}
-> Spec a world
-> Spec b world
-> Spec c world
-> Spec d world
-> world
-> world

same as step2 only with 4 components

foldl : (comp1 -> acc -> acc) -> Set comp1 -> acc -> acc
foldl2 : (comp1 -> comp2 -> acc -> acc) -> Set comp1 -> Set comp2 -> acc -> acc
(comp1 -> comp2 -> comp3 -> acc -> acc)
-> Set comp1
-> Set comp2
-> Set comp3
-> acc
-> acc
(comp1 -> comp2 -> comp3 -> comp4 -> acc -> acc)
-> Set comp1
-> Set comp2
-> Set comp3
-> Set comp4
-> acc
-> acc
indexedFoldl : (EntityID -> comp1 -> acc -> acc) -> Set comp1 -> acc -> acc
indexedFoldl2 : (Int -> comp1 -> comp2 -> acc -> acc) -> Set comp1 -> Set comp2 -> acc -> acc
(EntityID -> comp1 -> comp2 -> comp3 -> acc -> acc)
-> Set comp1
-> Set comp2
-> Set comp3
-> acc
-> acc

Util

applyIf : Bool -> (a -> a) -> a -> a

Custom Systems

type UnfinishedSystem world acc next func
( ( comp
, acc -> ( Array (Maybe acc), next ) -> ( Array (Maybe acc), next )
)
-> func
)
-> Spec comp world
-> world
-> UnfinishedSystem world ( Set comp, next ) next func

3 times slower then foldN

Spec comp world
world
acc
( Set comp, next )
(( comp, comp -> acc -> acc ) -> newFunc)
-> UnfinishedSystem world acc next newFunc
end : UnfinishedSystem world acc () (acc -> acc) -> world
custom
world
acc
()
(( acc, custom ) -> ( acc, custom ))
-> ( world, custom )

Helper types

type alias SetsReducer2 a b acc =
( a, a -> acc -> acc ) -> ( b, b -> acc -> acc ) -> acc -> acc
type alias SetsReducer3 a b c acc =
( a, a -> acc -> acc )
-> ( b, b -> acc -> acc )
-> ( c, c -> acc -> acc )
-> acc
-> acc
type alias SetsReducer4 a b c d acc =
( a, a -> acc -> acc )
-> ( b, b -> acc -> acc )
-> ( c, c -> acc -> acc )
-> ( d, d -> acc -> acc )
-> acc
-> acc