evtc\event/
common.rs
1use crate::{Affinity, AgentId, Event};
2
3#[cfg(feature = "serde")]
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone)]
8#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9pub struct CommonEvent {
10 pub time: u64,
12
13 pub src: AgentId,
15
16 pub dst: AgentId,
18
19 pub skill_id: u32,
21
22 pub affinity: Affinity,
26
27 pub is_ninety: u8,
29
30 pub is_fifty: u8,
32
33 pub is_moving: u8,
35
36 pub is_flanking: u8,
40}
41
42impl From<&Event> for CommonEvent {
43 #[inline]
44 fn from(event: &Event) -> Self {
45 Self {
46 time: event.time,
47 src: AgentId::from_src(event),
48 dst: AgentId::from_dst(event),
49 skill_id: event.skill_id,
50 affinity: event.get_affinity(),
51 is_ninety: event.is_ninety,
52 is_fifty: event.is_fifty,
53 is_moving: event.is_moving,
54 is_flanking: event.is_flanking,
55 }
56 }
57}
58
59macro_rules! impl_common {
61 ($ty:ty) => {
62 impl ::core::convert::AsRef<$crate::event::CommonEvent> for $ty {
63 #[inline]
64 fn as_ref(&self) -> &$crate::event::CommonEvent {
65 &self.common
66 }
67 }
68
69 impl ::core::convert::AsMut<$crate::event::CommonEvent> for $ty {
70 #[inline]
71 fn as_mut(&mut self) -> &mut $crate::event::CommonEvent {
72 &mut self.common
73 }
74 }
75
76 impl ::core::convert::From<$ty> for $crate::event::CommonEvent {
77 #[inline]
78 fn from(value: $ty) -> Self {
79 value.common
80 }
81 }
82
83 impl ::core::ops::Deref for $ty {
84 type Target = $crate::event::CommonEvent;
85
86 #[inline]
87 fn deref(&self) -> &Self::Target {
88 &self.common
89 }
90 }
91
92 impl ::core::ops::DerefMut for $ty {
93 #[inline]
94 fn deref_mut(&mut self) -> &mut Self::Target {
95 &mut self.common
96 }
97 }
98 };
99}
100
101pub(crate) use impl_common;