Skip to content

Commit

Permalink
Add provider function to get job for class
Browse files Browse the repository at this point in the history
  • Loading branch information
karashiiro committed Apr 19, 2022
1 parent 2f62768 commit 280960e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
32 changes: 24 additions & 8 deletions classjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/xivapi/godestone/v2/internal/selectors"
)

var nonDigits = regexp.MustCompile("[^\\d]")
var nonDigits = regexp.MustCompile(`[^\d]`)

func (s *Scraper) buildClassJobCollector(charData *Character) *colly.Collector {
c := colly.NewCollector(
Expand Down Expand Up @@ -96,21 +96,37 @@ func (s *Scraper) buildClassJobCollector(charData *Character) *colly.Collector {

curCj.IsSpecialized = strings.Contains(e.Attr("class"), "meister")

jobInfo, err := s.dataProvider.ClassJob(names[0])
if err == nil {
curCj.JobID = uint8(jobInfo.ID)
}

if len(names) > 1 {
// "Job / Class"
jobInfo, err := s.dataProvider.ClassJob(names[0])
if err == nil {
curCj.JobID = uint8(jobInfo.ID)
}

classInfo, err := s.dataProvider.ClassJob(names[1])
if err == nil {
curCj.ClassID = uint8(classInfo.ID)
}
} else {
curCj.ClassID = uint8(curCj.JobID)
// "Job" or "Class"
cjInfo1, err := s.dataProvider.ClassJob(names[0])
if err == nil {
curCj.ClassID = uint8(cjInfo1.Parent) // Get the class (or job if there's no class)
}

if cjInfo1.JobIndex != 0 {
// This is already the job
curCj.JobID = uint8(cjInfo1.ID)
} else {
// This is a class; get the corresponding job
cjInfo2, err := s.dataProvider.JobForClass(names[0])
if err == nil {
curCj.JobID = uint8(cjInfo2.ID)
}
}
}

cjInfo, err := s.dataProvider.ClassJob(curCj.UnlockedState.Name)
cjInfo, err := s.dataProvider.ClassJob(names[0])
if err == nil {
curCj.UnlockedState.ID = uint8(cjInfo.ID)
}
Expand Down
5 changes: 4 additions & 1 deletion provider/data-provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ type DataProvider interface {
Achievement(name string) (*models.NamedEntity, error)

// ClassJob returns expanded game data for the ClassJob with the specified name.
ClassJob(name string) (*models.NamedEntity, error)
ClassJob(name string) (*models.ClassJobInternal, error)

// JobForClass returns the job associated with the specified class name.
JobForClass(name string) (*models.ClassJobInternal, error)

// Deity returns expanded game data for the deity with the specified name.
Deity(name string) (*models.NamedEntity, error)
Expand Down
8 changes: 8 additions & 0 deletions provider/models/records.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,11 @@ type TitleInternal struct {

Prefix bool
}

// ClassJobInternal represents a ClassJob entry.
type ClassJobInternal struct {
*NamedEntity

Parent uint32
JobIndex uint32
}

0 comments on commit 280960e

Please sign in to comment.