Add /spawn command to let an account spawn it's primary instance
This commit is contained in:
parent
0a1f7a37c4
commit
50c970fea2
6 changed files with 151 additions and 11 deletions
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,5 +20,7 @@ func TestWorld_CreateInstance(t *testing.T) {
|
|||
// Basic duplicate check
|
||||
if a == b {
|
||||
t.Errorf("Created identical instances")
|
||||
} else if len(world.instances) != 2 {
|
||||
t.Errorf("Incorrect number of instances created")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue