package com.edinarobotics.utils.autonomous;

import edu.wpi.first.wpilibj.RobotBase;
import java.util.Vector;

/**
 * This class manages the executions of the several {@link AutonomousStep}
 * objects that are used in an autonomous program.
 */
public class AutonomousManager {
    private AutonomousStep[] autonomousSteps;
    private RobotBase robot;
    
    /**
     * Constructs an AutonomousManager using the given steps.
     * @param steps The steps that this AutonomousManager will run.
     * @param robot The robot that will be running these steps. This is 
     * used to check whether or not this robot is in autonomous.
     */
    public AutonomousManager(AutonomousStep[] steps, RobotBase robot){
        this.robot = robot;
        autonomousSteps = steps;
    }
    
    /**
     * Constructs an AutonomousManager using the given steps.
     * @param steps The steps that this AutonomousManager will run.
     * @param robot The robot that will be running these steps. This is 
     * used to check whether or not this robot is in autonomous.
     */
    public AutonomousManager(Vector steps, RobotBase robot){
        this(convertVector(steps), robot);
    }
    
    /**
     * Used internally to convert a Vector to an array of
     * AutonomousStep objects.
     * @param toConvert The Vector to convert to an array
     * @return an array of AutonomousStep objects.
     */
    private static AutonomousStep[] convertVector(Vector toConvert){
        AutonomousStep[] tempSteps = new AutonomousStep[toConvert.size()];
        for(int i=0;i<toConvert.size();i++){
            tempSteps[i] = (AutonomousStep)toConvert.elementAt(i);
        }
        return tempSteps;
    }
    
    /**
     * Starts this AutonomousManager. This method should only be called
     * once and will handle all of the steps.
     * This method will return when the autonomous phase ends or when all the
     * steps have finished.
     */
    public void start(){
        int currentStep = 0;
        autonomousSteps[currentStep].start();
        while(robot.isEnabled() && robot.isAutonomous()){
            //Autonomous loop
            if(!autonomousSteps[currentStep].isFinished()){
                //Step not finished, call run().
                autonomousSteps[currentStep].run();
            }
            else{
                //Step finished, call stop().
                autonomousSteps[currentStep].stop();
                currentStep++;
                if(currentStep>=autonomousSteps.length){
                    //All steps have run, we're done.
                    return;
                }
                autonomousSteps[currentStep].start();
            }
            //End of autonomous loop
        }
        autonomousSteps[currentStep].stop();
    }
}

@@ -38,16 +38,90 @@
 omous;%0A%0A
+import com.edinarobotics.utils.autonomous.conditions.AutonomousCondition;%0A
 import e
@@ -152,16 +152,16 @@
 otBase;%0A
-
 import j
@@ -403,31 +403,45 @@
 private 
-RobotBase robot
+BooleanCondition runCondition
 ;%0A    %0A 
@@ -810,22 +810,511 @@
 this
-.robot = robot
+(steps, new AutonomousCondition(robot));%0A    %7D%0A    %0A    /**%0A     * Constructs an AutonomousManager using the given steps.%0A     * @param steps The steps that this AutonomousManager will run.%0A     * @param runCondition The %7B@link BooleanCondition%7D that will be used%0A     * the test whether or not this AutonomousManager should continue running%0A     * in %7B@link #start()%7D.%0A     */%0A    public AutonomousManager(AutonomousStep%5B%5D steps, BooleanCondition runCondition)%7B%0A        this.runCondition = runCondition
 ;%0A  
@@ -2630,46 +2630,23 @@
 le(r
-obot.isEnabled() && robot.isAutonomous
+unCondition.get
 ())%7B

Change AutonomousManager to take BooleanCondition in the constructor.