Move default rover params to function
This commit is contained in:
parent
faa1271c5a
commit
ddbbdce1f8
2 changed files with 15 additions and 10 deletions
|
@ -5,6 +5,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
"github.com/mdiluz/rove/pkg/atlas"
|
"github.com/mdiluz/rove/pkg/atlas"
|
||||||
"github.com/mdiluz/rove/pkg/maths"
|
"github.com/mdiluz/rove/pkg/maths"
|
||||||
)
|
)
|
||||||
|
@ -51,6 +52,19 @@ type Rover struct {
|
||||||
Logs []RoverLogEntry `json:"logs"`
|
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
|
// AddLogEntryf adds an entry to the rovers log
|
||||||
func (r *Rover) AddLogEntryf(format string, args ...interface{}) {
|
func (r *Rover) AddLogEntryf(format string, args ...interface{}) {
|
||||||
text := fmt.Sprintf(format, args...)
|
text := fmt.Sprintf(format, args...)
|
||||||
|
|
|
@ -8,7 +8,6 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
|
||||||
"github.com/mdiluz/rove/pkg/atlas"
|
"github.com/mdiluz/rove/pkg/atlas"
|
||||||
"github.com/mdiluz/rove/pkg/maths"
|
"github.com/mdiluz/rove/pkg/maths"
|
||||||
"github.com/mdiluz/rove/proto/roveapi"
|
"github.com/mdiluz/rove/proto/roveapi"
|
||||||
|
@ -78,15 +77,7 @@ func (w *World) SpawnRover() (string, error) {
|
||||||
defer w.worldMutex.Unlock()
|
defer w.worldMutex.Unlock()
|
||||||
|
|
||||||
// Initialise the rover
|
// Initialise the rover
|
||||||
rover := Rover{
|
rover := DefaultRover()
|
||||||
Range: 4,
|
|
||||||
Integrity: 10,
|
|
||||||
MaximumIntegrity: 10,
|
|
||||||
Capacity: 10,
|
|
||||||
Charge: 10,
|
|
||||||
MaximumCharge: 10,
|
|
||||||
Name: uuid.New().String(),
|
|
||||||
}
|
|
||||||
|
|
||||||
// Assign a random name if we have words
|
// Assign a random name if we have words
|
||||||
if len(w.words) > 0 {
|
if len(w.words) > 0 {
|
||||||
|
|
Loading…
Add table
Reference in a new issue