diff --git a/Cargo.lock b/Cargo.lock index e336dc8..da50bc6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -96,17 +96,6 @@ dependencies = [ "portable-atomic", ] -[[package]] -name = "async-trait" -version = "0.1.89" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.106", -] - [[package]] name = "atomic-waker" version = "1.1.2" @@ -131,35 +120,6 @@ dependencies = [ "bevy_internal", ] -[[package]] -name = "bevy-butler" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a837ab609be8353552de441031ee101ac86ffb19ccf9e6d3d2b922aa545f0ff9" -dependencies = [ - "bevy-butler-proc-macro", - "bevy_app 0.16.1", - "bevy_ecs 0.16.1", - "bevy_log", - "bevy_state", - "inventory", - "linkme", -] - -[[package]] -name = "bevy-butler-proc-macro" -version = "0.6.2-alpha.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4150a4732c48044ec63efd1ebe51a889647391dab5e59603802eac3a1bde63b0" -dependencies = [ - "deluxe", - "deluxe-core", - "proc-macro2", - "quote", - "sha256", - "syn 2.0.106", -] - [[package]] name = "bevy_android" version = "0.17.0-rc.2" @@ -739,15 +699,6 @@ dependencies = [ "serde", ] -[[package]] -name = "block-buffer" -version = "0.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" -dependencies = [ - "generic-array", -] - [[package]] name = "bumpalo" version = "3.19.0" @@ -872,15 +823,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32b13ea120a812beba79e34316b3942a857c86ec1593cb34f27bb28272ce2cca" -[[package]] -name = "cpufeatures" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" -dependencies = [ - "libc", -] - [[package]] name = "critical-section" version = "1.2.0" @@ -902,16 +844,6 @@ version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" -[[package]] -name = "crypto-common" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" -dependencies = [ - "generic-array", - "typenum", -] - [[package]] name = "ctrlc" version = "3.5.0" @@ -943,7 +875,7 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "strsim 0.11.1", + "strsim", "syn 2.0.106", ] @@ -958,47 +890,6 @@ dependencies = [ "syn 2.0.106", ] -[[package]] -name = "deluxe" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ed332aaf752b459088acf3dd4eca323e3ef4b83c70a84ca48fb0ec5305f1488" -dependencies = [ - "deluxe-core", - "deluxe-macros", - "once_cell", - "proc-macro2", - "syn 2.0.106", -] - -[[package]] -name = "deluxe-core" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eddada51c8576df9d6a8450c351ff63042b092c9458b8ac7d20f89cbd0ffd313" -dependencies = [ - "arrayvec", - "proc-macro2", - "quote", - "strsim 0.10.0", - "syn 2.0.106", -] - -[[package]] -name = "deluxe-macros" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f87546d9c837f0b7557e47b8bd6eae52c3c223141b76aa233c345c9ab41d9117" -dependencies = [ - "deluxe-core", - "heck", - "if_chain", - "proc-macro-crate 1.3.1", - "proc-macro2", - "quote", - "syn 2.0.106", -] - [[package]] name = "derive_more" version = "1.0.0" @@ -1041,16 +932,6 @@ dependencies = [ "unicode-xid", ] -[[package]] -name = "digest" -version = "0.10.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" -dependencies = [ - "block-buffer", - "crypto-common", -] - [[package]] name = "dispatch" version = "0.2.0" @@ -1182,16 +1063,6 @@ dependencies = [ "pin-project-lite", ] -[[package]] -name = "generic-array" -version = "0.14.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" -dependencies = [ - "typenum", - "version_check", -] - [[package]] name = "getrandom" version = "0.2.16" @@ -1283,36 +1154,17 @@ dependencies = [ "stable_deref_trait", ] -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" - -[[package]] -name = "hex" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" - [[package]] name = "ident_case" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" -[[package]] -name = "if_chain" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd62e6b5e86ea8eeeb8db1de02880a6abc01a397b2ebb64b5d74ac255318f5cb" - [[package]] name = "immediate_stats" version = "0.3.0-rc.1" dependencies = [ "bevy", - "bevy-butler", "bevy_app 0.17.0-rc.2", "bevy_auto_plugin", "bevy_ecs 0.17.0-rc.2", @@ -1587,7 +1439,7 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" dependencies = [ - "proc-macro-crate 3.4.0", + "proc-macro-crate", "proc-macro2", "quote", "syn 2.0.106", @@ -1688,16 +1540,6 @@ dependencies = [ "syn 2.0.106", ] -[[package]] -name = "proc-macro-crate" -version = "1.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" -dependencies = [ - "once_cell", - "toml_edit 0.19.15", -] - [[package]] name = "proc-macro-crate" version = "3.4.0" @@ -1904,29 +1746,6 @@ dependencies = [ "syn 2.0.106", ] -[[package]] -name = "sha2" -version = "0.10.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "sha256" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f880fc8562bdeb709793f00eb42a2ad0e672c4f883bbe59122b926eca935c8f6" -dependencies = [ - "async-trait", - "bytes", - "hex", - "sha2", -] - [[package]] name = "sharded-slab" version = "0.1.7" @@ -2007,12 +1826,6 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" -[[package]] -name = "strsim" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" - [[package]] name = "strsim" version = "0.11.1" @@ -2104,17 +1917,6 @@ dependencies = [ "serde_core", ] -[[package]] -name = "toml_edit" -version = "0.19.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" -dependencies = [ - "indexmap", - "toml_datetime 0.6.11", - "winnow 0.5.40", -] - [[package]] name = "toml_edit" version = "0.22.27" @@ -2123,7 +1925,7 @@ checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a" dependencies = [ "indexmap", "toml_datetime 0.6.11", - "winnow 0.7.13", + "winnow", ] [[package]] @@ -2135,7 +1937,7 @@ dependencies = [ "indexmap", "toml_datetime 0.7.2", "toml_parser", - "winnow 0.7.13", + "winnow", ] [[package]] @@ -2144,7 +1946,7 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4cf893c33be71572e0e9aa6dd15e6677937abd686b066eac3f8cd3531688a627" dependencies = [ - "winnow 0.7.13", + "winnow", ] [[package]] @@ -2240,12 +2042,6 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc7d623258602320d5c55d1bc22793b57daff0ec7efc270ea7d55ce1d5f5471c" -[[package]] -name = "typenum" -version = "1.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f" - [[package]] name = "unicode-ident" version = "1.0.19" @@ -2595,15 +2391,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" -[[package]] -name = "winnow" -version = "0.5.40" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876" -dependencies = [ - "memchr", -] - [[package]] name = "winnow" version = "0.7.13" diff --git a/immediate_stats/Cargo.toml b/immediate_stats/Cargo.toml index 194443e..e8e37cd 100644 --- a/immediate_stats/Cargo.toml +++ b/immediate_stats/Cargo.toml @@ -20,7 +20,6 @@ bevy = [ "dep:bevy_reflect", "immediate_stats_macros/bevy", ] -bevy_butler = ["bevy", "dep:bevy-butler", "immediate_stats_macros/bevy_butler"] bevy_auto_plugin = [ "bevy", "dep:bevy_auto_plugin", @@ -31,7 +30,6 @@ bevy_auto_plugin = [ bevy_app = { version = "0.17.0-rc.1", default-features = false, optional = true, features = [ "bevy_reflect", ] } -bevy-butler = { version = "0.6", optional = true } bevy_auto_plugin = { version = "0.5.0", optional = true } bevy_ecs = { version = "0.17.0-rc.1", default-features = false, optional = true, features = [ "bevy_reflect", @@ -58,11 +56,6 @@ name = "simple_bevy" path = "examples/simple_bevy.rs" required-features = ["bevy"] -[[example]] -name = "simple_bevy_butler" -path = "examples/simple_bevy_butler.rs" -required-features = ["bevy_butler"] - [[example]] name = "simple_bevy_auto_plugin" path = "examples/simple_bevy_auto_plugin.rs" diff --git a/immediate_stats/examples/simple_bevy_butler.rs b/immediate_stats/examples/simple_bevy_butler.rs deleted file mode 100644 index 9a627de..0000000 --- a/immediate_stats/examples/simple_bevy_butler.rs +++ /dev/null @@ -1,44 +0,0 @@ -//! A very simple example using Bevy Butler. Requires the `bevy_butler` feature flag, which is *depreciated*. -//! -//! **Please see the Bevy Auto Plugin example instead.** - -use bevy::prelude::*; -use bevy_butler::*; -use immediate_stats::*; - -fn main() { - App::new() - .add_plugins((MinimalPlugins, ImmediateStatsPlugin, SpeedPlugin)) - .run(); -} - -#[butler_plugin] -struct SpeedPlugin; - -// Implements `reset_modifiers` by passing the call onto `Stat`. -// This will also add the `ResetComponentPlugin` to `SpeedPlugin`. -#[derive(StatContainer, Component)] -#[add_component(plugin = SpeedPlugin)] -struct Speed(Stat); - -#[add_system(plugin = SpeedPlugin, schedule = Startup)] -fn init_speed(mut commands: Commands) { - commands.spawn(Speed(Stat::new(10))); // Set base speed to 10. -} - -#[add_system(plugin = SpeedPlugin, schedule = Update, in_set = StatSystems::Modify)] -fn apply_modifiers(mut speeds: Query<&mut Speed>) { - for mut speed in &mut speeds { - speed.0 *= 2.0; // Applies a multiplier to the final result. - speed.0 += 5; // Adds a bonus to the final result. - // The order does not matter, bonuses are always applied before multipliers. - } -} - -#[add_system(plugin = SpeedPlugin, schedule = Update, in_set = StatSystems::Read)] -fn read_speed(speeds: Query<&Speed>) { - for speed in &speeds { - println!("The current speed is {}.", speed.0.total()); - assert_eq!(speed.0.total(), 30); // (10 + 5) * 2 = 30 - } -} diff --git a/immediate_stats/tests/bevy_butler.rs b/immediate_stats/tests/bevy_butler.rs deleted file mode 100644 index 02c3e11..0000000 --- a/immediate_stats/tests/bevy_butler.rs +++ /dev/null @@ -1,108 +0,0 @@ -//! Tests the `add_component` attribute for automatic system registration. -#![cfg(feature = "bevy_butler")] - -extern crate immediate_stats; -use crate::{Stat, StatContainer}; -use bevy_app::App; -use bevy_butler::*; -use bevy_ecs::prelude::*; -use immediate_stats::*; - -#[butler_plugin] -struct MyPlugin; - -#[derive(Resource, Component, StatContainer, Default, PartialEq, Debug)] -#[add_component(plugin = MyPlugin)] -#[insert_resource(plugin = MyPlugin)] -struct Health(Stat); - -#[test] -fn reset_component_auto() { - let mut app = App::new(); - - app.add_plugins(MyPlugin); - - let entity = app - .world_mut() - .spawn(Health(Stat { - base: 100, - bonus: 50, - multiplier: 2.0, - })) - .id(); - - app.update(); - - assert_eq!( - app.world().get::(entity), - Some(Health(Stat::new(100))).as_ref() - ); -} - -#[test] -fn reset_resource_auto() { - let mut app = App::new(); - - app.add_plugins(MyPlugin); - - app.insert_resource(Health(Stat { - base: 100, - bonus: 50, - multiplier: 2.0, - })); - - app.update(); - - assert_eq!( - app.world().get_resource::(), - Some(Health(Stat::new(100))).as_ref() - ); -} - -#[derive(Resource, Component, StatContainer, Default, PartialEq, Debug)] -#[add_component(plugin(MyPlugin))] -#[insert_resource(plugin(MyPlugin))] -struct AlternateSyntax(Stat); - -#[test] -fn reset_component_auto_alternate_syntax() { - let mut app = App::new(); - - app.add_plugins(MyPlugin); - - let entity = app - .world_mut() - .spawn(AlternateSyntax(Stat { - base: 100, - bonus: 50, - multiplier: 2.0, - })) - .id(); - - app.update(); - - assert_eq!( - app.world().get::(entity), - Some(AlternateSyntax(Stat::new(100))).as_ref() - ); -} - -#[test] -fn reset_resource_auto_alternate_syntax() { - let mut app = App::new(); - - app.add_plugins(MyPlugin); - - app.insert_resource(AlternateSyntax(Stat { - base: 100, - bonus: 50, - multiplier: 2.0, - })); - - app.update(); - - assert_eq!( - app.world().get_resource::(), - Some(AlternateSyntax(Stat::new(100))).as_ref() - ); -} diff --git a/immediate_stats_macros/Cargo.toml b/immediate_stats_macros/Cargo.toml index aa901ed..b5c109a 100644 --- a/immediate_stats_macros/Cargo.toml +++ b/immediate_stats_macros/Cargo.toml @@ -18,7 +18,6 @@ proc-macro = true [features] bevy = [] -bevy_butler = ["bevy"] bevy_auto_plugin = ["bevy"] [dependencies] diff --git a/immediate_stats_macros/src/bevy_butler.rs b/immediate_stats_macros/src/bevy_butler.rs deleted file mode 100644 index f3a332e..0000000 --- a/immediate_stats_macros/src/bevy_butler.rs +++ /dev/null @@ -1,119 +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 Butler. -pub fn register_systems(input: &DeriveInput) -> darling::Result { - let struct_name = &input.ident; - - let mut butler_attributes = ButlerAttributes::new(struct_name); - - for attr in &input.attrs { - if attr.path().is_ident("add_component") { - let plugin = PluginPath::from_meta(&attr.meta)?; - butler_attributes.component_plugin = Some(plugin); - } else if attr.path().is_ident("insert_resource") { - let plugin = PluginPath::from_meta(&attr.meta)?; - butler_attributes.resource_plugin = Some(plugin); - } - } - - Ok(butler_attributes.into_token_stream()) -} - -pub struct ButlerAttributes<'a> { - ident: &'a Ident, - component_plugin: Option, - resource_plugin: Option, -} - -impl<'a> ButlerAttributes<'a> { - pub fn new(ident: &'a Ident) -> Self { - Self { - ident, - component_plugin: None, - resource_plugin: None, - } - } -} - -impl<'a> ToTokens for ButlerAttributes<'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 use_as = format_ident!("__{ident}_component"); - - // Due to some strange import scoping issues, we cannot use the plugins. - // Instead, we can just recreate the plugin's functionality. - tokens.extend(quote! { - #[bevy_butler::add_system( - generics = <#ident>, - plugin = #plugin, - schedule = immediate_stats::__PreUpdate, - in_set = immediate_stats::StatSystems::Reset, - )] - use immediate_stats::reset_component_modifiers as #use_as; - }); - } - - if let Some(plugin_path) = &self.resource_plugin { - let ident = &self.ident; - let plugin = &plugin_path.0; - let use_as = format_ident!("__{ident}_resource"); - - // Due to some strange import scoping issues, we cannot use the plugins. - // Instead, we can just recreate the plugin's functionality. - tokens.extend(quote! { - #[bevy_butler::add_system( - generics = <#ident>, - plugin = #plugin, - schedule = immediate_stats::__PreUpdate, - in_set = immediate_stats::StatSystems::Reset, - )] - use immediate_stats::reset_resource_modifiers as #use_as; - }); - } - } -} - -/// 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 a butler 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 2332306..36d89a7 100644 --- a/immediate_stats_macros/src/lib.rs +++ b/immediate_stats_macros/src/lib.rs @@ -1,7 +1,5 @@ #[cfg(feature = "bevy_auto_plugin")] mod bevy_auto_plugin; -#[cfg(feature = "bevy_butler")] -mod bevy_butler; mod derive_enum; mod derive_struct; @@ -25,7 +23,7 @@ pub fn stat_container_derive(item: proc_macro::TokenStream) -> proc_macro::Token } }; - let mut trait_impl = quote! { + let trait_impl = quote! { impl StatContainer for #ident { fn reset_modifiers(&mut self) { #method_contents @@ -33,25 +31,14 @@ pub fn stat_container_derive(item: proc_macro::TokenStream) -> proc_macro::Token } }; - #[cfg(feature = "bevy_butler")] - { - emit_warning!( - proc_macro2::Span::call_site(), - "The `bevy_butler` feature flag is depreciated." - ); - - let systems = - bevy_butler::register_systems(&tree).unwrap_or_else(darling::Error::write_errors); - trait_impl = quote! { #trait_impl #systems }; - } - #[cfg(feature = "bevy_auto_plugin")] { let systems = bevy_auto_plugin::register_systems(&tree).unwrap_or_else(darling::Error::write_errors); - trait_impl = quote! { #trait_impl #systems }; + quote! { #trait_impl #systems }.into() } - + + #[cfg(not(feature = "bevy_auto_plugin"))] trait_impl.into() }