|
@@ -22,25 +22,30 @@ impl<'a> System<'a> for DamageSystem {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-pub fn delete_the_dead(ecs: &mut World) {
|
|
|
- let mut dead: Vec<Entity> = Vec::new();
|
|
|
- // Using a scope to make the borrow checker happy
|
|
|
- {
|
|
|
- let combat_stats = ecs.read_storage::<CombatStats>();
|
|
|
- let players = ecs.read_storage::<Player>();
|
|
|
- let entities = ecs.entities();
|
|
|
- for (entity, stats) in (&entities, &combat_stats).join() {
|
|
|
+pub struct CleanupDead;
|
|
|
+
|
|
|
+impl<'a> System<'a> for CleanupDead {
|
|
|
+ type SystemData = (
|
|
|
+ Entities<'a>,
|
|
|
+ ReadStorage<'a, CombatStats>,
|
|
|
+ ReadStorage<'a, Player>,
|
|
|
+ );
|
|
|
+
|
|
|
+ fn run(&mut self, (entities, stats, player): Self::SystemData) {
|
|
|
+ let mut dead = Vec::new();
|
|
|
+
|
|
|
+ for (entity, stats) in (&entities, &stats).join() {
|
|
|
if stats.hp < 1 {
|
|
|
- let player = players.get(entity);
|
|
|
- match player {
|
|
|
- None => dead.push(entity),
|
|
|
- Some(_) => console::log("You are dead"),
|
|
|
+ if player.contains(entity) {
|
|
|
+ console::log("You are dead");
|
|
|
+ } else {
|
|
|
+ dead.push(entity)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- for victim in dead {
|
|
|
- ecs.delete_entity(victim).expect("Unable to delete");
|
|
|
+ for e in dead {
|
|
|
+ entities.delete(e).expect("Unable to delete");
|
|
|
+ }
|
|
|
}
|
|
|
}
|