/
commands.go
98 lines (91 loc) · 1.48 KB
/
commands.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
// 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"
"fmt"
)
type Command uint8
const (
Fight Command = iota
ItemCmd
Magic
Morph
Revert
Steal
Capture
Swdtech
Throw
Tools
BlitzCmd
Runic
LoreCmd
Sketch
Control
Slot
Rage
Leap
Mimic
DanceCmd
Row
Def
Jump
XMagic
GP_Rain
Summon
Health
Shock
Possess
MagiTek
NoCommand Command = 255
)
var cmdName = map[Command]string{
Fight: "Fight",
ItemCmd: "Item",
Magic: "Magic",
Morph: "Morph",
Revert: "Revert",
Steal: "Steal",
Capture: "Capture",
Swdtech: "Swdtech",
Throw: "Throw",
Tools: "Tools",
BlitzCmd: "Blitz",
Runic: "Runic",
LoreCmd: "Lore",
Sketch: "Sketch",
Control: "Control",
Slot: "Slot",
Rage: "Rage",
Leap: "Leap",
Mimic: "Mimic",
DanceCmd: "Dance",
Row: "Row",
Def: "Def",
Jump: "Jump",
XMagic: "XMagic",
GP_Rain: "GP_Rain",
Summon: "Summon",
Health: "Health",
Shock: "Shock",
Possess: "Possess",
MagiTek: "MagiTek",
NoCommand: "",
}
func (c Command) MarshalJSON() ([]byte, error) {
return json.Marshal(cmdName[c])
}
func (c *Command) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return err
}
for k, v := range cmdName {
if v == s {
*c = k
return nil
}
}
return fmt.Errorf("\"%s\" isn't a known command", s)
}