naia_client/world/
entity_ref.rs1use std::hash::Hash;
2
3use naia_shared::{EntityAuthStatus, ReplicaRefWrapper, ReplicatedComponent, WorldRefType};
4
5use crate::{world::entity_owner::EntityOwner, Client};
6use naia_shared::Publicity;
7
8pub struct EntityRef<'s, E: Copy + Eq + Hash + Send + Sync, W: WorldRefType<E>> {
14 client: &'s Client<E>,
15 world: W,
16 entity: E,
17}
18
19impl<'s, E: Copy + Eq + Hash + Send + Sync, W: WorldRefType<E>> EntityRef<'s, E, W> {
20 pub fn new(client: &'s Client<E>, world: W, entity: &E) -> Self {
22 Self {
23 client,
24 world,
25 entity: *entity,
26 }
27 }
28
29 pub fn id(&self) -> E {
31 self.entity
32 }
33
34 pub fn has_component<R: ReplicatedComponent>(&self) -> bool {
36 self.world.has_component::<R>(&self.entity)
37 }
38
39 pub fn component<R: ReplicatedComponent>(&'_ self) -> Option<ReplicaRefWrapper<'_, R>> {
42 self.world.component::<R>(&self.entity)
43 }
44
45 pub fn replication_config(&self) -> Option<Publicity> {
48 self.client.entity_replication_config(&self.entity)
49 }
50
51 pub fn authority(&self) -> Option<EntityAuthStatus> {
54 self.client.entity_authority_status(&self.entity)
55 }
56
57 pub fn owner(&self) -> EntityOwner {
60 self.client.entity_owner(&self.entity)
61 }
62}
63
64cfg_if! {
65 if #[cfg(feature = "interior_visibility")] {
66
67 use naia_shared::LocalEntity;
68
69 impl<'s, E: Copy + Eq + Hash + Send + Sync, W: WorldRefType<E>> EntityRef<'s, E, W> {
70
71 pub fn local_entity(&self) -> Option<LocalEntity> {
76 self.client.world_to_local_entity(&self.entity)
77 }
78 }
79 }
80}