Implements three extension traits
* ConditionalInsertComponentsExt for EntityCommands and EntityMut\
with methods:
- insert_if
- insert_if_lazy
- insert_if_else
- insert_if_else_lazy
- insert_bundle_if
- insert_bundle_if_lazy
- insert_bundle_if_else
- insert_bundle_if_else_lazy
- insert_some
- insert_some_or
- insert_some_or_else
- insert_bundle_some
- insert_bundle_some_or
- insert_bundle_some_or_else
* ConditionalChildBuilderExt for EntityCommands\
with method:
- with_children_if
* ConditionalWorldChildBuilderExt for EntityMut\
with method:
- with_children_if
that allow for conditional component, bundle, and child insertion without the need for an intermediate EntityCommands or EntityMut binding.
The if_else methods are generic on both arguments, there is no requirement for the components or bundles to be of the same type.
#
insert_some_or_else methods. If present, insert the inner value of an Option, otherwise insert the alternative valueinsert_some methods. If present, insert the inner value of an Option.Implementated traits for EntityMut.
*_if_else methods.
```rust use conditional_commands::*;
struct Even;
struct Odd;
fn exclusivesystem(world: &mut World) { for n in 0..10 { world.spawn() .insertif_else(n % 2 == 0, Even, Odd); } } ```
#
Add to your Cargo.toml [Dependencies] section
conditional_commands = "0.6"
Then access with the use declaration
rust
use conditional_commands::*;
#
```rust use bevy::prelude::*;
struct Number(usize);
struct Fizz;
struct Buzz;
fn fizzbuzz
```rust use conditional_commands::*;
fn fizzbuzz
``` cargo run --example exclusize cargo run --example fizzbuzz cargo run --example insertif cargo run --example lazy cargo run --example withchildrenif
``` #
Some ergonomic compromises I had to make:
EntityCommands and EntityMut.Component or an Fn() -> Component. That doesn't seem possible because Rust doesn't have negative trait bound. So I have an explosion of ifelse / ifelse lazy methods that isn't very satisfying. Any solutions for either issue would be very welcome.
Considering seperating the lazy methods into a seperate trait or feature gating them.
Also not happy with the naming of the methods.