2020-01-26 00:39:13 -05:00
|
|
|
package d2data
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"strings"
|
2020-09-20 20:30:27 -04:00
|
|
|
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2datautils"
|
2020-01-26 00:39:13 -05:00
|
|
|
)
|
|
|
|
|
2020-08-06 16:45:38 -04:00
|
|
|
const (
|
|
|
|
numCofNameBytes = 8
|
|
|
|
numFlagBytes = 144
|
|
|
|
)
|
|
|
|
|
2020-01-26 00:39:13 -05:00
|
|
|
// AnimationDataRecord represents a single entry in the animation data dictionary file
|
|
|
|
type AnimationDataRecord struct {
|
|
|
|
// COFName is the name of the COF file used for this animation
|
|
|
|
COFName string
|
|
|
|
// FramesPerDirection specifies how many frames are in each direction
|
|
|
|
FramesPerDirection int
|
|
|
|
// AnimationSpeed represents a value of X where the rate is a ration of (x/255) at 25FPS
|
|
|
|
AnimationSpeed int
|
|
|
|
// Flags are used in keyframe triggers
|
|
|
|
Flags []byte
|
|
|
|
}
|
|
|
|
|
|
|
|
// AnimationData represents all of the animation data records, mapped by the COF index
|
2020-09-20 20:30:27 -04:00
|
|
|
type AnimationData map[string][]*AnimationDataRecord
|
2020-01-26 00:39:13 -05:00
|
|
|
|
|
|
|
// LoadAnimationData loads the animation data table into the global AnimationData dictionary
|
2020-09-20 20:30:27 -04:00
|
|
|
func LoadAnimationData(rawData []byte) AnimationData {
|
|
|
|
animdata := make(AnimationData)
|
2020-09-08 15:58:35 -04:00
|
|
|
streamReader := d2datautils.CreateStreamReader(rawData)
|
2020-06-30 09:17:07 -04:00
|
|
|
|
2020-07-08 09:16:56 -04:00
|
|
|
for !streamReader.EOF() {
|
2020-01-26 00:39:13 -05:00
|
|
|
dataCount := int(streamReader.GetInt32())
|
|
|
|
for i := 0; i < dataCount; i++ {
|
2020-08-06 16:45:38 -04:00
|
|
|
cofNameBytes := streamReader.ReadBytes(numCofNameBytes)
|
2020-01-26 00:39:13 -05:00
|
|
|
data := &AnimationDataRecord{
|
2020-09-06 17:09:05 -04:00
|
|
|
COFName: strings.ReplaceAll(string(cofNameBytes), string(byte(0)), ""),
|
2020-01-26 00:39:13 -05:00
|
|
|
FramesPerDirection: int(streamReader.GetInt32()),
|
|
|
|
AnimationSpeed: int(streamReader.GetInt32()),
|
|
|
|
}
|
2020-08-06 16:45:38 -04:00
|
|
|
data.Flags = streamReader.ReadBytes(numFlagBytes)
|
2020-01-26 00:39:13 -05:00
|
|
|
cofIndex := strings.ToLower(data.COFName)
|
2020-06-30 09:17:07 -04:00
|
|
|
|
2020-09-20 20:30:27 -04:00
|
|
|
if _, found := animdata[cofIndex]; !found {
|
|
|
|
animdata[cofIndex] = make([]*AnimationDataRecord, 0)
|
2020-01-26 00:39:13 -05:00
|
|
|
}
|
2020-06-30 09:17:07 -04:00
|
|
|
|
2020-09-20 20:30:27 -04:00
|
|
|
animdata[cofIndex] = append(animdata[cofIndex], data)
|
2020-01-26 00:39:13 -05:00
|
|
|
}
|
|
|
|
}
|
2020-06-30 09:17:07 -04:00
|
|
|
|
2020-09-20 20:30:27 -04:00
|
|
|
log.Printf("Loaded %d animation data records", len(animdata))
|
|
|
|
|
|
|
|
return animdata
|
2020-01-26 00:39:13 -05:00
|
|
|
}
|