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.

Update docs to match new Auto Plugin

+13 -41
+5 -9
README.md
··· 51 51 ### Bevy Auto Plugin 52 52 53 53 If you use [Bevy Auto Plugin](https://github.com/strikeforcezero/bevy_auto_plugin/), you can also use the `bevy_auto_plugin` feature flag. 54 - This automatically registers the required system(s) by leveraging the existing `auto_component` and `auto_resource` macros. 54 + This adds build hooks that automatically add the reset plugin. 55 55 56 56 ```rust 57 57 fn main() { ··· 62 62 #[auto_plugin(impl_plugin_trait)] 63 63 struct MyPlugin; 64 64 65 - // `StatContainer` derive hooks into the existing `auto_component` and `auto_resource` macros. 66 - #[derive(StatContainer, Component, Resource)] 67 - #[auto_component(plugin = MyPlugin)] // Adds `reset_component_modifiers` system. 68 - #[auto_init_resource(plugin = MyPlugin)] // Adds `reset_resource_modifiers` system. 65 + #[derive(StatContainer, Component)] 66 + // Use hook to add the `ResetComponentPlugin` to `MyPlugin` automatically. 67 + #[auto_plugin_build_hook(plugin = MyPlugin, hook = ResetComponentHook)] 69 68 struct Speed(Stat); 70 69 ``` 71 - 72 - It is important to note that this only works when the `derive` is above the `auto_*` macro, 73 - and does *not* work with `auto_bind_plugin`. 74 70 75 71 ### Version Compatibility 76 72 | Bevy | Immediate Stats | 77 73 |--------|-----------------| 78 74 | `0.18` | `0.4` | 79 75 | `0.17` | `0.3` | 80 - | `0.16` | `0.1` - `0.2` | 76 + | `0.16` | `0.1` - `0.2` |
+7 -31
immediate_stats/src/lib.rs
··· 50 50 //! 51 51 //! ### Bevy Auto Plugin 52 52 //! 53 - //! If you use [Bevy Auto Plugin](https://github.com/strikeforcezero/bevy_auto_plugin/), 54 - //! you can also use the `bevy_auto_plugin` feature flag. This automatically registers the required 55 - //! system(s) by leveraging the existing `auto_component` and `auto_resource` macros. 53 + //! If you use [Bevy Auto Plugin](https://github.com/strikeforcezero/bevy_auto_plugin/), you can also use the `bevy_auto_plugin` feature flag. 54 + //! This adds build hooks that automatically add the reset plugin. 56 55 //! 57 56 #![cfg_attr(not(feature = "bevy_auto_plugin"), doc = "```rust ignore")] 58 57 #![cfg_attr(feature = "bevy_auto_plugin", doc = "```rust")] 59 58 //! # use bevy_app::prelude::*; 60 59 //! # use bevy_ecs::prelude::*; 61 60 //! # use immediate_stats::*; 62 - //! # use bevy_auto_plugin::prelude::{AutoPlugin, auto_component, auto_resource}; 61 + //! # use bevy_auto_plugin::prelude::{AutoPlugin, auto_plugin_build_hook, auto_resource}; 62 + //! 63 63 //! fn main() { 64 64 //! App::new().add_plugins((ImmediateStatsPlugin, MyPlugin)).run(); 65 65 //! } ··· 68 68 //! #[auto_plugin(impl_plugin_trait)] 69 69 //! struct MyPlugin; 70 70 //! 71 - //! // `StatContainer` derive hooks into the existing `auto_component` and `auto_resource` macros. 72 - //! #[derive(StatContainer, Component, Resource)] 73 - //! #[auto_component(plugin = MyPlugin)] // Adds `reset_component_modifiers` system. 74 - //! #[auto_resource(plugin = MyPlugin)] // Adds `reset_resource_modifiers` system. 71 + //! #[derive(StatContainer, Component)] 72 + //! // Use hook to add the `ResetComponentPlugin` to `MyPlugin` automatically. 73 + //! #[auto_plugin_build_hook(plugin = MyPlugin, hook = ResetComponentHook)] 75 74 //! struct Speed(Stat); 76 75 //! ``` 77 - //! 78 - //! It is important to note that this only works when the `derive` is above the `auto_*` macro, 79 - //! and does *not* work with `auto_bind_plugin`. 80 76 //! 81 77 //! ### Version Compatibility 82 78 //! | Bevy | Immediate Stats | ··· 143 139 /// assert_eq!(partial.custom, Health::default()); 144 140 /// assert_eq!(partial.ignored, Stat::default().with_bonus(10)); 145 141 /// } 146 - /// ``` 147 - /// # Bevy Auto Plugin 148 - /// If the `bevy_auto_plugin` feature flag is enabled, the existing `auto_component` and 149 - /// `auto_resource` macros will register [`reset_component_modifiers`] and/or 150 - /// [`reset_resource_modifiers`] automatically. 151 - #[cfg_attr(not(feature = "bevy_auto_plugin"), doc = "```rust ignore")] 152 - #[cfg_attr(feature = "bevy_auto_plugin", doc = "```rust")] 153 - /// # use bevy_app::prelude::*; 154 - /// # use bevy_ecs::prelude::*; 155 - /// # use immediate_stats::*; 156 - /// # use bevy_auto_plugin::prelude::{AutoPlugin, auto_component, auto_resource}; 157 - /// #[derive(AutoPlugin)] 158 - /// #[auto_plugin(impl_plugin_trait)] 159 - /// struct MyPlugin; 160 - /// 161 - /// // `StatContainer` derive hooks into the existing `auto_component` and `auto_resource` macros. 162 - /// #[derive(StatContainer, Component, Resource)] 163 - /// #[auto_component(plugin = MyPlugin)] // Adds `reset_component_modifiers` system. 164 - /// #[auto_resource(plugin = MyPlugin)] // Adds `reset_resource_modifiers` system. 165 - /// struct Speed(Stat); 166 142 /// ``` 167 143 pub use immediate_stats_macros::StatContainer; 168 144 pub use modifier::*;
+1 -1
immediate_stats/tests/bevy_auto_plugin.rs
··· 1 - //! Tests the `add_component` attribute for automatic system registration. 1 + //! Tests the `ResetComponentHook` and `ResetResourceHook`. 2 2 #![cfg(feature = "bevy_auto_plugin")] 3 3 4 4 extern crate immediate_stats;