Fix up gocritic issues

This commit is contained in:
Marc Di Luzio 2020-06-10 12:32:15 +01:00
parent 2ee68e74ac
commit 14c4e61660
9 changed files with 72 additions and 56 deletions

View file

@ -29,7 +29,7 @@ type Atlas struct {
}
// NewAtlas creates a new empty atlas
func NewAtlas(size int, chunkSize int) Atlas {
func NewAtlas(size, chunkSize int) Atlas {
if size%2 != 0 {
log.Fatal("atlas size must always be even")
}
@ -77,11 +77,11 @@ func (a *Atlas) SpawnWalls() error {
if err := a.SetTile(vector.Vector{X: i, Y: extent - 1}, TileWall); err != nil { // N
return err
} else if a.SetTile(vector.Vector{X: extent - 1, Y: i}, TileWall); err != nil { // E
} else if err := a.SetTile(vector.Vector{X: extent - 1, Y: i}, TileWall); err != nil { // E
return err
} else if a.SetTile(vector.Vector{X: i, Y: -extent}, TileWall); err != nil { // S
} else if err := a.SetTile(vector.Vector{X: i, Y: -extent}, TileWall); err != nil { // S
return err
} else if a.SetTile(vector.Vector{X: -extent, Y: i}, TileWall); err != nil { // W
} else if err := a.SetTile(vector.Vector{X: -extent, Y: i}, TileWall); err != nil { // W
return err
}
}
@ -155,7 +155,7 @@ func (a *Atlas) ChunkOrigin(chunk int) vector.Vector {
}
// GetWorldExtent gets the min and max valid coordinates of world
func (a *Atlas) GetWorldExtents() (min vector.Vector, max vector.Vector) {
func (a *Atlas) GetWorldExtents() (min, max vector.Vector) {
min = vector.Vector{
X: -(a.Size / 2) * a.ChunkSize,
Y: -(a.Size / 2) * a.ChunkSize,

View file

@ -3,7 +3,6 @@ package game
import (
"testing"
"github.com/mdiluz/rove/pkg/bearing"
"github.com/mdiluz/rove/pkg/vector"
"github.com/stretchr/testify/assert"
)
@ -23,10 +22,9 @@ func TestCommand_Move(t *testing.T) {
err = world.WarpRover(a, pos)
assert.NoError(t, err, "Failed to set position for rover")
bearing := bearing.North
duration := 1
// Try the move command
moveCommand := Command{Command: CommandMove, Bearing: bearing.String(), Duration: duration}
moveCommand := Command{Command: CommandMove, Bearing: "N", Duration: duration}
assert.NoError(t, world.Enqueue(a, moveCommand), "Failed to execute move command")
// Tick the world

View file

@ -36,7 +36,7 @@ type World struct {
}
// NewWorld creates a new world object
func NewWorld(size int, chunkSize int) *World {
func NewWorld(size, chunkSize int) *World {
return &World{
Rovers: make(map[uuid.UUID]Rover),
CommandQueue: make(map[uuid.UUID]CommandStream),
@ -183,7 +183,7 @@ func (w *World) WarpRover(id uuid.UUID, pos vector.Vector) error {
}
// SetPosition sets an rovers position
func (w *World) MoveRover(id uuid.UUID, bearing bearing.Bearing) (RoverAttributes, error) {
func (w *World) MoveRover(id uuid.UUID, b bearing.Bearing) (RoverAttributes, error) {
w.worldMutex.Lock()
defer w.worldMutex.Unlock()
@ -192,7 +192,7 @@ func (w *World) MoveRover(id uuid.UUID, bearing bearing.Bearing) (RoverAttribute
distance := i.Attributes.Speed
// Calculate the full movement based on the bearing
move := bearing.Vector().Multiplied(distance)
move := b.Vector().Multiplied(distance)
// Try the new move position
newPos := i.Attributes.Pos.Added(move)

View file

@ -79,16 +79,16 @@ func TestWorld_GetSetMovePosition(t *testing.T) {
assert.NoError(t, err, "Failed to set position for rover")
assert.Equal(t, pos, newAttribs.Pos, "Failed to correctly set position for rover")
bearing := bearing.North
b := bearing.North
duration := 1
newAttribs, err = world.MoveRover(a, bearing)
newAttribs, err = world.MoveRover(a, b)
assert.NoError(t, err, "Failed to set position for rover")
pos.Add(vector.Vector{X: 0, Y: attribs.Speed * duration}) // We should have move one unit of the speed north
assert.Equal(t, pos, newAttribs.Pos, "Failed to correctly move position for rover")
// Place a tile in front of the rover
assert.NoError(t, world.Atlas.SetTile(vector.Vector{X: 0, Y: 2}, TileWall))
newAttribs, err = world.MoveRover(a, bearing)
newAttribs, err = world.MoveRover(a, b)
assert.Equal(t, pos, newAttribs.Pos, "Failed to correctly not move position for rover into wall")
}