summaryrefslogtreecommitdiff
path: root/ecs/src/component.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2024-08-01 12:36:35 +0200
committerHampusM <hampus@hampusmat.com>2024-08-01 12:36:35 +0200
commit70c7d745f918dd23343599963a619539f4f880cb (patch)
tree076779b4364649fcea76ce07a6cd1d6b8d6956f2 /ecs/src/component.rs
parenta5c45dab18399461aff5dc13c471ea6c5ec80c34 (diff)
refactor(ecs): add & use component metadata struct
Diffstat (limited to 'ecs/src/component.rs')
-rw-r--r--ecs/src/component.rs29
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()
+ },
)*
]
}