cmd: upgrade group
This commit is contained in:
@@ -7,34 +7,34 @@ import (
|
||||
e "github.com/iliadenisov/galaxy/internal/error"
|
||||
)
|
||||
|
||||
type PlanetProduction string
|
||||
type ProductionType string
|
||||
|
||||
const (
|
||||
ProductionNone PlanetProduction = "-"
|
||||
ProductionMaterial PlanetProduction = "MAT" // Сырьё
|
||||
ProductionCapital PlanetProduction = "CAP" // Промышленность
|
||||
ProductionNone ProductionType = "-"
|
||||
ProductionMaterial ProductionType = "MAT" // Сырьё
|
||||
ProductionCapital ProductionType = "CAP" // Промышленность
|
||||
|
||||
ResearchDrive PlanetProduction = "DRIVE"
|
||||
ResearchWeapons PlanetProduction = "WEAPONS"
|
||||
ResearchShields PlanetProduction = "SHIELDS"
|
||||
ResearchCargo PlanetProduction = "CARGO"
|
||||
ResearchDrive ProductionType = "DRIVE"
|
||||
ResearchWeapons ProductionType = "WEAPONS"
|
||||
ResearchShields ProductionType = "SHIELDS"
|
||||
ResearchCargo ProductionType = "CARGO"
|
||||
|
||||
ResearchScience PlanetProduction = "SCIENCE"
|
||||
ProductionShip PlanetProduction = "SHIP"
|
||||
ResearchScience ProductionType = "SCIENCE"
|
||||
ProductionShip ProductionType = "SHIP"
|
||||
)
|
||||
|
||||
type ProductionType struct {
|
||||
Production PlanetProduction `json:"type"`
|
||||
SubjectID *uuid.UUID `json:"subjectId"`
|
||||
Progress *float64 `json:"progress"`
|
||||
type Production struct {
|
||||
Type ProductionType `json:"type"`
|
||||
SubjectID *uuid.UUID `json:"subjectId"`
|
||||
Progress *float64 `json:"progress"`
|
||||
}
|
||||
|
||||
func (p PlanetProduction) AsType(subject uuid.UUID) ProductionType {
|
||||
func (p ProductionType) AsType(subject uuid.UUID) Production {
|
||||
switch p {
|
||||
case ResearchScience, ProductionShip:
|
||||
return ProductionType{Production: p, SubjectID: &subject}
|
||||
return Production{Type: p, SubjectID: &subject}
|
||||
default:
|
||||
return ProductionType{Production: p, SubjectID: nil}
|
||||
return Production{Type: p, SubjectID: nil}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,8 +43,8 @@ func (g Game) PlanetProduction(raceName string, planetNumber int, prodType, subj
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var prod PlanetProduction
|
||||
switch PlanetProduction(prodType) {
|
||||
var prod ProductionType
|
||||
switch ProductionType(prodType) {
|
||||
case ProductionMaterial:
|
||||
prod = ProductionMaterial
|
||||
case ProductionCapital:
|
||||
@@ -67,7 +67,7 @@ func (g Game) PlanetProduction(raceName string, planetNumber int, prodType, subj
|
||||
return g.planetProductionInternal(ri, planetNumber, prod, subject)
|
||||
}
|
||||
|
||||
func (g Game) planetProductionInternal(ri int, number int, prod PlanetProduction, subj string) error {
|
||||
func (g Game) planetProductionInternal(ri int, number int, prod ProductionType, subj string) error {
|
||||
if number < 0 {
|
||||
return e.NewPlanetNumberError(number)
|
||||
}
|
||||
@@ -95,7 +95,7 @@ func (g Game) planetProductionInternal(ri int, number int, prod PlanetProduction
|
||||
if i < 0 {
|
||||
return e.NewEntityNotExistsError("ship type %w", subj)
|
||||
}
|
||||
if g.Map.Planet[i].Production.Production == ProductionShip &&
|
||||
if g.Map.Planet[i].Production.Type == ProductionShip &&
|
||||
g.Map.Planet[i].Production.SubjectID != nil &&
|
||||
*g.Map.Planet[i].Production.SubjectID == g.Race[ri].ShipTypes[i].ID {
|
||||
// Planet already produces this ship type, keeping progress intact
|
||||
@@ -105,7 +105,7 @@ func (g Game) planetProductionInternal(ri int, number int, prod PlanetProduction
|
||||
var progress float64 = 0.
|
||||
g.Map.Planet[i].Production.Progress = &progress
|
||||
}
|
||||
if g.Map.Planet[i].Production.Production == ProductionShip {
|
||||
if g.Map.Planet[i].Production.Type == ProductionShip {
|
||||
if g.Map.Planet[i].Production.SubjectID == nil {
|
||||
return e.NewGameStateError("planet #%d produces ship but SubjectID is empty", g.Map.Planet[i].Number)
|
||||
}
|
||||
@@ -122,7 +122,7 @@ func (g Game) planetProductionInternal(ri int, number int, prod PlanetProduction
|
||||
extra := mat * progress
|
||||
g.Map.Planet[i].Material += extra
|
||||
}
|
||||
g.Map.Planet[i].Production.Production = prod
|
||||
g.Map.Planet[i].Production.Type = prod
|
||||
g.Map.Planet[i].Production.SubjectID = subjectID
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user