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.

Add `Modifier::scaled` method.

+28 -1
+10
immediate_stats/src/modifier.rs
··· 42 42 ..Self::default() 43 43 } 44 44 } 45 + 46 + /// Returns a new modifier scaled by a fraction. 47 + /// 48 + /// When the scale is zero, the bonus will be zero while the multiplier will be one. 49 + pub fn scaled(&self, fraction: f32) -> Self { 50 + Self { 51 + bonus: (self.bonus as f32 * fraction) as i32, 52 + multiplier: (1.0 - fraction) * 1.0 + fraction * self.multiplier, 53 + } 54 + } 45 55 } 46 56 47 57 impl Default for Modifier {
+3 -1
immediate_stats/src/stat.rs
··· 80 80 self.multiplier *= modifier.multiplier; 81 81 } 82 82 83 - /// Scales and applies the [`Modifier`] values to the bonus and multiplier. 83 + /// [Scales](Modifier::scaled) and applies the [`Modifier`] values to the bonus and multiplier. 84 + /// 85 + /// When the scale is zero, the bonus will be zero while the multiplier will be one. 84 86 /// 85 87 /// This adds the bonuses, and multiplies the multipliers. 86 88 pub fn apply_scaled(&mut self, modifier: Modifier, fraction: f32) {
+15
immediate_stats/tests/modifier.rs
··· 53 53 } 54 54 ); 55 55 } 56 + 57 + #[test] 58 + fn scaled() { 59 + let modifier = Modifier { 60 + bonus: 10, 61 + multiplier: 3.0, 62 + }; 63 + assert_eq!( 64 + modifier.scaled(0.5), 65 + Modifier { 66 + bonus: 5, 67 + multiplier: 2.0, 68 + } 69 + ); 70 + }