Add /spawn command to let an account spawn it's primary instance

This commit is contained in:
Marc Di Luzio 2020-06-02 17:44:39 +01:00
parent 0a1f7a37c4
commit 50c970fea2
6 changed files with 151 additions and 11 deletions

View file

@ -1,20 +1,30 @@
package game
import "github.com/google/uuid"
import (
"fmt"
"github.com/google/uuid"
)
// World describes a self contained universe and everything in it
type World struct {
instances []Instance
instances map[uuid.UUID]Instance
}
// Instance describes a single entity or instance of an entity in the world
type Instance struct {
// id is a unique ID for this instance
id uuid.UUID
// pos represents where this instance is in the world
pos Position
}
// NewWorld creates a new world object
func NewWorld() *World {
return &World{}
return &World{
instances: make(map[uuid.UUID]Instance),
}
}
// Adds an instance to the game
@ -27,7 +37,16 @@ func (w *World) CreateInstance() uuid.UUID {
}
// Append the instance to the list
w.instances = append(w.instances, instance)
w.instances[id] = instance
return id
}
// GetPosition returns the position of a given instance
func (w World) GetPosition(id uuid.UUID) (Position, error) {
if i, ok := w.instances[id]; ok {
return i.pos, nil
} else {
return Position{}, fmt.Errorf("no instance matching id")
}
}