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 documentation for derive macro.

+54 -1
+54 -1
immediate_stats/src/lib.rs
··· 5 5 pub mod modifier; 6 6 pub mod stat; 7 7 8 - /// Todo 8 + /// Implements [`reset_modifiers`](StatContainer::reset_modifiers) 9 + /// by passing on the call to any sub-stats. 10 + /// ```rust 11 + /// # use immediate_stats::*; 12 + /// #[derive(StatContainer, Default, Debug, PartialEq)] 13 + /// struct Health { 14 + /// max: Stat, // `Health::reset_modifiers` calls will be passed onto `max`. 15 + /// current: i32, 16 + /// } 17 + /// 18 + /// fn main() { 19 + /// let mut health = Health { 20 + /// max: Stat::new(10), 21 + /// current: 10 22 + /// }; 23 + /// 24 + /// health.max += 5; 25 + /// health.reset_modifiers(); 26 + /// assert_eq!(health.max, Stat::new(10)); 27 + /// } 28 + /// ``` 29 + /// # Configuration 30 + /// By default, it will consider any value of type `Stat` to be a sub-stat. 31 + /// You can use `#[stat]` to add a sub-stat and `#[stat_ignore]` to ignore one. 32 + /// ```rust 33 + /// # use immediate_stats::*; 34 + /// # #[derive(StatContainer, Default, Debug, PartialEq)] 35 + /// # struct Health { 36 + /// # max: Stat, 37 + /// # current: i32, 38 + /// # } 39 + /// #[derive(StatContainer)] 40 + /// struct PartialReset { 41 + /// #[stat] 42 + /// custom: Health, 43 + /// #[stat_ignore] 44 + /// ignored: Stat, 45 + /// } 46 + /// 47 + /// fn main () { 48 + /// let mut partial = PartialReset { 49 + /// custom: Health::default(), 50 + /// ignored: Stat::new(1), 51 + /// }; 52 + /// 53 + /// partial.custom.max += 10; 54 + /// partial.ignored += 10; 55 + /// 56 + /// partial.reset_modifiers(); 57 + /// 58 + /// assert_eq!(partial.custom, Health::default()); 59 + /// assert_eq!(partial.ignored, Stat::new(1).with_bonus(10)); 60 + /// } 61 + /// ``` 9 62 pub use immediate_stats_macros::StatContainer; 10 63 pub use modifier::*; 11 64 pub use stat::*;