wow_world_base/inner/vanilla/
character_race_flags.rs1#[derive(Debug, PartialEq, Eq, Hash, Ord, PartialOrd, Copy, Clone, Default)]
16#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
17#[cfg_attr(feature = "serde", serde(transparent))]
18pub struct CharacterRaceFlags {
19 inner: u8,
20}
21
22#[cfg(feature = "print-testcase")]
23impl CharacterRaceFlags {
24 #[allow(clippy::missing_const_for_fn)]
25 pub fn as_test_case_value(&self) -> String {
26 let mut s = String::new();
27 let mut first = true;
28 if self.is_empty() {
29 use std::fmt::Write;
30 if !first {
31 write!(s, " | ").unwrap();
32 }
33 write!(s, "NONE").unwrap();
34 first = false;
35 }
36 if self.is_not_playable() {
37 use std::fmt::Write;
38 if !first {
39 write!(s, " | ").unwrap();
40 }
41 write!(s, "NOT_PLAYABLE").unwrap();
42 first = false;
43 }
44 if self.is_bare_feet() {
45 use std::fmt::Write;
46 if !first {
47 write!(s, " | ").unwrap();
48 }
49 write!(s, "BARE_FEET").unwrap();
50 first = false;
51 }
52 if self.is_can_current_form_mount() {
53 use std::fmt::Write;
54 if !first {
55 write!(s, " | ").unwrap();
56 }
57 write!(s, "CAN_CURRENT_FORM_MOUNT").unwrap();
58 first = false;
59 }
60 if self.is_unknown2() {
61 use std::fmt::Write;
62 if !first {
63 write!(s, " | ").unwrap();
64 }
65 write!(s, "UNKNOWN2").unwrap();
66 first = false;
67 }
68 s
69 }
70
71}
72
73impl CharacterRaceFlags {
74 pub const fn new(inner: u8) -> Self {
75 Self { inner }
76 }
77
78 pub const NONE: u8 = 0x00;
79 pub const NOT_PLAYABLE: u8 = 0x01;
80 pub const BARE_FEET: u8 = 0x02;
81 pub const CAN_CURRENT_FORM_MOUNT: u8 = 0x04;
82 pub const UNKNOWN2: u8 = 0x08;
83
84 pub const fn empty() -> Self {
85 Self { inner: 0 }
86 }
87
88 pub const fn is_empty(&self) -> bool {
89 self.inner == 0
90 }
91
92 pub const fn all() -> Self {
93 Self {
94 inner: Self::NONE
95 | Self::NOT_PLAYABLE
96 | Self::BARE_FEET
97 | Self::CAN_CURRENT_FORM_MOUNT
98 | Self::UNKNOWN2
99 }
100 }
101
102 pub const fn is_not_playable(&self) -> bool {
103 (self.inner & Self::NOT_PLAYABLE) != 0
104 }
105
106 pub const fn new_not_playable() -> Self {
107 Self { inner: Self::NOT_PLAYABLE }
108 }
109
110 pub fn set_not_playable(&mut self) -> Self {
111 self.inner |= Self::NOT_PLAYABLE;
112 *self
113 }
114
115 pub fn clear_not_playable(&mut self) -> Self {
116 self.inner &= Self::NOT_PLAYABLE.reverse_bits();
117 *self
118 }
119
120 pub const fn is_bare_feet(&self) -> bool {
121 (self.inner & Self::BARE_FEET) != 0
122 }
123
124 pub const fn new_bare_feet() -> Self {
125 Self { inner: Self::BARE_FEET }
126 }
127
128 pub fn set_bare_feet(&mut self) -> Self {
129 self.inner |= Self::BARE_FEET;
130 *self
131 }
132
133 pub fn clear_bare_feet(&mut self) -> Self {
134 self.inner &= Self::BARE_FEET.reverse_bits();
135 *self
136 }
137
138 pub const fn is_can_current_form_mount(&self) -> bool {
139 (self.inner & Self::CAN_CURRENT_FORM_MOUNT) != 0
140 }
141
142 pub const fn new_can_current_form_mount() -> Self {
143 Self { inner: Self::CAN_CURRENT_FORM_MOUNT }
144 }
145
146 pub fn set_can_current_form_mount(&mut self) -> Self {
147 self.inner |= Self::CAN_CURRENT_FORM_MOUNT;
148 *self
149 }
150
151 pub fn clear_can_current_form_mount(&mut self) -> Self {
152 self.inner &= Self::CAN_CURRENT_FORM_MOUNT.reverse_bits();
153 *self
154 }
155
156 pub const fn is_unknown2(&self) -> bool {
157 (self.inner & Self::UNKNOWN2) != 0
158 }
159
160 pub const fn new_unknown2() -> Self {
161 Self { inner: Self::UNKNOWN2 }
162 }
163
164 pub fn set_unknown2(&mut self) -> Self {
165 self.inner |= Self::UNKNOWN2;
166 *self
167 }
168
169 pub fn clear_unknown2(&mut self) -> Self {
170 self.inner &= Self::UNKNOWN2.reverse_bits();
171 *self
172 }
173
174 pub const fn as_int(&self) -> u8 {
175 self.inner
176 }
177
178}
179
180impl std::fmt::UpperHex for CharacterRaceFlags {
181 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
182 std::fmt::UpperHex::fmt(&self.inner, f)
183 }
184}
185
186impl std::fmt::LowerHex for CharacterRaceFlags {
187 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
188 std::fmt::LowerHex::fmt(&self.inner, f)
189 }
190}
191
192impl std::fmt::Octal for CharacterRaceFlags {
193 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
194 std::fmt::Octal::fmt(&self.inner, f)
195 }
196}
197
198impl std::fmt::Binary for CharacterRaceFlags {
199 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
200 std::fmt::Binary::fmt(&self.inner, f)
201 }
202}
203
204impl std::ops::BitAnd for CharacterRaceFlags {
205 type Output = Self;
206 fn bitand(self, rhs: Self) -> Self::Output {
207 Self { inner: self.inner.bitand(rhs.inner), }
208 }
209}
210
211impl std::ops::BitAndAssign for CharacterRaceFlags {
212 fn bitand_assign(&mut self, rhs: Self) {
213 self.inner.bitand_assign(rhs.inner)
214 }
215}
216
217impl std::ops::BitOr for CharacterRaceFlags {
218 type Output = Self;
219 fn bitor(self, rhs: Self) -> Self::Output {
220 Self { inner: self.inner.bitor(rhs.inner), }
221 }
222}
223
224impl std::ops::BitOrAssign for CharacterRaceFlags {
225 fn bitor_assign(&mut self, rhs: Self) {
226 self.inner.bitor_assign(rhs.inner)
227 }
228}
229
230impl std::ops::BitXor for CharacterRaceFlags {
231 type Output = Self;
232 fn bitxor(self, rhs: Self) -> Self::Output {
233 Self { inner: self.inner.bitxor(rhs.inner), }
234 }
235}
236
237impl std::ops::BitXorAssign for CharacterRaceFlags {
238 fn bitxor_assign(&mut self, rhs: Self) {
239 self.inner.bitxor_assign(rhs.inner)
240 }
241}
242
243impl From<u8> for CharacterRaceFlags {
244 fn from(value: u8) -> Self {
245 Self::new(value)
246 }
247}
248
249impl TryFrom<u16> for CharacterRaceFlags {
250 type Error = u16;
251 fn try_from(value: u16) -> Result<Self, Self::Error> {
252 let a = TryInto::<u8>::try_into(value).ok().ok_or(value)?;
253 Ok(Self::new(a))
254 }
255}
256
257impl TryFrom<u32> for CharacterRaceFlags {
258 type Error = u32;
259 fn try_from(value: u32) -> Result<Self, Self::Error> {
260 let a = TryInto::<u8>::try_into(value).ok().ok_or(value)?;
261 Ok(Self::new(a))
262 }
263}
264
265impl TryFrom<u64> for CharacterRaceFlags {
266 type Error = u64;
267 fn try_from(value: u64) -> Result<Self, Self::Error> {
268 let a = TryInto::<u8>::try_into(value).ok().ok_or(value)?;
269 Ok(Self::new(a))
270 }
271}
272
273impl From<i8> for CharacterRaceFlags {
274 fn from(value: i8) -> Self {
275 Self::new(u8::from_le_bytes(value.to_le_bytes()))
276 }
277}
278
279impl TryFrom<i16> for CharacterRaceFlags {
280 type Error = i16;
281 fn try_from(value: i16) -> Result<Self, Self::Error> {
282 let v = u16::from_le_bytes(value.to_le_bytes());
283 let a = TryInto::<u8>::try_into(v).ok().ok_or(value)?;
284 Ok(Self::new(a))
285 }
286}
287
288impl TryFrom<i32> for CharacterRaceFlags {
289 type Error = i32;
290 fn try_from(value: i32) -> Result<Self, Self::Error> {
291 let v = u32::from_le_bytes(value.to_le_bytes());
292 let a = TryInto::<u8>::try_into(v).ok().ok_or(value)?;
293 Ok(Self::new(a))
294 }
295}
296
297impl TryFrom<i64> for CharacterRaceFlags {
298 type Error = i64;
299 fn try_from(value: i64) -> Result<Self, Self::Error> {
300 let v = u64::from_le_bytes(value.to_le_bytes());
301 let a = TryInto::<u8>::try_into(v).ok().ok_or(value)?;
302 Ok(Self::new(a))
303 }
304}
305
306impl TryFrom<usize> for CharacterRaceFlags {
307 type Error = usize;
308 fn try_from(value: usize) -> Result<Self, Self::Error> {
309 let a = TryInto::<u8>::try_into(value).ok().ok_or(value)?;
310 Ok(Self::new(a))
311 }
312}
313