mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2025-02-02 22:57:04 -05:00
Fix string splitting on delimited list (#493)
Would include extraneous quotation marks Also fix mistake in monstats2
This commit is contained in:
parent
5ea6ada452
commit
eb69eebcc1
@ -226,16 +226,16 @@ type MonStats2Record struct {
|
||||
}
|
||||
|
||||
//nolint:gochecknoglobals // Current design issue
|
||||
var MonStats2 map[string]MonStats2Record
|
||||
var MonStats2 map[string]*MonStats2Record
|
||||
|
||||
//nolint:funlen //just a big data loader
|
||||
func LoadMonStats2(file []byte) {
|
||||
dict := d2common.LoadDataDictionary(string(file))
|
||||
numRecords := len(dict.Data)
|
||||
MonStats2 = make(map[string]MonStats2Record, numRecords)
|
||||
MonStats2 = make(map[string]*MonStats2Record, numRecords)
|
||||
|
||||
for idx := range dict.Data {
|
||||
record := MonStats2Record{
|
||||
record := &MonStats2Record{
|
||||
Key: dict.GetString("Id", idx),
|
||||
Height: dict.GetNumber("Height", idx),
|
||||
OverlayHeight: dict.GetNumber("OverlayHeight", idx),
|
||||
@ -251,7 +251,7 @@ func LoadMonStats2(file []byte) {
|
||||
LGv: dict.GetDelimitedList("LGv", idx),
|
||||
Rav: dict.GetDelimitedList("Rav", idx),
|
||||
Lav: dict.GetDelimitedList("Lav", idx),
|
||||
RHv: dict.GetDelimitedList("RDv", idx),
|
||||
RHv: dict.GetDelimitedList("RHv", idx),
|
||||
LHv: dict.GetDelimitedList("LHv", idx),
|
||||
SHv: dict.GetDelimitedList("SHv", idx),
|
||||
S1v: dict.GetDelimitedList("S1v", idx),
|
||||
|
@ -49,7 +49,20 @@ func (v *DataDictionary) GetNumber(fieldName string, index int) int {
|
||||
}
|
||||
|
||||
func (v *DataDictionary) GetDelimitedList(fieldName string, index int) []string {
|
||||
return strings.Split(v.GetString(fieldName, index), ",")
|
||||
unsplit := v.GetString(fieldName, index)
|
||||
|
||||
// Commo delimited fields are quoted, not terribly pretty to do it here but...
|
||||
s := []byte(unsplit)
|
||||
j := 0
|
||||
|
||||
for i := range s {
|
||||
if s[i] != '"' {
|
||||
s[j] = s[i]
|
||||
j++
|
||||
}
|
||||
}
|
||||
|
||||
return strings.Split(string(s), ",")
|
||||
}
|
||||
|
||||
func (v *DataDictionary) GetBool(fieldName string, index int) bool {
|
||||
|
Loading…
Reference in New Issue
Block a user