mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
Implement From<bool>
for ShouldRun
. (#5306)
Make writing simple yes/no run criteria easier. Co-authored-by: devil-ira <justthecooldude@gmail.com>
This commit is contained in:
parent
847f47d8d4
commit
234e5af882
3 changed files with 13 additions and 16 deletions
|
@ -147,12 +147,7 @@ pub fn run_criteria_yes_with_query(criterion: &mut Criterion) {
|
|||
group.measurement_time(std::time::Duration::from_secs(3));
|
||||
fn empty() {}
|
||||
fn yes_with_query(query: Query<&TestBool>) -> ShouldRun {
|
||||
let test_bool = query.single();
|
||||
if test_bool.0 {
|
||||
ShouldRun::Yes
|
||||
} else {
|
||||
ShouldRun::No
|
||||
}
|
||||
query.single().0.into()
|
||||
}
|
||||
for amount in 0..21 {
|
||||
let mut stage = SystemStage::parallel();
|
||||
|
@ -184,11 +179,7 @@ pub fn run_criteria_yes_with_resource(criterion: &mut Criterion) {
|
|||
group.measurement_time(std::time::Duration::from_secs(3));
|
||||
fn empty() {}
|
||||
fn yes_with_resource(res: Res<TestBool>) -> ShouldRun {
|
||||
if res.0 {
|
||||
ShouldRun::Yes
|
||||
} else {
|
||||
ShouldRun::No
|
||||
}
|
||||
res.0.into()
|
||||
}
|
||||
for amount in 0..21 {
|
||||
let mut stage = SystemStage::parallel();
|
||||
|
|
|
@ -56,6 +56,16 @@ impl ShouldRun {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<bool> for ShouldRun {
|
||||
fn from(value: bool) -> Self {
|
||||
if value {
|
||||
ShouldRun::Yes
|
||||
} else {
|
||||
ShouldRun::No
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub(crate) struct BoxedRunCriteria {
|
||||
criteria_system: Option<BoxedSystem<(), ShouldRun>>,
|
||||
|
|
|
@ -104,11 +104,7 @@ fn run_for_a_second(time: Res<Time>, mut done: ResMut<Done>) -> ShouldRun {
|
|||
|
||||
/// Another run criteria, simply using a resource.
|
||||
fn is_done(done: Res<Done>) -> ShouldRun {
|
||||
if done.0 {
|
||||
ShouldRun::Yes
|
||||
} else {
|
||||
ShouldRun::No
|
||||
}
|
||||
done.0.into()
|
||||
}
|
||||
|
||||
/// Used with [`RunCritera::pipe`], inverts the result of the
|
||||
|
|
Loading…
Reference in a new issue