mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-11-02 17:27:23 -04:00
515b66736d
* main, d2common: load Magic/Rare/Unique Affix * d2common: item affixes only removed Rare/Unique Prefix/Suffix as those are related to monsters, not items. * removed debug print from item_affix.go * changed item affix type names for clarity, removed debug print from data_dictionary * d2common: item affix datadict and records Item Affixes are defined in `/data/global/excel/Magic{Prefix,Suffix}.txt` Rare and Unique Pre/Suffixes seem to be for monsters, not items. d2common: item affixes only removed Rare/Unique Prefix/Suffix as those are related to monsters, not items. removed debug print from item_affix.go changed item affix type names for clarity, removed debug print from data_dictionary * reverting to pre-allocating memory for parsing txt lines * removing the rest of the rare/unique definitions * removing the rest of the rare/unique definitions
50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
package d2common
|
|
|
|
import (
|
|
"log"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
// DataDictionary represents a data file (Excel)
|
|
type DataDictionary struct {
|
|
FieldNameLookup map[string]int
|
|
Data [][]string
|
|
}
|
|
|
|
func LoadDataDictionary(text string) *DataDictionary {
|
|
result := &DataDictionary{}
|
|
lines := strings.Split(text, "\r\n")
|
|
fileNames := strings.Split(lines[0], "\t")
|
|
result.FieldNameLookup = make(map[string]int)
|
|
for i, fieldName := range fileNames {
|
|
result.FieldNameLookup[fieldName] = i
|
|
}
|
|
result.Data = make([][]string, len(lines)-2)
|
|
for i, line := range lines[1:] {
|
|
if len(strings.TrimSpace(line)) == 0 {
|
|
continue
|
|
}
|
|
values := strings.Split(line, "\t")
|
|
if len(values) != len(result.FieldNameLookup) {
|
|
continue
|
|
}
|
|
result.Data[i] = values
|
|
}
|
|
return result
|
|
}
|
|
|
|
func (v *DataDictionary) GetString(fieldName string, index int) string {
|
|
return v.Data[index][v.FieldNameLookup[fieldName]]
|
|
}
|
|
|
|
func (v *DataDictionary) GetNumber(fieldName string, index int) int {
|
|
str := v.GetString(fieldName, index)
|
|
str = EmptyToZero(AsterToEmpty(str))
|
|
result, err := strconv.Atoi(str)
|
|
if err != nil {
|
|
log.Panic(err)
|
|
}
|
|
return result
|
|
}
|