wip: generate report

This commit is contained in:
Ilia Denisov
2026-02-03 23:41:18 +02:00
parent a567229f8a
commit adbe605783
36 changed files with 1037 additions and 391 deletions
+18 -9
View File
@@ -2,6 +2,7 @@ package controller
import (
"fmt"
"iter"
"slices"
"github.com/google/uuid"
@@ -30,15 +31,13 @@ func (c *Cache) CreateShipType(ri int, typeName string, drive float64, ammo int,
return e.NewEntityTypeNameDuplicateError("ship type %q", c.g.Race[ri].ShipTypes[st].Name)
}
c.g.Race[ri].ShipTypes = append(c.g.Race[ri].ShipTypes, game.ShipType{
ID: uuid.New(),
ShipTypeReport: game.ShipTypeReport{
Name: n,
Drive: drive,
Armament: uint(ammo),
Weapons: weapons,
Shields: shileds,
Cargo: cargo,
},
ID: uuid.New(),
Name: n,
Drive: drive,
Armament: uint(ammo),
Weapons: weapons,
Shields: shileds,
Cargo: cargo,
})
c.invalidateShipGroupCache()
c.invalidateFleetCache()
@@ -155,6 +154,16 @@ func (c *Cache) ShipTypes(ri int) []*game.ShipType {
return result
}
func (c *Cache) ListShipTypes(ri int) iter.Seq[*game.ShipType] {
return func(yield func(*game.ShipType) bool) {
for i := range c.g.Race[ri].ShipTypes {
if !yield(&c.g.Race[ri].ShipTypes[i]) {
return
}
}
}
}
func (c *Cache) ShipClass(ri int, name string) (*game.ShipType, int, bool) {
i := slices.IndexFunc(c.g.Race[ri].ShipTypes, func(st game.ShipType) bool { return st.Name == name })
if i < 0 {