chore: re-package
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
module galaxy/model
|
||||
|
||||
go 1.26.0
|
||||
|
||||
require github.com/google/uuid v1.6.0
|
||||
@@ -0,0 +1 @@
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
@@ -0,0 +1,223 @@
|
||||
package order
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
type Order struct {
|
||||
Commands []DecodableCommand `json:"cmd"`
|
||||
}
|
||||
|
||||
func (o Order) MarshalBinary() (data []byte, err error) {
|
||||
return json.Marshal(&o)
|
||||
}
|
||||
|
||||
func (o *Order) UnmarshalBinary(data []byte) error {
|
||||
return json.Unmarshal(data, o)
|
||||
}
|
||||
|
||||
func AsCommand[E DecodableCommand](c DecodableCommand) (result E, ok bool) {
|
||||
if v, ok := c.(E); ok {
|
||||
return v, true
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
type CommandType string
|
||||
|
||||
const (
|
||||
CommandTypeRaceQuit CommandType = "raceQuit"
|
||||
CommandTypeRaceVote CommandType = "raceVote"
|
||||
CommandTypeRaceRelation CommandType = "raceRelation"
|
||||
CommandTypeShipClassCreate CommandType = "shipClassCreate"
|
||||
CommandTypeShipClassMerge CommandType = "shipClassMerge"
|
||||
CommandTypeShipClassRemove CommandType = "shipClassRemove"
|
||||
CommandTypeShipGroupBreak CommandType = "shipGroupBreak"
|
||||
CommandTypeShipGroupLoad CommandType = "shipGroupLoad"
|
||||
CommandTypeShipGroupUnload CommandType = "shipGroupUnload"
|
||||
CommandTypeShipGroupSend CommandType = "shipGroupSend"
|
||||
CommandTypeShipGroupUpgrade CommandType = "shipGroupUpgrade"
|
||||
CommandTypeShipGroupMerge CommandType = "shipGroupMerge"
|
||||
CommandTypeShipGroupDismantle CommandType = "shipGroupDismantle"
|
||||
CommandTypeShipGroupTransfer CommandType = "shipGroupTransfer"
|
||||
CommandTypeShipGroupJoinFleet CommandType = "shipGroupJoinFleet"
|
||||
CommandTypeFleetMerge CommandType = "fleetMerge"
|
||||
CommandTypeFleetSend CommandType = "fleetSend"
|
||||
CommandTypeScienceCreate CommandType = "scienceCreate"
|
||||
CommandTypeScienceRemove CommandType = "scienceRemove"
|
||||
CommandTypePlanetRename CommandType = "planetRename"
|
||||
CommandTypePlanetProduce CommandType = "planetProduce"
|
||||
CommandTypePlanetRouteSet CommandType = "planetRouteSet"
|
||||
CommandTypePlanetRouteRemove CommandType = "planetRouteRemove"
|
||||
)
|
||||
|
||||
func (ct CommandType) String() string {
|
||||
return string(ct)
|
||||
}
|
||||
|
||||
type DecodableCommand interface {
|
||||
CommandID() string
|
||||
CommandType() CommandType
|
||||
}
|
||||
|
||||
type CommandMeta struct {
|
||||
CmdType CommandType `json:"@type" binding:"notblank"`
|
||||
CmdID string `json:"cmdId" binding:"required,uuid_rfc4122"`
|
||||
CmdApplied *bool `json:"cmdApplied,omitempty"`
|
||||
CmdErrCode *int `json:"cmdErrorCode,omitempty"`
|
||||
}
|
||||
|
||||
func (cm CommandMeta) CommandType() CommandType {
|
||||
return cm.CmdType
|
||||
}
|
||||
|
||||
func (cm CommandMeta) CommandID() string {
|
||||
return cm.CmdID
|
||||
}
|
||||
|
||||
func (cm *CommandMeta) Result(errCode int) {
|
||||
cm.CmdErrCode = &errCode
|
||||
cm.CmdApplied = new(bool(errCode == 0))
|
||||
}
|
||||
|
||||
type CommandRaceQuit struct {
|
||||
CommandMeta
|
||||
}
|
||||
|
||||
type CommandRaceVote struct {
|
||||
CommandMeta
|
||||
Acceptor string `json:"acceptor" binding:"notblank,entity"`
|
||||
}
|
||||
|
||||
type CommandRaceRelation struct {
|
||||
CommandMeta
|
||||
Acceptor string `json:"acceptor" binding:"notblank,entity"`
|
||||
Relation string `json:"relation" binding:"oneof=WAR PEACE"`
|
||||
}
|
||||
|
||||
type CommandShipClassCreate struct {
|
||||
CommandMeta
|
||||
Name string `json:"name" binding:"notblank,entity"`
|
||||
Drive float64 `json:"drive" binding:"eq=0|gte=1"`
|
||||
Armament int `json:"armament" binding:"ammoWeapons=Weapons"`
|
||||
Weapons float64 `json:"weapons" binding:"ammoWeapons=Armament"`
|
||||
Shields float64 `json:"shields" binding:"eq=0|gte=1"`
|
||||
Cargo float64 `json:"cargo" binding:"eq=0|gte=1"`
|
||||
}
|
||||
|
||||
type CommandShipClassMerge struct {
|
||||
CommandMeta
|
||||
Name string `json:"name" binding:"notblank,entity,nefield=Target"`
|
||||
Target string `json:"target" binding:"notblank,entity,nefield=Name"`
|
||||
}
|
||||
|
||||
type CommandShipClassRemove struct {
|
||||
CommandMeta
|
||||
Name string `json:"name" binding:"required,notblank,entity"`
|
||||
}
|
||||
|
||||
type CommandShipGroupLoad struct {
|
||||
CommandMeta
|
||||
ID string `json:"id" binding:"required,uuid_rfc4122"`
|
||||
Cargo string `json:"cargo" binding:"oneof=COL MAT CAP"`
|
||||
Quantity float64 `json:"quantity" binding:"gte=0"`
|
||||
}
|
||||
|
||||
type CommandShipGroupUnload struct {
|
||||
CommandMeta
|
||||
ID string `json:"id" binding:"required,uuid_rfc4122"`
|
||||
Quantity float64 `json:"quantity" binding:"gte=0"`
|
||||
}
|
||||
|
||||
type CommandShipGroupSend struct {
|
||||
CommandMeta
|
||||
ID string `json:"id" binding:"required,uuid_rfc4122"`
|
||||
Destination int `json:"planetNumber" binding:"gte=0"`
|
||||
}
|
||||
|
||||
type CommandShipGroupUpgrade struct {
|
||||
CommandMeta
|
||||
ID string `json:"id" binding:"required,uuid_rfc4122"`
|
||||
Tech string `json:"tech" binding:"oneof=ALL DRIVE WEAPONS SHIELDS CARGO"`
|
||||
Level float64 `json:"level" binding:"eq=0|gt=1"`
|
||||
}
|
||||
|
||||
type CommandShipGroupMerge struct {
|
||||
CommandMeta
|
||||
}
|
||||
|
||||
type CommandShipGroupBreak struct {
|
||||
CommandMeta
|
||||
ID string `json:"id" binding:"uuid_rfc4122,nefield=NewID"`
|
||||
NewID string `json:"newId" binding:"uuid_rfc4122,nefield=ID"`
|
||||
Quantity int `json:"quantity" binding:"gte=0"`
|
||||
}
|
||||
|
||||
type CommandShipGroupDismantle struct {
|
||||
CommandMeta
|
||||
ID string `json:"id" binding:"required,uuid_rfc4122"`
|
||||
}
|
||||
|
||||
type CommandShipGroupTransfer struct {
|
||||
CommandMeta
|
||||
ID string `json:"id" binding:"required,uuid_rfc4122"`
|
||||
Acceptor string `json:"acceptor" binding:"required,notblank,entity"`
|
||||
}
|
||||
|
||||
type CommandShipGroupJoinFleet struct {
|
||||
CommandMeta
|
||||
ID string `json:"id" binding:"required,uuid_rfc4122"`
|
||||
Name string `json:"name" binding:"required,notblank,entity"`
|
||||
}
|
||||
|
||||
type CommandFleetMerge struct {
|
||||
CommandMeta
|
||||
Name string `json:"name" binding:"required,notblank,entity,nefield=Target"`
|
||||
Target string `json:"target" binding:"required,notblank,entity,nefield=Name"`
|
||||
}
|
||||
|
||||
type CommandFleetSend struct {
|
||||
CommandMeta
|
||||
Name string `json:"name" binding:"required,notblank,entity"`
|
||||
Destination int `json:"planetNumber" binding:"gte=0"`
|
||||
}
|
||||
|
||||
type CommandScienceCreate struct {
|
||||
CommandMeta
|
||||
Name string `json:"name" binding:"required,notblank,entity"`
|
||||
Drive float64 `json:"drive" binding:"gte=0,lte=1"`
|
||||
Weapons float64 `json:"weapons" binding:"gte=0,lte=1"`
|
||||
Shields float64 `json:"shields" binding:"gte=0,lte=1"`
|
||||
Cargo float64 `json:"cargo" binding:"gte=0,lte=1"`
|
||||
}
|
||||
|
||||
type CommandScienceRemove struct {
|
||||
CommandMeta
|
||||
Name string `json:"name" binding:"required,notblank,entity"`
|
||||
}
|
||||
|
||||
type CommandPlanetRename struct {
|
||||
CommandMeta
|
||||
Number int `json:"planetNumber" binding:"gte=0"`
|
||||
Name string `json:"name" binding:"required,notblank,entity"`
|
||||
}
|
||||
|
||||
type CommandPlanetProduce struct {
|
||||
CommandMeta
|
||||
Number int `json:"planetNumber" binding:"gte=0"`
|
||||
Production string `json:"production" binding:"oneof=MAT CAP DRIVE WEAPONS SHIELDS CARGO SCIENCE SHIP"`
|
||||
Subject string `json:"subject" binding:"subject=Production"`
|
||||
}
|
||||
|
||||
type CommandPlanetRouteSet struct {
|
||||
CommandMeta
|
||||
Origin int `json:"fromPlanetNumber" binding:"gte=0,nefield=Destination"`
|
||||
Destination int `json:"toPlanetNumber" binding:"gte=0,nefield=Origin"`
|
||||
LoadType string `json:"loadType" binding:"oneof=MAT CAP COL EMP"`
|
||||
}
|
||||
|
||||
type CommandPlanetRouteRemove struct {
|
||||
CommandMeta
|
||||
Origin int `json:"fromPlanetNumber" binding:"gte=0"`
|
||||
LoadType string `json:"loadType" binding:"oneof=MAT CAP COL EMP"`
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package report
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type BattleReport struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
Planet uint `json:"planet"`
|
||||
PlanetName string `json:"planetName"`
|
||||
Races map[int]uuid.UUID `json:"races"`
|
||||
Ships map[int]BattleReportGroup `json:"ships"`
|
||||
Protocol []BattleActionReport `json:"protocol"`
|
||||
}
|
||||
|
||||
type BattleReportGroup struct {
|
||||
InBattle bool `json:"inBattle"`
|
||||
Number uint `json:"num"`
|
||||
NumberLeft uint `json:"numLeft"`
|
||||
LoadQuantity Float `json:"loadQuantity"`
|
||||
Tech map[string]Float `json:"tech"`
|
||||
Race string `json:"race"`
|
||||
ClassName string `json:"className"`
|
||||
LoadType string `json:"loadType"`
|
||||
}
|
||||
|
||||
type BattleActionReport struct {
|
||||
Attacker int `json:"a"`
|
||||
AttackerShipClass int `json:"sa"`
|
||||
Defender int `json:"d"`
|
||||
DefenderShipClass int `json:"sd"`
|
||||
Destroyed bool `json:"x"`
|
||||
}
|
||||
|
||||
func (b BattleReport) MarshalBinary() (data []byte, err error) {
|
||||
return json.Marshal(&b)
|
||||
}
|
||||
|
||||
func (b *BattleReport) UnmarshalBinary(data []byte) error {
|
||||
return json.Unmarshal(data, b)
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package report
|
||||
|
||||
import "github.com/google/uuid"
|
||||
|
||||
type Bombing struct {
|
||||
PlanetOwnedID uuid.UUID `json:"-"` // make report: filter by planet's owner before bombing
|
||||
Number uint `json:"planet"`
|
||||
Planet string `json:"planetName"`
|
||||
Owner string `json:"owner"`
|
||||
Attacker string `json:"attacker"`
|
||||
Production string `json:"production"`
|
||||
Industry Float `json:"industry"` // I - Промышленность
|
||||
Population Float `json:"population"` // P - Население
|
||||
Colonists Float `json:"colonists"` // COL C - Количество колонистов
|
||||
Capital Float `json:"capital"` // CAP $ - Запасы промышленности
|
||||
Material Float `json:"material"` // MAT M - Запасы ресурсов / сырья
|
||||
AttackPower Float `json:"attack"`
|
||||
Wiped bool `json:"wiped"`
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package report
|
||||
|
||||
type OtherPlanet struct {
|
||||
Owner string `json:"owner"`
|
||||
LocalPlanet
|
||||
}
|
||||
|
||||
type LocalPlanet struct {
|
||||
UninhabitedPlanet
|
||||
Industry Float `json:"industry"` // I - Промышленность
|
||||
Population Float `json:"population"` // P - Население
|
||||
Colonists Float `json:"colonists"` // COL C - Количество колонистов
|
||||
Production string `json:"production"`
|
||||
FreeIndustry Float `json:"freeInductry"` // Параметр "L" - Свободный производственный потенциал
|
||||
// [ ] FreeIndustry - неактуальная информация, т.к. модернизация происходит в процессе производства хода
|
||||
}
|
||||
|
||||
type UninhabitedPlanet struct {
|
||||
UnidentifiedPlanet
|
||||
Size Float `json:"size"`
|
||||
Name string `json:"name"`
|
||||
Resources Float `json:"resources"` // R - Ресурсы
|
||||
Capital Float `json:"capital"` // CAP $ - Запасы промышленности
|
||||
Material Float `json:"material"` // MAT M - Запасы ресурсов / сырьё
|
||||
}
|
||||
|
||||
type UnidentifiedPlanet struct {
|
||||
X Float `json:"x"`
|
||||
Y Float `json:"y"`
|
||||
Number uint `json:"number"`
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package report
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
n "galaxy/util"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type Float float64
|
||||
|
||||
func F(v float64) Float {
|
||||
return Float(n.Fixed3(v))
|
||||
}
|
||||
|
||||
type Report struct {
|
||||
Version uint `json:"version"`
|
||||
Turn uint `json:"turn"`
|
||||
Width uint32 `json:"mapWidth"`
|
||||
Height uint32 `json:"mapHeight"`
|
||||
PlanetCount uint32 `json:"mapPlanets"`
|
||||
Race string `json:"race"`
|
||||
RaceID uuid.UUID `json:"-"`
|
||||
Votes Float `json:"votes"`
|
||||
VoteFor string `json:"voteFor"`
|
||||
Player []Player `json:"player"`
|
||||
LocalScience []Science `json:"localScience,omitempty"`
|
||||
OtherScience []OtherScience `json:"otherScience,omitempty"`
|
||||
LocalShipClass []ShipClass `json:"localShipClass,omitempty"`
|
||||
OtherShipClass []OthersShipClass `json:"otherShipClass,omitempty"`
|
||||
Battle []uuid.UUID `json:"battle,omitempty"`
|
||||
Bombing []*Bombing `json:"bombing,omitempty"`
|
||||
IncomingGroup []IncomingGroup `json:"incomingGroup,omitempty"`
|
||||
LocalPlanet []LocalPlanet `json:"localPlanet,omitempty"`
|
||||
ShipProduction []ShipProduction `json:"shipProduction,omitempty"`
|
||||
Route []Route `json:"route,omitempty"`
|
||||
OtherPlanet []OtherPlanet `json:"otherPlanet,omitempty"`
|
||||
UninhabitedPlanet []UninhabitedPlanet `json:"uninhabitedPlanet,omitempty"`
|
||||
UnidentifiedPlanet []UnidentifiedPlanet `json:"unidentifiedPlanet,omitempty"`
|
||||
LocalFleet []LocalFleet `json:"localFleet,omitempty"`
|
||||
LocalGroup []LocalGroup `json:"localGroup,omitempty"`
|
||||
OtherGroup []OtherGroup `json:"otherGroup,omitempty"`
|
||||
UnidentifiedGroup []UnidentifiedGroup `json:"unidentifiedGroup,omitempty"`
|
||||
|
||||
OnPlanetGroupCache map[uint][]int `json:"-"`
|
||||
InSpaceGroupRangeCache map[int]map[uint]float64 `json:"-"`
|
||||
}
|
||||
|
||||
type Route struct {
|
||||
Planet uint `json:"planet"`
|
||||
Route map[uint]string `json:"route"`
|
||||
}
|
||||
|
||||
type Player struct {
|
||||
ID uuid.UUID `json:"-"`
|
||||
Name string `json:"name"`
|
||||
Drive Float `json:"drive"`
|
||||
Weapons Float `json:"weapons"`
|
||||
Shields Float `json:"shields"`
|
||||
Cargo Float `json:"cargo"`
|
||||
Population Float `json:"population"`
|
||||
Industry Float `json:"industry"`
|
||||
Planets uint16 `json:"planets"`
|
||||
Relation string `json:"relation"`
|
||||
Votes Float `json:"votes"`
|
||||
Extinct bool `json:"extinct"`
|
||||
}
|
||||
|
||||
func (r Report) MarshalBinary() (data []byte, err error) {
|
||||
return json.Marshal(&r)
|
||||
}
|
||||
|
||||
func (r *Report) UnmarshalBinary(data []byte) error {
|
||||
return json.Unmarshal(data, r)
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package report
|
||||
|
||||
type Science struct {
|
||||
Name string `json:"name"`
|
||||
Drive Float `json:"drive"`
|
||||
Weapons Float `json:"weapons"`
|
||||
Shields Float `json:"shields"`
|
||||
Cargo Float `json:"cargo"`
|
||||
}
|
||||
|
||||
type OtherScience struct {
|
||||
Race string `json:"race"`
|
||||
Science
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package report
|
||||
|
||||
import "github.com/google/uuid"
|
||||
|
||||
type ShipClass struct {
|
||||
Name string `json:"name"`
|
||||
Drive Float `json:"drive"`
|
||||
Armament uint `json:"armament"`
|
||||
Weapons Float `json:"weapons"`
|
||||
Shields Float `json:"shields"`
|
||||
Cargo Float `json:"cargo"`
|
||||
Mass Float `json:"mass"`
|
||||
}
|
||||
|
||||
type OthersShipClass struct {
|
||||
Race string `json:"race"`
|
||||
ShipClass
|
||||
}
|
||||
|
||||
type ShipProduction struct {
|
||||
Planet uint `json:"planet"` // Галактический номер планеты
|
||||
Class string `json:"class"` // Наименование типа строящегося корабля
|
||||
Cost Float `json:"cost"` // Стоимость постройки одного такого корабля (в производственных ед.) без учета расходов на добычу сырья
|
||||
ProdUsed Float `json:"prodUsed"` // Сколько производственных единиц уже было затрачено на постройку этого корабля (уже учитывая производство сырья)
|
||||
Percent Float `json:"percent"` // Процент завершения активного производства
|
||||
Free Float `json:"free"` // Свободный производственный потенциал
|
||||
}
|
||||
|
||||
type IncomingGroup struct {
|
||||
Origin uint `json:"origin"`
|
||||
Destination uint `json:"destination"`
|
||||
Distance Float `json:"distance"`
|
||||
Speed Float `json:"speed"`
|
||||
Mass Float `json:"mass"`
|
||||
}
|
||||
|
||||
type LocalGroup struct {
|
||||
OtherGroup
|
||||
ID uuid.UUID `json:"id"`
|
||||
State string `json:"state"`
|
||||
Fleet *string `json:"fleet"`
|
||||
}
|
||||
|
||||
type OtherGroup struct {
|
||||
Number uint `json:"number"`
|
||||
Class string `json:"class"`
|
||||
Tech map[string]Float `json:"tech"`
|
||||
Cargo string `json:"cargo"`
|
||||
Load Float `json:"load"`
|
||||
Destination uint `json:"destination"`
|
||||
Origin *uint `json:"origin,omitempty"`
|
||||
Range *Float `json:"range,omitempty"`
|
||||
Speed Float `json:"speed"`
|
||||
Mass Float `json:"mass"`
|
||||
}
|
||||
|
||||
type UnidentifiedGroup struct {
|
||||
X Float `json:"x"`
|
||||
Y Float `json:"y"`
|
||||
}
|
||||
|
||||
type LocalFleet struct {
|
||||
Name string `json:"name"`
|
||||
Groups uint `json:"groups"`
|
||||
Destination uint `json:"destination"`
|
||||
Origin *uint `json:"origin,omitempty"`
|
||||
Range *Float `json:"range,omitempty"`
|
||||
Speed Float `json:"speed"`
|
||||
State string `json:"state"`
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package rest
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
type Command struct {
|
||||
Actor string `json:"actor" binding:"notblank"`
|
||||
Commands []json.RawMessage `json:"cmd" binding:"min=1"`
|
||||
}
|
||||
|
||||
func (o Command) MarshalBinary() (data []byte, err error) {
|
||||
return json.Marshal(&o)
|
||||
}
|
||||
|
||||
func (o *Command) UnmarshalBinary(data []byte) error {
|
||||
return json.Unmarshal(data, o)
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package rest
|
||||
|
||||
type Init struct {
|
||||
Races []Race `json:"races" binding:"required,gte=10"`
|
||||
}
|
||||
|
||||
type Race struct {
|
||||
Name string `json:"name" binding:"required,notblank"`
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package rest
|
||||
|
||||
import "github.com/google/uuid"
|
||||
|
||||
type StateResponse struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
Turn uint `json:"turn"`
|
||||
Stage uint `json:"stage"`
|
||||
Players []PlayerState `json:"player"`
|
||||
}
|
||||
|
||||
type PlayerState struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Extinct bool `json:"extinct"`
|
||||
}
|
||||
Reference in New Issue
Block a user