naia_client/world/entity_owner.rs
1/// The authority origin of a client-tracked entity.
2///
3/// The client assigns an owner to every entity it knows about. This mirrors
4/// the server-side [`EntityOwner`] but uses only the variants observable from
5/// the client's perspective.
6///
7/// [`EntityOwner`]: naia_server::EntityOwner
8#[derive(Copy, Clone, PartialEq, Eq)]
9pub enum EntityOwner {
10 /// Originated on the server and replicated to this client.
11 ///
12 /// The server is the authoritative source of all component state. The
13 /// entity may be [`Delegated`], in which case this client (or another)
14 /// may hold temporary write authority — see [`EntityRef::authority`].
15 ///
16 /// [`Delegated`]: naia_shared::Publicity::Delegated
17 /// [`EntityRef::authority`]: crate::EntityRef::authority
18 Server,
19 /// Spawned by this client.
20 ///
21 /// While [`Private`](naia_shared::Publicity::Private) the entity is
22 /// only visible to the owning client. After the client publishes it
23 /// ([`Public`](naia_shared::Publicity::Public)) it replicates to peers
24 /// in the same room and scope.
25 Client,
26 /// A local-only entity that is never replicated to the server.
27 ///
28 /// Exists solely in the client's local world; the server has no knowledge
29 /// of it.
30 Local,
31}
32
33impl EntityOwner {
34 /// Returns `true` if this entity originated on the server.
35 pub fn is_server(&self) -> bool {
36 matches!(self, EntityOwner::Server)
37 }
38
39 /// Returns `true` if this entity was spawned by this client.
40 pub fn is_client(&self) -> bool {
41 matches!(self, EntityOwner::Client)
42 }
43}