@@ -24,8 +24,11 @@ mod sealed {
2424}
2525
2626pub mod common_conditions {
27- use crate :: schedule:: { State , States } ;
28- use crate :: system:: { Res , Resource } ;
27+ use super :: Condition ;
28+ use crate :: {
29+ schedule:: { State , States } ,
30+ system:: { In , IntoPipeSystem , ReadOnlySystem , Res , Resource } ,
31+ } ;
2932
3033 /// Generates a [`Condition`](super::Condition)-satisfying closure that returns `true`
3134 /// if the first time the condition is run and false every time after
@@ -105,4 +108,37 @@ pub mod common_conditions {
105108 None => false ,
106109 }
107110 }
111+
112+ /// Generates a [`Condition`](super::Condition) that inverses the result of passed one.
113+ ///
114+ /// # Examples
115+ ///
116+ /// ```
117+ /// use bevy_ecs::prelude::*;
118+ /// // Building a new schedule/app...
119+ /// let mut sched = Schedule::default();
120+ /// sched.add_system(
121+ /// // This system will always run.
122+ /// my_system.run_if(not(always_false))
123+ /// )
124+ /// // ...
125+ /// # ;
126+ /// # let mut world = World::new();
127+ /// # sched.run(&mut world);
128+ ///
129+ /// // A condition that always returns false.
130+ /// fn always_false() -> bool {
131+ /// false
132+ /// }
133+ ///
134+ /// # fn my_system() {}
135+ /// ```
136+ pub fn not < Params , C : Condition < Params > > (
137+ condition : C ,
138+ ) -> impl ReadOnlySystem < In = ( ) , Out = bool >
139+ where
140+ C :: System : ReadOnlySystem ,
141+ {
142+ condition. pipe ( |In ( val) : In < bool > | !val)
143+ }
108144}
0 commit comments