-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslots.go
104 lines (90 loc) · 1.88 KB
/
slots.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package eqtypes
import (
"encoding/json"
"strings"
)
type (
Slot int
SlotsBitmask int32
)
const (
SlotCharm Slot = 1 << iota
SlotEarL
SlotHead
SlotFace
SlotEarR
SlotNeck
SlotShoulders
SlotArms
SlotBack
SlotWristL
SlotWristR
SlotRange
SlotHands
SlotSecondary
SlotPrimary
SlotFingerL
SlotFingerR
SlotChest
SlotLegs
SlotFeet
SlotWaist
SlotPowerSource
SlotAmmo
)
var slotToString = map[Slot]string{
SlotCharm: "Charm",
SlotEarL: "Ear",
SlotHead: "Head",
SlotFace: "Face",
SlotEarR: "Ear",
SlotNeck: "Neck",
SlotShoulders: "Shoulders",
SlotArms: "Arms",
SlotBack: "Back",
SlotWristL: "Wrist",
SlotWristR: "Wrist",
SlotRange: "Range",
SlotHands: "Hands",
SlotSecondary: "Secondary",
SlotPrimary: "Primary",
SlotFingerL: "Finger",
SlotFingerR: "Finger",
SlotChest: "Chest",
SlotLegs: "Legs",
SlotFeet: "Feet",
SlotWaist: "Waist",
SlotPowerSource: "Power Source",
SlotAmmo: "Ammo",
}
func (s Slot) String() string {
return slotToString[s]
}
// list parses the SlotsBitmask and returns an array of strings with duplicate slots removed.
func (s SlotsBitmask) list() []string {
var slots []Slot
var i int32
for i = 1; i <= int32(s); i <<= 1 {
if i&int32(s) != 0 {
slots = append(slots, Slot(i))
}
}
type unique map[string]struct{}
// There are duplicate entries for things like ears, wrists that don't matter for item display.
// Create a unique map of slots by name, then concatenate them.
tmp := make(unique)
for _, slot := range slots {
tmp[slotToString[slot]] = struct{}{}
}
var sl []string
for slot := range tmp {
sl = append(sl, slot)
}
return sl
}
func (s SlotsBitmask) String() string {
return strings.Join(s.list(), " ")
}
func (s SlotsBitmask) MarshalJSON() ([]byte, error) {
return json.Marshal(s.list())
}