roguelike-game/src/map_indexing_system.rs

34 lines
906 B
Rust
Raw Normal View History

2021-10-29 11:11:17 -04:00
use specs::prelude::*;
2021-12-10 20:16:48 -05:00
use crate::{BlocksTile, Map, Position};
2021-10-29 11:11:17 -04:00
pub struct MapIndexingSystem {}
impl<'a> System<'a> for MapIndexingSystem {
type SystemData = (
WriteExpect<'a, Map>,
ReadStorage<'a, Position>,
ReadStorage<'a, BlocksTile>,
2021-10-29 15:15:22 -04:00
Entities<'a>,
2021-10-29 11:11:17 -04:00
);
fn run(&mut self, data: Self::SystemData) {
2021-10-29 15:15:22 -04:00
let (mut map, position, blockers, entities) = data;
2021-10-29 11:11:17 -04:00
map.populate_blocked();
2021-10-29 15:15:22 -04:00
map.clear_content_index();
for (entity, position) in (&entities, &position).join() {
2021-10-29 11:11:17 -04:00
let idx = map.xy_idx(position.x, position.y);
2021-10-29 15:15:22 -04:00
// If it's a blocking entity, note that in the map object
if let Some(_p) = blockers.get(entity) {
2021-10-29 15:15:22 -04:00
map.blocked[idx] = true;
}
// Push a copy of the entity to the indexed slot
map.tile_content[idx].push(entity);
2021-10-29 11:11:17 -04:00
}
}
}