System: main logic driver, that is used to stepping on each game-loop and update World
Update whole Component.Set
Single component mapping, Same asList.map - only for Component.Set inside World
gravitySystem =
Logic.System.step (Vec2.add gravity) accelerationSpecStep over all entities that have both components.
Example:
system =
Logic.System.step2
(\( v, _ ) ( p, setP ) -> setP (Vec2.add v p))
velocitySpec
positionSpecSame as step2 only with 3 components
Same as step2 only with 4 components
Same as step2 only with 5 components
Reduce a Component.Set from the left.
Example count how much enemies left in the world:
enemySet =
enemySpec.get world
count =
foldl (\_ -> (+) 1) enemySet 0Step over all entities that have both components and reduce an Component.Sets from the left.
Same as foldl2 only with 3 components
Same as foldl2 only with 4 components
Same as foldl2 only with 5 components
Variant of foldl that passes the index of the current element to the step function.
indexedFoldl is to foldl as List.indexedMap is to List.map.
Same as indexedFoldl2 only with 3 components
Same as indexedFoldl2 only with 4 components
Same as indexedFoldl2 only with 5 components
Specify that a component to be used in an advanced fold operation is optional.
Specify that a component to be used in an advanced fold operation is required.
similar to indexFoldl2, but allows you to specify which components are required and which are optional.
The tests are a good example of how this works
let
world =
withEntities
[ -- entity 1
[ ( fooSpec, 1 ) ]
-- entity 2
, [ ( fooSpec, 2 ), ( barSpec, 3 ) ]
-- entity 3
, [ ( barSpec, 999 ) ]
]
result =
Logic.System.advancedFoldl2
(\_ foo barMaybe acc -> acc + foo + Maybe.withDefault 0 barMaybe)
(Logic.System.isRequired world.foos)
(Logic.System.isOptional world.bars)
0
in
Expect.equal result 6a version of advancedFoldl2 that allows you to fold over 3 components
a version of advancedFoldl2 that allows you to fold over 4 components
a version of advancedFoldl2 that allows you to fold over 5 components
Just nice helper function to pipe into systems
update msg world =
world
|> system1
|> applyIf (msg === KeyUp "a") systemMoveLeft
|> system2Same as applyIf, but works with Maybe
update msg world =
world
|> system1
|> applyMaybe (decode saveDecoder msg) loadGame
|> system2