package game import ( "encoding/json" "fmt" "maps" "github.com/google/uuid" "github.com/iliadenisov/galaxy/internal/model/report" ) type TechSet map[Tech]float64 func (ts TechSet) Value(t Tech) float64 { if v, ok := ts[t]; ok { return v } else { panic(fmt.Sprintf("TechSet: Value: %s's value not set", t.String())) } } func (ts TechSet) Set(t Tech, v float64) TechSet { m := maps.Clone(ts) m[t] = v return m } type Game struct { ID uuid.UUID `json:"id"` Turn uint `json:"turn"` Map Map `json:"map"` Race []Race `json:"races"` Votes float64 `json:"votes"` ShipGroups []ShipGroup `json:"shipGroup,omitempty"` Fleets []Fleet `json:"fleet,omitempty"` } type GameMeta struct { Battles []BattleMeta `json:"battles,omitempty"` Bombings []report.BombingPlanetReport `json:"bombings,omitempty"` } type BattleMeta struct { Turn uint `json:"turn"` Planet uint `json:"planet"` BattleID uuid.UUID `json:"battle_id"` ObserverIDs []uuid.UUID `json:"observer_ids"` } // TODO: remove if not needed func (g Game) RaceVotes(raceID uuid.UUID) float64 { var result float64 for i := range g.Map.Planet { if g.Map.Planet[i].Owner == raceID { result += g.Map.Planet[i].Votes() } } return result } func (g Game) MarshalBinary() (data []byte, err error) { return json.Marshal(&g) } func (g *Game) UnmarshalBinary(data []byte) error { return json.Unmarshal(data, g) } func (b GameMeta) MarshalBinary() (data []byte, err error) { return json.Marshal(&b) } func (b *GameMeta) UnmarshalBinary(data []byte) error { return json.Unmarshal(data, b) }