map_indexing_system.rs 1.1 KB

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