1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-10-31 16:27:18 -04:00
OpenDiablo2/Common/ObjectTypes.go
ndechiara 46a60398d4 Load Objects.txt (#68)
* Missiles Parsing

* Missiles.txt lookup table and  fixes

* lost work

* Replaced old repo path with org path.

* Added editorconfig. Fixed line endings to LF.

* Fixed travis build badge path

* Added level warp data

* Added object type data load

* Load objects.txt

New Common class, Objects.go will load all of the object records in objects.txt
2019-11-03 11:04:58 -05:00

32 lines
837 B
Go

package Common
import (
"log"
"strings"
"github.com/OpenDiablo2/OpenDiablo2/ResourcePaths"
)
type ObjectTypeRecord struct {
Name string
Token string
}
var ObjectTypes []ObjectTypeRecord
func LoadObjectTypes(fileProvider FileProvider) {
objectTypeData := fileProvider.LoadFile(ResourcePaths.ObjectType)
streamReader := CreateStreamReader(objectTypeData)
count := streamReader.GetInt32()
ObjectTypes = make([]ObjectTypeRecord, count)
for i := range ObjectTypes {
nameBytes, _ := streamReader.ReadBytes(32)
tokenBytes, _ := streamReader.ReadBytes(20)
ObjectTypes[i] = ObjectTypeRecord{
Name: strings.TrimSpace(strings.ReplaceAll(string(nameBytes), string(0), "")),
Token: strings.TrimSpace(strings.ReplaceAll(string(tokenBytes), string(0), "")),
}
}
log.Printf("Loaded %d object types", len(ObjectTypes))
}