Fixed linter issues

This commit is contained in:
Intyre 2020-12-21 22:22:27 +01:00
parent 74a006c252
commit 570ec238ff
2 changed files with 36 additions and 27 deletions

View File

@ -18,8 +18,13 @@ func TestTerminal(t *testing.T) {
t.Fatalf("got %d expected %d", lenOutput, expected1)
}
term.Execute("clear")
term.Execute("ls")
if err := term.Execute("clear"); err != nil {
t.Fatal(err)
}
if err := term.Execute("ls"); err != nil {
t.Fatal(err)
}
lenOutput = len(term.outputHistory)
@ -58,9 +63,15 @@ func TestUnbind(t *testing.T) {
t.Fatal(err)
}
term.Unbind("clear")
if err := term.Unbind("clear"); err != nil {
t.Fatal(err)
}
term.Clear()
term.Execute("ls")
if err := term.Execute("ls"); err != nil {
t.Fatal(err)
}
lenOutput := len(term.outputHistory)

View File

@ -990,11 +990,9 @@ func (g *GameControls) commandSetLeftSkill(term d2interface.Terminal) func(args
return nil
}
skillRecord := g.asset.Records.Skill.Details[id]
skill, err := g.heroState.CreateHeroSkill(1, skillRecord.Skill)
skill, err := g.heroSkillByID(id)
if err != nil {
term.Errorf("cannot create skill with ID of %d, error: %s", id, err)
term.Errorf(err.Error())
return nil
}
@ -1012,11 +1010,9 @@ func (g *GameControls) commandSetRightSkill(term d2interface.Terminal) func(args
return nil
}
skillRecord := g.asset.Records.Skill.Details[id]
skill, err := g.heroState.CreateHeroSkill(0, skillRecord.Skill)
skill, err := g.heroSkillByID(id)
if err != nil {
term.Errorf("cannot create skill with ID of %d, error: %s", id, err)
term.Errorf(err.Error())
return nil
}
@ -1034,25 +1030,13 @@ func (g *GameControls) commandLearnSkillID(term d2interface.Terminal) func(args
return nil
}
skillRecord := g.asset.Records.Skill.Details[id]
if skillRecord == nil {
term.Errorf("cannot find a skill record for ID: %d", id)
return nil
}
skill, err := g.heroState.CreateHeroSkill(1, skillRecord.Skill)
if skill == nil {
term.Errorf("cannot create skill: %s", skillRecord.Skill)
skill, err := g.heroSkillByID(id)
if err != nil {
term.Errorf(err.Error())
return nil
}
g.hero.Skills[skill.ID] = skill
if err != nil {
term.Errorf("cannot learn skill for class, error: %s", err)
return nil
}
g.hud.skillSelectMenu.RegenerateImageCache()
g.Infof("Learned skill: " + skill.Skill)
@ -1060,6 +1044,20 @@ func (g *GameControls) commandLearnSkillID(term d2interface.Terminal) func(args
}
}
func (g *GameControls) heroSkillByID(id int) (*d2hero.HeroSkill, error) {
skillRecord := g.asset.Records.Skill.Details[id]
if skillRecord == nil {
return nil, fmt.Errorf("cannot find a skill record for ID: %d", id)
}
skill, err := g.heroState.CreateHeroSkill(1, skillRecord.Skill)
if err != nil {
return nil, fmt.Errorf("cannot create skill with ID of %d", id)
}
return skill, nil
}
func (g *GameControls) commandLearnSkills(term d2interface.Terminal) func(args []string) error {
const classTokenLength = 3