diff --git a/cmd/rove/main.go b/cmd/rove/main.go index 6613121..9fc853a 100644 --- a/cmd/rove/main.go +++ b/cmd/rove/main.go @@ -26,14 +26,14 @@ func printUsage() { fmt.Fprintln(os.Stderr, "Usage: rove ARG [OPT...]") fmt.Fprintf(os.Stderr, "\n") fmt.Fprintln(os.Stderr, "Arguments:") - fmt.Fprintln(os.Stderr, "\tversion outputs version") - fmt.Fprintln(os.Stderr, "\thelp outputs this usage text") - fmt.Fprintln(os.Stderr, "\tconfig [HOST] outputs the local config, optionally sets host") - fmt.Fprintln(os.Stderr, "\tserver-status prints the server status") - fmt.Fprintln(os.Stderr, "\tregister NAME registers an account and spawns a rover") - fmt.Fprintln(os.Stderr, "\tradar prints radar data in ASCII form") - fmt.Fprintln(os.Stderr, "\tstatus gets rover status") - fmt.Fprintln(os.Stderr, "\tcommand [NUM] CMD [VAL...] queues commands, accepts multiple, see below") + fmt.Fprintln(os.Stderr, "\tversion outputs version") + fmt.Fprintln(os.Stderr, "\thelp outputs this usage text") + fmt.Fprintln(os.Stderr, "\tconfig [HOST] outputs the local config, optionally sets host") + fmt.Fprintln(os.Stderr, "\tserver-status prints the server status") + fmt.Fprintln(os.Stderr, "\tregister NAME registers an account and spawns a rover") + fmt.Fprintln(os.Stderr, "\tradar prints radar data in ASCII form") + fmt.Fprintln(os.Stderr, "\tstatus gets rover status") + fmt.Fprintln(os.Stderr, "\tcommand [REPEAT] CMD [VAL...] queues commands, accepts multiple in sequence for command values see below") fmt.Fprintf(os.Stderr, "\n") fmt.Fprintln(os.Stderr, "Rover commands:") fmt.Fprintln(os.Stderr, "\ttoggle toggles the current sail mode") @@ -244,7 +244,7 @@ func InnerMain(command string, args ...string) error { number = num i++ if i >= len(args) { - return fmt.Errorf("must pass command after number") + return fmt.Errorf("must pass command after repeat number") } } @@ -262,7 +262,7 @@ func InnerMain(command string, args ...string) error { &roveapi.Command{ Command: roveapi.CommandType_turn, Bearing: b, - Number: int32(number), + Repeat: int32(number), }, ) case "broadcast": @@ -276,7 +276,7 @@ func InnerMain(command string, args ...string) error { &roveapi.Command{ Command: roveapi.CommandType_broadcast, Data: []byte(args[i]), - Number: int32(number), + Repeat: int32(number), }, ) default: @@ -284,7 +284,7 @@ func InnerMain(command string, args ...string) error { commands = append(commands, &roveapi.Command{ Command: roveapi.CommandType(roveapi.CommandType_value[args[i]]), - Number: int32(number), + Repeat: int32(number), }, ) } diff --git a/cmd/rove/main_test.go b/cmd/rove/main_test.go index 50fdf98..d0e12d6 100644 --- a/cmd/rove/main_test.go +++ b/cmd/rove/main_test.go @@ -60,6 +60,5 @@ func Test_InnerMain(t *testing.T) { // Give it malformed commands assert.Error(t, InnerMain("command", "unknown")) assert.Error(t, InnerMain("command", "broadcast")) - assert.Error(t, InnerMain("command", "0", "wait")) assert.Error(t, InnerMain("command", "1")) } diff --git a/pkg/rove/command_test.go b/pkg/rove/command_test.go index 592b40c..dde7070 100644 --- a/pkg/rove/command_test.go +++ b/pkg/rove/command_test.go @@ -229,10 +229,10 @@ func TestCommand_Wait(t *testing.T) { assert.NoError(t, err) assert.Equal(t, roveapi.SailPosition_SolarCharging, r.SailPosition) - err = w.Enqueue(a, &roveapi.Command{Command: roveapi.CommandType_wait, Number: 5}, &roveapi.Command{Command: roveapi.CommandType_toggle}) + err = w.Enqueue(a, &roveapi.Command{Command: roveapi.CommandType_wait, Repeat: 4}, &roveapi.Command{Command: roveapi.CommandType_toggle}) assert.NoError(t, err) - // Tick 5 times during the wait + // Tick 5 times during the wait (1 normal execute + 4) for i := 0; i < 5; i++ { w.Tick() diff --git a/pkg/rove/world.go b/pkg/rove/world.go index 4d08c7a..d2483b5 100644 --- a/pkg/rove/world.go +++ b/pkg/rove/world.go @@ -583,9 +583,6 @@ func (w *World) Enqueue(rover string, commands ...*roveapi.Command) error { return fmt.Errorf("turn command given unknown bearing") } case roveapi.CommandType_wait: - if c.GetNumber() <= 0 { - return fmt.Errorf("wait command must be given positie number of ticks to wait") - } case roveapi.CommandType_toggle: case roveapi.CommandType_stash: case roveapi.CommandType_repair: @@ -717,9 +714,6 @@ func (w *World) Tick() { func (w *World) ExecuteCommand(c *roveapi.Command, rover string) (done bool, err error) { log.Printf("Executing command: %+v for %s\n", c.Command, rover) - // Decrement the number of the command - c.Number-- - switch c.Command { case roveapi.CommandType_toggle: _, err = w.RoverToggle(rover) @@ -741,7 +735,9 @@ func (w *World) ExecuteCommand(c *roveapi.Command, rover string) (done bool, err return true, fmt.Errorf("unknown command: %s", c.Command) } - return c.Number <= 0, err + // Decrement the repeat number + c.Repeat-- + return c.Repeat < 0, err } // Daytime returns if it's currently daytime diff --git a/proto/roveapi/roveapi.pb.go b/proto/roveapi/roveapi.pb.go index 4c0178e..753c058 100644 --- a/proto/roveapi/roveapi.pb.go +++ b/proto/roveapi/roveapi.pb.go @@ -641,8 +641,8 @@ type Command struct { // The command type Command CommandType `protobuf:"varint,1,opt,name=command,proto3,enum=roveapi.CommandType" json:"command,omitempty"` - // The number of times to execute the command (assumes 1 if not present or 0) - Number int32 `protobuf:"varint,2,opt,name=number,proto3" json:"number,omitempty"` + // The number of times to repeat the command after the first + Repeat int32 `protobuf:"varint,2,opt,name=repeat,proto3" json:"repeat,omitempty"` // broadcast - a simple message, must be composed of up to 3 printable ASCII // glyphs (32-126) Data []byte `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"` @@ -689,9 +689,9 @@ func (x *Command) GetCommand() CommandType { return CommandType_none } -func (x *Command) GetNumber() int32 { +func (x *Command) GetRepeat() int32 { if x != nil { - return x.Number + return x.Repeat } return 0 } @@ -1427,8 +1427,8 @@ var file_roveapi_roveapi_proto_rawDesc = []byte{ 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x12, 0x2e, 0x0a, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x14, 0x2e, 0x72, 0x6f, 0x76, 0x65, 0x61, 0x70, 0x69, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x54, 0x79, 0x70, 0x65, 0x52, 0x07, 0x63, 0x6f, - 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x12, 0x0a, + 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x70, 0x65, 0x61, 0x74, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x72, 0x65, 0x70, 0x65, 0x61, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x2a, 0x0a, 0x07, 0x62, 0x65, 0x61, 0x72, 0x69, 0x6e, 0x67, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x10, 0x2e, 0x72, 0x6f, 0x76, 0x65, 0x61, 0x70, 0x69, 0x2e, 0x42, 0x65, 0x61, diff --git a/proto/roveapi/roveapi.proto b/proto/roveapi/roveapi.proto index 21c992b..9aad682 100644 --- a/proto/roveapi/roveapi.proto +++ b/proto/roveapi/roveapi.proto @@ -126,8 +126,8 @@ message Command { // The command type CommandType command = 1; - // The number of times to execute the command (assumes 1 if not present or 0) - int32 number = 2; + // The number of times to repeat the command after the first + int32 repeat = 2; // broadcast - a simple message, must be composed of up to 3 printable ASCII // glyphs (32-126)