Skip to content

Commit

Permalink
change lifeform booleans for an "enum" type
Browse files Browse the repository at this point in the history
  • Loading branch information
alaingilbert committed Sep 24, 2022
1 parent 668678e commit f5ef137
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
10 changes: 5 additions & 5 deletions pkg/extractor/v9/extracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ func GetNbr(doc *goquery.Document, name string) int64 {
func extractLfBuildingsFromDoc(doc *goquery.Document) (ogame.LfBuildings, error) {
res := ogame.LfBuildings{}
if doc.Find("#lifeform a div").HasClass("lifeform1") {
res.Humans = true
res.LifeformType = ogame.Humans
res.ResidentialSector = GetNbr(doc, "lifeformTech11101")
res.BiosphereFarm = GetNbr(doc, "lifeformTech11102")
res.ResearchCentre = GetNbr(doc, "lifeformTech11103")
Expand All @@ -588,7 +588,7 @@ func extractLfBuildingsFromDoc(doc *goquery.Document) (ogame.LfBuildings, error)
res.PlanetaryShield = GetNbr(doc, "lifeformTech11112")

} else if doc.Find("#lifeform a div").HasClass("lifeform2") {
res.Rocktal = true
res.LifeformType = ogame.Rocktal
res.MeditationEnclave = GetNbr(doc, "lifeformTech12101")
res.CrystalFarm = GetNbr(doc, "lifeformTech12102")
res.RuneTechnologium = GetNbr(doc, "lifeformTech12103")
Expand All @@ -603,7 +603,7 @@ func extractLfBuildingsFromDoc(doc *goquery.Document) (ogame.LfBuildings, error)
res.MetalRecyclingPlant = GetNbr(doc, "lifeformTech12112")

} else if doc.Find("#lifeform a div").HasClass("lifeform3") {
res.Mechas = true
res.LifeformType = ogame.Mechas
res.AssemblyLine = GetNbr(doc, "lifeformTech13101")
res.FusionCellFactory = GetNbr(doc, "lifeformTech13102")
res.RoboticsResearchCentre = GetNbr(doc, "lifeformTech13103")
Expand All @@ -618,7 +618,7 @@ func extractLfBuildingsFromDoc(doc *goquery.Document) (ogame.LfBuildings, error)
res.NanoRepairBots = GetNbr(doc, "lifeformTech13112")

} else if doc.Find("#lifeform a div").HasClass("lifeform4") {
res.Kaelesh = true
res.LifeformType = ogame.Kaelesh
res.Sanctuary = GetNbr(doc, "lifeformTech14101")
res.AntimatterCondenser = GetNbr(doc, "lifeformTech14102")
res.VortexChamber = GetNbr(doc, "lifeformTech14103")
Expand All @@ -633,7 +633,7 @@ func extractLfBuildingsFromDoc(doc *goquery.Document) (ogame.LfBuildings, error)
res.SupraRefractor = GetNbr(doc, "lifeformTech14112")

} else {
res.None = true
res.LifeformType = ogame.NoneLfType
}
return res, nil
}
Expand Down
31 changes: 26 additions & 5 deletions pkg/ogame/lfBuildings.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,34 @@ import (
// LazyLfBuildings ...
type LazyLfBuildings func() LfBuildings

type LifeformType int64

const (
NoneLfType LifeformType = iota
Humans
Rocktal
Mechas
Kaelesh
)

func (l *LifeformType) String() string {
switch *l {
case Humans:
return "humans"
case Rocktal:
return "rocktal"
case Mechas:
return "mechas"
case Kaelesh:
return "kaelesh"
default:
return "none"
}
}

// LfBuildings lifeform buildings
type LfBuildings struct {
None bool
Humans bool
Rocktal bool
Mechas bool
Kaelesh bool
LifeformType LifeformType
ResidentialSector int64 // 11101 // Lifeform (humans)
BiosphereFarm int64 // 11102
ResearchCentre int64 // 11103
Expand Down

0 comments on commit f5ef137

Please sign in to comment.