excaliburjs / Excalibur

🎮 Your friendly TypeScript 2D game engine for the web 🗡️
https://excaliburjs.com
BSD 2-Clause "Simplified" License
1.67k stars 182 forks source link

Customize default systems for all scenes #3101

Open mattjennings opened 3 weeks ago

mattjennings commented 3 weeks ago

Context

It would be helpful to configure the default systems to be used for all scenes. This spares having to make a base scene class with the system added if I want to make sure it's always used.

Proposal

// proposal 1
new ex.Engine({
   world: {
       systems: [...], // adds to current systems
       removeDefaultSystems: true/false // removes default if true
    }
})

// proposal 2
new ex.Engine({
   world: {
       systems: [...], // overrides systems, must add back ex.MotionSystem etc
    }
})
eonarheim commented 3 weeks ago

I'm into this, I'm leaning towards #1 because re-adding systems seems really rough... but on the other hand that's only once?

mattjennings commented 3 weeks ago

I agree, i feel like you'd need to expose the default systems somewhere to they can be spread in. Here's 2 more ideas:

// proposal 3
new ex.Engine({
   world: {
       systems: [...ex.DefaultSystems, MySystem],
    }
})

// proposal 4
new ex.Engine({
   world:  {
       setup(world) {
           world.systemManager.addSystem(MySystem)
       }
   }
})