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
@ -147,12 +147,7 @@ pub fn run_criteria_yes_with_query(criterion: &mut Criterion) {
|
|||||||
group.measurement_time(std::time::Duration::from_secs(3));
|
group.measurement_time(std::time::Duration::from_secs(3));
|
||||||
fn empty() {}
|
fn empty() {}
|
||||||
fn yes_with_query(query: Query<&TestBool>) -> ShouldRun {
|
fn yes_with_query(query: Query<&TestBool>) -> ShouldRun {
|
||||||
let test_bool = query.single();
|
query.single().0.into()
|
||||||
if test_bool.0 {
|
|
||||||
ShouldRun::Yes
|
|
||||||
} else {
|
|
||||||
ShouldRun::No
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for amount in 0..21 {
|
for amount in 0..21 {
|
||||||
let mut stage = SystemStage::parallel();
|
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));
|
group.measurement_time(std::time::Duration::from_secs(3));
|
||||||
fn empty() {}
|
fn empty() {}
|
||||||
fn yes_with_resource(res: Res<TestBool>) -> ShouldRun {
|
fn yes_with_resource(res: Res<TestBool>) -> ShouldRun {
|
||||||
if res.0 {
|
res.0.into()
|
||||||
ShouldRun::Yes
|
|
||||||
} else {
|
|
||||||
ShouldRun::No
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for amount in 0..21 {
|
for amount in 0..21 {
|
||||||
let mut stage = SystemStage::parallel();
|
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)]
|
#[derive(Default)]
|
||||||
pub(crate) struct BoxedRunCriteria {
|
pub(crate) struct BoxedRunCriteria {
|
||||||
criteria_system: Option<BoxedSystem<(), ShouldRun>>,
|
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.
|
/// Another run criteria, simply using a resource.
|
||||||
fn is_done(done: Res<Done>) -> ShouldRun {
|
fn is_done(done: Res<Done>) -> ShouldRun {
|
||||||
if done.0 {
|
done.0.into()
|
||||||
ShouldRun::Yes
|
|
||||||
} else {
|
|
||||||
ShouldRun::No
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Used with [`RunCritera::pipe`], inverts the result of the
|
/// Used with [`RunCritera::pipe`], inverts the result of the
|
||||||
|
Loading…
Reference in New Issue
Block a user