1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-06-12 10:40:42 +00:00
OpenDiablo2/d2core/d2records/object_types_loader.go
2020-12-18 18:46:34 +01:00

39 lines
781 B
Go

package d2records
import (
"strings"
"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{
Name: sanitizeObjectString(d.String("Name")),
Token: sanitizeObjectString(d.String("Token")),
}
records = append(records, record)
}
if d.Err != nil {
return d.Err
}
r.Debugf("Loaded %d ObjectType records", len(records))
r.Object.Types = records
return nil
}
func sanitizeObjectString(str string) string {
result := strings.TrimSpace(strings.ReplaceAll(str, string(byte(0)), ""))
result = strings.ToLower(result)
return result
}