Remove direction when transform is removed.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Nolan Darilek 2022-07-11 17:03:40 -05:00
parent a1cfc448db
commit 65067412af

View File

@ -6,6 +6,7 @@ use bevy_rapier2d::prelude::*;
use bevy_tts::Tts;
use crate::{
commands::RunIfExistsExt,
core::{Angle, CardinalDirection, Player},
error::error_handler,
exploration::{ExplorationFocused, Exploring},
@ -281,6 +282,14 @@ fn update_direction(
}
}
fn remove_direction(mut commands: Commands, removed: RemovedComponents<Transform>) {
for entity in removed.iter() {
commands.run_if_exists(entity, |mut entity| {
entity.remove::<CardinalDirection>();
});
}
}
fn speak_direction(
mut tts: ResMut<Tts>,
player: Query<
@ -385,6 +394,7 @@ where
.register_type::<RotationSpeed>()
.register_type::<Sprinting>()
.add_system(update_direction.before(SNAP))
.add_system_to_stage(CoreStage::PostUpdate, remove_direction)
.add_system(speak_direction.chain(error_handler))
.add_system(add_speed)
.add_system_to_stage(CoreStage::PostUpdate, remove_speed);