Skip to content

Commit

Permalink
Merge branch 'develop-revertResourceSettings' into develop
Browse files Browse the repository at this point in the history
# Conflicts:
#	pkg/extractor/v9/extractor.go
#	pkg/extractor/v9/extracts.go
  • Loading branch information
alaingilbert committed Sep 24, 2022
2 parents 8eae33f + 363fdad commit de02c8c
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 51 deletions.
5 changes: 0 additions & 5 deletions pkg/extractor/v9/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,6 @@ func (e *Extractor) ExtractResourceSettings(pageHTML []byte) (ogame.ResourceSett
return e.ExtractResourceSettingsFromDoc(doc)
}

// ExtractResourceSettingsFromDoc ...
func (e *Extractor) ExtractResourceSettingsFromDoc(doc *goquery.Document) (ogame.ResourceSettings, string, error) {
return extractResourceSettingsFromDoc(doc)
}

// ExtractLfBuildings ...
func (e *Extractor) ExtractLfBuildings(pageHTML []byte) (ogame.LfBuildings, error) {
doc, _ := goquery.NewDocumentFromReader(bytes.NewReader(pageHTML))
Expand Down
6 changes: 0 additions & 6 deletions pkg/extractor/v9/extractor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,6 @@ func TestGetConstructions(t *testing.T) {
assert.Equal(t, int64(18355), researchCountdown)
}

func TestExtractResourceSettings(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("../../../samples/v9.0.4/en/resource_settings.html")
settings, _, _ := NewExtractor().ExtractResourceSettings(pageHTMLBytes)
assert.Equal(t, ogame.ResourceSettings{MetalMine: 100, CrystalMine: 100, DeuteriumSynthesizer: 100, SolarPlant: 100, FusionReactor: 100, SolarSatellite: 100, Crawler: 100, PlasmaTechnology: 100}, settings)
}

func TestExtractUserInfos(t *testing.T) {
pageHTMLBytes, _ := ioutil.ReadFile("../../../samples/v9.0.4/en/overview.html")
info, err := NewExtractor().ExtractUserInfos(pageHTMLBytes)
Expand Down
37 changes: 0 additions & 37 deletions pkg/extractor/v9/extracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,43 +534,6 @@ func extractEspionageReportFromDoc(doc *goquery.Document, location *time.Locatio
return report, nil
}

func extractResourceSettingsFromDoc(doc *goquery.Document) (ogame.ResourceSettings, string, error) {
bodyID := v6.ExtractBodyIDFromDoc(doc)
if bodyID == "overview" {
return ogame.ResourceSettings{}, "", ogame.ErrInvalidPlanetID
}
vals := make([]int64, 0)
doc.Find("option").Each(func(i int, s *goquery.Selection) {
_, selectedExists := s.Attr("selected")
if selectedExists {
a, _ := s.Attr("value")
val := utils.DoParseI64(a)
vals = append(vals, val)
}
})

if len(vals) != 8 {
return ogame.ResourceSettings{}, "", errors.New("failed to find all resource settings")
}

res := ogame.ResourceSettings{}
res.MetalMine = vals[0]
res.CrystalMine = vals[1]
res.DeuteriumSynthesizer = vals[2]
res.SolarPlant = vals[3]
res.FusionReactor = vals[4]
res.SolarSatellite = vals[5]
res.Crawler = vals[6]
res.PlasmaTechnology = vals[7]

token, exists := doc.Find("form input[name=token]").Attr("value")
if !exists {
return ogame.ResourceSettings{}, "", errors.New("unable to find token")
}

return res, token, nil
}

func GetNbr(doc *goquery.Document, name string) int64 {
val := utils.DoParseI64(doc.Find("span."+name+" span.level").First().AttrOr("data-value", "0"))
return val
Expand Down
4 changes: 1 addition & 3 deletions pkg/ogame/resourceSettings.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ type ResourceSettings struct {
FusionReactor int64
SolarSatellite int64
Crawler int64
PlasmaTechnology int64
}

func (r ResourceSettings) String() string {
Expand All @@ -22,6 +21,5 @@ func (r ResourceSettings) String() string {
" Solar Plant: " + utils.FI64(r.SolarPlant) + "\n" +
" Fusion Reactor: " + utils.FI64(r.FusionReactor) + "\n" +
" Solar Satellite: " + utils.FI64(r.SolarSatellite) + "\n" +
" Crawler: " + utils.FI64(r.Crawler) + "\n" +
" Plasma Technology: " + utils.FI64(r.PlasmaTechnology)
" Crawler: " + utils.FI64(r.Crawler) + "\n"
}

0 comments on commit de02c8c

Please sign in to comment.