diff --git a/Cargo.lock b/Cargo.lock index 90997c3..4d9a894 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -148,7 +148,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "999eb3756d075ac95e169f71333ac211e54e961ac55708a89731eb6134f38b7e" dependencies = [ "bevy_app", - "darling 0.21.3", + "darling", "inventory", "linkme", "log", @@ -539,18 +539,8 @@ version = "0.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9cdf337090841a411e2a7f3deb9187445851f91b309c0c0a29e05f74a00a48c0" dependencies = [ - "darling_core 0.21.3", - "darling_macro 0.21.3", -] - -[[package]] -name = "darling" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25ae13da2f202d56bd7f91c25fba009e7717a1e4a1cc98a76d844b65ae912e9d" -dependencies = [ - "darling_core 0.23.0", - "darling_macro 0.23.0", + "darling_core", + "darling_macro", ] [[package]] @@ -567,37 +557,13 @@ dependencies = [ "syn 2.0.114", ] -[[package]] -name = "darling_core" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9865a50f7c335f53564bb694ef660825eb8610e0a53d3e11bf1b0d3df31e03b0" -dependencies = [ - "ident_case", - "proc-macro2", - "quote", - "strsim", - "syn 2.0.114", -] - [[package]] name = "darling_macro" version = "0.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d38308df82d1080de0afee5d069fa14b0326a88c14f15c5ccda35b4a6c414c81" dependencies = [ - "darling_core 0.21.3", - "quote", - "syn 2.0.114", -] - -[[package]] -name = "darling_macro" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3984ec7bd6cfa798e62b4a642426a5be0e68f9401cfc2a01e3fa9ea2fcdb8d" -dependencies = [ - "darling_core 0.23.0", + "darling_core", "quote", "syn 2.0.114", ] @@ -805,7 +771,6 @@ dependencies = [ name = "immediate_stats_macros" version = "0.4.0" dependencies = [ - "darling 0.23.0", "proc-macro-error", "proc-macro2", "quote", diff --git a/immediate_stats/Cargo.toml b/immediate_stats/Cargo.toml index c2a3f50..cec3202 100644 --- a/immediate_stats/Cargo.toml +++ b/immediate_stats/Cargo.toml @@ -20,11 +20,7 @@ bevy = [ "dep:bevy_reflect", "immediate_stats_macros/bevy", ] -bevy_auto_plugin = [ - "bevy", - "dep:bevy_auto_plugin", - "immediate_stats_macros/bevy_auto_plugin", -] +bevy_auto_plugin = ["bevy", "dep:bevy_auto_plugin"] [dependencies] bevy_app = { version = "0.18", default-features = false, optional = true, features = [ diff --git a/immediate_stats_macros/Cargo.toml b/immediate_stats_macros/Cargo.toml index c8ca10f..6791078 100644 --- a/immediate_stats_macros/Cargo.toml +++ b/immediate_stats_macros/Cargo.toml @@ -18,10 +18,8 @@ proc-macro = true [features] bevy = [] -bevy_auto_plugin = ["bevy"] [dependencies] -darling = "0.23" proc-macro2 = "1.0" proc-macro-error = "1.0" quote = "1.0" diff --git a/immediate_stats_macros/src/bevy_auto_plugin.rs b/immediate_stats_macros/src/bevy_auto_plugin.rs deleted file mode 100644 index e52a267..0000000 --- a/immediate_stats_macros/src/bevy_auto_plugin.rs +++ /dev/null @@ -1,130 +0,0 @@ -use darling::ast::NestedMeta; -use darling::{Error, FromMeta}; -use proc_macro2::{Ident, TokenStream}; -use quote::{ToTokens, format_ident, quote}; -use syn::{DeriveInput, Expr, Meta, Path}; - -/// Returns code that will register stat resetting system(s) with Bevy Auto Plugin. -pub fn register_systems(input: &DeriveInput) -> darling::Result { - let struct_name = &input.ident; - - let mut auto_plugin_attributes = AutoPluginAttributes::new(struct_name); - - for attr in &input.attrs { - if attr.path().is_ident("auto_component") { - let plugin = PluginPath::from_meta(&attr.meta)?; - auto_plugin_attributes.component_plugin = Some(plugin); - } else if attr.path().is_ident("auto_resource") - || attr.path().is_ident("auto_init_resource") - || attr.path().is_ident("auto_insert_resource") - { - let plugin = PluginPath::from_meta(&attr.meta)?; - auto_plugin_attributes.resource_plugin = Some(plugin); - } - } - - Ok(auto_plugin_attributes.into_token_stream()) -} - -pub struct AutoPluginAttributes<'a> { - ident: &'a Ident, - component_plugin: Option, - resource_plugin: Option, -} - -impl<'a> AutoPluginAttributes<'a> { - pub fn new(ident: &'a Ident) -> Self { - Self { - ident, - component_plugin: None, - resource_plugin: None, - } - } -} - -impl<'a> ToTokens for AutoPluginAttributes<'a> { - fn to_tokens(&self, tokens: &mut TokenStream) { - if let Some(plugin_path) = &self.component_plugin { - let ident = &self.ident; - let plugin = &plugin_path.0; - let system_ident = format_ident!("__reset_{ident}_component_modifiers"); - - tokens.extend(quote! { - #[bevy_auto_plugin::prelude::auto_system( - plugin = #plugin, - schedule = immediate_stats::__PreUpdate, - config( - in_set = immediate_stats::StatSystems::Reset, - ) - )] - fn #system_ident( - mut query: Query<&mut #ident, Without>, - ) { - for mut stat in &mut query { - stat.reset_modifiers(); - } - } - }); - } - - if let Some(plugin_path) = &self.resource_plugin { - let ident = &self.ident; - let plugin = &plugin_path.0; - let system_ident = format_ident!("__reset_{ident}_resource_modifiers"); - - tokens.extend(quote! { - #[bevy_auto_plugin::prelude::auto_system( - plugin = #plugin, - schedule = immediate_stats::__PreUpdate, - config( - in_set = immediate_stats::StatSystems::Reset, - ) - )] - fn #system_ident(res: Option>) { - if let Some(mut res) = res { - res.reset_modifiers(); - } - } - }); - } - } -} - -/// Represents a `plugin(PATH)` or `plugin = PATH` attribute meta. -pub struct PluginPath(pub Path); - -impl FromMeta for PluginPath { - fn from_list(items: &[NestedMeta]) -> darling::Result { - for item in items { - return match item { - NestedMeta::Meta(meta) => match meta { - Meta::Path(_) => Err(Error::custom("Expected a value for `plugin`")), - Meta::List(list) => { - if list.path.require_ident()? != "plugin" { - continue; - } - - let mut path = None; - - list.parse_nested_meta(|value_meta| { - path = Some(value_meta.path); - Ok(()) - })?; - - match path { - None => Err(Error::custom("Expected `plugin` attribute")), - Some(path) => Ok(PluginPath(path)), - } - } - Meta::NameValue(name_value) => match &name_value.value { - Expr::Path(p) => Ok(PluginPath(p.path.clone())), - _ => Err(Error::custom("Expected a path to an auto plugin")), - }, - }, - NestedMeta::Lit(_) => Err(Error::custom("Expected `plugin` attribute")), - }; - } - - Err(Error::custom("Expected `plugin` attribute")) - } -} diff --git a/immediate_stats_macros/src/lib.rs b/immediate_stats_macros/src/lib.rs index c34de75..8fae6f5 100644 --- a/immediate_stats_macros/src/lib.rs +++ b/immediate_stats_macros/src/lib.rs @@ -1,5 +1,3 @@ -#[cfg(feature = "bevy_auto_plugin")] -mod bevy_auto_plugin; mod derive_enum; mod derive_struct; @@ -31,14 +29,6 @@ pub fn stat_container_derive(item: proc_macro::TokenStream) -> proc_macro::Token } }; - #[cfg(feature = "bevy_auto_plugin")] - { - let systems = - bevy_auto_plugin::register_systems(&tree).unwrap_or_else(darling::Error::write_errors); - quote! { #trait_impl #systems }.into() - } - - #[cfg(not(feature = "bevy_auto_plugin"))] trait_impl.into() }