forked from ajhager/spine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
skin.go
46 lines (39 loc) · 971 Bytes
/
skin.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
package spine
import (
"fmt"
)
type skinData struct {
Index int
Name string
Attachment Attachment
}
type Skin struct {
name string
attachments map[string]*skinData
}
func NewSkin(name string) *Skin {
skin := new(Skin)
skin.name = name
skin.attachments = make(map[string]*skinData)
return skin
}
func (s *Skin) AddAttachment(slotIndex int, name string, attachment Attachment) {
data := &skinData{slotIndex, name, attachment}
s.attachments[fmt.Sprintf("%v:%v", slotIndex, name)] = data
}
func (s *Skin) Attachment(slotIndex int, name string) Attachment {
values, ok := s.attachments[fmt.Sprintf("%v:%v", slotIndex, name)]
if !ok {
return nil
}
return values.Attachment
}
func (s *Skin) attachAll(skeleton *Skeleton, oldSkin *Skin) {
for _, val := range oldSkin.attachments {
slot := skeleton.Slots[val.Index]
attachment := s.Attachment(val.Index, val.Name)
if attachment != nil {
slot.SetAttachment(attachment)
}
}
}