diff options
Diffstat (limited to 'src/systems/updatecooldowns.rs')
| -rw-r--r-- | src/systems/updatecooldowns.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/systems/updatecooldowns.rs b/src/systems/updatecooldowns.rs new file mode 100644 index 0000000..73ca770 --- /dev/null +++ b/src/systems/updatecooldowns.rs @@ -0,0 +1,33 @@ + +use specs::{ + WriteStorage, + Entities, + System, + Join +}; + +use crate::components::ControlCooldown; + + +pub struct UpdateCooldowns; +impl <'a> System<'a> for UpdateCooldowns { + type SystemData = ( + Entities<'a>, + WriteStorage<'a, ControlCooldown> + ); + fn run(&mut self, (entities, mut cooldowns): Self::SystemData) { + let mut to_remove = Vec::new(); + for (entity, cooldown) in (&entities, &mut cooldowns).join() { + if cooldown.amount > 0 { + cooldown.amount -= 1; + } + if cooldown.amount <= 0 { + to_remove.push(entity); + } + } + for entity in to_remove { + cooldowns.remove(entity); + } + } +} + |
