Simplify duplicate command types
This commit is contained in:
parent
97d3583384
commit
e3ce87e964
8 changed files with 28 additions and 56 deletions
|
@ -146,10 +146,7 @@ func HandleCommand(s *Server, vars map[string]string, b io.ReadCloser, w io.Writ
|
|||
} else if inst, err := s.accountant.GetRover(id); err != nil {
|
||||
response.Error = fmt.Sprintf("Provided account has no rover: %s", err)
|
||||
|
||||
} else if cmds, err := s.ConvertCommands(data.Commands, inst); err != nil {
|
||||
response.Error = fmt.Sprintf("Couldn't convert commands: %s", err)
|
||||
|
||||
} else if err := s.world.Execute(cmds...); err != nil {
|
||||
} else if err := s.world.Execute(inst, data.Commands...); err != nil {
|
||||
response.Error = fmt.Sprintf("Failed to execute commands: %s", err)
|
||||
|
||||
} else {
|
||||
|
|
|
@ -96,9 +96,9 @@ func TestHandleCommand(t *testing.T) {
|
|||
assert.NoError(t, err, "Couldn't get rover position")
|
||||
|
||||
data := rove.CommandData{
|
||||
Commands: []rove.Command{
|
||||
Commands: []game.Command{
|
||||
{
|
||||
Command: rove.CommandMove,
|
||||
Command: game.CommandMove,
|
||||
Bearing: "N",
|
||||
Duration: 1,
|
||||
},
|
||||
|
|
|
@ -15,7 +15,6 @@ import (
|
|||
"github.com/mdiluz/rove/pkg/accounts"
|
||||
"github.com/mdiluz/rove/pkg/game"
|
||||
"github.com/mdiluz/rove/pkg/persistence"
|
||||
"github.com/mdiluz/rove/pkg/rove"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -195,19 +194,3 @@ func (s *Server) SpawnRoverForAccount(accountid uuid.UUID) (game.Vector, uuid.UU
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ConvertCommands converts server commands to game commands
|
||||
func (s *Server) ConvertCommands(commands []rove.Command, inst uuid.UUID) ([]game.Command, error) {
|
||||
var cmds []game.Command
|
||||
for _, c := range commands {
|
||||
switch c.Command {
|
||||
case rove.CommandMove:
|
||||
if bearing, err := game.DirectionFromString(c.Bearing); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
cmds = append(cmds, s.world.CommandMove(inst, bearing, c.Duration))
|
||||
}
|
||||
}
|
||||
}
|
||||
return cmds, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue