hmans / miniplex

A 👩‍💻 developer-friendly entity management system for 🕹 games and similarly demanding applications, based on 🛠 ECS architecture.
MIT License
827 stars 38 forks source link

[Idea] Allow `World.add` to take a setup function as an optional second argument #263

Open hmans opened 1 year ago

hmans commented 1 year ago

This is just some convenience glue to make initializing newly created entities a little easier without requiring the user to store them in a variable first.

As is:

const entity = world.add({
  transform: new Mesh(
    new DodecahedronGeometry(),
    new MeshStandardMaterial({ color: "orange" })
  )
})

entity.transform.position.set(-3, 0, 0)

To be:

world.add({
  transform: new Mesh(
    new DodecahedronGeometry(),
    new MeshStandardMaterial({ color: "orange" })
  )
}, (entity) => { 
  entity.transform.position.set(-3, 0, 0)
})