naia_shared/world/
entity_event.rs1use crate::{
2 ComponentKind, EntityAuthStatus, EntityMessageType, GlobalEntity, RemoteEntity, Replicate, Tick,
3};
4
5pub enum EntityEvent {
7 Spawn(GlobalEntity),
9 Despawn(GlobalEntity),
11 InsertComponent(GlobalEntity, ComponentKind),
13 RemoveComponent(GlobalEntity, Box<dyn Replicate>),
15 UpdateComponent(Tick, GlobalEntity, ComponentKind),
17
18 Publish(GlobalEntity),
20 Unpublish(GlobalEntity),
22 EnableDelegation(GlobalEntity),
24 DisableDelegation(GlobalEntity),
26 SetAuthority(GlobalEntity, EntityAuthStatus),
28
29 RequestAuthority(GlobalEntity),
31 ReleaseAuthority(GlobalEntity),
33 EnableDelegationResponse(GlobalEntity),
35 MigrateResponse(GlobalEntity, RemoteEntity),
37}
38
39impl EntityEvent {
40 pub fn to_type(&self) -> Option<EntityMessageType> {
42 match self {
43 Self::Spawn(_) => Some(EntityMessageType::Spawn),
44 Self::Despawn(_) => Some(EntityMessageType::Despawn),
45 Self::InsertComponent(_, _) => Some(EntityMessageType::InsertComponent),
46 Self::RemoveComponent(_, _) => Some(EntityMessageType::RemoveComponent),
47 Self::Publish(_) => Some(EntityMessageType::Publish),
48 Self::Unpublish(_) => Some(EntityMessageType::Unpublish),
49 Self::EnableDelegation(_) => Some(EntityMessageType::EnableDelegation),
50 Self::EnableDelegationResponse(_) => Some(EntityMessageType::EnableDelegationResponse),
51 Self::DisableDelegation(_) => Some(EntityMessageType::DisableDelegation),
52 Self::RequestAuthority(_) => Some(EntityMessageType::RequestAuthority),
53 Self::ReleaseAuthority(_) => Some(EntityMessageType::ReleaseAuthority),
54 Self::SetAuthority(_, _) => Some(EntityMessageType::SetAuthority),
55 Self::MigrateResponse(_, _) => Some(EntityMessageType::MigrateResponse),
56 Self::UpdateComponent(_, _, _) => None, }
58 }
59
60 pub fn entity(&self) -> GlobalEntity {
62 match self {
63 Self::Spawn(entity) => *entity,
64 Self::Despawn(entity) => *entity,
65 Self::InsertComponent(entity, _) => *entity,
66 Self::RemoveComponent(entity, _) => *entity,
67 Self::UpdateComponent(_, entity, _) => *entity,
68 Self::Publish(entity) => *entity,
69 Self::Unpublish(entity) => *entity,
70 Self::EnableDelegation(entity) => *entity,
71 Self::EnableDelegationResponse(entity) => *entity,
72 Self::DisableDelegation(entity) => *entity,
73 Self::RequestAuthority(entity) => *entity,
74 Self::ReleaseAuthority(entity) => *entity,
75 Self::SetAuthority(entity, _) => *entity,
76 Self::MigrateResponse(entity, _) => *entity,
77 }
78 }
79
80 pub fn log(&self) -> String {
82 let entity = self.entity();
83 if let Some(ev_type) = self.to_type() {
84 format!("{:?} {:?}", ev_type, entity)
85 } else {
86 format!("UpdateComponent {:?}", entity)
87 }
88 }
89}