Prepare to refactor movement to be based on attributes

This commit is contained in:
Marc Di Luzio 2020-06-04 18:54:33 +01:00
parent d0a5b91de7
commit 33f25a7414
8 changed files with 45 additions and 47 deletions

View file

@ -1,7 +1,5 @@
package server
import "github.com/mdiluz/rove/pkg/game"
// ==============================
// API: /status method: GET
// Queries the status of the server
@ -45,7 +43,9 @@ type SpawnResponse struct {
Success bool `json:"success"`
Error string `json:"error"`
Position game.Vector `json:"position"`
// The location of the spawned entity
X float64 `json:"x"`
Y float64 `json:"y"`
}
// ==============================
@ -76,7 +76,8 @@ type Command struct {
Command string `json:"command"`
// Used for CommandMove
Vector game.Vector `json:"vector"`
Bearing float64 `json:"bearing"` // The direction to move in degrees
Duration int64 `json:"duration"` // The duration of the move in seconds
}
// ================

View file

@ -135,7 +135,8 @@ func HandleSpawn(s *Server, b io.ReadCloser, w io.Writer) error {
response.Error = err.Error()
} else {
response.Success = true
response.Position = pos
response.X = pos.X
response.Y = pos.Y
}
}
@ -179,7 +180,7 @@ func HandleCommands(s *Server, b io.ReadCloser, w io.Writer) error {
for _, c := range data.Commands {
switch c.Command {
case CommandMove:
cmds = append(cmds, s.world.CommandMove(inst, c.Vector))
cmds = append(cmds, s.world.CommandMove(inst, c.Bearing, c.Duration))
}
}

View file

@ -7,7 +7,6 @@ import (
"net/http/httptest"
"testing"
"github.com/mdiluz/rove/pkg/game"
"github.com/stretchr/testify/assert"
)
@ -81,14 +80,13 @@ func TestHandleCommands(t *testing.T) {
// Spawn the primary instance for the account
_, inst, err := s.SpawnPrimaryForAccount(a.Id)
move := game.Vector{X: 1, Y: 2, Z: 3}
data := CommandsData{
Id: a.Id.String(),
Commands: []Command{
{
Command: CommandMove,
Vector: move,
Command: CommandMove,
Bearing: 0.0,
Duration: 1,
},
},
}
@ -108,9 +106,9 @@ func TestHandleCommands(t *testing.T) {
t.Errorf("got false for /commands")
}
if pos, err := s.world.GetPosition(inst); err != nil {
if _, err := s.world.GetPosition(inst); err != nil {
t.Error("Couldn't get position for the primary instance")
} else if pos != move {
t.Error("Mismatched position after commands")
}
// TODO: Check position is correct
}