summaryrefslogtreecommitdiff
path: root/src/systems/remove.rs
blob: a228a32f6562401a8ff8ae29d08b5b5831f3d625 (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::{
	ReadStorage,
	System,
	Join,
	Write,
	Entities
};

use crate::components::{Removed, Position};
use crate::resources::Ground;


pub struct Remove;
impl <'a> System<'a> for Remove {
	type SystemData = (
		Entities<'a>,
		ReadStorage<'a, Removed>,
		ReadStorage<'a, Position>,
		Write<'a, Ground>
	);
	
	fn run(&mut self, (entities, removals, positions, mut ground): Self::SystemData) {
		for (ent, _) in (&*entities, &removals, ).join() {
			if let Err(msg) = entities.delete(ent){
				println!("{:?}", msg);
			}
			if let Some(position) = positions.get(ent) {
				ground.remove(&position.pos, ent);
			}
		}
	}
}