cmd: join ship groups

This commit is contained in:
Ilia Denisov
2025-11-13 21:53:10 +03:00
parent 33efa86065
commit 126f381b04
10 changed files with 661 additions and 153 deletions
+19
View File
@@ -0,0 +1,19 @@
package game
import "github.com/iliadenisov/galaxy/pkg/model/game"
func JoinEqualGroups(configure func(*Param), race string) (err error) {
control(configure, func(c *ctrl) {
c.execute(func(r Repo, g game.Game) {
err = joinEqualGroups(r, g, race)
})
})
return
}
func joinEqualGroups(r Repo, g game.Game, race string) error {
if err := g.JoinEqualGroups(race); err != nil {
return err
}
return r.SaveState(g)
}
+16
View File
@@ -0,0 +1,16 @@
package game_test
import (
"testing"
"github.com/iliadenisov/galaxy/pkg/game"
mg "github.com/iliadenisov/galaxy/pkg/model/game"
"github.com/stretchr/testify/assert"
)
func TestJoinEqualGroups(t *testing.T) {
g(t, func(p func(*game.Param), g func() mg.Game) {
err := game.JoinEqualGroups(p, "race_01")
assert.NoError(t, err)
})
}
+4 -4
View File
@@ -65,7 +65,7 @@ func buildGameOnMap(races []string, m generator.Map) (*game.Game, error) {
Shields: 1,
Cargo: 1,
}
gameMap.Planet = append(gameMap.Planet, newPlanet(
gameMap.Planet = append(gameMap.Planet, NewPlanet(
planetCount,
m.HomePlanets[i].HW.RandomName(),
raceID,
@@ -79,7 +79,7 @@ func buildGameOnMap(races []string, m generator.Map) (*game.Game, error) {
))
planetCount++
for dw := range m.HomePlanets[i].DW {
gameMap.Planet = append(gameMap.Planet, newPlanet(
gameMap.Planet = append(gameMap.Planet, NewPlanet(
planetCount,
m.HomePlanets[i].DW[dw].RandomName(),
raceID,
@@ -101,7 +101,7 @@ func buildGameOnMap(races []string, m generator.Map) (*game.Game, error) {
}
for i := range m.FreePlanets {
gameMap.Planet = append(gameMap.Planet, newPlanet(
gameMap.Planet = append(gameMap.Planet, NewPlanet(
planetCount,
m.FreePlanets[i].RandomName(),
uuid.Nil,
@@ -125,7 +125,7 @@ func buildGameOnMap(races []string, m generator.Map) (*game.Game, error) {
return g, nil
}
func newPlanet(num uint, name string, owner uuid.UUID, x, y, size, pop, ind, res float64, prod game.ProductionType) game.Planet {
func NewPlanet(num uint, name string, owner uuid.UUID, x, y, size, pop, ind, res float64, prod game.ProductionType) game.Planet {
return game.Planet{
Owner: owner,
PlanetReport: game.PlanetReport{