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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
use crate::Attribute;
use strum_macros::{Display, EnumString, EnumIter, EnumCount};
use num_enum::{TryFromPrimitive, IntoPrimitive};
use serde_repr::{Serialize_repr, Deserialize_repr};
#[derive(Serialize_repr, Deserialize_repr, Debug, Hash, Eq, PartialEq, Display, EnumString, EnumIter, EnumCount, TryFromPrimitive, IntoPrimitive, Clone, Copy)]
#[repr(u32)]
pub enum Paint {
#[strum(serialize = "A Color Similar to Slate")]
AColorSimilarToSlate = 3100495,
#[strum(serialize = "A Deep Commitment to Purple")]
ADeepCommitmentToPurple = 8208497,
#[strum(serialize = "A Distinctive Lack of Hue")]
ADistinctiveLackOfHue = 1315860,
#[strum(serialize = "A Mann's Mint")]
AMannsMint = 12377523,
#[strum(serialize = "After Eight")]
AfterEight = 2960676,
#[strum(serialize = "Aged Moustache Grey")]
AgedMoustacheGrey = 8289918,
#[strum(serialize = "An Extraordinary Abundance of Tinge")]
AnExtraordinaryAbundanceOfTinge = 15132390,
#[strum(serialize = "Australium Gold")]
AustraliumGold = 15185211,
#[strum(serialize = "Color No. 216-190-216")]
ColorNo216190216 = 14204632,
#[strum(serialize = "Dark Salmon Injustice")]
DarkSalmonInjustice = 15308410,
#[strum(serialize = "Drably Olive")]
DrablyOlive = 8421376,
#[strum(serialize = "Indubitably Green")]
IndubitablyGreen = 7511618,
#[strum(serialize = "Mann Co. Orange")]
MannCoOrange = 13595446,
#[strum(serialize = "Muskelmannbraun")]
Muskelmannbraun = 10843461,
#[strum(serialize = "Noble Hatter's Violet")]
NobleHattersViolet = 5322826,
#[strum(serialize = "Peculiarly Drab Tincture")]
PeculiarlyDrabTincture = 12955537,
#[strum(serialize = "Pink as Hell")]
PinkAsHell = 16738740,
#[strum(serialize = "Radigan Conagher Brown")]
RadiganConagherBrown = 6901050,
#[strum(serialize = "The Bitter Taste of Defeat and Lime")]
TheBitterTasteOfDefeatAndLime = 3329330,
#[strum(serialize = "The Color of a Gentlemann's Business Pants")]
TheColorOfAGentlemannsBusinessPants = 15787660,
#[strum(serialize = "Ye Olde Rustic Colour")]
YeOldeRusticColour = 8154199,
#[strum(serialize = "Zepheniah's Greed")]
ZepheniahsGreed = 4345659,
#[strum(serialize = "An Air of Debonair")]
AnAirOfDebonair = 6637376,
#[strum(serialize = "Balaclavas Are Forever")]
BalaclavasAreForever = 3874595,
#[strum(serialize = "Cream Spirit")]
CreamSpirit = 12807213,
#[strum(serialize = "Operator's Overalls")]
OperatorsOveralls = 4732984,
#[strum(serialize = "Team Spirit")]
TeamSpirit = 12073019,
#[strum(serialize = "The Value of Teamwork")]
TheValueOfTeamwork = 8400928,
#[strum(serialize = "Waterlogged Lab Coat")]
WaterloggedLabCoat = 11049612,
}
impl Paint {
pub fn color(&self) -> u32 {
u32::from(*self)
}
pub fn from_color(color: u32) -> Option<Self> {
Self::try_from(color).ok()
}
pub fn from_color_str(color: &str) -> Option<Self> {
let len = color.len();
let mut color = color;
if len == 7 && color.starts_with('#') {
color = &color[1..len];
} else if len != 6 {
return None;
}
let color = u32::from_str_radix(color, 16).ok()?;
Self::from_color(color)
}
pub fn colors(&self) -> (u32, u32) {
match self {
Paint::AColorSimilarToSlate => (0x2F4F4F, 0x2F4F4F),
Paint::ADeepCommitmentToPurple => (0x7D4071, 0x7D4071),
Paint::ADistinctiveLackOfHue => (0x141414, 0x141414),
Paint::AMannsMint => (0xBCDDB3, 0xBCDDB3),
Paint::AfterEight => (0x2D2D24, 0x2D2D24),
Paint::AgedMoustacheGrey => (0x7E7E7E, 0x7E7E7E),
Paint::AnExtraordinaryAbundanceOfTinge => (0xE6E6E6, 0xE6E6E6),
Paint::AustraliumGold => (0xE7B53B, 0xE7B53B),
Paint::ColorNo216190216 => (0xD8BED8, 0xD8BED8),
Paint::DarkSalmonInjustice => (0xE9967A, 0xE9967A),
Paint::DrablyOlive => (0x808000, 0x808000),
Paint::IndubitablyGreen => (0x729E42, 0x729E42),
Paint::MannCoOrange => (0xCF7336, 0xCF7336),
Paint::Muskelmannbraun => (0xA57545, 0xA57545),
Paint::NobleHattersViolet => (0x51384A, 0x51384A),
Paint::PeculiarlyDrabTincture => (0xC5AF91, 0xC5AF91),
Paint::PinkAsHell => (0xFF69B4, 0xFF69B4),
Paint::RadiganConagherBrown => (0x694D3A, 0x694D3A),
Paint::TheBitterTasteOfDefeatAndLime => (0x32CD32, 0x32CD32),
Paint::TheColorOfAGentlemannsBusinessPants => (0xF0E68C, 0xF0E68C),
Paint::YeOldeRusticColour => (0x7C6C57, 0x7C6C57),
Paint::ZepheniahsGreed => (0x424F3B, 0x424F3B),
Paint::AnAirOfDebonair => (0x654740, 0x28394D),
Paint::BalaclavasAreForever => (0x3B1F23, 0x18233D),
Paint::CreamSpirit => (0xC36C2D, 0xB88035),
Paint::OperatorsOveralls => (0x483838, 0x384248),
Paint::TeamSpirit => (0xB8383B, 0x5885A2),
Paint::TheValueOfTeamwork => (0x803020, 0x256D8D),
Paint::WaterloggedLabCoat => (0xA89A8C, 0x839FA3),
}
}
pub fn is_team_paint(&self) -> bool {
let (red, blu) = self.colors();
red != blu
}
pub fn from_defindex(defindex: u32) -> Option<Self> {
match defindex {
5052 => Some(Paint::AColorSimilarToSlate),
5031 => Some(Paint::ADeepCommitmentToPurple),
5040 => Some(Paint::ADistinctiveLackOfHue),
5076 => Some(Paint::AMannsMint),
5077 => Some(Paint::AfterEight),
5038 => Some(Paint::AgedMoustacheGrey),
5039 => Some(Paint::AnExtraordinaryAbundanceOfTinge),
5037 => Some(Paint::AustraliumGold),
5030 => Some(Paint::ColorNo216190216),
5056 => Some(Paint::DarkSalmonInjustice),
5053 => Some(Paint::DrablyOlive),
5027 => Some(Paint::IndubitablyGreen),
5032 => Some(Paint::MannCoOrange),
5033 => Some(Paint::Muskelmannbraun),
5029 => Some(Paint::NobleHattersViolet),
5034 => Some(Paint::PeculiarlyDrabTincture),
5051 => Some(Paint::PinkAsHell),
5035 => Some(Paint::RadiganConagherBrown),
5054 => Some(Paint::TheBitterTasteOfDefeatAndLime),
5055 => Some(Paint::TheColorOfAGentlemannsBusinessPants),
5036 => Some(Paint::YeOldeRusticColour),
5028 => Some(Paint::ZepheniahsGreed),
5063 => Some(Paint::AnAirOfDebonair),
5062 => Some(Paint::BalaclavasAreForever),
5065 => Some(Paint::CreamSpirit),
5060 => Some(Paint::OperatorsOveralls),
5046 => Some(Paint::TeamSpirit),
5064 => Some(Paint::TheValueOfTeamwork),
5061 => Some(Paint::WaterloggedLabCoat),
_ => None,
}
}
pub fn defindex(&self) -> u32 {
match self {
Paint::AColorSimilarToSlate => 5052,
Paint::ADeepCommitmentToPurple => 5031,
Paint::ADistinctiveLackOfHue => 5040,
Paint::AMannsMint => 5076,
Paint::AfterEight => 5077,
Paint::AgedMoustacheGrey => 5038,
Paint::AnExtraordinaryAbundanceOfTinge => 5039,
Paint::AustraliumGold => 5037,
Paint::ColorNo216190216 => 5030,
Paint::DarkSalmonInjustice => 5056,
Paint::DrablyOlive => 5053,
Paint::IndubitablyGreen => 5027,
Paint::MannCoOrange => 5032,
Paint::Muskelmannbraun => 5033,
Paint::NobleHattersViolet => 5029,
Paint::PeculiarlyDrabTincture => 5034,
Paint::PinkAsHell => 5051,
Paint::RadiganConagherBrown => 5035,
Paint::TheBitterTasteOfDefeatAndLime => 5054,
Paint::TheColorOfAGentlemannsBusinessPants => 5055,
Paint::YeOldeRusticColour => 5036,
Paint::ZepheniahsGreed => 5028,
Paint::AnAirOfDebonair => 5063,
Paint::BalaclavasAreForever => 5062,
Paint::CreamSpirit => 5065,
Paint::OperatorsOveralls => 5060,
Paint::TeamSpirit => 5046,
Paint::TheValueOfTeamwork => 5064,
Paint::WaterloggedLabCoat => 5061,
}
}
}
impl Attribute for Paint {
const DEFINDEX: u32 = 142;
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn converts_to_primitive() {
assert_eq!(16738740 as u32, Paint::PinkAsHell.into());
}
#[test]
fn gets_defindex() {
assert_eq!(5051 as u32, Paint::PinkAsHell.defindex());
}
#[test]
fn displays_as_string() {
assert_eq!("Pink as Hell", &format!("{}", Paint::PinkAsHell));
}
#[test]
fn converts_to_hex() {
assert_eq!(0xFF69B4, Paint::PinkAsHell.color());
}
#[test]
fn converts_from_hex_str() {
assert_eq!(Paint::from_color_str("FF69B4").unwrap(), Paint::PinkAsHell);
}
#[test]
fn converts_from_hex_str_lowercase() {
assert_eq!(Paint::from_color_str("ff69b4").unwrap(), Paint::PinkAsHell);
}
#[test]
fn converts_from_hex_str_lowercase_with_pound() {
assert_eq!(Paint::from_color_str("#FF69B4").unwrap(), Paint::PinkAsHell);
}
}