use specs::prelude::*;
#[derive(Component, Default)]
#[storage(NullStorage)]
pub struct NewlyCreated;
pub struct DeflagNewAtomsSystem;
impl<'a> System<'a> for DeflagNewAtomsSystem {
type SystemData = (
Entities<'a>,
ReadStorage<'a, NewlyCreated>,
Read<'a, LazyUpdate>,
);
fn run(&mut self, (ent, newly_created, updater): Self::SystemData) {
for (ent, _newly_created) in (&ent, &newly_created).join() {
updater.remove::<NewlyCreated>(ent);
}
}
}
pub mod tests {
#[allow(unused_imports)]
use super::*;
extern crate specs;
#[allow(unused_imports)]
use specs::{Builder, DispatcherBuilder, World};
#[test]
fn test_deflag_new_atoms_system() {
let mut test_world = World::new();
let mut dispatcher = DispatcherBuilder::new()
.with(DeflagNewAtomsSystem, "deflagger", &[])
.build();
dispatcher.setup(&mut test_world);
let test_entity = test_world.create_entity().with(NewlyCreated).build();
dispatcher.dispatch(&test_world);
test_world.maintain();
let created_flags = test_world.read_storage::<NewlyCreated>();
assert!(!created_flags.contains(test_entity));
}
}