2020-01-26 00:39:13 -05:00
|
|
|
package d2datadict
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
2020-01-31 23:18:11 -05:00
|
|
|
|
2020-06-22 11:53:44 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common"
|
2020-01-26 00:39:13 -05:00
|
|
|
)
|
|
|
|
|
2020-06-30 09:17:07 -04:00
|
|
|
func mapHeaders(line string) map[string]int {
|
2020-01-26 00:39:13 -05:00
|
|
|
m := make(map[string]int)
|
|
|
|
r := strings.Split(line, "\t")
|
2020-06-29 12:37:11 -04:00
|
|
|
|
2020-01-26 00:39:13 -05:00
|
|
|
for index, header := range r {
|
|
|
|
m[header] = index
|
|
|
|
}
|
2020-06-29 12:37:11 -04:00
|
|
|
|
2020-01-26 00:39:13 -05:00
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2020-06-30 09:17:07 -04:00
|
|
|
func mapLoadInt(r *[]string, mapping map[string]int, field string) int {
|
|
|
|
index, ok := (mapping)[field]
|
2020-01-26 00:39:13 -05:00
|
|
|
if ok {
|
2020-06-22 11:53:44 -04:00
|
|
|
return d2common.StringToInt(d2common.EmptyToZero(d2common.AsterToEmpty((*r)[index])))
|
2020-01-26 00:39:13 -05:00
|
|
|
}
|
2020-06-29 12:37:11 -04:00
|
|
|
|
2020-01-26 00:39:13 -05:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2020-06-30 09:17:07 -04:00
|
|
|
func mapLoadString(r *[]string, mapping map[string]int, field string) string {
|
|
|
|
index, ok := (mapping)[field]
|
2020-01-26 00:39:13 -05:00
|
|
|
if ok {
|
2020-06-22 11:53:44 -04:00
|
|
|
return d2common.AsterToEmpty((*r)[index])
|
2020-01-26 00:39:13 -05:00
|
|
|
}
|
2020-06-29 12:37:11 -04:00
|
|
|
|
2020-01-26 00:39:13 -05:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2020-06-30 09:17:07 -04:00
|
|
|
func mapLoadBool(r *[]string, mapping map[string]int, field string) bool {
|
|
|
|
return mapLoadInt(r, mapping, field) == 1
|
2020-01-26 00:39:13 -05:00
|
|
|
}
|
|
|
|
|
2020-06-30 09:17:07 -04:00
|
|
|
func mapLoadUint8(r *[]string, mapping map[string]int, field string) uint8 {
|
|
|
|
index, ok := (mapping)[field]
|
2020-01-26 00:39:13 -05:00
|
|
|
if ok {
|
2020-06-22 11:53:44 -04:00
|
|
|
return d2common.StringToUint8(d2common.EmptyToZero(d2common.AsterToEmpty((*r)[index])))
|
2020-01-26 00:39:13 -05:00
|
|
|
}
|
2020-06-29 12:37:11 -04:00
|
|
|
|
2020-01-26 00:39:13 -05:00
|
|
|
return 0
|
|
|
|
}
|