diff options
| author | HampusM <hampus@hampusmat.com> | 2026-06-07 00:41:15 +0200 |
|---|---|---|
| committer | HampusM <hampus@hampusmat.com> | 2026-06-07 01:20:04 +0200 |
| commit | 3f099cddf16f2e7e002cc24217ed3cc5da422156 (patch) | |
| tree | e6ed78738b3b9fff8f4502d4ed909380b9bebf75 /engine-ecs/src/component.rs | |
| parent | 582128a649abc2f460ca00f45571deaf28dd526e (diff) | |
Diffstat (limited to 'engine-ecs/src/component.rs')
| -rw-r--r-- | engine-ecs/src/component.rs | 60 |
1 files changed, 38 insertions, 22 deletions
diff --git a/engine-ecs/src/component.rs b/engine-ecs/src/component.rs index 17b279b..f881128 100644 --- a/engine-ecs/src/component.rs +++ b/engine-ecs/src/component.rs @@ -2,6 +2,7 @@ use std::any::{type_name, Any}; use std::fmt::Debug; use std::ops::{Deref, DerefMut}; +use engine_ecs_macros::Component; use seq_macro::seq; use crate::event::component::Changed; @@ -30,6 +31,10 @@ pub trait Component: SystemInput + Any where Self: Sized; + fn type_reflection() -> Option<&'static crate::reflection::Type> + where + Self: Sized; + /// Returns the name of this component. fn name(&self) -> &'static str; } @@ -243,6 +248,7 @@ where { Parts::builder() .name(type_name::<Self>()) + .type_reflection(Self::type_reflection()) .build(Self::id(), self) } } @@ -252,41 +258,26 @@ where #[non_exhaustive] pub struct Parts { - id: Uid, - name: &'static str, - data: Box<dyn Any>, + pub id: Uid, + pub name: &'static str, + pub type_reflection: Option<&'static crate::reflection::Type>, + pub data: Box<dyn Any>, } impl Parts { #[must_use] - pub fn id(&self) -> Uid - { - self.id - } - - #[must_use] - pub fn name(&self) -> &'static str - { - self.name - } - - #[must_use] pub fn builder() -> PartsBuilder { PartsBuilder::default() } - - pub(crate) fn into_data(self) -> Box<dyn Any> - { - self.data - } } #[derive(Debug)] pub struct PartsBuilder { name: &'static str, + type_reflection: Option<&'static crate::reflection::Type>, } impl PartsBuilder @@ -299,11 +290,22 @@ impl PartsBuilder } #[must_use] + pub fn type_reflection( + mut self, + type_reflection: Option<&'static crate::reflection::Type>, + ) -> Self + { + self.type_reflection = type_reflection; + self + } + + #[must_use] pub fn build<Data: 'static>(self, id: Uid, data: Data) -> Parts { Parts { id, name: self.name, + type_reflection: self.type_reflection, data: Box::new(data), } } @@ -311,7 +313,12 @@ impl PartsBuilder #[must_use] pub fn build_with_any_data(self, id: Uid, data: Box<dyn Any>) -> Parts { - Parts { id, name: self.name, data } + Parts { + id, + name: self.name, + type_reflection: self.type_reflection, + data, + } } } @@ -319,6 +326,15 @@ impl Default for PartsBuilder { fn default() -> Self { - Self { name: "(unspecified)" } + Self { + name: "(unspecified)", + type_reflection: None, + } } } + +#[derive(Debug, Clone, Component)] +pub struct Type +{ + pub type_reflection: &'static crate::reflection::Type, +} |
