map_indexing_system.rs 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. extern crate specs;
  2. use super::{BlocksTile, Map, Position};
  3. use specs::prelude::*;
  4. pub struct MapIndexingSystem {}
  5. impl<'a> System<'a> for MapIndexingSystem {
  6. type SystemData = (
  7. 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. map.populate_blocked();
  15. map.clear_content_index();
  16. for (entity, position) in (&entities, &position).join() {
  17. let idx = map.xy_idx(position.x, position.y);
  18. // If they block, update the blocking list
  19. let _p: Option<&BlocksTile> = blockers.get(entity);
  20. if let Some(_p) = _p {
  21. map.blocked[idx] = true;
  22. }
  23. // Push the entity to the appropriate index slot. It's a Copy
  24. // type, so we don't need to clone it (we want to avoid moving it out of the ECS!)
  25. map.tile_content[idx].push(entity);
  26. }
  27. }
  28. }