[commands] Add onlyWhile and onlyIf (#5291)

This commit is contained in:
Joseph Eng
2023-04-30 14:09:02 -07:00
committed by GitHub
parent 40ca094686
commit ee3b4621e5
7 changed files with 183 additions and 3 deletions

View File

@@ -159,6 +159,17 @@ class CommandPtr final {
*/
[[nodiscard]] CommandPtr Until(std::function<bool()> condition) &&;
/**
* Decorates this command with a run condition. If the specified condition
* becomes false before the command finishes normally, the command will be
* interrupted and un-scheduled. Note that this only applies to the command
* returned by this method; the calling command is not itself changed.
*
* @param condition the interrupt condition
* @return the command with the interrupt condition added
*/
[[nodiscard]] CommandPtr OnlyWhile(std::function<bool()> condition) &&;
/**
* Decorates this command to only run if this condition is not met. If the
* command is already running and the condition changes to true, the command
@@ -170,6 +181,17 @@ class CommandPtr final {
*/
[[nodiscard]] CommandPtr Unless(std::function<bool()> condition) &&;
/**
* Decorates this command to only run if this condition is met. If the command
* is already running and the condition changes to false, the command will not
* stop running. The requirements of this command will be kept for the new
* conditional command.
*
* @param condition the condition that will allow the command to run
* @return the decorated command
*/
[[nodiscard]] CommandPtr OnlyIf(std::function<bool()> condition) &&;
/**
* Decorates this command with a set of commands to run parallel to it, ending
* when the calling command ends and interrupting all the others. Often more