-
Notifications
You must be signed in to change notification settings - Fork 1
/
blitz.go
57 lines (50 loc) · 1.04 KB
/
blitz.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
// Copyright 2014
// Use of this source code is governed by a 2-clause
// BSD-style license that can be found in the LICENSE file.
package main
import "encoding/json"
type (
Blitz uint8
BlitzMastery uint8
)
const (
RagingFist Blitz = 1 << iota
AuraCannon
MeteorStrike
RisingPhoenix
Chakra
RazorGale
SoulSpiral
PhantomRush
)
func (b *BlitzMastery) UnmarshalJSON(data []byte) error {
d := make(map[string]bool)
if err := json.Unmarshal(data, &d); err != nil {
return err
}
var i Blitz
for k, v := range blitznames {
if d[v] {
i |= k
}
}
*b = BlitzMastery(i)
return nil
}
func (b BlitzMastery) MarshalJSON() ([]byte, error) {
d := make(map[string]bool)
for k, v := range blitznames {
d[v] = Blitz(b)&k != 0
}
return json.Marshal(d)
}
var blitznames = map[Blitz]string{
RagingFist: "Raging Fist",
AuraCannon: "Aura Cannon",
MeteorStrike: "Meteor Strike",
RisingPhoenix: "Rising Phoenix",
Chakra: "Chakra",
RazorGale: "Razor Gale",
SoulSpiral: "Soul Spiral",
PhantomRush: "Phantom Rush",
}