Prefer writing a component value where possible, and other minor cleanup.
This commit is contained in:
parent
1176c65ce9
commit
6c97ff6be4
|
@ -58,7 +58,7 @@ fn movement_controls<S, A: 'static>(
|
||||||
),
|
),
|
||||||
With<Player>,
|
With<Player>,
|
||||||
>,
|
>,
|
||||||
exploration_focused: Query<(Entity, &ExplorationFocused)>,
|
exploration_focused: Query<Entity, With<ExplorationFocused>>,
|
||||||
) where
|
) where
|
||||||
S: bevy::ecs::component::Component + Clone + Debug + Eq + Hash,
|
S: bevy::ecs::component::Component + Clone + Debug + Eq + Hash,
|
||||||
A: Hash + Eq + Clone + Send + Sync,
|
A: Hash + Eq + Clone + Send + Sync,
|
||||||
|
@ -117,7 +117,7 @@ fn movement_controls<S, A: 'static>(
|
||||||
if direction.length_squared() != 0. {
|
if direction.length_squared() != 0. {
|
||||||
commands.entity(entity).remove::<Destination>();
|
commands.entity(entity).remove::<Destination>();
|
||||||
commands.entity(entity).remove::<Exploring>();
|
commands.entity(entity).remove::<Exploring>();
|
||||||
for (entity, _) in exploration_focused.iter() {
|
for entity in exploration_focused.iter() {
|
||||||
commands.entity(entity).remove::<ExplorationFocused>();
|
commands.entity(entity).remove::<ExplorationFocused>();
|
||||||
}
|
}
|
||||||
direction = direction.normalize();
|
direction = direction.normalize();
|
||||||
|
@ -176,16 +176,20 @@ fn movement_controls<S, A: 'static>(
|
||||||
|
|
||||||
fn update_direction(
|
fn update_direction(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
query: Query<
|
mut query: Query<
|
||||||
(Entity, &Transform, Option<&CardinalDirection>),
|
(Entity, &Transform, Option<&mut CardinalDirection>),
|
||||||
(With<Player>, Changed<Transform>),
|
(With<Player>, Changed<Transform>),
|
||||||
>,
|
>,
|
||||||
) {
|
) {
|
||||||
for (entity, transform, direction) in query.iter() {
|
for (entity, transform, direction) in query.iter_mut() {
|
||||||
let forward = transform.local_x();
|
let forward = transform.local_x();
|
||||||
let yaw = Angle::Radians(forward.y.atan2(forward.x));
|
let yaw = Angle::Radians(forward.y.atan2(forward.x));
|
||||||
let new_direction: CardinalDirection = yaw.into();
|
let new_direction: CardinalDirection = yaw.into();
|
||||||
if direction != Some(&new_direction) {
|
if let Some(mut direction) = direction {
|
||||||
|
if *direction != new_direction {
|
||||||
|
*direction = new_direction;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
commands.entity(entity).insert(new_direction);
|
commands.entity(entity).insert(new_direction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user