mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-11-05 09:47:18 -05:00
9ffbf1320c
* logger for d2audio & d2map * logger for d2ui e.t.c * d2inventory now passes on error messages * no more importing log in d2core * implemented #925 * added logger to part of d2networking & fixed "need to be changed" comments * fixed lints * fixed errors Co-authored-by: M. Sz <mszeptuch@protonmail.com>
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package d2hero
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"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 {
|
|
return nil, err
|
|
}
|
|
|
|
return bytes, nil
|
|
}
|
|
|
|
// 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
|
|
}
|