diff --git a/cmd/rove-server/api_test.go b/cmd/rove-server/api_test.go index 25dbdc9..344cfe4 100644 --- a/cmd/rove-server/api_test.go +++ b/cmd/rove-server/api_test.go @@ -17,7 +17,7 @@ var serv rove.Server func TestMain(m *testing.M) { s := server.NewServer() - if err := s.Initialise(); err != nil { + if err := s.Initialise(true); err != nil { fmt.Println(err) os.Exit(1) } diff --git a/cmd/rove-server/main.go b/cmd/rove-server/main.go index 445af36..0cd4232 100644 --- a/cmd/rove-server/main.go +++ b/cmd/rove-server/main.go @@ -40,7 +40,7 @@ func InnerMain() { server.OptionTick(*tick)) // Initialise the server - if err := s.Initialise(); err != nil { + if err := s.Initialise(true); err != nil { panic(err) } diff --git a/cmd/rove/main_test.go b/cmd/rove/main_test.go index b47a133..2a48e8c 100644 --- a/cmd/rove/main_test.go +++ b/cmd/rove/main_test.go @@ -16,7 +16,7 @@ var address string func TestMain(m *testing.M) { s := server.NewServer() - if err := s.Initialise(); err != nil { + if err := s.Initialise(true); err != nil { fmt.Println(err) os.Exit(1) } diff --git a/pkg/game/world.go b/pkg/game/world.go index a4d1912..2d02c52 100644 --- a/pkg/game/world.go +++ b/pkg/game/world.go @@ -39,9 +39,11 @@ func NewWorld(size int, chunkSize int) *World { } // SpawnWorld spawns a border at the edge of the world atlas -func (w *World) SpawnWorld() error { - if err := w.Atlas.SpawnRocks(); err != nil { - return err +func (w *World) SpawnWorld(fillWorld bool) error { + if fillWorld { + if err := w.Atlas.SpawnRocks(); err != nil { + return err + } } return w.Atlas.SpawnWalls() } diff --git a/pkg/server/routes_test.go b/pkg/server/routes_test.go index b933ec0..ce5cffa 100644 --- a/pkg/server/routes_test.go +++ b/pkg/server/routes_test.go @@ -19,7 +19,7 @@ func TestHandleStatus(t *testing.T) { response := httptest.NewRecorder() s := NewServer() - s.Initialise() + s.Initialise(true) s.router.ServeHTTP(response, request) assert.Equal(t, http.StatusOK, response.Code) @@ -46,7 +46,7 @@ func TestHandleRegister(t *testing.T) { response := httptest.NewRecorder() s := NewServer() - s.Initialise() + s.Initialise(true) s.router.ServeHTTP(response, request) assert.Equal(t, http.StatusOK, response.Code) @@ -60,7 +60,7 @@ func TestHandleRegister(t *testing.T) { func TestHandleSpawn(t *testing.T) { s := NewServer() - s.Initialise() + s.Initialise(true) a, err := s.accountant.RegisterAccount("test") assert.NoError(t, err, "Error registering account") data := rove.SpawnData{} @@ -85,12 +85,13 @@ func TestHandleSpawn(t *testing.T) { func TestHandleCommand(t *testing.T) { s := NewServer() - s.Initialise() + s.Initialise(false) // Leave the world empty with no obstacles a, err := s.accountant.RegisterAccount("test") assert.NoError(t, err, "Error registering account") // Spawn the rover rover for the account _, inst, err := s.SpawnRoverForAccount(a.Id) + assert.NoError(t, s.world.WarpRover(inst, game.Vector{})) attribs, err := s.world.RoverAttributes(inst) assert.NoError(t, err, "Couldn't get rover position") @@ -135,7 +136,7 @@ func TestHandleCommand(t *testing.T) { func TestHandleRadar(t *testing.T) { s := NewServer() - s.Initialise() + s.Initialise(false) // Spawn a clean world a, err := s.accountant.RegisterAccount("test") assert.NoError(t, err, "Error registering account") @@ -189,7 +190,7 @@ func TestHandleRadar(t *testing.T) { func TestHandleRover(t *testing.T) { s := NewServer() - s.Initialise() + s.Initialise(true) a, err := s.accountant.RegisterAccount("test") assert.NoError(t, err, "Error registering account") diff --git a/pkg/server/server.go b/pkg/server/server.go index 206d135..ae4dd3b 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -104,13 +104,13 @@ func NewServer(opts ...ServerOption) *Server { } // Initialise sets up internal state ready to serve -func (s *Server) Initialise() (err error) { +func (s *Server) Initialise(fillWorld bool) (err error) { // Add to our sync s.sync.Add(1) // Spawn a border on the default world - if err := s.world.SpawnWorld(); err != nil { + if err := s.world.SpawnWorld(fillWorld); err != nil { return err } diff --git a/pkg/server/server_test.go b/pkg/server/server_test.go index e4face7..cf07bdc 100644 --- a/pkg/server/server_test.go +++ b/pkg/server/server_test.go @@ -33,7 +33,7 @@ func TestServer_Run(t *testing.T) { server := NewServer() if server == nil { t.Error("Failed to create server") - } else if err := server.Initialise(); err != nil { + } else if err := server.Initialise(true); err != nil { t.Error(err) } @@ -48,7 +48,7 @@ func TestServer_RunPersistentData(t *testing.T) { server := NewServer(OptionPersistentData()) if server == nil { t.Error("Failed to create server") - } else if err := server.Initialise(); err != nil { + } else if err := server.Initialise(true); err != nil { t.Error(err) }