1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-11-06 18:27:20 -05:00
OpenDiablo2/d2common/d2data/d2datadict/map_helper.go
2020-02-01 21:06:22 -05:00

45 lines
972 B
Go

package d2datadict
import (
"strings"
dh "github.com/OpenDiablo2/OpenDiablo2/d2common"
)
func MapHeaders(line string) map[string]int {
m := make(map[string]int)
r := strings.Split(line, "\t")
for index, header := range r {
m[header] = index
}
return m
}
func MapLoadInt(r *[]string, mapping *map[string]int, field string) int {
index, ok := (*mapping)[field]
if ok {
return dh.StringToInt(dh.EmptyToZero(dh.AsterToEmpty((*r)[index])))
}
return 0
}
func MapLoadString(r *[]string, mapping *map[string]int, field string) string {
index, ok := (*mapping)[field]
if ok {
return dh.AsterToEmpty((*r)[index])
}
return ""
}
func MapLoadBool(r *[]string, mapping *map[string]int, field string) bool {
return MapLoadInt(r, mapping, field) == 1
}
func MapLoadUint8(r *[]string, mapping *map[string]int, field string) uint8 {
index, ok := (*mapping)[field]
if ok {
return dh.StringToUint8(dh.EmptyToZero(dh.AsterToEmpty((*r)[index])))
}
return 0
}