-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from gucio321/hotkeys
`d2s`: extract hotkeys structure from d2s.go; move it into d2shotkeys…
- Loading branch information
Showing
3 changed files
with
63 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Package d2shotkeys stores skill hotkeys | ||
package d2shotkeys |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package d2shotkeys | ||
|
||
import ( | ||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2datautils" | ||
|
||
"github.com/gucio321/d2d2s/d2senums" | ||
) | ||
|
||
const ( | ||
// NumHotkeysBytes is a len of hotkey's binary form | ||
NumHotkeysBytes = 64 | ||
|
||
numHotKeys = 16 | ||
) | ||
|
||
// Hotkeys represents a skill hotkeys data | ||
type Hotkeys map[byte]d2senums.SkillID | ||
|
||
// New creates a new Hotkeys | ||
func New() *Hotkeys { | ||
result := &Hotkeys{} | ||
*result = make(Hotkeys) | ||
|
||
return result | ||
} | ||
|
||
// Load loads hotkeys | ||
func (h *Hotkeys) Load(data [NumHotkeysBytes]byte) { | ||
sr := d2datautils.CreateBitMuncher(data[:], 0) | ||
for i := byte(0); i < numHotKeys; i++ { | ||
id := sr.GetUInt32() | ||
(*h)[i] = d2senums.SkillID(id) | ||
} | ||
} | ||
|
||
// Encode encodes hotkeys back into binary form | ||
func (h *Hotkeys) Encode() (result [NumHotkeysBytes]byte) { | ||
sw := d2datautils.CreateStreamWriter() | ||
|
||
for i := byte(0); i < numHotKeys; i++ { | ||
sw.PushUint32(uint32((*h)[i])) | ||
} | ||
|
||
data := sw.GetBytes() | ||
copy(result[:], data[:NumHotkeysBytes]) | ||
|
||
return result | ||
} |