mirror of
https://github.com/bevyengine/bevy
synced 2025-01-10 04:08:55 +00:00
eb07d16871
# Objective > Can anyone explain to me the reasoning of renaming all the types named Query to Data. I'm talking about this PR https://github.com/bevyengine/bevy/pull/10779 It doesn't make sense to me that a bunch of types that are used to run queries aren't named Query anymore. Like ViewQuery on the ViewNode is the type of the Query. I don't really understand the point of the rename, it just seems like it hides the fact that a query will run based on those types. [@IceSentry](https://discord.com/channels/691052431525675048/692572690833473578/1184946251431694387) ## Solution Revert several renames in #10779. ## Changelog - `ViewNode::ViewData` is now `ViewNode::ViewQuery` again. ## Migration Guide - This PR amends the migration guide in https://github.com/bevyengine/bevy/pull/10779 --------- Co-authored-by: atlas dostal <rodol@rivalrebels.com>
51 lines
1.5 KiB
Rust
51 lines
1.5 KiB
Rust
use proc_macro::TokenStream;
|
|
use quote::quote;
|
|
use syn::{parse_macro_input, parse_quote, DeriveInput, Path};
|
|
|
|
pub fn derive_extract_component(input: TokenStream) -> TokenStream {
|
|
let mut ast = parse_macro_input!(input as DeriveInput);
|
|
let bevy_render_path: Path = crate::bevy_render_path();
|
|
let bevy_ecs_path: Path = bevy_macro_utils::BevyManifest::default()
|
|
.maybe_get_path("bevy_ecs")
|
|
.expect("bevy_ecs should be found in manifest");
|
|
|
|
ast.generics
|
|
.make_where_clause()
|
|
.predicates
|
|
.push(parse_quote! { Self: Clone });
|
|
|
|
let struct_name = &ast.ident;
|
|
let (impl_generics, type_generics, where_clause) = &ast.generics.split_for_impl();
|
|
|
|
let filter = if let Some(attr) = ast
|
|
.attrs
|
|
.iter()
|
|
.find(|a| a.path().is_ident("extract_component_filter"))
|
|
{
|
|
let filter = match attr.parse_args::<syn::Type>() {
|
|
Ok(filter) => filter,
|
|
Err(e) => return e.to_compile_error().into(),
|
|
};
|
|
|
|
quote! {
|
|
#filter
|
|
}
|
|
} else {
|
|
quote! {
|
|
()
|
|
}
|
|
};
|
|
|
|
TokenStream::from(quote! {
|
|
impl #impl_generics #bevy_render_path::extract_component::ExtractComponent for #struct_name #type_generics #where_clause {
|
|
type QueryData = &'static Self;
|
|
|
|
type QueryFilter = #filter;
|
|
type Out = Self;
|
|
|
|
fn extract_component(item: #bevy_ecs_path::query::QueryItem<'_, Self::QueryData>) -> Option<Self::Out> {
|
|
Some(item.clone())
|
|
}
|
|
}
|
|
})
|
|
}
|