map_indexing_system.rs 1.1 KB

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