naia-bevy-shared 0.25.0

Library to faciliate naia & Bevy interop, functionality shared by client & server versions
Documentation
use std::any::{Any, TypeId};
use std::collections::HashMap;

use bevy_ecs::{component::Component, entity::Entity, resource::Resource};

#[derive(Component, Clone, Copy)]
pub struct HostOwned {
    type_id: TypeId,
}

impl HostOwned {
    pub fn new<T: Any>() -> Self {
        Self {
            type_id: TypeId::of::<T>(),
        }
    }

    pub fn type_id(&self) -> TypeId {
        self.type_id
    }
}

#[derive(Resource, Default)]
pub struct HostOwnedMap {
    map: HashMap<Entity, HostOwned>,
}

impl HostOwnedMap {
    pub fn insert(&mut self, entity: Entity, host_owned: HostOwned) {
        self.map.insert(entity, host_owned);
    }

    pub fn remove(&mut self, entity: &Entity) -> Option<HostOwned> {
        self.map.remove(entity)
    }
}