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.

Added Bevy Butler info to macro docs.

Also fixed doc tests for feature flagged content not getting tested.

+96 -30
+3 -14
README.md
··· 4 4 5 5 == Todo Info about derive macro. 6 6 7 - ```rust no_run 8 - use immediate_stats::*; 9 - 7 + ```rust 10 8 #[derive(StatContainer)] 11 9 struct Speed(Stat); 12 10 ··· 29 27 There is build-in integration with the [Bevy Engine](https://bevyengine.org) via the `bevy` feature flag. 30 28 This adds systems for resetting `StatContainer` components and resources. 31 29 32 - ```rust ignore 33 - use bevy_app::prelude::*; 34 - use bevy_ecs::prelude::*; 35 - use immediate_stats::*; 36 - 30 + ```rust 37 31 #[derive(StatContainer, Component, Resource)] 38 32 struct Speed(Stat); 39 33 ··· 52 46 If you use [Bevy Butler](https://github.com/TGRCdev/bevy-butler/), you can also use the `bevy_butler` feature flag. 53 47 This automatically registers the required system(s) using the `add_component` attribute. 54 48 55 - ```rust ignore 56 - use bevy_app::prelude::*; 57 - use bevy_ecs::prelude::*; 58 - use immediate_stats::*; 59 - use bevy_butler::*; 60 - 49 + ```rust 61 50 #[butler_plugin] 62 51 struct MyPlugin; 63 52
+3 -14
immediate_stats/README.md
··· 4 4 5 5 == Todo Info about derive macro. 6 6 7 - ```rust no_run 8 - use immediate_stats::*; 9 - 7 + ```rust 10 8 #[derive(StatContainer)] 11 9 struct Speed(Stat); 12 10 ··· 29 27 There is build-in integration with the [Bevy Engine](https://bevyengine.org) via the `bevy` feature flag. 30 28 This adds systems for resetting `StatContainer` components and resources. 31 29 32 - ```rust ignore 33 - use bevy_app::prelude::*; 34 - use bevy_ecs::prelude::*; 35 - use immediate_stats::*; 36 - 30 + ```rust 37 31 #[derive(StatContainer, Component, Resource)] 38 32 struct Speed(Stat); 39 33 ··· 52 46 If you use [Bevy Butler](https://github.com/TGRCdev/bevy-butler/), you can also use the `bevy_butler` feature flag. 53 47 This automatically registers the required system(s) using the `add_component` attribute. 54 48 55 - ```rust ignore 56 - use bevy_app::prelude::*; 57 - use bevy_ecs::prelude::*; 58 - use immediate_stats::*; 59 - use bevy_butler::*; 60 - 49 + ```rust 61 50 #[butler_plugin] 62 51 struct MyPlugin; 63 52
+90 -2
immediate_stats/src/lib.rs
··· 1 - #![doc = include_str!("../README.md")] 1 + //! Game stats that reset every frame. 2 + //! Inspired by immediate mode rendering. 3 + //! 4 + //! == Todo Info about derive macro. 5 + //! ```rust no_run 6 + //! # use immediate_stats::*; 7 + //! #[derive(StatContainer)] 8 + //! struct Speed(Stat); 9 + //! 10 + //! fn main() { 11 + //! loop { 12 + //! let mut speed = Speed(Stat::new(10)); // Set base speed to 10. 13 + //! 14 + //! speed.0 *= 2.0; // Applies a multiplier to the final result. 15 + //! speed.0 += 5; // Adds a bonus to the final result. 16 + //! // The order does not matter. Bonuses are always applied before multipliers. 17 + //! assert_eq!(speed.0.total(), 30); // (10 + 5) * 2 = 30 18 + //! 19 + //! speed.reset_modifiers(); // Reset bonus and multiplier, so speed is back to 10. 20 + //! } 21 + //! } 22 + //! ``` 23 + //! 24 + //! ## Bevy 25 + //! 26 + //! There is build-in integration with the [Bevy Engine](https://bevyengine.org) 27 + //! via the `bevy` feature flag. 28 + //! This adds systems for resetting `StatContainer` components and resources. 29 + //! 30 + #![cfg_attr(not(feature = "bevy"), doc = "```rust ignore")] 31 + #![cfg_attr(feature = "bevy", doc = "```rust")] 32 + //! # use bevy_app::prelude::*; 33 + //! # use bevy_ecs::prelude::*; 34 + //! # use immediate_stats::*; 35 + //! #[derive(StatContainer, Component, Resource)] 36 + //! struct Speed(Stat); 37 + //! 38 + //! fn main() { 39 + //! App::new() 40 + //! .add_systems(PreUpdate, ( 41 + //! reset_component_modifiers::<Speed>, 42 + //! reset_resource_modifiers::<Speed>, 43 + //! )) 44 + //! .run(); 45 + //! } 46 + //! ``` 47 + //! 48 + //! ### Bevy Butler 49 + //! 50 + //! If you use [Bevy Butler](https://github.com/TGRCdev/bevy-butler/), 51 + //! you can also use the `bevy_butler` feature flag. 52 + //! This automatically registers the required system(s) using the `add_component` attribute. 53 + //! 54 + #![cfg_attr(not(feature = "bevy_butler"), doc = "```rust ignore")] 55 + #![cfg_attr(feature = "bevy_butler", doc = "```rust")] 56 + //! use bevy_app::prelude::*; 57 + //! use bevy_ecs::prelude::*; 58 + //! use immediate_stats::*; 59 + //! use bevy_butler::*; 60 + //! 61 + //! #[butler_plugin] 62 + //! struct MyPlugin; 63 + //! 64 + //! #[derive(StatContainer, Component)] 65 + //! #[add_component(plugin = MyPlugin)] // Added by `StatContainer` derive. 66 + //! struct Speed(Stat); 67 + //! ``` 68 + //! 69 + //! ### Version Compatibility 70 + //! | bevy | immediate_stats | 71 + //! |--------|-----------------| 72 + //! | `0.16` | `0.1` | 2 73 3 74 #[cfg(feature = "bevy")] 4 75 pub mod bevy; ··· 59 130 /// assert_eq!(partial.ignored, Stat::new(1).with_bonus(10)); 60 131 /// } 61 132 /// ``` 133 + /// # Bevy Butler 134 + /// If the `bevy_butler` feature flag is enabled, you may also use the `add_component` attribute 135 + /// to register [`reset_component_modifiers`] and/or [`reset_resource_modifiers`] automatically. 136 + #[cfg_attr(not(feature = "bevy_butler"), doc = "```rust ignore")] 137 + #[cfg_attr(feature = "bevy_butler", doc = "```rust")] 138 + /// # use bevy_butler::*; 139 + /// # use bevy_ecs::prelude::*; 140 + /// # use immediate_stats::*; 141 + /// #[butler_plugin] 142 + /// struct MyPlugin; 143 + /// 144 + /// #[derive(Component, StatContainer)] 145 + /// #[add_component(plugin = MyPlugin)] 146 + /// struct Speed(Stat); 147 + /// ``` 62 148 pub use immediate_stats_macros::StatContainer; 63 149 pub use modifier::*; 64 150 pub use stat::*; 65 151 66 152 #[cfg(feature = "bevy")] 67 153 pub use bevy::*; 68 - #[cfg(feature = "bevy")] // Used by derive macro. 154 + 155 + // Used by derive macro. 156 + #[cfg(feature = "bevy")] 69 157 #[doc(hidden)] 70 158 pub use bevy_app::prelude::PreUpdate; 71 159