refactor: group uuid instead of index
This commit is contained in:
@@ -46,7 +46,8 @@ func (c *Cache) FleetState(fleetID uuid.UUID) FleetState {
|
||||
InSpace: func() (game.InSpace, bool) { return game.InSpace{}, false },
|
||||
AtPlanet: func() (uint, bool) { return 0, false },
|
||||
}
|
||||
for sg := range c.FleetGroups(ri, fi) {
|
||||
for sgi := range c.FleetGroupIdx(ri, fi) {
|
||||
sg := c.ShipGroup(sgi)
|
||||
if fs.State == fleetStateNil {
|
||||
fs.State = sg.State()
|
||||
fs.Destination = sg.Destination
|
||||
@@ -100,15 +101,15 @@ func (c *Cache) FleetSpeedAndMass(fi int) (float64, float64) {
|
||||
return speed, mass
|
||||
}
|
||||
|
||||
func (c *Cache) ShipGroupJoinFleet(ri int, fleetName string, groupIndex, quantity uint) (err error) {
|
||||
func (c *Cache) ShipGroupJoinFleet(ri int, fleetName string, groupID uuid.UUID, quantity uint) (err error) {
|
||||
c.validateRaceIndex(ri)
|
||||
name, ok := util.ValidateTypeName(fleetName)
|
||||
if !ok {
|
||||
return e.NewEntityTypeNameValidationError("%q", name)
|
||||
}
|
||||
sgi, ok := c.raceShipGroupIndex(ri, groupIndex)
|
||||
sgi, ok := c.raceShipGroupIndex(ri, groupID)
|
||||
if !ok {
|
||||
return e.NewEntityNotExistsError("group #%d", groupIndex)
|
||||
return e.NewEntityNotExistsError("group %s", groupID)
|
||||
}
|
||||
|
||||
if state := c.ShipGroup(sgi).State(); state != game.StateInOrbit {
|
||||
@@ -139,7 +140,7 @@ func (c *Cache) ShipGroupJoinFleet(ri int, fleetName string, groupIndex, quantit
|
||||
}
|
||||
|
||||
if quantity > 0 && quantity < c.ShipGroup(sgi).Number {
|
||||
nsgi, err := c.breakGroupSafe(ri, groupIndex, quantity)
|
||||
nsgi, err := c.breakGroupSafe(ri, groupID, quantity)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -268,13 +269,14 @@ func (c *Cache) MustFleetIndex(ID uuid.UUID) int {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Cache) FleetGroups(ri, fi int) iter.Seq[*game.ShipGroup] {
|
||||
func (c *Cache) FleetGroupIdx(ri, fi int) iter.Seq[int] {
|
||||
c.validateRaceIndex(ri)
|
||||
c.validateFleetIndex(fi)
|
||||
return func(yield func(*game.ShipGroup) bool) {
|
||||
for sg := range c.listShipGroups(ri) {
|
||||
return func(yield func(int) bool) {
|
||||
for sgi := range c.listShipGroupIdx(ri) {
|
||||
sg := c.ShipGroup(sgi)
|
||||
if sg.FleetID != nil && *sg.FleetID == c.g.Fleets[fi].ID {
|
||||
if !yield(sg) {
|
||||
if !yield(sgi) {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user