refactor: group uuid instead of index
This commit is contained in:
@@ -1,13 +1,32 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"iter"
|
||||
|
||||
"github.com/google/uuid"
|
||||
e "github.com/iliadenisov/galaxy/internal/error"
|
||||
"github.com/iliadenisov/galaxy/internal/model/game"
|
||||
)
|
||||
|
||||
func (c *Cache) CreateShips(ri int, shipTypeName string, planetNumber uint, quantity int) error {
|
||||
class, _, ok := c.ShipClass(ri, shipTypeName)
|
||||
if !ok {
|
||||
return e.NewEntityNotExistsError("ship class q", shipTypeName)
|
||||
}
|
||||
|
||||
p, ok := c.Planet(planetNumber)
|
||||
if !ok {
|
||||
return e.NewEntityNotExistsError("planet #%d", planetNumber)
|
||||
}
|
||||
if !p.OwnedBy(c.g.Race[ri].ID) {
|
||||
return e.NewEntityNotOwnedError("planet #%d", planetNumber)
|
||||
}
|
||||
|
||||
c.createShipsUnsafe(ri, class.ID, p.Number, uint(quantity))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Cache) AddRace(n string) (int, uuid.UUID) {
|
||||
id := uuid.New()
|
||||
r := &game.Race{
|
||||
@@ -57,15 +76,6 @@ func (c *Cache) MustFleetID(ri int, name string) uuid.UUID {
|
||||
panic("fleet not found")
|
||||
}
|
||||
|
||||
func (c *Cache) MustShipGroup(ri int, index uint) *game.ShipGroup {
|
||||
for sg := range c.listShipGroups(ri) {
|
||||
if sg.Index == index {
|
||||
return sg
|
||||
}
|
||||
}
|
||||
panic(fmt.Sprintf("race i=%d have no group i=%d", ri, index))
|
||||
}
|
||||
|
||||
func (c *Cache) MustShipClass(ri int, name string) *game.ShipType {
|
||||
st, _, ok := c.ShipClass(ri, name)
|
||||
if !ok {
|
||||
|
||||
Reference in New Issue
Block a user