1
0
Fork 0
roguelike-game/src/map_indexing_system.rs

34 lines
951 B
Rust

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