Add the concept of commands to the world and executing them

This commit is contained in:
Marc Di Luzio 2020-06-03 18:12:08 +01:00
parent 013a69fa63
commit e5d5d123a6
6 changed files with 163 additions and 19 deletions

23
pkg/game/command.go Normal file
View file

@ -0,0 +1,23 @@
package game
import "github.com/google/uuid"
// A command is simply a function that acts on the a given instance in the world
type Command func() error
// CommandMove will move the instance in question
func (w *World) CommandMove(id uuid.UUID, vec Vector) Command {
return func() error {
// Move the instance
_, err := w.MovePosition(id, vec)
return err
}
}
// CommandSpawn
// TODO: Two spawn commands with the same id could trigger a fail later on, we should prevent that somehow
func (w *World) CommandSpawn(id uuid.UUID) Command {
return func() error {
return w.Spawn(id)
}
}