forked from Racinettee/asefile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ase_file.go
42 lines (35 loc) · 812 Bytes
/
ase_file.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package asefile
import (
"io"
"os"
)
type AsepriteFile struct {
Header AsepriteHeader
Frames []AsepriteFrame
}
func (aseFile *AsepriteFile) Decode(r io.Reader) error {
aseFile.Header.Decode(r)
aseFile.Frames = make([]AsepriteFrame, aseFile.Header.Frames)
for x := range aseFile.Frames {
aseFile.Frames[x].parentHeader = &aseFile.Header
err := aseFile.Frames[x].Decode(r)
if err != nil {
return err
}
}
return nil
}
func (aseFile *AsepriteFile) Encode(w io.Writer) {
aseFile.Header.Encode(w)
aseFile.Frames = make([]AsepriteFrame, aseFile.Header.Frames)
for _, frame := range aseFile.Frames {
frame.Encode(w)
}
}
func (aseFile *AsepriteFile) DecodeFile(fName string) error {
spriteFile, err := os.Open(fName)
if err != nil {
return err
}
return aseFile.Decode(spriteFile)
}