wow_world_base/inner/tbc/
group_update_flags.rs1#[derive(Debug, PartialEq, Eq, Hash, Ord, PartialOrd, Copy, Clone, Default)]
27#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
28#[cfg_attr(feature = "serde", serde(transparent))]
29pub struct GroupUpdateFlags {
30 inner: u32,
31}
32
33#[cfg(feature = "print-testcase")]
34impl GroupUpdateFlags {
35 #[allow(clippy::missing_const_for_fn)]
36 pub fn as_test_case_value(&self) -> String {
37 let mut s = String::new();
38 let mut first = true;
39 if self.is_empty() {
40 use std::fmt::Write;
41 if !first {
42 write!(s, " | ").unwrap();
43 }
44 write!(s, "NONE").unwrap();
45 first = false;
46 }
47 if self.is_status() {
48 use std::fmt::Write;
49 if !first {
50 write!(s, " | ").unwrap();
51 }
52 write!(s, "STATUS").unwrap();
53 first = false;
54 }
55 if self.is_cur_hp() {
56 use std::fmt::Write;
57 if !first {
58 write!(s, " | ").unwrap();
59 }
60 write!(s, "CUR_HP").unwrap();
61 first = false;
62 }
63 if self.is_max_hp() {
64 use std::fmt::Write;
65 if !first {
66 write!(s, " | ").unwrap();
67 }
68 write!(s, "MAX_HP").unwrap();
69 first = false;
70 }
71 if self.is_power_type() {
72 use std::fmt::Write;
73 if !first {
74 write!(s, " | ").unwrap();
75 }
76 write!(s, "POWER_TYPE").unwrap();
77 first = false;
78 }
79 if self.is_cur_power() {
80 use std::fmt::Write;
81 if !first {
82 write!(s, " | ").unwrap();
83 }
84 write!(s, "CUR_POWER").unwrap();
85 first = false;
86 }
87 if self.is_max_power() {
88 use std::fmt::Write;
89 if !first {
90 write!(s, " | ").unwrap();
91 }
92 write!(s, "MAX_POWER").unwrap();
93 first = false;
94 }
95 if self.is_level() {
96 use std::fmt::Write;
97 if !first {
98 write!(s, " | ").unwrap();
99 }
100 write!(s, "LEVEL").unwrap();
101 first = false;
102 }
103 if self.is_zone() {
104 use std::fmt::Write;
105 if !first {
106 write!(s, " | ").unwrap();
107 }
108 write!(s, "ZONE").unwrap();
109 first = false;
110 }
111 if self.is_position() {
112 use std::fmt::Write;
113 if !first {
114 write!(s, " | ").unwrap();
115 }
116 write!(s, "POSITION").unwrap();
117 first = false;
118 }
119 if self.is_auras() {
120 use std::fmt::Write;
121 if !first {
122 write!(s, " | ").unwrap();
123 }
124 write!(s, "AURAS").unwrap();
125 first = false;
126 }
127 if self.is_pet_guid() {
128 use std::fmt::Write;
129 if !first {
130 write!(s, " | ").unwrap();
131 }
132 write!(s, "PET_GUID").unwrap();
133 first = false;
134 }
135 if self.is_pet_name() {
136 use std::fmt::Write;
137 if !first {
138 write!(s, " | ").unwrap();
139 }
140 write!(s, "PET_NAME").unwrap();
141 first = false;
142 }
143 if self.is_pet_model_id() {
144 use std::fmt::Write;
145 if !first {
146 write!(s, " | ").unwrap();
147 }
148 write!(s, "PET_MODEL_ID").unwrap();
149 first = false;
150 }
151 if self.is_pet_cur_hp() {
152 use std::fmt::Write;
153 if !first {
154 write!(s, " | ").unwrap();
155 }
156 write!(s, "PET_CUR_HP").unwrap();
157 first = false;
158 }
159 if self.is_pet_max_hp() {
160 use std::fmt::Write;
161 if !first {
162 write!(s, " | ").unwrap();
163 }
164 write!(s, "PET_MAX_HP").unwrap();
165 first = false;
166 }
167 if self.is_pet_power_type() {
168 use std::fmt::Write;
169 if !first {
170 write!(s, " | ").unwrap();
171 }
172 write!(s, "PET_POWER_TYPE").unwrap();
173 first = false;
174 }
175 if self.is_pet_cur_power() {
176 use std::fmt::Write;
177 if !first {
178 write!(s, " | ").unwrap();
179 }
180 write!(s, "PET_CUR_POWER").unwrap();
181 first = false;
182 }
183 if self.is_pet_max_power() {
184 use std::fmt::Write;
185 if !first {
186 write!(s, " | ").unwrap();
187 }
188 write!(s, "PET_MAX_POWER").unwrap();
189 first = false;
190 }
191 if self.is_pet_auras() {
192 use std::fmt::Write;
193 if !first {
194 write!(s, " | ").unwrap();
195 }
196 write!(s, "PET_AURAS").unwrap();
197 first = false;
198 }
199 s
200 }
201
202}
203
204impl GroupUpdateFlags {
205 pub const fn new(inner: u32) -> Self {
206 Self { inner }
207 }
208
209 pub const NONE: u32 = 0x00;
210 pub const STATUS: u32 = 0x01;
211 pub const CUR_HP: u32 = 0x02;
212 pub const MAX_HP: u32 = 0x04;
213 pub const POWER_TYPE: u32 = 0x08;
214 pub const CUR_POWER: u32 = 0x10;
215 pub const MAX_POWER: u32 = 0x20;
216 pub const LEVEL: u32 = 0x40;
217 pub const ZONE: u32 = 0x80;
218 pub const POSITION: u32 = 0x100;
219 pub const AURAS: u32 = 0x200;
220 pub const PET_GUID: u32 = 0x400;
221 pub const PET_NAME: u32 = 0x800;
222 pub const PET_MODEL_ID: u32 = 0x1000;
223 pub const PET_CUR_HP: u32 = 0x2000;
224 pub const PET_MAX_HP: u32 = 0x4000;
225 pub const PET_POWER_TYPE: u32 = 0x8000;
226 pub const PET_CUR_POWER: u32 = 0x10000;
227 pub const PET_MAX_POWER: u32 = 0x20000;
228 pub const PET_AURAS: u32 = 0x40000;
229
230 pub const fn empty() -> Self {
231 Self { inner: 0 }
232 }
233
234 pub const fn is_empty(&self) -> bool {
235 self.inner == 0
236 }
237
238 pub const fn all() -> Self {
239 Self {
240 inner: Self::NONE
241 | Self::STATUS
242 | Self::CUR_HP
243 | Self::MAX_HP
244 | Self::POWER_TYPE
245 | Self::CUR_POWER
246 | Self::MAX_POWER
247 | Self::LEVEL
248 | Self::ZONE
249 | Self::POSITION
250 | Self::AURAS
251 | Self::PET_GUID
252 | Self::PET_NAME
253 | Self::PET_MODEL_ID
254 | Self::PET_CUR_HP
255 | Self::PET_MAX_HP
256 | Self::PET_POWER_TYPE
257 | Self::PET_CUR_POWER
258 | Self::PET_MAX_POWER
259 | Self::PET_AURAS
260 }
261 }
262
263 pub const fn is_status(&self) -> bool {
264 (self.inner & Self::STATUS) != 0
265 }
266
267 pub const fn new_status() -> Self {
269 Self { inner: Self::STATUS }
270 }
271
272 pub fn set_status(&mut self) -> Self {
273 self.inner |= Self::STATUS;
274 *self
275 }
276
277 pub fn clear_status(&mut self) -> Self {
278 self.inner &= Self::STATUS.reverse_bits();
279 *self
280 }
281
282 pub const fn is_cur_hp(&self) -> bool {
283 (self.inner & Self::CUR_HP) != 0
284 }
285
286 pub const fn new_cur_hp() -> Self {
288 Self { inner: Self::CUR_HP }
289 }
290
291 pub fn set_cur_hp(&mut self) -> Self {
292 self.inner |= Self::CUR_HP;
293 *self
294 }
295
296 pub fn clear_cur_hp(&mut self) -> Self {
297 self.inner &= Self::CUR_HP.reverse_bits();
298 *self
299 }
300
301 pub const fn is_max_hp(&self) -> bool {
302 (self.inner & Self::MAX_HP) != 0
303 }
304
305 pub const fn new_max_hp() -> Self {
307 Self { inner: Self::MAX_HP }
308 }
309
310 pub fn set_max_hp(&mut self) -> Self {
311 self.inner |= Self::MAX_HP;
312 *self
313 }
314
315 pub fn clear_max_hp(&mut self) -> Self {
316 self.inner &= Self::MAX_HP.reverse_bits();
317 *self
318 }
319
320 pub const fn is_power_type(&self) -> bool {
321 (self.inner & Self::POWER_TYPE) != 0
322 }
323
324 pub const fn new_power_type() -> Self {
326 Self { inner: Self::POWER_TYPE }
327 }
328
329 pub fn set_power_type(&mut self) -> Self {
330 self.inner |= Self::POWER_TYPE;
331 *self
332 }
333
334 pub fn clear_power_type(&mut self) -> Self {
335 self.inner &= Self::POWER_TYPE.reverse_bits();
336 *self
337 }
338
339 pub const fn is_cur_power(&self) -> bool {
340 (self.inner & Self::CUR_POWER) != 0
341 }
342
343 pub const fn new_cur_power() -> Self {
345 Self { inner: Self::CUR_POWER }
346 }
347
348 pub fn set_cur_power(&mut self) -> Self {
349 self.inner |= Self::CUR_POWER;
350 *self
351 }
352
353 pub fn clear_cur_power(&mut self) -> Self {
354 self.inner &= Self::CUR_POWER.reverse_bits();
355 *self
356 }
357
358 pub const fn is_max_power(&self) -> bool {
359 (self.inner & Self::MAX_POWER) != 0
360 }
361
362 pub const fn new_max_power() -> Self {
364 Self { inner: Self::MAX_POWER }
365 }
366
367 pub fn set_max_power(&mut self) -> Self {
368 self.inner |= Self::MAX_POWER;
369 *self
370 }
371
372 pub fn clear_max_power(&mut self) -> Self {
373 self.inner &= Self::MAX_POWER.reverse_bits();
374 *self
375 }
376
377 pub const fn is_level(&self) -> bool {
378 (self.inner & Self::LEVEL) != 0
379 }
380
381 pub const fn new_level() -> Self {
383 Self { inner: Self::LEVEL }
384 }
385
386 pub fn set_level(&mut self) -> Self {
387 self.inner |= Self::LEVEL;
388 *self
389 }
390
391 pub fn clear_level(&mut self) -> Self {
392 self.inner &= Self::LEVEL.reverse_bits();
393 *self
394 }
395
396 pub const fn is_zone(&self) -> bool {
397 (self.inner & Self::ZONE) != 0
398 }
399
400 pub const fn new_zone() -> Self {
402 Self { inner: Self::ZONE }
403 }
404
405 pub fn set_zone(&mut self) -> Self {
406 self.inner |= Self::ZONE;
407 *self
408 }
409
410 pub fn clear_zone(&mut self) -> Self {
411 self.inner &= Self::ZONE.reverse_bits();
412 *self
413 }
414
415 pub const fn is_position(&self) -> bool {
416 (self.inner & Self::POSITION) != 0
417 }
418
419 pub const fn new_position() -> Self {
421 Self { inner: Self::POSITION }
422 }
423
424 pub fn set_position(&mut self) -> Self {
425 self.inner |= Self::POSITION;
426 *self
427 }
428
429 pub fn clear_position(&mut self) -> Self {
430 self.inner &= Self::POSITION.reverse_bits();
431 *self
432 }
433
434 pub const fn is_auras(&self) -> bool {
435 (self.inner & Self::AURAS) != 0
436 }
437
438 pub const fn new_auras() -> Self {
440 Self { inner: Self::AURAS }
441 }
442
443 pub fn set_auras(&mut self) -> Self {
444 self.inner |= Self::AURAS;
445 *self
446 }
447
448 pub fn clear_auras(&mut self) -> Self {
449 self.inner &= Self::AURAS.reverse_bits();
450 *self
451 }
452
453 pub const fn is_pet_guid(&self) -> bool {
454 (self.inner & Self::PET_GUID) != 0
455 }
456
457 pub const fn new_pet_guid() -> Self {
459 Self { inner: Self::PET_GUID }
460 }
461
462 pub fn set_pet_guid(&mut self) -> Self {
463 self.inner |= Self::PET_GUID;
464 *self
465 }
466
467 pub fn clear_pet_guid(&mut self) -> Self {
468 self.inner &= Self::PET_GUID.reverse_bits();
469 *self
470 }
471
472 pub const fn is_pet_name(&self) -> bool {
473 (self.inner & Self::PET_NAME) != 0
474 }
475
476 pub const fn new_pet_name() -> Self {
478 Self { inner: Self::PET_NAME }
479 }
480
481 pub fn set_pet_name(&mut self) -> Self {
482 self.inner |= Self::PET_NAME;
483 *self
484 }
485
486 pub fn clear_pet_name(&mut self) -> Self {
487 self.inner &= Self::PET_NAME.reverse_bits();
488 *self
489 }
490
491 pub const fn is_pet_model_id(&self) -> bool {
492 (self.inner & Self::PET_MODEL_ID) != 0
493 }
494
495 pub const fn new_pet_model_id() -> Self {
497 Self { inner: Self::PET_MODEL_ID }
498 }
499
500 pub fn set_pet_model_id(&mut self) -> Self {
501 self.inner |= Self::PET_MODEL_ID;
502 *self
503 }
504
505 pub fn clear_pet_model_id(&mut self) -> Self {
506 self.inner &= Self::PET_MODEL_ID.reverse_bits();
507 *self
508 }
509
510 pub const fn is_pet_cur_hp(&self) -> bool {
511 (self.inner & Self::PET_CUR_HP) != 0
512 }
513
514 pub const fn new_pet_cur_hp() -> Self {
516 Self { inner: Self::PET_CUR_HP }
517 }
518
519 pub fn set_pet_cur_hp(&mut self) -> Self {
520 self.inner |= Self::PET_CUR_HP;
521 *self
522 }
523
524 pub fn clear_pet_cur_hp(&mut self) -> Self {
525 self.inner &= Self::PET_CUR_HP.reverse_bits();
526 *self
527 }
528
529 pub const fn is_pet_max_hp(&self) -> bool {
530 (self.inner & Self::PET_MAX_HP) != 0
531 }
532
533 pub const fn new_pet_max_hp() -> Self {
535 Self { inner: Self::PET_MAX_HP }
536 }
537
538 pub fn set_pet_max_hp(&mut self) -> Self {
539 self.inner |= Self::PET_MAX_HP;
540 *self
541 }
542
543 pub fn clear_pet_max_hp(&mut self) -> Self {
544 self.inner &= Self::PET_MAX_HP.reverse_bits();
545 *self
546 }
547
548 pub const fn is_pet_power_type(&self) -> bool {
549 (self.inner & Self::PET_POWER_TYPE) != 0
550 }
551
552 pub const fn new_pet_power_type() -> Self {
554 Self { inner: Self::PET_POWER_TYPE }
555 }
556
557 pub fn set_pet_power_type(&mut self) -> Self {
558 self.inner |= Self::PET_POWER_TYPE;
559 *self
560 }
561
562 pub fn clear_pet_power_type(&mut self) -> Self {
563 self.inner &= Self::PET_POWER_TYPE.reverse_bits();
564 *self
565 }
566
567 pub const fn is_pet_cur_power(&self) -> bool {
568 (self.inner & Self::PET_CUR_POWER) != 0
569 }
570
571 pub const fn new_pet_cur_power() -> Self {
573 Self { inner: Self::PET_CUR_POWER }
574 }
575
576 pub fn set_pet_cur_power(&mut self) -> Self {
577 self.inner |= Self::PET_CUR_POWER;
578 *self
579 }
580
581 pub fn clear_pet_cur_power(&mut self) -> Self {
582 self.inner &= Self::PET_CUR_POWER.reverse_bits();
583 *self
584 }
585
586 pub const fn is_pet_max_power(&self) -> bool {
587 (self.inner & Self::PET_MAX_POWER) != 0
588 }
589
590 pub const fn new_pet_max_power() -> Self {
592 Self { inner: Self::PET_MAX_POWER }
593 }
594
595 pub fn set_pet_max_power(&mut self) -> Self {
596 self.inner |= Self::PET_MAX_POWER;
597 *self
598 }
599
600 pub fn clear_pet_max_power(&mut self) -> Self {
601 self.inner &= Self::PET_MAX_POWER.reverse_bits();
602 *self
603 }
604
605 pub const fn is_pet_auras(&self) -> bool {
606 (self.inner & Self::PET_AURAS) != 0
607 }
608
609 pub const fn new_pet_auras() -> Self {
611 Self { inner: Self::PET_AURAS }
612 }
613
614 pub fn set_pet_auras(&mut self) -> Self {
615 self.inner |= Self::PET_AURAS;
616 *self
617 }
618
619 pub fn clear_pet_auras(&mut self) -> Self {
620 self.inner &= Self::PET_AURAS.reverse_bits();
621 *self
622 }
623
624 pub const fn as_int(&self) -> u32 {
625 self.inner
626 }
627
628}
629
630impl std::fmt::UpperHex for GroupUpdateFlags {
631 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
632 std::fmt::UpperHex::fmt(&self.inner, f)
633 }
634}
635
636impl std::fmt::LowerHex for GroupUpdateFlags {
637 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
638 std::fmt::LowerHex::fmt(&self.inner, f)
639 }
640}
641
642impl std::fmt::Octal for GroupUpdateFlags {
643 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
644 std::fmt::Octal::fmt(&self.inner, f)
645 }
646}
647
648impl std::fmt::Binary for GroupUpdateFlags {
649 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
650 std::fmt::Binary::fmt(&self.inner, f)
651 }
652}
653
654impl std::ops::BitAnd for GroupUpdateFlags {
655 type Output = Self;
656 fn bitand(self, rhs: Self) -> Self::Output {
657 Self { inner: self.inner.bitand(rhs.inner), }
658 }
659}
660
661impl std::ops::BitAndAssign for GroupUpdateFlags {
662 fn bitand_assign(&mut self, rhs: Self) {
663 self.inner.bitand_assign(rhs.inner)
664 }
665}
666
667impl std::ops::BitOr for GroupUpdateFlags {
668 type Output = Self;
669 fn bitor(self, rhs: Self) -> Self::Output {
670 Self { inner: self.inner.bitor(rhs.inner), }
671 }
672}
673
674impl std::ops::BitOrAssign for GroupUpdateFlags {
675 fn bitor_assign(&mut self, rhs: Self) {
676 self.inner.bitor_assign(rhs.inner)
677 }
678}
679
680impl std::ops::BitXor for GroupUpdateFlags {
681 type Output = Self;
682 fn bitxor(self, rhs: Self) -> Self::Output {
683 Self { inner: self.inner.bitxor(rhs.inner), }
684 }
685}
686
687impl std::ops::BitXorAssign for GroupUpdateFlags {
688 fn bitxor_assign(&mut self, rhs: Self) {
689 self.inner.bitxor_assign(rhs.inner)
690 }
691}
692
693impl From<u32> for GroupUpdateFlags {
694 fn from(value: u32) -> Self {
695 Self::new(value)
696 }
697}
698
699impl From<u8> for GroupUpdateFlags {
700 fn from(value: u8) -> Self {
701 Self::new(value.into())
702 }
703}
704
705impl From<u16> for GroupUpdateFlags {
706 fn from(value: u16) -> Self {
707 Self::new(value.into())
708 }
709}
710
711impl TryFrom<u64> for GroupUpdateFlags {
712 type Error = u64;
713 fn try_from(value: u64) -> Result<Self, Self::Error> {
714 let a = TryInto::<u32>::try_into(value).ok().ok_or(value)?;
715 Ok(Self::new(a))
716 }
717}
718
719impl TryFrom<i8> for GroupUpdateFlags {
720 type Error = i8;
721 fn try_from(value: i8) -> Result<Self, Self::Error> {
722 let v = u8::from_le_bytes(value.to_le_bytes());
723 Ok(Self::new(v.into()))
724 }
725}
726
727impl TryFrom<i16> for GroupUpdateFlags {
728 type Error = i16;
729 fn try_from(value: i16) -> Result<Self, Self::Error> {
730 let v = u16::from_le_bytes(value.to_le_bytes());
731 Ok(Self::new(v.into()))
732 }
733}
734
735impl From<i32> for GroupUpdateFlags {
736 fn from(value: i32) -> Self {
737 Self::new(u32::from_le_bytes(value.to_le_bytes()))
738 }
739}
740
741impl TryFrom<i64> for GroupUpdateFlags {
742 type Error = i64;
743 fn try_from(value: i64) -> Result<Self, Self::Error> {
744 let v = u64::from_le_bytes(value.to_le_bytes());
745 let a = TryInto::<u32>::try_into(v).ok().ok_or(value)?;
746 Ok(Self::new(a))
747 }
748}
749
750impl TryFrom<usize> for GroupUpdateFlags {
751 type Error = usize;
752 fn try_from(value: usize) -> Result<Self, Self::Error> {
753 let a = TryInto::<u32>::try_into(value).ok().ok_or(value)?;
754 Ok(Self::new(a))
755 }
756}
757