Skip to content
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 by Bors] - Add example for run conditions #7652

Closed
wants to merge 7 commits into from

Conversation

LiamGallagher737
Copy link
Contributor

@LiamGallagher737 LiamGallagher737 commented Feb 13, 2023

Added an example for run conditions. Fixes #7646 if we wait till #7605 is merged and include some of it features.

@github-actions
Copy link
Contributor

Welcome, new contributor!

Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨

@alice-i-cecile alice-i-cecile added A-ECS Entities, components, systems, and events C-Examples An addition or correction to our examples labels Feb 13, 2023
// this is useful for small, simple run conditions you don't need to reuse.
// All the normal rules still apply, all parameters must be read only except for local parameters
// In this case we will only run if the input counter resource exists and has changed but not just been added
.run_if(|res: Option<Res<InputCounter>>| {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I correct in thinking that once #7605 in merged we could do something like this?

.run_if(resource_exists::<InputCounter>())
.and_then(|counter: Res<InputCounter>| counter.is_changed() && !counter.is_added())

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, precisely :) Interestingly, the short circuiting nature would make sure that the second run condition doesn't panic. That's nice.

Copy link
Member

@JoJoJet JoJoJet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall I'm happy with this, I just have a few grammar nitpicks.

examples/ecs/run_conditions.rs Outdated Show resolved Hide resolved
examples/ecs/run_conditions.rs Outdated Show resolved Hide resolved
examples/ecs/run_conditions.rs Outdated Show resolved Hide resolved
examples/ecs/run_conditions.rs Outdated Show resolved Hide resolved
examples/ecs/run_conditions.rs Outdated Show resolved Hide resolved
examples/ecs/run_conditions.rs Outdated Show resolved Hide resolved
examples/ecs/run_conditions.rs Outdated Show resolved Hide resolved
Co-authored-by: JoJoJet <21144246+JoJoJet@users.noreply.github.com>
@alice-i-cecile
Copy link
Member

bors r+

@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Feb 18, 2023
@bors
Copy link
Contributor

bors bot commented Feb 18, 2023

Timed out.

@alice-i-cecile
Copy link
Member

Github plz.

bors r+

bors bot pushed a commit that referenced this pull request Feb 18, 2023
Added an example for run conditions. Fixes #7646 if we wait till #7605 is merged and include some of it features.
@bors bors bot changed the title Add example for run conditions [Merged by Bors] - Add example for run conditions Feb 18, 2023
@bors bors bot closed this Feb 18, 2023
myreprise1 pushed a commit to myreprise1/bevy that referenced this pull request Feb 18, 2023
Added an example for run conditions. Fixes bevyengine#7646 if we wait till bevyengine#7605 is merged and include some of it features.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Examples An addition or correction to our examples S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add an example demonstrating run conditions
4 participants