Skip to content

Commit

Permalink
package structure (#8):
Browse files Browse the repository at this point in the history
- move quests.go into d2squests package
  • Loading branch information
gucio321 committed May 17, 2021
1 parent ed81f70 commit 2780bad
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
32 changes: 16 additions & 16 deletions d2s.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ import (
"github.com/gucio321/d2d2s/d2sitems"
"github.com/gucio321/d2d2s/d2smercenary"
"github.com/gucio321/d2d2s/d2snpc"
"github.com/gucio321/d2d2s/d2squests"
"github.com/gucio321/d2d2s/d2swaypoints"
"github.com/gucio321/d2d2s/datautils"
)

const (
saveFileSignature = 0xaa55aa55
characterNameSize = 16
skillHotKeys = 16
unknown6BytesCount = 32
unknown8BytesCount = 144
expectedQuestHeaderID = "Woo!"
skillsHeaderID = "if"
numSkills = 30
int32Size = 4
fileSizePosition = 8
checksumPosition = 12
saveFileSignature = 0xaa55aa55
characterNameSize = 16
skillHotKeys = 16
unknown6BytesCount = 32
unknown8BytesCount = 144
skillsHeaderID = "if"
numSkills = 30
int32Size = 4
fileSizePosition = 8
checksumPosition = 12
)

type hotkeys map[byte]d2senums.SkillID
Expand Down Expand Up @@ -60,7 +60,7 @@ type D2S struct {
unknown7 uint16
Mercenary *d2smercenary.Mercenary
unknown8 [unknown8BytesCount]byte
Quests *Quests
Quests *d2squests.Quests
Waypoints *d2swaypoints.Waypoints
NPC *d2snpc.NPC
Stats *Stats
Expand All @@ -78,7 +78,7 @@ func New() *D2S {
Hotkeys: make(hotkeys),
Difficulty: d2sdifficulty.New(),
Mercenary: d2smercenary.New(),
Quests: NewQuests(),
Quests: d2squests.New(),
Waypoints: d2swaypoints.New(),
NPC: d2snpc.New(),
Stats: &Stats{},
Expand Down Expand Up @@ -197,11 +197,11 @@ func Unmarshal(data []byte) (*D2S, error) {

copy(result.unknown8[:], unknown8[:unknown8BytesCount])

qd := sr.GetBytes(numQuestsBytes)
qd := sr.GetBytes(d2squests.NumQuestsBytes)

var questsData [numQuestsBytes]byte
var questsData [d2squests.NumQuestsBytes]byte

copy(questsData[:], qd[:numQuestsBytes])
copy(questsData[:], qd[:d2squests.NumQuestsBytes])

err = result.Quests.Unmarshal(&questsData)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions d2squests/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package d2squests provides quests data structure
package d2squests
17 changes: 10 additions & 7 deletions quests.go → d2squests/quests.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package d2d2s
package d2squests

import (
"errors"
Expand All @@ -11,7 +11,10 @@ import (
)

const (
numQuestsBytes = 298
// NumQuestsBytes is a total number of quests data bytes
NumQuestsBytes = 298

expectedQuestHeaderID = "Woo!"
questHeaderUnknownBytesCount = 6
defaultQuestsCount = 6
act4QuestsCount = 3
Expand All @@ -22,8 +25,8 @@ const (
// Quests represents quests status structure
type Quests map[d2enum.DifficultyType]*[d2senums.NumActs]*QuestsSet

// NewQuests creates a new quests structure
func NewQuests() *Quests {
// New creates a new quests structure
func New() *Quests {
result := &Quests{}
*result = make(Quests)

Expand Down Expand Up @@ -65,7 +68,7 @@ func unknownQuestsHeaderBytes() [questHeaderUnknownBytesCount]byte {
}

// Unmarshal unmarshals quests status data
func (q *Quests) Unmarshal(data *[numQuestsBytes]byte) error {
func (q *Quests) Unmarshal(data *[NumQuestsBytes]byte) error {
sr := datautils.CreateBitMuncher((*data)[:], 0)

questHeaderID := sr.GetBytes(4) // nolint:gomnd // header
Expand All @@ -89,7 +92,7 @@ func (q *Quests) Unmarshal(data *[numQuestsBytes]byte) error {
}

// Encode encodes quests back into byte array
func (q *Quests) Encode() (result [numQuestsBytes]byte) {
func (q *Quests) Encode() (result [NumQuestsBytes]byte) {
sw := d2datautils.CreateStreamWriter()

sw.PushBytes([]byte(expectedQuestHeaderID)...)
Expand All @@ -105,7 +108,7 @@ func (q *Quests) Encode() (result [numQuestsBytes]byte) {
}

data := sw.GetBytes()
copy(result[:], data[:numQuestsBytes])
copy(result[:], data[:NumQuestsBytes])

return result
}
Expand Down

0 comments on commit 2780bad

Please sign in to comment.