diff options
Diffstat (limited to 'ecs/src/component.rs')
-rw-r--r-- | ecs/src/component.rs | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/ecs/src/component.rs b/ecs/src/component.rs index be5756f..67ae453 100644 --- a/ecs/src/component.rs +++ b/ecs/src/component.rs @@ -139,13 +139,33 @@ pub trait Sequence fn into_vec(self) -> Vec<Box<dyn Component>>; - fn ids() -> Vec<(Id, IsOptional)>; + fn metadata() -> Vec<Metadata>; fn from_components<'component>( components: impl Iterator<Item = &'component EntityComponent>, ) -> Self::Refs<'component>; } +/// [`Component`] metadata. +#[derive(Debug, Clone)] +#[non_exhaustive] +pub struct Metadata +{ + pub id: Id, + pub is_optional: IsOptional, +} + +impl Metadata +{ + pub fn of<ComponentT: Component + ?Sized>(component: &ComponentT) -> Self + { + Self { + id: component.id(), + is_optional: component.is_optional().into(), + } + } +} + /// Whether or not a `Component` is optional. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum IsOptional @@ -201,11 +221,14 @@ macro_rules! inner { Vec::from_iter([#(Box::new(self.I) as Box<dyn Component>,)*]) } - fn ids() -> Vec<(Id, IsOptional)> + fn metadata() -> Vec<Metadata> { vec![ #( - (Id::of::<Comp~I>(), is_optional::<Comp~I>().into()), + Metadata { + id: Id::of::<Comp~I>(), + is_optional: is_optional::<Comp~I>().into() + }, )* ] } |