mlange-42 / arche-model

Everything you need to rapidly build a model with the Arche Entity Component System (ECS).
https://pkg.go.dev/github.com/mlange-42/arche-model
MIT License
14 stars 0 forks source link

Add One shot systems #55

Open delaneyj opened 6 months ago

delaneyj commented 6 months ago

Would be nice for setup to have some systems run initialize then remove self

mlange-42 commented 6 months ago

Hi @delaneyj!

thanks for coming along!

You can easily do this yourself, as the systems are accessible as the resource Systems. About like this (not tested):

func (s *MySys) Initialize(world *ecs.World) {
    // Do your stuff...

    sysRes := generic.NewResource[model.Systems](world)
    systems := sysRes.Get()
    systems.RemoveSystem(s)
}
delaneyj commented 6 months ago

Right, I just thought it might be clearer to have a OneShot intereface that only has Init and a System interface extends that interface to be more explicit and to auto handle to removal.

mlange-42 commented 6 months ago

Well, ok, this is worth a consideration.