refactor: exclude from fleet when break group
This commit is contained in:
@@ -135,7 +135,7 @@ func (c *Cache) ShipGroupJoinFleet(ri int, fleetName string, groupID uuid.UUID)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.internalShipGroupJoinFleet(sgi, &c.g.Fleets[fi].ID)
|
c.internalShipGroupJoinFleet(sgi, c.g.Fleets[fi].ID)
|
||||||
|
|
||||||
if oldFleetID != nil {
|
if oldFleetID != nil {
|
||||||
keepOldFleet := false
|
keepOldFleet := false
|
||||||
|
|||||||
@@ -18,9 +18,9 @@ func (c *Cache) ShipGroup(groupIndex int) *game.ShipGroup {
|
|||||||
return &c.g.ShipGroups[groupIndex]
|
return &c.g.ShipGroups[groupIndex]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cache) internalShipGroupJoinFleet(groupIndex int, fID *uuid.UUID) {
|
func (c *Cache) internalShipGroupJoinFleet(groupIndex int, fID uuid.UUID) {
|
||||||
c.validateShipGroupIndex(groupIndex)
|
c.validateShipGroupIndex(groupIndex)
|
||||||
c.g.ShipGroups[groupIndex].FleetID = fID
|
c.g.ShipGroups[groupIndex].FleetID = &fID
|
||||||
c.invalidateFleetCache()
|
c.invalidateFleetCache()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -377,7 +377,7 @@ func (c *Cache) shipGroupTransfer(ri, riAccept int, groupID uuid.UUID) (err erro
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cache) ShipGroupBreak(ri int, groupID, newID uuid.UUID, quantity uint) error {
|
func (c *Cache) ShipGroupBreak(ri int, groupID, newID uuid.UUID, quantity uint) (err error) {
|
||||||
c.validateRaceIndex(ri)
|
c.validateRaceIndex(ri)
|
||||||
sgi, ok := c.raceShipGroupIndex(ri, groupID)
|
sgi, ok := c.raceShipGroupIndex(ri, groupID)
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -397,15 +397,14 @@ func (c *Cache) ShipGroupBreak(ri int, groupID, newID uuid.UUID, quantity uint)
|
|||||||
return e.NewBeakGroupNumberNotEnoughError("%d<%d", c.ShipGroup(sgi).Number, quantity)
|
return e.NewBeakGroupNumberNotEnoughError("%d<%d", c.ShipGroup(sgi).Number, quantity)
|
||||||
}
|
}
|
||||||
|
|
||||||
if quantity == 0 || quantity == c.ShipGroup(sgi).Number {
|
if quantity > 0 && quantity < c.ShipGroup(sgi).Number {
|
||||||
c.internalShipGroupJoinFleet(sgi, nil)
|
if sgi, err = c.breakGroup(ri, groupID, quantity); err != nil {
|
||||||
} else {
|
return
|
||||||
// TODO: which group stays in fleet?
|
|
||||||
if _, err := c.breakGroup(ri, groupID, quantity); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.ShipGroup(sgi).FleetID = nil
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ var allowedSpecialChars = map[rune]bool{
|
|||||||
'_': true,
|
'_': true,
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: router validator
|
|
||||||
func ValidateTypeName(input string) (string, bool) {
|
func ValidateTypeName(input string) (string, bool) {
|
||||||
// Trim leading and trailing spaces
|
// Trim leading and trailing spaces
|
||||||
trimmed := strings.TrimSpace(input)
|
trimmed := strings.TrimSpace(input)
|
||||||
|
|||||||
Reference in New Issue
Block a user