2020-09-19 14:33:40 -04:00
|
|
|
package d2records
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
2020-09-20 20:30:27 -04:00
|
|
|
"strings"
|
2020-09-19 14:33:40 -04: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-20 20:30:27 -04:00
|
|
|
Name: sanitizeObjectString(d.String("Name")),
|
|
|
|
Token: sanitizeObjectString(d.String("Token")),
|
2020-09-19 14:33:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
records = append(records, record)
|
|
|
|
}
|
|
|
|
|
|
|
|
if d.Err != nil {
|
|
|
|
return d.Err
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Printf("Loaded %d object types", len(records))
|
|
|
|
|
|
|
|
r.Object.Types = records
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2020-09-20 20:30:27 -04:00
|
|
|
|
|
|
|
func sanitizeObjectString(str string) string {
|
|
|
|
result := strings.TrimSpace(strings.ReplaceAll(str, string(byte(0)), ""))
|
|
|
|
result = strings.ToLower(result)
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|