Use log instead of fmt for logging

Also fix up a few errors to lower case
This commit is contained in:
Marc Di Luzio 2020-06-11 19:04:53 +01:00
parent 1cafd4f2ce
commit 2f5863b17a
10 changed files with 49 additions and 47 deletions

View file

@ -56,7 +56,7 @@ func FromString(s string) (Bearing, error) {
return Bearing(i), nil
}
}
return -1, fmt.Errorf("Unknown bearing: %s", s)
return -1, fmt.Errorf("unknown bearing: %s", s)
}
var bearingVectors = []vector.Vector{

View file

@ -174,7 +174,7 @@ func (a *Atlas) Grow(size int) error {
}
delta := size - a.Size
if delta < 0 {
return fmt.Errorf("Cannot shrink an atlas")
return fmt.Errorf("cannot shrink an atlas")
} else if delta == 0 {
return nil
}

View file

@ -2,6 +2,7 @@ package game
import (
"fmt"
"log"
"math"
"math/rand"
"strings"
@ -101,7 +102,7 @@ func (w *World) SpawnRover() (uuid.UUID, error) {
return uuid.Nil, err
}
fmt.Printf("Spawned rover at %+v\n", rover.Attributes.Pos)
log.Printf("Spawned rover at %+v\n", rover.Attributes.Pos)
// Append the rover to the list
w.Rovers[rover.Id] = rover
@ -167,7 +168,7 @@ func (w *World) WarpRover(id uuid.UUID, pos vector.Vector) error {
if tile, err := w.Atlas.GetTile(pos); err != nil {
return fmt.Errorf("coudln't get state of destination rover tile: %s", err)
} else if tile == TileRover {
return fmt.Errorf("Can't warp rover to occupied tile, check before warping")
return fmt.Errorf("can't warp rover to occupied tile, check before warping")
} else if err := w.Atlas.SetTile(pos, TileRover); err != nil {
return fmt.Errorf("coudln't set rover tile: %s", err)
} else if err := w.Atlas.SetTile(i.Attributes.Pos, TileEmpty); err != nil {
@ -328,7 +329,7 @@ func (w *World) ExecuteCommandQueues() {
// Execute the command and clear up if requested
if done, err := w.ExecuteCommand(&c, rover); err != nil {
w.CommandQueue[rover] = cmds[1:]
fmt.Println(err)
log.Println(err)
} else if done {
w.CommandQueue[rover] = cmds[1:]
} else {
@ -349,7 +350,7 @@ func (w *World) ExecuteCommandQueues() {
// ExecuteCommand will execute a single command
func (w *World) ExecuteCommand(c *Command, rover uuid.UUID) (finished bool, err error) {
fmt.Printf("Executing command: %+v\n", *c)
log.Printf("Executing command: %+v\n", *c)
switch c.Command {
case "move":
@ -380,7 +381,7 @@ func PrintTiles(tiles []Tile) {
num := int(math.Sqrt(float64(len(tiles))))
for j := num - 1; j >= 0; j-- {
for i := 0; i < num; i++ {
fmt.Printf("%d", tiles[i+num*j])
log.Printf("%d", tiles[i+num*j])
}
fmt.Print("\n")
}

View file

@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
"path"
)
@ -38,7 +39,7 @@ func Save(name string, data interface{}) error {
}
}
fmt.Printf("Saved %s\n", p)
log.Printf("Saved %s\n", p)
return nil
}
@ -48,7 +49,7 @@ func Load(name string, data interface{}) error {
// Don't load anything if the file doesn't exist
_, err := os.Stat(p)
if os.IsNotExist(err) {
fmt.Printf("File %s didn't exist, loading with fresh data\n", p)
log.Printf("File %s didn't exist, loading with fresh data\n", p)
return nil
}
@ -56,13 +57,13 @@ func Load(name string, data interface{}) error {
if b, err := ioutil.ReadFile(p); err != nil {
return err
} else if len(b) == 0 {
fmt.Printf("File %s was empty, loading with fresh data\n", p)
log.Printf("File %s was empty, loading with fresh data\n", p)
return nil
} else if err := json.Unmarshal(b, data); err != nil {
return fmt.Errorf("failed to load file %s error: %s", p, err)
}
fmt.Printf("Loaded %s\n", p)
log.Printf("Loaded %s\n", p)
return nil
}
@ -76,7 +77,7 @@ func doAll(f saveLoadFunc, args ...interface{}) error {
var ok bool
name, ok = a.(string)
if !ok {
return fmt.Errorf("Incorrect args")
return fmt.Errorf("incorrect args")
}
} else {
if err := f(name, a); err != nil {