Game stats that reset every frame, inspired by immediate mode GUI.
gamedev bevy stats
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Remove old Auto Plugin macro systems.

+5 -186
+4 -39
Cargo.lock
··· 148 148 checksum = "999eb3756d075ac95e169f71333ac211e54e961ac55708a89731eb6134f38b7e" 149 149 dependencies = [ 150 150 "bevy_app", 151 - "darling 0.21.3", 151 + "darling", 152 152 "inventory", 153 153 "linkme", 154 154 "log", ··· 539 539 source = "registry+https://github.com/rust-lang/crates.io-index" 540 540 checksum = "9cdf337090841a411e2a7f3deb9187445851f91b309c0c0a29e05f74a00a48c0" 541 541 dependencies = [ 542 - "darling_core 0.21.3", 543 - "darling_macro 0.21.3", 544 - ] 545 - 546 - [[package]] 547 - name = "darling" 548 - version = "0.23.0" 549 - source = "registry+https://github.com/rust-lang/crates.io-index" 550 - checksum = "25ae13da2f202d56bd7f91c25fba009e7717a1e4a1cc98a76d844b65ae912e9d" 551 - dependencies = [ 552 - "darling_core 0.23.0", 553 - "darling_macro 0.23.0", 542 + "darling_core", 543 + "darling_macro", 554 544 ] 555 545 556 546 [[package]] ··· 568 558 ] 569 559 570 560 [[package]] 571 - name = "darling_core" 572 - version = "0.23.0" 573 - source = "registry+https://github.com/rust-lang/crates.io-index" 574 - checksum = "9865a50f7c335f53564bb694ef660825eb8610e0a53d3e11bf1b0d3df31e03b0" 575 - dependencies = [ 576 - "ident_case", 577 - "proc-macro2", 578 - "quote", 579 - "strsim", 580 - "syn 2.0.114", 581 - ] 582 - 583 - [[package]] 584 561 name = "darling_macro" 585 562 version = "0.21.3" 586 563 source = "registry+https://github.com/rust-lang/crates.io-index" 587 564 checksum = "d38308df82d1080de0afee5d069fa14b0326a88c14f15c5ccda35b4a6c414c81" 588 565 dependencies = [ 589 - "darling_core 0.21.3", 590 - "quote", 591 - "syn 2.0.114", 592 - ] 593 - 594 - [[package]] 595 - name = "darling_macro" 596 - version = "0.23.0" 597 - source = "registry+https://github.com/rust-lang/crates.io-index" 598 - checksum = "ac3984ec7bd6cfa798e62b4a642426a5be0e68f9401cfc2a01e3fa9ea2fcdb8d" 599 - dependencies = [ 600 - "darling_core 0.23.0", 566 + "darling_core", 601 567 "quote", 602 568 "syn 2.0.114", 603 569 ] ··· 805 771 name = "immediate_stats_macros" 806 772 version = "0.4.0" 807 773 dependencies = [ 808 - "darling 0.23.0", 809 774 "proc-macro-error", 810 775 "proc-macro2", 811 776 "quote",
+1 -5
immediate_stats/Cargo.toml
··· 20 20 "dep:bevy_reflect", 21 21 "immediate_stats_macros/bevy", 22 22 ] 23 - bevy_auto_plugin = [ 24 - "bevy", 25 - "dep:bevy_auto_plugin", 26 - "immediate_stats_macros/bevy_auto_plugin", 27 - ] 23 + bevy_auto_plugin = ["bevy", "dep:bevy_auto_plugin"] 28 24 29 25 [dependencies] 30 26 bevy_app = { version = "0.18", default-features = false, optional = true, features = [
-2
immediate_stats_macros/Cargo.toml
··· 18 18 19 19 [features] 20 20 bevy = [] 21 - bevy_auto_plugin = ["bevy"] 22 21 23 22 [dependencies] 24 - darling = "0.23" 25 23 proc-macro2 = "1.0" 26 24 proc-macro-error = "1.0" 27 25 quote = "1.0"
-130
immediate_stats_macros/src/bevy_auto_plugin.rs
··· 1 - use darling::ast::NestedMeta; 2 - use darling::{Error, FromMeta}; 3 - use proc_macro2::{Ident, TokenStream}; 4 - use quote::{ToTokens, format_ident, quote}; 5 - use syn::{DeriveInput, Expr, Meta, Path}; 6 - 7 - /// Returns code that will register stat resetting system(s) with Bevy Auto Plugin. 8 - pub fn register_systems(input: &DeriveInput) -> darling::Result<TokenStream> { 9 - let struct_name = &input.ident; 10 - 11 - let mut auto_plugin_attributes = AutoPluginAttributes::new(struct_name); 12 - 13 - for attr in &input.attrs { 14 - if attr.path().is_ident("auto_component") { 15 - let plugin = PluginPath::from_meta(&attr.meta)?; 16 - auto_plugin_attributes.component_plugin = Some(plugin); 17 - } else if attr.path().is_ident("auto_resource") 18 - || attr.path().is_ident("auto_init_resource") 19 - || attr.path().is_ident("auto_insert_resource") 20 - { 21 - let plugin = PluginPath::from_meta(&attr.meta)?; 22 - auto_plugin_attributes.resource_plugin = Some(plugin); 23 - } 24 - } 25 - 26 - Ok(auto_plugin_attributes.into_token_stream()) 27 - } 28 - 29 - pub struct AutoPluginAttributes<'a> { 30 - ident: &'a Ident, 31 - component_plugin: Option<PluginPath>, 32 - resource_plugin: Option<PluginPath>, 33 - } 34 - 35 - impl<'a> AutoPluginAttributes<'a> { 36 - pub fn new(ident: &'a Ident) -> Self { 37 - Self { 38 - ident, 39 - component_plugin: None, 40 - resource_plugin: None, 41 - } 42 - } 43 - } 44 - 45 - impl<'a> ToTokens for AutoPluginAttributes<'a> { 46 - fn to_tokens(&self, tokens: &mut TokenStream) { 47 - if let Some(plugin_path) = &self.component_plugin { 48 - let ident = &self.ident; 49 - let plugin = &plugin_path.0; 50 - let system_ident = format_ident!("__reset_{ident}_component_modifiers"); 51 - 52 - tokens.extend(quote! { 53 - #[bevy_auto_plugin::prelude::auto_system( 54 - plugin = #plugin, 55 - schedule = immediate_stats::__PreUpdate, 56 - config( 57 - in_set = immediate_stats::StatSystems::Reset, 58 - ) 59 - )] 60 - fn #system_ident( 61 - mut query: Query<&mut #ident, Without<immediate_stats::PauseStatReset>>, 62 - ) { 63 - for mut stat in &mut query { 64 - stat.reset_modifiers(); 65 - } 66 - } 67 - }); 68 - } 69 - 70 - if let Some(plugin_path) = &self.resource_plugin { 71 - let ident = &self.ident; 72 - let plugin = &plugin_path.0; 73 - let system_ident = format_ident!("__reset_{ident}_resource_modifiers"); 74 - 75 - tokens.extend(quote! { 76 - #[bevy_auto_plugin::prelude::auto_system( 77 - plugin = #plugin, 78 - schedule = immediate_stats::__PreUpdate, 79 - config( 80 - in_set = immediate_stats::StatSystems::Reset, 81 - ) 82 - )] 83 - fn #system_ident(res: Option<ResMut<#ident>>) { 84 - if let Some(mut res) = res { 85 - res.reset_modifiers(); 86 - } 87 - } 88 - }); 89 - } 90 - } 91 - } 92 - 93 - /// Represents a `plugin(PATH)` or `plugin = PATH` attribute meta. 94 - pub struct PluginPath(pub Path); 95 - 96 - impl FromMeta for PluginPath { 97 - fn from_list(items: &[NestedMeta]) -> darling::Result<Self> { 98 - for item in items { 99 - return match item { 100 - NestedMeta::Meta(meta) => match meta { 101 - Meta::Path(_) => Err(Error::custom("Expected a value for `plugin`")), 102 - Meta::List(list) => { 103 - if list.path.require_ident()? != "plugin" { 104 - continue; 105 - } 106 - 107 - let mut path = None; 108 - 109 - list.parse_nested_meta(|value_meta| { 110 - path = Some(value_meta.path); 111 - Ok(()) 112 - })?; 113 - 114 - match path { 115 - None => Err(Error::custom("Expected `plugin` attribute")), 116 - Some(path) => Ok(PluginPath(path)), 117 - } 118 - } 119 - Meta::NameValue(name_value) => match &name_value.value { 120 - Expr::Path(p) => Ok(PluginPath(p.path.clone())), 121 - _ => Err(Error::custom("Expected a path to an auto plugin")), 122 - }, 123 - }, 124 - NestedMeta::Lit(_) => Err(Error::custom("Expected `plugin` attribute")), 125 - }; 126 - } 127 - 128 - Err(Error::custom("Expected `plugin` attribute")) 129 - } 130 - }
-10
immediate_stats_macros/src/lib.rs
··· 1 - #[cfg(feature = "bevy_auto_plugin")] 2 - mod bevy_auto_plugin; 3 1 mod derive_enum; 4 2 mod derive_struct; 5 3 ··· 31 29 } 32 30 }; 33 31 34 - #[cfg(feature = "bevy_auto_plugin")] 35 - { 36 - let systems = 37 - bevy_auto_plugin::register_systems(&tree).unwrap_or_else(darling::Error::write_errors); 38 - quote! { #trait_impl #systems }.into() 39 - } 40 - 41 - #[cfg(not(feature = "bevy_auto_plugin"))] 42 32 trait_impl.into() 43 33 } 44 34