summaryrefslogtreecommitdiff
path: root/src/systems/updatecooldowns.rs
blob: 705561d854da2b6eaaf9c9b6a05c1cec1a9e7e6b (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
34
35

use specs::{
	WriteStorage,
	Entities,
	System,
	Join
};

use crate::components::{Controller, ControlCooldown};


pub struct UpdateCooldowns;
impl <'a> System<'a> for UpdateCooldowns {
	type SystemData = (
		Entities<'a>,
		WriteStorage<'a, ControlCooldown>,
		WriteStorage<'a, Controller>
	);
	fn run(&mut self, (entities, mut cooldowns, mut controllers): Self::SystemData) {
		controllers.clear();
		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);
		}
	}
}