mirror of
https://github.com/bevyengine/bevy
synced 2024-11-25 22:20:20 +00:00
Optional .system()
, part 3 (#2422)
# Objective - Continue work of #2398 and #2403. - Make `.system()` syntax optional when using `.config()` API. ## Solution - Introduce new prelude trait, `ConfigurableSystem`, that shorthands `my_system.system().config(...)` as `my_system.config(...)`. - Expand `configure_system_local` test to also cover the new syntax.
This commit is contained in:
parent
c8e2415eaf
commit
afb33234db
3 changed files with 46 additions and 4 deletions
|
@ -29,8 +29,8 @@ pub mod prelude {
|
||||||
Schedule, Stage, StageLabel, State, SystemLabel, SystemSet, SystemStage,
|
Schedule, Stage, StageLabel, State, SystemLabel, SystemSet, SystemStage,
|
||||||
},
|
},
|
||||||
system::{
|
system::{
|
||||||
Commands, In, IntoChainSystem, IntoExclusiveSystem, IntoSystem, Local, NonSend,
|
Commands, ConfigurableSystem, In, IntoChainSystem, IntoExclusiveSystem, IntoSystem,
|
||||||
NonSendMut, Query, QuerySet, RemovedComponents, Res, ResMut, System,
|
Local, NonSend, NonSendMut, Query, QuerySet, RemovedComponents, Res, ResMut, System,
|
||||||
},
|
},
|
||||||
world::{FromWorld, Mut, World},
|
world::{FromWorld, Mut, World},
|
||||||
};
|
};
|
||||||
|
|
|
@ -263,6 +263,42 @@ impl<In, Out, Param: SystemParam, Marker, F> FunctionSystem<In, Out, Param, Mark
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Provides `my_system.config(...)` API.
|
||||||
|
pub trait ConfigurableSystem<In, Out, Param: SystemParam, Marker>:
|
||||||
|
IntoSystem<In, Out, (IsFunctionSystem, Param, Marker)>
|
||||||
|
{
|
||||||
|
/// See [`FunctionSystem::config()`](crate::system::FunctionSystem::config).
|
||||||
|
fn config(
|
||||||
|
self,
|
||||||
|
f: impl FnOnce(&mut <Param::Fetch as SystemParamState>::Config),
|
||||||
|
) -> Self::System;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<In, Out, Param: SystemParam, Marker, F> ConfigurableSystem<In, Out, Param, Marker> for F
|
||||||
|
where
|
||||||
|
In: 'static,
|
||||||
|
Out: 'static,
|
||||||
|
Param: SystemParam + 'static,
|
||||||
|
Marker: 'static,
|
||||||
|
F: SystemParamFunction<In, Out, Param, Marker>
|
||||||
|
+ IntoSystem<
|
||||||
|
In,
|
||||||
|
Out,
|
||||||
|
(IsFunctionSystem, Param, Marker),
|
||||||
|
System = FunctionSystem<In, Out, Param, Marker, F>,
|
||||||
|
> + Send
|
||||||
|
+ Sync
|
||||||
|
+ 'static,
|
||||||
|
{
|
||||||
|
fn config(
|
||||||
|
self,
|
||||||
|
f: impl FnOnce(&mut <<Param as SystemParam>::Fetch as SystemParamState>::Config),
|
||||||
|
) -> Self::System {
|
||||||
|
self.system().config(f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct IsFunctionSystem;
|
pub struct IsFunctionSystem;
|
||||||
|
|
||||||
impl<In, Out, Param, Marker, F> IntoSystem<In, Out, (IsFunctionSystem, Param, Marker)> for F
|
impl<In, Out, Param, Marker, F> IntoSystem<In, Out, (IsFunctionSystem, Param, Marker)> for F
|
||||||
|
|
|
@ -27,8 +27,8 @@ mod tests {
|
||||||
query::{Added, Changed, Or, With, Without},
|
query::{Added, Changed, Or, With, Without},
|
||||||
schedule::{Schedule, Stage, SystemStage},
|
schedule::{Schedule, Stage, SystemStage},
|
||||||
system::{
|
system::{
|
||||||
IntoExclusiveSystem, IntoSystem, Local, Query, QuerySet, RemovedComponents, Res,
|
ConfigurableSystem, IntoExclusiveSystem, IntoSystem, Local, Query, QuerySet,
|
||||||
ResMut, System, SystemState,
|
RemovedComponents, Res, ResMut, System, SystemState,
|
||||||
},
|
},
|
||||||
world::{FromWorld, World},
|
world::{FromWorld, World},
|
||||||
};
|
};
|
||||||
|
@ -372,7 +372,13 @@ mod tests {
|
||||||
|
|
||||||
// ensure the system actually ran
|
// ensure the system actually ran
|
||||||
assert!(*world.get_resource::<bool>().unwrap());
|
assert!(*world.get_resource::<bool>().unwrap());
|
||||||
|
|
||||||
|
// Now do the same with omitted `.system()`.
|
||||||
|
world.insert_resource(false);
|
||||||
|
run_system(&mut world, sys.config(|config| config.0 = Some(42)));
|
||||||
|
assert!(*world.get_resource::<bool>().unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn world_collections_system() {
|
fn world_collections_system() {
|
||||||
let mut world = World::default();
|
let mut world = World::default();
|
||||||
|
|
Loading…
Reference in a new issue