2020-09-19 18:33:40 +00:00
|
|
|
package d2records
|
|
|
|
|
|
|
|
import (
|
2020-09-21 00:30:27 +00:00
|
|
|
"strings"
|
2020-09-19 18:33:40 +00:00
|
|
|
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt"
|
|
|
|
)
|
|
|
|
|
|
|
|
// LoadObjectTypes loads ObjectTypeRecords from objtype.txt
|
|
|
|
func objectTypesLoader(r *RecordManager, d *d2txt.DataDictionary) error {
|
|
|
|
records := make(ObjectTypes, 0)
|
|
|
|
|
|
|
|
for d.Next() {
|
|
|
|
record := ObjectTypeRecord{
|
2020-09-21 00:30:27 +00:00
|
|
|
Name: sanitizeObjectString(d.String("Name")),
|
|
|
|
Token: sanitizeObjectString(d.String("Token")),
|
2020-09-19 18:33:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
records = append(records, record)
|
|
|
|
}
|
|
|
|
|
|
|
|
if d.Err != nil {
|
|
|
|
return d.Err
|
|
|
|
}
|
|
|
|
|
2020-12-18 06:40:54 +00:00
|
|
|
r.Debugf("Loaded %d ObjectType records", len(records))
|
2020-09-19 18:33:40 +00:00
|
|
|
|
|
|
|
r.Object.Types = records
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2020-09-21 00:30:27 +00:00
|
|
|
|
|
|
|
func sanitizeObjectString(str string) string {
|
|
|
|
result := strings.TrimSpace(strings.ReplaceAll(str, string(byte(0)), ""))
|
|
|
|
result = strings.ToLower(result)
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|