Move default rover params to function

This commit is contained in:
Marc Di Luzio 2020-07-19 18:23:11 +01:00
parent faa1271c5a
commit ddbbdce1f8
2 changed files with 15 additions and 10 deletions

View file

@ -5,6 +5,7 @@ import (
"log"
"time"
"github.com/google/uuid"
"github.com/mdiluz/rove/pkg/atlas"
"github.com/mdiluz/rove/pkg/maths"
)
@ -51,6 +52,19 @@ type Rover struct {
Logs []RoverLogEntry `json:"logs"`
}
// DefaultRover returns a default rover object with default settings
func DefaultRover() Rover {
return Rover{
Range: 4,
Integrity: 10,
MaximumIntegrity: 10,
Capacity: 10,
Charge: 10,
MaximumCharge: 10,
Name: uuid.New().String(),
}
}
// AddLogEntryf adds an entry to the rovers log
func (r *Rover) AddLogEntryf(format string, args ...interface{}) {
text := fmt.Sprintf(format, args...)

View file

@ -8,7 +8,6 @@ import (
"os"
"sync"
"github.com/google/uuid"
"github.com/mdiluz/rove/pkg/atlas"
"github.com/mdiluz/rove/pkg/maths"
"github.com/mdiluz/rove/proto/roveapi"
@ -78,15 +77,7 @@ func (w *World) SpawnRover() (string, error) {
defer w.worldMutex.Unlock()
// Initialise the rover
rover := Rover{
Range: 4,
Integrity: 10,
MaximumIntegrity: 10,
Capacity: 10,
Charge: 10,
MaximumCharge: 10,
Name: uuid.New().String(),
}
rover := DefaultRover()
// Assign a random name if we have words
if len(w.words) > 0 {