summaryrefslogtreecommitdiff
path: root/ecs-macros/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ecs-macros/src/lib.rs')
-rw-r--r--ecs-macros/src/lib.rs54
1 files changed, 23 insertions, 31 deletions
diff --git a/ecs-macros/src/lib.rs b/ecs-macros/src/lib.rs
index b58671d..862b0b1 100644
--- a/ecs-macros/src/lib.rs
+++ b/ecs-macros/src/lib.rs
@@ -47,7 +47,7 @@ pub fn component_derive(input: TokenStream) -> TokenStream
{
let item: TypeItem = parse::<Item>(input).unwrap().try_into().unwrap();
- let ComponentAttribute { ref_type, ref_mut_type } = item
+ let ComponentAttribute { handle_type, handle_mut_type } = item
.attribute::<ComponentAttribute>("component")
.unwrap_or_default();
@@ -114,8 +114,10 @@ pub fn component_derive(input: TokenStream) -> TokenStream
Removed as ComponentRemovedEvent,
Kind as ComponentEventKind,
};
- use #ecs_path::system::ComponentRefMut;
- use #ecs_path::system::ComponentRef;
+ use #ecs_path::component::{
+ Handle as ComponentHandle,
+ HandleMut as ComponentHandleMut
+ };
use #ecs_path::uid::{Uid, Kind as UidKind};
use #ecs_path::system::Input as SystemInput;
use #ecs_path::type_name::TypeName;
@@ -129,8 +131,8 @@ pub fn component_derive(input: TokenStream) -> TokenStream
{
type Component = Self;
- type RefMut<'component> = #ref_mut_type;
- type Ref<'component> = #ref_type;
+ type HandleMut<'component> = #handle_mut_type;
+ type Handle<'component> = #handle_type;
fn id() -> Uid
{
@@ -148,16 +150,6 @@ pub fn component_derive(input: TokenStream) -> TokenStream
}
}
}
-
- fn as_any_mut(&mut self) -> &mut dyn Any
- {
- self
- }
-
- fn as_any(&self) -> &dyn Any
- {
- self
- }
}
impl #impl_generics SystemInput for #item_ident #type_generics
@@ -389,32 +381,32 @@ fn find_engine_ecs_crate_path() -> Option<Path>
#[derive(Debug)]
struct ComponentAttribute
{
- ref_type: proc_macro2::TokenStream,
- ref_mut_type: proc_macro2::TokenStream,
+ handle_type: proc_macro2::TokenStream,
+ handle_mut_type: proc_macro2::TokenStream,
}
impl FromAttribute for ComponentAttribute
{
fn from_attribute(attribute: &Attribute) -> Result<Self, syn::Error>
{
- let mut ref_type: Option<Type> = None;
- let mut ref_mut_type: Option<Type> = None;
+ let mut handle_type: Option<Type> = None;
+ let mut handle_mut_type: Option<Type> = None;
attribute.parse_nested_meta(|meta| {
let Some(flag) = meta.path.get_ident() else {
return Err(meta.error("Not a single identifier"));
};
- if flag == "ref_type" {
+ if flag == "handle_type" {
let value = meta.value()?;
- ref_type = Some(value.parse::<Type>()?);
+ handle_type = Some(value.parse::<Type>()?);
return Ok(());
- } else if flag == "ref_mut_type" {
+ } else if flag == "handle_mut_type" {
let value = meta.value()?;
- ref_mut_type = Some(value.parse::<Type>()?);
+ handle_mut_type = Some(value.parse::<Type>()?);
return Ok(());
}
@@ -423,12 +415,12 @@ impl FromAttribute for ComponentAttribute
})?;
Ok(Self {
- ref_type: ref_type
- .map(|ref_type| ref_type.into_token_stream())
- .unwrap_or_else(|| Self::default().ref_type),
- ref_mut_type: ref_mut_type
- .map(|ref_mut_type| ref_mut_type.into_token_stream())
- .unwrap_or_else(|| Self::default().ref_mut_type),
+ handle_type: handle_type
+ .map(|handle_type| handle_type.into_token_stream())
+ .unwrap_or_else(|| Self::default().handle_type),
+ handle_mut_type: handle_mut_type
+ .map(|handle_mut_type| handle_mut_type.into_token_stream())
+ .unwrap_or_else(|| Self::default().handle_mut_type),
})
}
}
@@ -438,8 +430,8 @@ impl Default for ComponentAttribute
fn default() -> Self
{
Self {
- ref_type: quote! { ComponentRef<'component, Self> },
- ref_mut_type: quote! { ComponentRefMut<'component, Self> },
+ handle_type: quote! { ComponentHandle<'component, Self> },
+ handle_mut_type: quote! { ComponentHandleMut<'component, Self> },
}
}
}