diff options
Diffstat (limited to 'src/systems/makefloor.rs')
| -rw-r--r-- | src/systems/makefloor.rs | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/src/systems/makefloor.rs b/src/systems/makefloor.rs index 8b550bc..74e4389 100644 --- a/src/systems/makefloor.rs +++ b/src/systems/makefloor.rs @@ -1,4 +1,5 @@ +use std::collections::HashSet; use specs::{ ReadStorage, @@ -8,20 +9,40 @@ use specs::{ Join }; -use super::super::components::Position; +use crate::components::{ + Position, + New, + Moved, + Removed +}; -use super::super::resources::{ +use crate::resources::{ Ground }; +#[derive(Default)] pub struct MakeFloor; impl <'a> System<'a> for MakeFloor { - type SystemData = (Entities<'a>, Write<'a, Ground>, ReadStorage<'a, Position>); - fn run(&mut self, (entities, mut ground, positions): Self::SystemData) { - ground.cells.clear(); - for (ent, pos) in (&entities, &positions).join() { - ground.cells.entry(pos.pos).or_insert(Vec::new()).push(ent); + type SystemData = ( + Entities<'a>, + Write<'a, Ground>, + ReadStorage<'a, Position>, + ReadStorage<'a, New>, + ReadStorage<'a, Moved>, + ReadStorage<'a, Removed> + ); + fn run(&mut self, (entities, mut ground, positions, new, moved, removed): Self::SystemData) { + for (ent, pos, _new) in (&entities, &positions, &new).join() { + ground.cells.entry(pos.pos).or_insert(HashSet::new()).insert(ent); + } + for (ent, pos, mov) in (&entities, &positions, &moved).join() { + ground.cells.entry(pos.pos).or_insert(HashSet::new()).insert(ent); + ground.cells.get_mut(&mov.from).unwrap().remove(&ent); + } + for (ent, pos, _removed) in (&entities, &positions, &removed).join() { + ground.cells.get_mut(&pos.pos).unwrap().remove(&ent); } } } + |
