mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2025-02-02 22:57:04 -05:00
animdata: the game now uses animation data manager from d2fileformats/d2animdata (instead of d2data/animation_data.go)
This commit is contained in:
parent
1125a7dd45
commit
00e26fb862
@ -6,7 +6,7 @@ import (
|
|||||||
|
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2loader/asset/types"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2loader/asset/types"
|
||||||
|
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2animdata"
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2util"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2util"
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2config"
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2config"
|
||||||
@ -150,12 +150,12 @@ func (a *App) initAnimationData(path string) error {
|
|||||||
|
|
||||||
a.Debugf(fmtLoadAnimData, path)
|
a.Debugf(fmtLoadAnimData, path)
|
||||||
|
|
||||||
animData, err := d2data.LoadAnimationData(animDataBytes)
|
animData, err := d2animdata.Load(animDataBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.Error(err.Error())
|
a.Error(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
a.Infof("Loaded %d animation data records", len(animData))
|
a.Infof("Loaded %d animation data records", animData.GetRecordsCount())
|
||||||
|
|
||||||
a.asset.Records.Animation.Data = animData
|
a.asset.Records.Animation.Data = animData
|
||||||
|
|
||||||
|
@ -1,83 +0,0 @@
|
|||||||
package d2data
|
|
||||||
|
|
||||||
import (
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2datautils"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
numCofNameBytes = 8
|
|
||||||
numFlagBytes = 144
|
|
||||||
)
|
|
||||||
|
|
||||||
// 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
|
|
||||||
type AnimationData map[string][]*AnimationDataRecord
|
|
||||||
|
|
||||||
// LoadAnimationData loads the animation data table into the global AnimationData dictionary
|
|
||||||
func LoadAnimationData(rawData []byte) (AnimationData, error) {
|
|
||||||
animdata := make(AnimationData)
|
|
||||||
streamReader := d2datautils.CreateStreamReader(rawData)
|
|
||||||
|
|
||||||
for !streamReader.EOF() {
|
|
||||||
var dataCount int
|
|
||||||
|
|
||||||
b, err := streamReader.ReadInt32()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
dataCount = int(b)
|
|
||||||
|
|
||||||
for i := 0; i < dataCount; i++ {
|
|
||||||
cofNameBytes, err := streamReader.ReadBytes(numCofNameBytes)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
fpd, err := streamReader.ReadInt32()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
animSpeed, err := streamReader.ReadInt32()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
data := &AnimationDataRecord{
|
|
||||||
COFName: strings.ReplaceAll(string(cofNameBytes), string(byte(0)), ""),
|
|
||||||
FramesPerDirection: int(fpd),
|
|
||||||
AnimationSpeed: int(animSpeed),
|
|
||||||
}
|
|
||||||
|
|
||||||
flagBytes, err := streamReader.ReadBytes(numFlagBytes)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
data.Flags = flagBytes
|
|
||||||
cofIndex := strings.ToLower(data.COFName)
|
|
||||||
|
|
||||||
if _, found := animdata[cofIndex]; !found {
|
|
||||||
animdata[cofIndex] = make([]*AnimationDataRecord, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
animdata[cofIndex] = append(animdata[cofIndex], data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return animdata, nil
|
|
||||||
}
|
|
@ -56,6 +56,10 @@ func (ad *AnimationData) GetRecords(name string) []*AnimationDataRecord {
|
|||||||
return ad.entries[name]
|
return ad.entries[name]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ad *AnimationData) GetRecordsCount() int {
|
||||||
|
return len(ad.entries)
|
||||||
|
}
|
||||||
|
|
||||||
// Load loads the data into an AnimationData struct
|
// Load loads the data into an AnimationData struct
|
||||||
//nolint:gocognit,funlen // can't reduce
|
//nolint:gocognit,funlen // can't reduce
|
||||||
func Load(data []byte) (*AnimationData, error) {
|
func Load(data []byte) (*AnimationData, error) {
|
||||||
|
@ -8,6 +8,14 @@ type AnimationDataRecord struct {
|
|||||||
events map[int]AnimationEvent
|
events map[int]AnimationEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *AnimationDataRecord) FramesPerDirection() int {
|
||||||
|
return int(r.framesPerDirection)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *AnimationDataRecord) Speed() int {
|
||||||
|
return int(r.speed)
|
||||||
|
}
|
||||||
|
|
||||||
// FPS returns the frames per second for this animation record
|
// FPS returns the frames per second for this animation record
|
||||||
func (r *AnimationDataRecord) FPS() float64 {
|
func (r *AnimationDataRecord) FPS() float64 {
|
||||||
speedf := float64(r.speed)
|
speedf := float64(r.speed)
|
||||||
|
@ -265,9 +265,9 @@ func (c *Composite) createMode(animationMode animationMode, weaponClass string)
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
animationKey := strings.ToLower(c.token + animationMode.String() + weaponClass)
|
animationKey := strings.ToUpper(c.token + animationMode.String() + weaponClass)
|
||||||
|
|
||||||
animationData := c.Records.Animation.Data[animationKey]
|
animationData := c.Records.Animation.Data.GetRecords(animationKey)
|
||||||
if len(animationData) == 0 {
|
if len(animationData) == 0 {
|
||||||
return nil, errors.New("could not find Animation data")
|
return nil, errors.New("could not find Animation data")
|
||||||
}
|
}
|
||||||
@ -277,8 +277,8 @@ func (c *Composite) createMode(animationMode animationMode, weaponClass string)
|
|||||||
animationMode: animationMode,
|
animationMode: animationMode,
|
||||||
weaponClass: weaponClass,
|
weaponClass: weaponClass,
|
||||||
layers: make([]d2interface.Animation, d2enum.CompositeTypeMax),
|
layers: make([]d2interface.Animation, d2enum.CompositeTypeMax),
|
||||||
frameCount: animationData[0].FramesPerDirection,
|
frameCount: animationData[0].FramesPerDirection(),
|
||||||
animationSpeed: 1.0 / (float64(animationData[0].AnimationSpeed) * speedUnit), //nolint:gomnd // taking inverse
|
animationSpeed: 1.0 / (float64(animationData[0].Speed()) * speedUnit), //nolint:gomnd // taking inverse
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, cofLayer := range cof.CofLayers {
|
for _, cofLayer := range cof.CofLayers {
|
||||||
|
@ -108,8 +108,8 @@ func (f *MapEntityFactory) NewPlayer(id, name string, x, y, direction int, heroT
|
|||||||
result.mapEntity.uuid = id
|
result.mapEntity.uuid = id
|
||||||
result.SetSpeed(baseWalkSpeed)
|
result.SetSpeed(baseWalkSpeed)
|
||||||
result.mapEntity.directioner = result.rotate
|
result.mapEntity.directioner = result.rotate
|
||||||
err = composite.SetMode(d2enum.PlayerAnimationModeTownNeutral, equipment.RightHand.GetWeaponClass())
|
|
||||||
|
|
||||||
|
err = composite.SetMode(d2enum.PlayerAnimationModeTownNeutral, equipment.RightHand.GetWeaponClass())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,8 @@ import (
|
|||||||
|
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2util"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2util"
|
||||||
|
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data"
|
|
||||||
|
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||||
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2animdata"
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt"
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
|
||||||
)
|
)
|
||||||
@ -39,7 +38,7 @@ type RecordManager struct {
|
|||||||
*d2util.Logger
|
*d2util.Logger
|
||||||
boundLoaders map[string][]recordLoader // there can be more than one loader bound for a file
|
boundLoaders map[string][]recordLoader // there can be more than one loader bound for a file
|
||||||
Animation struct {
|
Animation struct {
|
||||||
Data d2data.AnimationData
|
Data *d2animdata.AnimationData
|
||||||
Token struct {
|
Token struct {
|
||||||
Player PlayerTypes
|
Player PlayerTypes
|
||||||
Composite CompositeTypes
|
Composite CompositeTypes
|
||||||
|
Loading…
Reference in New Issue
Block a user