-
Notifications
You must be signed in to change notification settings - Fork 0
/
textures.go
90 lines (76 loc) · 2.2 KB
/
textures.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package osrscache
import "fmt"
type Texture struct {
ID uint16
SpriteIDs []uint16
Opaque bool // Not 100% sure this is Opaque
Colors []int32 // Not 100% sure this is Colors
AverageRGB uint16 // Not 100% sure this is AverageRGB
BlendModes []uint8 // Not 100% sure this is BlendModes
AnimationSpeed uint8
AnimationDirection uint8
AnimationFrames []uint8 // Not 100% sure this is AnimationFrames
}
func NewTexture(id uint16) *Texture {
return &Texture{ID: id}
}
func (t *Texture) Read(data []byte) error {
var err error
reader := NewReader(data)
t.AverageRGB, err = reader.ReadUint16()
if err != nil {
return fmt.Errorf("reading average rgb: %w", err)
}
opaque, err := reader.ReadByte()
if err != nil {
return fmt.Errorf("reading opaque: %w", err)
}
t.Opaque = opaque != 0
spriteCount, err := reader.ReadUint8()
if err != nil {
return fmt.Errorf("reading sprite count: %w", err)
}
t.SpriteIDs = make([]uint16, 0, spriteCount)
for i := 0; i < int(spriteCount); i++ {
spriteID, err := reader.ReadUint16()
if err != nil {
return fmt.Errorf("reading sprite id: %w", err)
}
t.SpriteIDs = append(t.SpriteIDs, spriteID)
}
if spriteCount > 1 {
t.BlendModes = make([]uint8, spriteCount-1)
for i := 0; i < int(spriteCount-1); i++ {
blendMode, err := reader.ReadUint8()
if err != nil {
return fmt.Errorf("reading blend mode: %w", err)
}
t.BlendModes[i] = blendMode
}
t.AnimationFrames = make([]uint8, spriteCount-1)
for i := 0; i < int(spriteCount-1); i++ {
animationFrame, err := reader.ReadUint8()
if err != nil {
return fmt.Errorf("reading animation frame: %w", err)
}
t.AnimationFrames[i] = animationFrame
}
}
t.Colors = make([]int32, spriteCount)
for i := 0; i < int(spriteCount); i++ {
color, err := reader.ReadInt32()
if err != nil {
return fmt.Errorf("reading color: %w", err)
}
t.Colors[i] = color
}
t.AnimationDirection, err = reader.ReadUint8()
if err != nil {
return fmt.Errorf("reading animation direction: %w", err)
}
t.AnimationSpeed, err = reader.ReadUint8()
if err != nil {
return fmt.Errorf("reading animation speed: %w", err)
}
return nil
}