···11+# Immediate Stats
22+33+Game stats that reset every frame. Inspired by immediate mode rendering.
44+55+== Todo Info about derive macro.
66+77+```rust no_run
88+use immediate_stats::*;
99+1010+#[derive(StatContainer)]
1111+struct Speed(Stat);
1212+1313+fn main() {
1414+ loop {
1515+ let mut speed = Speed(Stat::new(10)); // Set base speed to 10.
1616+1717+ speed.0 *= 2.0; // Applies a multiplier to the final result.
1818+ speed.0 += 5; // Adds a bonus to the final result.
1919+ // The order does not matter. Bonuses are always applied before multipliers.
2020+ assert_eq!(speed.0.total(), 30); // (10 + 5) * 2 = 30
2121+2222+ speed.reset_modifiers(); // Reset bonus and multiplier, so speed is back to 10.
2323+ }
2424+}
2525+```
2626+2727+## Bevy
2828+2929+There is build-in integration with the [Bevy Engine](https://bevyengine.org) via the `bevy` feature flag.
3030+This adds systems for resetting `StatContainer` components and resources.
3131+3232+```rust ignore
3333+use bevy_app::prelude::*;
3434+use bevy_ecs::prelude::*;
3535+use immediate_stats::*;
3636+3737+#[derive(StatContainer, Component, Resource)]
3838+struct Speed(Stat);
3939+4040+fn main() {
4141+ App::new()
4242+ .add_plugins(ImmediateStatesPlugin)
4343+ .add_systems(PreUpdate, (
4444+ reset_component_modifiers::<Speed>,
4545+ reset_resource_modifiers::<Speed>,
4646+ ))
4747+ .run();
4848+}
4949+```
5050+5151+### Bevy Butler
5252+5353+If you use [Bevy Butler](https://github.com/TGRCdev/bevy-butler/), you can also use the `bevy_butler` feature flag.
5454+This automatically registers the required system(s) using the `add_component` attribute.
5555+5656+```rust ignore
5757+use bevy_app::prelude::*;
5858+use bevy_ecs::prelude::*;
5959+use immediate_stats::*;
6060+use bevy_butler::*;
6161+6262+#[butler_plugin]
6363+struct MyPlugin;
6464+6565+#[derive(StatContainer, Component)]
6666+#[add_component(plugin = MyPlugin)] // Added by `StatContainer` derive.
6767+struct Speed(Stat);
6868+```
6969+7070+### Version Compatibility
7171+| bevy | immediate_stats |
7272+|--------|-----------------|
7373+| `0.16` | `0.1` |
···11+# Immediate Stats
22+33+Game stats that reset every frame. Inspired by immediate mode rendering.
44+55+== Todo Info about derive macro.
66+77+```rust no_run
88+use immediate_stats::*;
99+1010+#[derive(StatContainer)]
1111+struct Speed(Stat);
1212+1313+fn main() {
1414+ loop {
1515+ let mut speed = Speed(Stat::new(10)); // Set base speed to 10.
1616+1717+ speed.0 *= 2.0; // Applies a multiplier to the final result.
1818+ speed.0 += 5; // Adds a bonus to the final result.
1919+ // The order does not matter. Bonuses are always applied before multipliers.
2020+ assert_eq!(speed.0.total(), 30); // (10 + 5) * 2 = 30
2121+2222+ speed.reset_modifiers(); // Reset bonus and multiplier, so speed is back to 10.
2323+ }
2424+}
2525+```
2626+2727+## Bevy
2828+2929+There is build-in integration with the [Bevy Engine](https://bevyengine.org) via the `bevy` feature flag.
3030+This adds systems for resetting `StatContainer` components and resources.
3131+3232+```rust ignore
3333+use bevy_app::prelude::*;
3434+use bevy_ecs::prelude::*;
3535+use immediate_stats::*;
3636+3737+#[derive(StatContainer, Component, Resource)]
3838+struct Speed(Stat);
3939+4040+fn main() {
4141+ App::new()
4242+ .add_plugins(ImmediateStatesPlugin)
4343+ .add_systems(PreUpdate, (
4444+ reset_component_modifiers::<Speed>,
4545+ reset_resource_modifiers::<Speed>,
4646+ ))
4747+ .run();
4848+}
4949+```
5050+5151+### Bevy Butler
5252+5353+If you use [Bevy Butler](https://github.com/TGRCdev/bevy-butler/), you can also use the `bevy_butler` feature flag.
5454+This automatically registers the required system(s) using the `add_component` attribute.
5555+5656+```rust ignore
5757+use bevy_app::prelude::*;
5858+use bevy_ecs::prelude::*;
5959+use immediate_stats::*;
6060+use bevy_butler::*;
6161+6262+#[butler_plugin]
6363+struct MyPlugin;
6464+6565+#[derive(StatContainer, Component)]
6666+#[add_component(plugin = MyPlugin)] // Added by `StatContainer` derive.
6767+struct Speed(Stat);
6868+```
6969+7070+### Version Compatibility
7171+| bevy | immediate_stats |
7272+|--------|-----------------|
7373+| `0.16` | `0.1` |
···11+#![doc = include_str!("../README.md")]
22+13#[cfg(feature = "bevy")]
24pub mod bevy;
35pub mod stat;
4677+// Todo Move into internal module called `__internal` like Bevy Butler.
88+#[cfg(feature = "bevy")]
59pub use bevy_app::prelude::PreUpdate;
610pub use immediate_stats_macros::StatContainer;
1111+1212+#[cfg(feature = "bevy")]
1313+pub use bevy::*;
1414+pub use stat::*;
715816/// Types that contain stats that need to be reset.
917///
+5-2
immediate_stats/src/stat.rs
···1717/// [mul]:Stat::mul_assign
1818/// [div]:Stat::div_assign
1919#[derive(PartialEq, Debug, Copy, Clone)]
2020-#[cfg_attr(feature = "bevy", derive(bevy_reflect::Reflect))]
2121-#[reflect(PartialEq, Debug, Clone)]
2020+#[cfg_attr(
2121+ feature = "bevy",
2222+ derive(bevy_reflect::Reflect),
2323+ reflect(PartialEq, Debug, Clone)
2424+)]
2225pub struct Stat {
2326 /// The persistent value of the stat.
2427 pub base: i32,
+5-2
immediate_stats/src/stat/modifier.rs
···2233/// Modifier values that can be applied to a [`super::Stat`].
44#[derive(PartialEq, Debug, Copy, Clone)]
55-#[cfg_attr(feature = "bevy", derive(bevy_reflect::Reflect))]
66-#[reflect(PartialEq, Debug, Clone)]
55+#[cfg_attr(
66+ feature = "bevy",
77+ derive(bevy_reflect::Reflect),
88+ reflect(PartialEq, Debug, Clone)
99+)]
710pub struct Modifier {
811 /// Added to `base` of a [`super::Stat`] during calculation.
912 pub bonus: i32,