Comments (6)
{-| Add Additional component to spawn Entity.
-}
spawnEntityWith : ( ComponentSpec a (EntitySet world), a ) -> ( EntitySet world, EntityID, EntityID ) -> ( EntitySet world, EntityID, EntityID )
spawnEntityWith ( { getter, setter }, a ) ( updatedSet, id, uid ) =
let
updatedComponents =
getter updatedSet
|> setComponent id a
in
( setter updatedComponents updatedSet, id, uid )
usage:
spawnPlayer : Component.Position -> Component.Dimension -> World -> World
spawnPlayer position dimension world =
let
( newEntity, id, uid ) =
Slime.spawnEntity World.positions world { a = position }
|> Slime.spawnEntityWith ( World.velocities, { vx = 0, vy = 0 } )
|> Slime.spawnEntityWith ( World.dimensions, dimension )
|> Slime.spawnEntityWith ( World.controls, { x = 0, y = 0 } )
in
newEntity
from slime.
Are you looking for forNewEntity
and &=>
? Be sure you're on 2.1.0. It's got necessities like that.
To use your example, it would be:
spawnPlayer : Component.Position -> Component.Dimension -> World -> World
spawnPlayer position dimension world =
let
( entityId, updatedWorld ) =
Slime.forNewEntity world
&=> ( World.positions, position )
&=> ( World.velocities, { vx = 0, vy = 0 } )
&=> ( World.dimensions, dimension )
&=> ( World.controls, { x = 0, y = 0 } )
in
updatedWorld
Looking at the docs, I completely forgot spawnEmpty
, spawnEntity(2)
, and spawnEntities(2)
even existed. 3.0.0 might remove them, since forNewEntity
and forNewEntities
are better.
from slime.
tnx for info - would be nice see somethink like that in Docs..
from slime.
thanks for help.. maybe would be nice reference to it from "spawnEntity" that this method is "better" (and exist)..
from slime.
maybe there is something like &=>
also for Slime.stepEntities
- to not use
control : Time -> World -> World
control delta =
Slime.stepEntities (Slime.entities2 World.controls World.velocities)(\({ a, b } as ent2) -> ent2)
but something like
Slime.stepEntities (Slime.forEntity world &=> World.controls &=> World.velocities)(\({x, y}, {vx, vy}) as ent2 -> ent2)
from slime.
The problem with that is you can't build tuples like that, I don't think. Unless they're secretly cons cells and I didn't notice. Even if they were, what would the type of forEntity
be? The a/b/c notation is a serious disappointment, but it is less of an issue, since systems should rarely need to key on more than 2 or 3 components. Still, I'll look into another method that might be nicer, as I've just had a bit of inspiration.
from slime.
Related Issues (2)
- cannot install package HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from slime.