[commands] RepeatCommand: restart on following iteration (#4706)

This fixes InstantCommand.repeatedly().
This commit is contained in:
Starlight220
2022-11-26 09:50:42 +02:00
committed by GitHub
parent dd1da77d20
commit 58ed112b51
7 changed files with 79 additions and 11 deletions

View File

@@ -16,15 +16,20 @@ RepeatCommand::RepeatCommand(std::unique_ptr<Command>&& command) {
}
void RepeatCommand::Initialize() {
m_ended = false;
m_command->Initialize();
}
void RepeatCommand::Execute() {
if (m_ended) {
m_ended = false;
m_command->Initialize();
}
m_command->Execute();
if (m_command->IsFinished()) {
// restart command
m_command->End(false);
m_command->Initialize();
m_ended = true;
}
}
@@ -39,3 +44,7 @@ void RepeatCommand::End(bool interrupted) {
bool RepeatCommand::RunsWhenDisabled() const {
return m_command->RunsWhenDisabled();
}
Command::InterruptionBehavior RepeatCommand::GetInterruptionBehavior() const {
return m_command->GetInterruptionBehavior();
}