simple/simple.rs
1use game_stat::prelude::*;
2// info: demonstrates the use of an armor stat that we modify by "equipping different gears"
3// the modifier is valid as long as you hold a key generated by the add_modifier() function
4
5fn main() {
6 // our use case will never exceed 2 modifiers 'should be set according to your constraints'
7 let mut armor_stat: Stat<2> = Stat::new(10f32);
8 println!("armor_stat: {}", armor_stat.value());
9 {
10 // let's make our armor stat stronger
11 // this modifier is valid as long as the key generated from add_modifier() exists
12 let _modifier_key = armor_stat.add_modifier(StatModifier::Flat(5f32));
13 println!("armor_stat: {}", armor_stat.value());
14 } // _modifier_key is dropped here, that invalidates the modifiers and gets removed next .value() call
15
16 // our stat should be 10 again
17 println!("armor_stat: {}", armor_stat.value());
18}