nori/animation.go

39 lines
703 B
Go
Raw Normal View History

2022-03-25 05:14:03 +00:00
package nori
import (
"encoding/binary"
"io"
)
type Animation struct {
2022-03-25 07:33:23 +00:00
Title [32]byte
2022-03-25 05:14:03 +00:00
FrameCount uint32
Frames []*Frame
2022-03-25 21:00:43 +00:00
Version int
}
func NewAnimation(version int) *Animation {
return &Animation{Version: version}
2022-03-25 05:14:03 +00:00
}
2022-03-25 21:00:43 +00:00
func (a *Animation) Decode(rd io.Reader) error {
2022-03-25 07:33:23 +00:00
if err := binary.Read(rd, end, a.Title[:]); err != nil {
return err
}
2022-03-25 05:14:03 +00:00
if err := binary.Read(rd, end, &a.FrameCount); err != nil {
return err
}
2022-03-25 21:00:43 +00:00
if err := discardN(rd, 4*int(a.FrameCount)); err != nil {
2022-03-25 07:33:23 +00:00
return err
}
2022-03-25 05:14:03 +00:00
a.Frames = make([]*Frame, int(a.FrameCount))
for i := range a.Frames {
2022-03-25 21:00:43 +00:00
a.Frames[i] = NewFrame(a.Version)
if err := a.Frames[i].Decode(rd); err != nil {
2022-03-25 05:14:03 +00:00
return err
}
}
return nil
}