#[cfg(feature = "bevy_ecs")]
mod bevy_integration_impl {
use bevy_ecs::{component::Component, entity::Entity as BevyEntity, prelude::Resource};
use std::collections::HashMap;
use crate::GlobalEntity;
#[derive(Component, Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[allow(dead_code)] pub struct Replicated;
#[derive(Component, Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[allow(dead_code)] pub struct ServerAuthority;
#[derive(Component, Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[allow(dead_code)] pub struct ClientAuthority;
#[derive(Component, Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[allow(dead_code)] pub struct GlobalEntityId(pub GlobalEntity);
#[derive(Resource, Default, Debug)]
#[allow(dead_code)] pub struct NaiaEntityMapping {
bevy_to_global: HashMap<BevyEntity, GlobalEntity>,
global_to_bevy: HashMap<GlobalEntity, BevyEntity>,
}
#[allow(dead_code)] impl NaiaEntityMapping {
pub fn new() -> Self {
Self::default()
}
pub fn register(&mut self, bevy_entity: BevyEntity, global_entity: GlobalEntity) {
self.bevy_to_global.insert(bevy_entity, global_entity);
self.global_to_bevy.insert(global_entity, bevy_entity);
}
pub fn unregister_bevy(&mut self, bevy_entity: BevyEntity) -> Option<GlobalEntity> {
if let Some(global_entity) = self.bevy_to_global.remove(&bevy_entity) {
self.global_to_bevy.remove(&global_entity);
Some(global_entity)
} else {
None
}
}
pub fn unregister_global(&mut self, global_entity: GlobalEntity) -> Option<BevyEntity> {
if let Some(bevy_entity) = self.global_to_bevy.remove(&global_entity) {
self.bevy_to_global.remove(&bevy_entity);
Some(bevy_entity)
} else {
None
}
}
pub fn get_global(&self, bevy_entity: BevyEntity) -> Option<GlobalEntity> {
self.bevy_to_global.get(&bevy_entity).copied()
}
pub fn get_bevy(&self, global_entity: GlobalEntity) -> Option<BevyEntity> {
self.global_to_bevy.get(&global_entity).copied()
}
pub fn contains_bevy(&self, bevy_entity: BevyEntity) -> bool {
self.bevy_to_global.contains_key(&bevy_entity)
}
pub fn contains_global(&self, global_entity: GlobalEntity) -> bool {
self.global_to_bevy.contains_key(&global_entity)
}
pub fn len(&self) -> usize {
self.bevy_to_global.len()
}
pub fn is_empty(&self) -> bool {
self.bevy_to_global.is_empty()
}
pub fn clear(&mut self) {
self.bevy_to_global.clear();
self.global_to_bevy.clear();
}
}
}
#[cfg(feature = "bevy_ecs")]
#[allow(unused_imports)] pub use bevy_integration_impl::{
ClientAuthority, GlobalEntityId, NaiaEntityMapping, Replicated, ServerAuthority,
};