forked from ajhager/spine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
slot.go
73 lines (63 loc) · 1.38 KB
/
slot.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
package spine
type SlotData struct {
name string
boneData *BoneData
r, g, b, a float32
attachmentName string
}
func NewSlotData(name string, boneData *BoneData) *SlotData {
slotData := new(SlotData)
slotData.name = name
slotData.boneData = boneData
slotData.r = 1
slotData.g = 1
slotData.b = 1
slotData.a = 1
return slotData
}
type Slot struct {
data *SlotData
skeleton *Skeleton
Bone *Bone
R, G, B, A float32
attachmentTime float32
Attachment Attachment
}
func NewSlot(slotData *SlotData, skeleton *Skeleton, bone *Bone) *Slot {
slot := new(Slot)
slot.data = slotData
slot.skeleton = skeleton
slot.Bone = bone
slot.R = 1
slot.G = 1
slot.B = 1
slot.A = 1
slot.SetToSetupPose()
return slot
}
func (s *Slot) SetToSetupPose() {
data := s.data
s.R = data.r
s.G = data.g
s.B = data.b
s.A = data.a
for i, slotData := range s.skeleton.data.slots {
if slotData == data {
s.SetAttachment(s.skeleton.AttachmentBySlotIndex(i, data.attachmentName))
return
}
}
}
func (s *Slot) SetAttachment(attachment Attachment) {
s.Attachment = attachment
s.attachmentTime = s.skeleton.time
}
func (s *Slot) SetAttachmentTime(time float32) {
s.attachmentTime = s.skeleton.time - time
}
func (s *Slot) AttachmentTime() float32 {
return s.skeleton.time - s.attachmentTime
}
func (s *Slot) Skeleton() *Skeleton {
return s.skeleton
}