1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-12-24 19:18:12 -05:00
OpenDiablo2/d2core/d2hero/hero_skill.go
gravestench 6f8b43f8d6
Various lint error fixes and suppressions (#846)
* suppressing the magic number lint errors in mapgen, it will get a heavy refactor soon, hopefully...

* adding string token constants for SkillClass

* adding panic on error to left/right skill select render

* fixed cuddle lint error

* fixed unnecessary conversion, unused func param lint errors in dcc_animation.go

* adding comment for skill class tokens

* fixed typo in comment

* removed unused parameter in dcc/dc6 animations

* supress warning about Object.setMode always being passed direction value of 0

* fixed all invalid golint directives

* fixed a couple gocritic lint errors
2020-10-26 02:04:50 -07:00

47 lines
1.2 KiB
Go

package d2hero
import (
"encoding/json"
"log"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2records"
)
// HeroSkill stores additional payload for a skill of a hero.
type HeroSkill struct {
*d2records.SkillRecord
*d2records.SkillDescriptionRecord
SkillPoints int
shallow *shallowHeroSkill
}
// An auxiliary struct which only stores the ID of the SkillRecord, instead of the whole SkillRecord
// and SkillDescrptionRecord.
type shallowHeroSkill struct {
SkillID int `json:"skillId"`
SkillPoints int `json:"skillPoints"`
}
// MarshalJSON overrides the default logic used when the HeroSkill is serialized to a byte array.
func (hs *HeroSkill) MarshalJSON() ([]byte, error) {
// only serialize the shallow object instead of the SkillRecord & SkillDescriptionRecord
bytes, err := json.Marshal(hs.shallow)
if err != nil {
log.Fatalln(err)
}
return bytes, err
}
// UnmarshalJSON overrides the default logic used when the HeroSkill is deserialized from a byte array.
func (hs *HeroSkill) UnmarshalJSON(data []byte) error {
shallow := &shallowHeroSkill{}
if err := json.Unmarshal(data, shallow); err != nil {
return err
}
hs.shallow = shallow
return nil
}