use super::registry::{Ref, RefMut};
use crate::{
collections::{Arena, IterableMapMut, MapMut},
TypedIndex,
};
use core::any::Any;
#[cfg(feature = "index-u64")]
pub type GenIndexType = crate::IndexU64;
#[cfg(not(feature = "index-u64"))]
pub type GenIndexType = crate::IndexF64;
pub type EntityId<E> = TypedIndex<E, GenIndexType>;
pub trait Entity: Sized {
type Storage: EntityStorage<Self>;
}
pub trait EntityStorage<E: Entity>:
Default + Arena<Key = EntityId<E>, Value = E> + for<'a> IterableMapMut<'a> + 'static
{
}
pub trait Component<E: Entity>: Sized {
type Storage: ComponentStorage<E, Self>;
}
pub trait ComponentStorage<E: Entity, C: Component<E>>:
Default + MapMut<Key = EntityId<E>, Value = C> + for<'a> IterableMapMut<'a> + 'static
{
}
pub type EntityStorageOf<E> = <E as Entity>::Storage;
pub type ComponentStorageOf<E, C> = <C as Component<E>>::Storage;
pub trait Entities {
fn register_entity<E: Entity + Any>(&mut self);
fn has_entity<E: Entity + Any>(&self) -> bool;
fn entities<'a, E: Entity + Any>(&'a self) -> Ref<'a, E::Storage>;
fn entities_mut<'a, E: Entity + Any>(&'a self) -> RefMut<'a, E::Storage>;
}
pub trait Components {
fn register_component<E: Entity + Any, C: Component<E> + Any>(&mut self);
fn has_component<E: Entity + Any, C: Component<E> + Any>(&self) -> bool;
fn components<'a, E: Entity + Any, C: Component<E> + Any>(&'a self) -> Ref<'a, C::Storage>;
fn components_mut<'a, E: Entity + Any, C: Component<E> + Any>(
&'a self,
) -> RefMut<'a, C::Storage>;
}