2
0
mirror of https://github.com/OrbTools/OrbCommon synced 2024-11-18 03:25:32 +00:00

io load/save changes

This commit is contained in:
Minizbot2012 2021-07-28 02:41:03 -04:00
parent 3e5f9691e0
commit 7531ccd5ca
No known key found for this signature in database
GPG Key ID: 977C8ADE12361917
2 changed files with 6 additions and 10 deletions

View File

@ -8,7 +8,6 @@ import (
"encoding/json"
"io"
"io/fs"
"os"
"strings"
)
@ -27,18 +26,16 @@ func init() {
}
//LoadKM Load Orbmap KM structure
func LoadKeymap(file string, dev *DeviceDef) *KeyMap {
func LoadKeymap(file io.ReadCloser, dev *DeviceDef) *KeyMap {
mapped := new(KeyMap)
of, _ := os.Open(file)
defer of.Close()
mapped.Keymap = make([]uint16, dev.NumKeys)
binary.Read(of, binary.LittleEndian, mapped.Keymap)
binary.Read(of, binary.LittleEndian, mapped.Color)
binary.Read(file, binary.LittleEndian, mapped.Keymap)
binary.Read(file, binary.LittleEndian, mapped.Color)
return mapped
}
//SavePKMKeymap saves an orb after edit
func SaveKeymap(mapped interface{}, file io.WriteCloser) {
func SaveKeymap(file io.WriteCloser, mapped interface{}) {
binary.Write(file, binary.LittleEndian, mapped)
file.Close()
}

View File

@ -27,15 +27,14 @@ func init() {
}
//LoadKeymap Load Orbmap KM structure
func LoadKeymap(file string, dev *DeviceDef) *KeyMap {
func LoadKeymap(file io.ReadCloser, dev *DeviceDef) *KeyMap {
mapped := new(KeyMap)
of, _ := os.Open(file)
xdr.Unmarshal(of, mapped)
return mapped
}
//SavePKMKeymap saves an orb after edit
func SaveKeymap(mapped interface{}, file io.WriteCloser) {
func SaveKeymap(file io.WriteCloser, mapped interface{}) {
xdr.Marshal(file, mapped)
file.Close()
}