diff options
| -rw-r--r-- | engine-ecs-macros/src/lib.rs | 13 | ||||
| -rw-r--r-- | engine-ecs/src/component.rs | 21 |
2 files changed, 22 insertions, 12 deletions
diff --git a/engine-ecs-macros/src/lib.rs b/engine-ecs-macros/src/lib.rs index 1cae24b..3a025fb 100644 --- a/engine-ecs-macros/src/lib.rs +++ b/engine-ecs-macros/src/lib.rs @@ -136,12 +136,7 @@ pub fn component_derive(input: TokenStream) -> TokenStream { #ecs_path::component::Parts::builder() .component_info( - #ecs_path::component::Info::default() - .with_name(<#item_ident as Component>::name()) - .with_type_name(std::any::type_name::<#item_ident>()) - .with_type_reflection( - <#item_ident as Component>::type_reflection() - ) + #ecs_path::component::Info::of_component::<#item_ident>() ) .build( <#item_ident as #ecs_path::component::WithAssociatedId>::id(), @@ -263,11 +258,7 @@ pub fn sole_derive(input: TokenStream) -> TokenStream { #ecs_path::component::Parts::builder() .component_info( - #ecs_path::component::Info::default() - .with_name(<#item_ident as Sole>::name()) - .with_type_name(std::any::type_name::<#item_ident>()) - .with_is_sole(true) - .with_type_reflection(<#item_ident as Sole>::type_reflection()) + #ecs_path::component::Info::of_sole::<#item_ident>() ) .is_sole(true) .build( diff --git a/engine-ecs/src/component.rs b/engine-ecs/src/component.rs index 71608b1..eb51c03 100644 --- a/engine-ecs/src/component.rs +++ b/engine-ecs/src/component.rs @@ -1,4 +1,4 @@ -use std::any::Any; +use std::any::{type_name, Any}; use std::borrow::Cow; use std::fmt::Debug; use std::ops::{Deref, DerefMut}; @@ -17,6 +17,7 @@ use crate::lock::{ }; use crate::pair::{MemberMetadata as PairMemberMetadata, Pair}; use crate::reflection::Type as TypeReflection; +use crate::sole::Sole; use crate::system::Input as SystemInput; use crate::uid::Uid; use crate::{EntityComponentRef, World}; @@ -379,6 +380,24 @@ impl Default for Info impl Info { + pub fn of_component<ComponentT: Component>() -> Self + { + Self::default() + .with_name(ComponentT::name()) + .with_type_name(type_name::<ComponentT>()) + .with_is_sole(false) + .with_type_reflection(ComponentT::type_reflection()) + } + + pub fn of_sole<SoleT: Sole>() -> Self + { + Self::default() + .with_name(SoleT::name()) + .with_type_name(type_name::<SoleT>()) + .with_is_sole(true) + .with_type_reflection(SoleT::type_reflection()) + } + #[must_use] pub fn with_name(mut self, name: impl Into<Cow<'static, str>>) -> Self { |
