Git Product home page Git Product logo

Comments (6)

justgook avatar justgook commented on July 3, 2024
{-| 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.

seurimas avatar seurimas commented on July 3, 2024

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.

justgook avatar justgook commented on July 3, 2024

tnx for info - would be nice see somethink like that in Docs..

from slime.

justgook avatar justgook commented on July 3, 2024

thanks for help.. maybe would be nice reference to it from "spawnEntity" that this method is "better" (and exist)..

from slime.

justgook avatar justgook commented on July 3, 2024

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.

seurimas avatar seurimas commented on July 3, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.