Beginning the conversion to an Effects system

This commit is contained in:
Llywelwyn 2023-08-16 15:11:49 +01:00
parent a6690029e6
commit efe15705ad
13 changed files with 382 additions and 67 deletions

View file

@ -0,0 +1,33 @@
use crate::{spatial, BlocksTile, Map, Pools, Position};
use specs::prelude::*;
pub struct MapIndexingSystem {}
impl<'a> System<'a> for MapIndexingSystem {
type SystemData = (
ReadExpect<'a, Map>,
ReadStorage<'a, Position>,
ReadStorage<'a, BlocksTile>,
Entities<'a>,
ReadStorage<'a, Pools>,
);
fn run(&mut self, data: Self::SystemData) {
let (map, position, blockers, entities, pools) = data;
spatial::clear();
spatial::populate_blocked_from_map(&*map);
for (entity, position) in (&entities, &position).join() {
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());
}
}
}
}

View file

@ -2,6 +2,9 @@ use crate::{tile_walkable, Map, RunState};
use specs::prelude::*;
use std::sync::Mutex;
mod map_indexing_system;
pub use map_indexing_system::MapIndexingSystem;
struct SpatialMap {
blocked: Vec<(bool, bool)>,
tile_content: Vec<Vec<(Entity, bool)>>,