roguelike-game/src/map_indexing_system.rs

38 lines
1.0 KiB
Rust
Raw Normal View History

2021-12-24 10:38:44 -05:00
use ::specs::prelude::*;
2021-10-29 11:11:17 -04:00
2022-01-12 11:12:59 -05:00
use crate::components::{BlocksTile, Pools, Position};
use crate::{spatial, Map};
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 = (
ReadExpect<'a, Map>,
2021-10-29 11:11:17 -04:00
ReadStorage<'a, Position>,
ReadStorage<'a, BlocksTile>,
2022-01-12 11:12:59 -05:00
ReadStorage<'a, Pools>,
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 11:12:59 -05:00
let (map, position, blockers, pools, entities) = data;
2021-10-29 11:11:17 -04:00
spatial::clear();
spatial::populate_blocked_from_map(&*map);
2021-10-29 15:15:22 -04:00
for (entity, position) in (&entities, &position).join() {
2022-01-12 11:12:59 -05:00
let mut alive = true;
if let Some(pools) = pools.get(entity) {
if pools.hit_points.current < 1 {
alive = false;
}
}
if alive {
let idx = map.xy_idx(position.x, position.y);
spatial::index_entity(entity, idx, blockers.get(entity).is_some());
}
2021-10-29 11:11:17 -04:00
}
}
}