2021-12-24 10:38:44 -05:00
|
|
|
use ::specs::prelude::*;
|
2021-10-29 11:11:17 -04:00
|
|
|
|
2022-01-12 10:45:13 -05:00
|
|
|
use crate::{spatial, BlocksTile, Map, Position};
|
2021-12-10 20:16:48 -05:00
|
|
|
|
2021-10-29 11:11:17 -04:00
|
|
|
pub struct MapIndexingSystem {}
|
|
|
|
|
|
|
|
impl<'a> System<'a> for MapIndexingSystem {
|
|
|
|
type SystemData = (
|
2022-01-12 10:45:13 -05:00
|
|
|
ReadExpect<'a, Map>,
|
2021-10-29 11:11:17 -04:00
|
|
|
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) {
|
2022-01-12 10:45:13 -05:00
|
|
|
let (map, position, blockers, entities) = data;
|
2021-10-29 11:11:17 -04:00
|
|
|
|
2022-01-12 10:45:13 -05:00
|
|
|
spatial::clear();
|
|
|
|
spatial::populate_blocked_from_map(&*map);
|
2021-10-29 15:15:22 -04:00
|
|
|
|
|
|
|
for (entity, position) in (&entities, &position).join() {
|
2021-10-29 11:11:17 -04:00
|
|
|
let idx = map.xy_idx(position.x, position.y);
|
2022-01-12 10:45:13 -05:00
|
|
|
spatial::index_entity(entity, idx, blockers.get(entity).is_some());
|
2021-10-29 11:11:17 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|