-
Notifications
You must be signed in to change notification settings - Fork 140
/
colour.go
180 lines (157 loc) · 3.57 KB
/
colour.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
package block
import "fmt"
// Colour represents the colour of a block. Typically, Minecraft blocks have a total of 16 different colours.
type Colour struct {
colour
}
// ColourWhite returns the white colour.
func ColourWhite() Colour {
return Colour{colour(0)}
}
// ColourOrange returns the orange colour.
func ColourOrange() Colour {
return Colour{colour(1)}
}
// ColourMagenta returns the magenta colour.
func ColourMagenta() Colour {
return Colour{colour(2)}
}
// ColourLightBlue returns the light blue colour.
func ColourLightBlue() Colour {
return Colour{colour(3)}
}
// ColourYellow returns the yellow colour.
func ColourYellow() Colour {
return Colour{colour(4)}
}
// ColourLime returns the lime colour.
func ColourLime() Colour {
return Colour{colour(5)}
}
// ColourPink returns the pink colour.
func ColourPink() Colour {
return Colour{colour(6)}
}
// ColourGrey returns the grey colour.
func ColourGrey() Colour {
return Colour{colour(7)}
}
// ColourLightGrey returns the light grey colour.
func ColourLightGrey() Colour {
return Colour{colour(8)}
}
// ColourCyan returns the cyan colour.
func ColourCyan() Colour {
return Colour{colour(9)}
}
// ColourPurple returns the purple colour.
func ColourPurple() Colour {
return Colour{colour(10)}
}
// ColourBlue returns the blue colour.
func ColourBlue() Colour {
return Colour{colour(11)}
}
// ColourBrown returns the brown colour.
func ColourBrown() Colour {
return Colour{colour(12)}
}
// ColourGreen returns the green colour.
func ColourGreen() Colour {
return Colour{colour(13)}
}
// ColourRed returns the red colour.
func ColourRed() Colour {
return Colour{colour(14)}
}
// ColourBlack returns the black colour.
func ColourBlack() Colour {
return Colour{colour(15)}
}
// Colours returns a list of all existing colours.
func Colours() []Colour {
return []Colour{
ColourWhite(), ColourOrange(), ColourMagenta(), ColourLightBlue(), ColourYellow(), ColourLime(), ColourPink(), ColourGrey(),
ColourLightGrey(), ColourCyan(), ColourPurple(), ColourBlue(), ColourBrown(), ColourGreen(), ColourRed(), ColourBlack(),
}
}
type colour uint8
// String ...
func (c colour) String() string {
switch c {
default:
return "white"
case 1:
return "orange"
case 2:
return "magenta"
case 3:
return "light_blue"
case 4:
return "yellow"
case 5:
return "lime"
case 6:
return "pink"
case 7:
return "gray"
case 8:
return "silver"
case 9:
return "cyan"
case 10:
return "purple"
case 11:
return "blue"
case 12:
return "brown"
case 13:
return "green"
case 14:
return "red"
case 15:
return "black"
}
}
// FromString ...
func (c colour) FromString(s string) (interface{}, error) {
switch s {
case "white":
return Colour{colour(0)}, nil
case "orange":
return Colour{colour(1)}, nil
case "magenta":
return Colour{colour(2)}, nil
case "light_blue":
return Colour{colour(3)}, nil
case "yellow":
return Colour{colour(4)}, nil
case "lime", "light_green":
return Colour{colour(5)}, nil
case "pink":
return Colour{colour(6)}, nil
case "grey", "gray":
return Colour{colour(7)}, nil
case "light_grey", "light_gray", "silver":
return Colour{colour(8)}, nil
case "cyan":
return Colour{colour(9)}, nil
case "purple":
return Colour{colour(10)}, nil
case "blue":
return Colour{colour(11)}, nil
case "brown":
return Colour{colour(12)}, nil
case "green":
return Colour{colour(13)}, nil
case "red":
return Colour{colour(14)}, nil
case "black":
return Colour{colour(15)}, nil
}
return nil, fmt.Errorf("unexpected colour '%v'", s)
}
// Uint8 ...
func (c colour) Uint8() uint8 {
return uint8(c)
}