summaryrefslogtreecommitdiff
path: root/src/systems/updatecooldowns.rs
blob: 73ca77070d8e762479fd0755eb932b59a32e1c1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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);
		}
	}
}