2020-09-08 15:59:38 -04:00
|
|
|
package d2animdata
|
|
|
|
|
|
|
|
// AnimationDataRecord represents a single record from the AnimData.d2 file
|
|
|
|
type AnimationDataRecord struct {
|
|
|
|
name string
|
|
|
|
framesPerDirection uint32
|
|
|
|
speed uint16
|
|
|
|
events map[int]AnimationEvent
|
|
|
|
}
|
|
|
|
|
2021-02-26 05:56:49 -05:00
|
|
|
func (r *AnimationDataRecord) FramesPerDirection() int {
|
|
|
|
return int(r.framesPerDirection)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *AnimationDataRecord) Speed() int {
|
|
|
|
return int(r.speed)
|
|
|
|
}
|
|
|
|
|
2020-09-08 15:59:38 -04:00
|
|
|
// FPS returns the frames per second for this animation record
|
|
|
|
func (r *AnimationDataRecord) FPS() float64 {
|
|
|
|
speedf := float64(r.speed)
|
|
|
|
divisorf := float64(speedDivisor)
|
|
|
|
basef := float64(speedBaseFPS)
|
|
|
|
|
|
|
|
return basef * speedf / divisorf
|
|
|
|
}
|
|
|
|
|
|
|
|
// FrameDurationMS returns the duration in milliseconds that a frame is displayed
|
|
|
|
func (r *AnimationDataRecord) FrameDurationMS() float64 {
|
|
|
|
return milliseconds / r.FPS()
|
|
|
|
}
|