src/map_indexing_system.rs
1	use specs::prelude::*;
2 use super::{Map, Position, BlocksTile};
3
4 pub struct MapIndexingSystem {}
5
6 impl<'a> System<'a> for MapIndexingSystem {
7 type SystemData = ( WriteExpect<'a, Map>,
8 ReadStorage<'a, Position>,
9 ReadStorage<'a, BlocksTile>,
10 Entities<'a>,);
11
12 fn run(&mut self, data : Self::SystemData) {
13 let (mut map, position, blockers, entities) = data;
14
15 map.populate_blocked();
16 map.clear_content_index();
17 for (entity, position) in (&entities, &position).join() {
18 let idx = map.xy_idx(position.x, position.y);
19
20 // If they block, update the blocking list
21 let _p : Option<&BlocksTile> = blockers.get(entity);
22 if let Some(_p) = _p {
23 map.blocked[idx] = true;
24 }
25
26 // Push the entity to the appropriate index slot. It's a Copy
27 // type, so we don't need to clone it (we want to avoid moving it out of the ECS!)
28 map.tile_content[idx].push(entity);
29 }
30 }
31 }