bevy/examples/ecs
JoJoJet 0c98f9a225 Add AND/OR combinators for run conditions (#7605)
# Objective

Fix #7584.

## Solution

Add an abstraction for creating custom system combinators with minimal boilerplate. Use this to implement AND/OR combinators. Use this to simplify the implementation of `PipeSystem`.

## Example

Feel free to bikeshed on the syntax.

I chose the names `and_then`/`or_else` to emphasize the fact that these short-circuit, while I chose method syntax to empasize that the arguments are *not* treated equally.

```rust
app.add_systems((
    my_system.run_if(resource_exists::<R>().and_then(resource_equals(R(0)))),
    our_system.run_if(resource_exists::<R>().or_else(resource_exists::<S>())),
));
```

---

## Todo

- [ ] Decide on a syntax
- [x] Write docs
- [x] Write tests

## Changelog

+ Added the extension methods `.and_then(...)` and `.or_else(...)` to run conditions, which allows combining run conditions with short-circuiting behavior.
+ Added the trait `Combine`, which can be used with the new `CombinatorSystem` to create system combinators with custom behavior.
2023-02-20 18:16:11 +00:00
..
component_change_detection.rs Deprecate ChangeTrackers<T> in favor of Ref<T> (#7306) 2023-02-19 16:19:56 +00:00
custom_query_param.rs fix nightly clippy warnings (#6395) 2022-10-28 21:03:01 +00:00
ecs_guide.rs Fix panics in ecs_guide example (#7525) 2023-02-08 23:01:53 +00:00
event.rs Replace the bool argument of Timer with TimerMode (#6247) 2022-10-17 13:47:01 +00:00
fixed_timestep.rs Migrate engine to Schedule v3 (#7267) 2023-02-06 02:04:50 +00:00
generic_system.rs Remove .on_update method to improve API consistency and clarity (#7667) 2023-02-14 00:13:10 +00:00
hierarchy.rs Base Sets (#7466) 2023-02-06 03:10:08 +00:00
iter_combinations.rs Base Sets (#7466) 2023-02-06 03:10:08 +00:00
nondeterministic_system_order.rs Cleanup ScheduleBuildSettings (#7721) 2023-02-17 15:17:52 +00:00
parallel_query.rs Base Sets (#7466) 2023-02-06 03:10:08 +00:00
removal_detection.rs Base Sets (#7466) 2023-02-06 03:10:08 +00:00
run_conditions.rs Add AND/OR combinators for run conditions (#7605) 2023-02-20 18:16:11 +00:00
startup_system.rs Doc/module style doc blocks for examples (#4438) 2022-05-16 13:53:20 +00:00
state.rs Fixed a typo in an example state.rs (#7666) 2023-02-14 01:16:33 +00:00
system_closure.rs fix nightly clippy warnings (#6395) 2022-10-28 21:03:01 +00:00
system_param.rs Spawn now takes a Bundle (#6054) 2022-09-23 19:55:54 +00:00
system_piping.rs Remove Anyhow::Result in system_piping.rs example (#7657) 2023-02-14 03:33:47 +00:00
timers.rs Replace the bool argument of Timer with TimerMode (#6247) 2022-10-17 13:47:01 +00:00