refactor: remove group & fleet
This commit is contained in:
@@ -68,22 +68,18 @@ func (c *Cache) ShipGroupDestroyItem(i int) {
|
|||||||
sg.Number -= 1
|
sg.Number -= 1
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cache) DeleteShipGroup(i int) {
|
|
||||||
c.validateShipGroupIndex(i)
|
|
||||||
c.unsafeDeleteShipGroup(i)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Cache) DeleteKilledShipGroups() {
|
func (c *Cache) DeleteKilledShipGroups() {
|
||||||
keepFleet := make(map[uuid.UUID]bool, len(c.g.Fleets))
|
keepFleet := make(map[uuid.UUID]bool, len(c.g.Fleets))
|
||||||
for i := len(c.g.ShipGroups) - 1; i >= 0; i-- {
|
for sgi := len(c.g.ShipGroups) - 1; sgi >= 0; sgi-- {
|
||||||
if c.g.ShipGroups[i].FleetID != nil {
|
if c.g.ShipGroups[sgi].FleetID != nil {
|
||||||
id := *c.g.ShipGroups[i].FleetID
|
id := *c.g.ShipGroups[sgi].FleetID
|
||||||
keepFleet[id] = keepFleet[id] || c.g.ShipGroups[i].Number > 0
|
keepFleet[id] = keepFleet[id] || c.g.ShipGroups[sgi].Number > 0
|
||||||
}
|
}
|
||||||
if c.g.ShipGroups[i].Number == 0 {
|
if c.g.ShipGroups[sgi].Number == 0 {
|
||||||
c.unsafeDeleteShipGroup(i)
|
c.g.ShipGroups = append(c.g.ShipGroups[:sgi], c.g.ShipGroups[sgi+1:]...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
c.invalidateShipGroupCache()
|
||||||
for id, keep := range keepFleet {
|
for id, keep := range keepFleet {
|
||||||
if keep {
|
if keep {
|
||||||
continue
|
continue
|
||||||
@@ -122,7 +118,7 @@ func (c *Cache) shipGroupMerge(ri int) {
|
|||||||
for i := 0; i < len(raceGroups)-1; i++ {
|
for i := 0; i < len(raceGroups)-1; i++ {
|
||||||
for j := len(raceGroups) - 1; j > i; j-- {
|
for j := len(raceGroups) - 1; j > i; j-- {
|
||||||
if raceGroups[i].Equal(raceGroups[j]) {
|
if raceGroups[i].Equal(raceGroups[j]) {
|
||||||
raceGroups[i].ID = raceGroups[j].ID
|
raceGroups[i].ID = raceGroups[j].ID // resulting group will have latest ID
|
||||||
raceGroups[i].Number += raceGroups[j].Number
|
raceGroups[i].Number += raceGroups[j].Number
|
||||||
raceGroups = append(raceGroups[:j], raceGroups[j+1:]...)
|
raceGroups = append(raceGroups[:j], raceGroups[j+1:]...)
|
||||||
}
|
}
|
||||||
@@ -141,8 +137,8 @@ func (c *Cache) shipGroupMerge(ri int) {
|
|||||||
|
|
||||||
slices.Sort(toDelete)
|
slices.Sort(toDelete)
|
||||||
slices.Reverse(toDelete)
|
slices.Reverse(toDelete)
|
||||||
for _, idx := range toDelete {
|
for _, sgi := range toDelete {
|
||||||
c.unsafeDeleteShipGroup(idx)
|
c.unsafeDeleteShipGroup(sgi)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range raceGroups {
|
for i := range raceGroups {
|
||||||
|
|||||||
Reference in New Issue
Block a user