34 lines
906 B
Rust
34 lines
906 B
Rust
use specs::prelude::*;
|
|
|
|
use crate::{BlocksTile, Map, Position};
|
|
|
|
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
|
|
if let Some(_p) = blockers.get(entity) {
|
|
map.blocked[idx] = true;
|
|
}
|
|
|
|
// Push a copy of the entity to the indexed slot
|
|
map.tile_content[idx].push(entity);
|
|
}
|
|
}
|
|
}
|