naia_client/world/
entity_ref.rs1use std::hash::Hash;
2
3use naia_shared::{EntityAuthStatus, ReplicaRefWrapper, ReplicatedComponent, WorldRefType};
4
5use crate::{Client, ReplicationConfig};
6
7pub struct EntityRef<'s, E: Copy + Eq + Hash + Send + Sync, W: WorldRefType<E>> {
9 client: &'s Client<E>,
10 world: W,
11 entity: E,
12}
13
14impl<'s, E: Copy + Eq + Hash + Send + Sync, W: WorldRefType<E>> EntityRef<'s, E, W> {
15 pub fn new(client: &'s Client<E>, world: W, entity: &E) -> Self {
16 EntityRef {
17 client,
18 world,
19 entity: *entity,
20 }
21 }
22
23 pub fn id(&self) -> E {
24 self.entity
25 }
26
27 pub fn has_component<R: ReplicatedComponent>(&self) -> bool {
28 self.world.has_component::<R>(&self.entity)
29 }
30
31 pub fn component<R: ReplicatedComponent>(&self) -> Option<ReplicaRefWrapper<R>> {
32 self.world.component::<R>(&self.entity)
33 }
34
35 pub fn replication_config(&self) -> Option<ReplicationConfig> {
36 self.client.entity_replication_config(&self.entity)
37 }
38
39 pub fn authority(&self) -> Option<EntityAuthStatus> {
40 self.client.entity_authority_status(&self.entity)
41 }
42}