Skip to content

feat: Implement WithoutAny filter #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 28, 2024
Merged

Conversation

RobWalt
Copy link
Collaborator

@RobWalt RobWalt commented May 11, 2024

This PR:

  1. implements WithoutAny, a QueryFilter which is supposed to be the opposite of WithOne
  2. cleans up some parts of WithOne to make it QueryFilter only

Note that 2. is a breaking change since we can't use it in the Data position anymore. However, I think this is fine since there is One which already fills this gap. So this is really a fix since it clears up the separation of concerns of the two structs.


This should also solve #50. My use case is something similar as described there. I want to query for things that have / don't have components of a certain class. Small pseudo code example:

struct Food;

trait Fruit {}
struct Banana;
impl Fruit for Banana {}
struct Apple;
impl Fruit for Apple {}

struct Sweets;
struct Cake;

fn eat_unhealthy(
  mut commands: Commands,
  q_non_fruits: Query<Entity, (With<Food>, WithoutAny<&dyn Fruit>)>
) {
  q_non_fruits.iter().for_each(|food| {
    // only sweets and cakes without fruits
    commands.eat(food); 
  });
}  

(adding all the missing things to make this actually run is left as an exercise to the reader)


@RobWalt RobWalt changed the title feat: Implement WithoutOne feat: Implement WithoutAny filter Oct 28, 2024
@RobWalt RobWalt merged commit 5df9eb3 into joseph-gio:main Oct 28, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant