Skip to content

Commit

Permalink
refactor: Change Option<With<T>> query params to Has<T> (#9959)
Browse files Browse the repository at this point in the history
# Objective
`Has<T>` was added to bevy_ecs, but we're still using the
`Option<With<T>>` pattern in multiple locations.

## Solution
Replace them with `Has<T>`.
  • Loading branch information
james7132 authored Oct 2, 2023
1 parent dfdc9f8 commit 21518de
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions crates/bevy_animation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,16 +453,16 @@ fn entity_from_path(
/// Verify that there are no ancestors of a given entity that have an [`AnimationPlayer`].
fn verify_no_ancestor_player(
player_parent: Option<&Parent>,
parents: &Query<(Option<With<AnimationPlayer>>, Option<&Parent>)>,
parents: &Query<(Has<AnimationPlayer>, Option<&Parent>)>,
) -> bool {
let Some(mut current) = player_parent.map(Parent::get) else {
return true;
};
loop {
let Ok((maybe_player, parent)) = parents.get(current) else {
let Ok((has_player, parent)) = parents.get(current) else {
return true;
};
if maybe_player.is_some() {
if has_player {
return false;
}
if let Some(parent) = parent {
Expand All @@ -483,7 +483,7 @@ pub fn animation_player(
names: Query<&Name>,
transforms: Query<&mut Transform>,
morphs: Query<&mut MorphWeights>,
parents: Query<(Option<With<AnimationPlayer>>, Option<&Parent>)>,
parents: Query<(Has<AnimationPlayer>, Option<&Parent>)>,
mut animation_players: Query<(Entity, Option<&Parent>, &mut AnimationPlayer)>,
) {
animation_players
Expand Down Expand Up @@ -515,7 +515,7 @@ fn run_animation_player(
transforms: &Query<&mut Transform>,
morphs: &Query<&mut MorphWeights>,
maybe_parent: Option<&Parent>,
parents: &Query<(Option<With<AnimationPlayer>>, Option<&Parent>)>,
parents: &Query<(Has<AnimationPlayer>, Option<&Parent>)>,
children: &Query<&Children>,
) {
let paused = player.paused;
Expand Down Expand Up @@ -601,7 +601,7 @@ fn apply_animation(
transforms: &Query<&mut Transform>,
morphs: &Query<&mut MorphWeights>,
maybe_parent: Option<&Parent>,
parents: &Query<(Option<With<AnimationPlayer>>, Option<&Parent>)>,
parents: &Query<(Has<AnimationPlayer>, Option<&Parent>)>,
children: &Query<&Children>,
) {
if let Some(animation_clip) = animations.get(&animation.animation_clip) {
Expand Down
8 changes: 4 additions & 4 deletions crates/bevy_pbr/src/render/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ pub fn extract_meshes(
&GlobalTransform,
Option<&PreviousGlobalTransform>,
&Handle<Mesh>,
Option<With<NotShadowReceiver>>,
Option<With<NotShadowCaster>>,
Has<NotShadowReceiver>,
Has<NotShadowCaster>,
Has<NoAutomaticBatching>,
)>,
>,
Expand All @@ -278,7 +278,7 @@ pub fn extract_meshes(
}
let transform = transform.affine();
let previous_transform = previous_transform.map(|t| t.0).unwrap_or(transform);
let mut flags = if not_receiver.is_some() {
let mut flags = if not_receiver {
MeshFlags::empty()
} else {
MeshFlags::SHADOW_RECEIVER
Expand All @@ -298,7 +298,7 @@ pub fn extract_meshes(
RenderMeshInstance {
mesh_asset_id: handle.id(),
transforms,
shadow_caster: not_caster.is_none(),
shadow_caster: !not_caster,
material_bind_group_id: MaterialBindGroupId::default(),
automatic_batching: !no_automatic_batching,
},
Expand Down

0 comments on commit 21518de

Please sign in to comment.