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

Add an all purpose run condition inversion tool #7202

Closed
alice-i-cecile opened this issue Jan 15, 2023 · 5 comments
Closed

Add an all purpose run condition inversion tool #7202

alice-i-cecile opened this issue Jan 15, 2023 · 5 comments
Labels
A-ECS Entities, components, systems, and events C-Usability A simple quality-of-life change that makes Bevy easier to use

Comments

@alice-i-cecile
Copy link
Member

alice-i-cecile commented Jan 15, 2023

          If someone run something on `resource_exists` they may also need to run something on `unless_resource_exists`.

General inversion method would be better, of course.

Originally posted by @Shatur in #6587 (comment)

This can optionally be combined with other logical combinators, like OR, XOR and AND.

@alice-i-cecile alice-i-cecile added A-ECS Entities, components, systems, and events C-Usability A simple quality-of-life change that makes Bevy easier to use labels Jan 15, 2023
@Shatur
Copy link
Contributor

Shatur commented Feb 6, 2023

Since we have run_if maybe we could have run_if_not?

@alice-i-cecile
Copy link
Member Author

Hmm. I don't mind it, but I think my ideal would be to have something that can be used to mutate arbitrary Condition types, so then you can combine it with e.g. Or or And later.

@Shatur
Copy link
Contributor

Shatur commented Feb 6, 2023

I think my ideal would be to have something that can be used to mutate arbitrary Condition types

I like it! So we could implement traits like Not on Conditions?

@alice-i-cecile
Copy link
Member Author

Yep, ideally :) Unsure exactly how that would work here, but maybe !(my_condition.into) would work?

@alice-i-cecile
Copy link
Member Author

Actually, I bet you could impl Not for T where T impl Into<Condition>.

bors bot pushed a commit that referenced this issue Feb 7, 2023
# Objective

Run conditions are a special type of system that do not modify the world, and which return a bool. Due to the way they are currently implemented, you can *only* use bare function systems as a run condition. Among other things, this prevents the use of system piping with run conditions. This make very basic constructs impossible, such as `my_system.run_if(my_condition.pipe(not))`.

Unblocks a basic solution for #7202.

## Solution

Add the trait `ReadOnlySystem`, which is implemented for any system whose parameters all implement `ReadOnlySystemParam`. Allow any `-> bool` system implementing this trait to be used as a run condition.

---

## Changelog

+ Added the trait `ReadOnlySystem`, which is implemented for any `System` type whose parameters all implement `ReadOnlySystemParam`.
+ Added the function `bevy::ecs::system::assert_is_read_only_system`.
@bors bors bot closed this as completed in 1ffeff1 Feb 8, 2023
myreprise1 pushed a commit to myreprise1/bevy that referenced this issue Feb 11, 2023
# Objective

Run conditions are a special type of system that do not modify the world, and which return a bool. Due to the way they are currently implemented, you can *only* use bare function systems as a run condition. Among other things, this prevents the use of system piping with run conditions. This make very basic constructs impossible, such as `my_system.run_if(my_condition.pipe(not))`.

Unblocks a basic solution for bevyengine#7202.

## Solution

Add the trait `ReadOnlySystem`, which is implemented for any system whose parameters all implement `ReadOnlySystemParam`. Allow any `-> bool` system implementing this trait to be used as a run condition.

---

## Changelog

+ Added the trait `ReadOnlySystem`, which is implemented for any `System` type whose parameters all implement `ReadOnlySystemParam`.
+ Added the function `bevy::ecs::system::assert_is_read_only_system`.
myreprise1 pushed a commit to myreprise1/bevy that referenced this issue Feb 11, 2023
# Objective

Closes bevyengine#7202

## Solution

~~Introduce a `not` helper to pipe conditions. Opened mostly for discussion. Maybe create an extension trait with `not` method? Please, advice.~~
Introduce `not(condition)` condition that inverses the result of the passed.

---

## Changelog

### Added

- `not` condition.
myreprise1 pushed a commit to myreprise1/bevy that referenced this issue Feb 11, 2023
# Objective

Run conditions are a special type of system that do not modify the world, and which return a bool. Due to the way they are currently implemented, you can *only* use bare function systems as a run condition. Among other things, this prevents the use of system piping with run conditions. This make very basic constructs impossible, such as `my_system.run_if(my_condition.pipe(not))`.

Unblocks a basic solution for bevyengine#7202.

## Solution

Add the trait `ReadOnlySystem`, which is implemented for any system whose parameters all implement `ReadOnlySystemParam`. Allow any `-> bool` system implementing this trait to be used as a run condition.

---

## Changelog

+ Added the trait `ReadOnlySystem`, which is implemented for any `System` type whose parameters all implement `ReadOnlySystemParam`.
+ Added the function `bevy::ecs::system::assert_is_read_only_system`.
myreprise1 pushed a commit to myreprise1/bevy that referenced this issue Feb 11, 2023
# Objective

Closes bevyengine#7202

## Solution

~~Introduce a `not` helper to pipe conditions. Opened mostly for discussion. Maybe create an extension trait with `not` method? Please, advice.~~
Introduce `not(condition)` condition that inverses the result of the passed.

---

## Changelog

### Added

- `not` condition.
myreprise1 pushed a commit to myreprise1/bevy that referenced this issue Feb 15, 2023
# Objective

Run conditions are a special type of system that do not modify the world, and which return a bool. Due to the way they are currently implemented, you can *only* use bare function systems as a run condition. Among other things, this prevents the use of system piping with run conditions. This make very basic constructs impossible, such as `my_system.run_if(my_condition.pipe(not))`.

Unblocks a basic solution for bevyengine#7202.

## Solution

Add the trait `ReadOnlySystem`, which is implemented for any system whose parameters all implement `ReadOnlySystemParam`. Allow any `-> bool` system implementing this trait to be used as a run condition.

---

## Changelog

+ Added the trait `ReadOnlySystem`, which is implemented for any `System` type whose parameters all implement `ReadOnlySystemParam`.
+ Added the function `bevy::ecs::system::assert_is_read_only_system`.
myreprise1 pushed a commit to myreprise1/bevy that referenced this issue Feb 15, 2023
# Objective

Closes bevyengine#7202

## Solution

~~Introduce a `not` helper to pipe conditions. Opened mostly for discussion. Maybe create an extension trait with `not` method? Please, advice.~~
Introduce `not(condition)` condition that inverses the result of the passed.

---

## Changelog

### Added

- `not` condition.
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-Usability A simple quality-of-life change that makes Bevy easier to use
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants