added builder pattern instead of object pool

This commit is contained in:
66945
2023-02-25 21:14:25 -07:00
parent bf00f64737
commit 0fa6749dbf
2 changed files with 11 additions and 13 deletions
@@ -105,8 +105,9 @@ public class RobotContainer {
// chooser.addOption("Taxi", taxi);
playbackChooser = new PlaybackChooser(m_robotSwerveDrive,
"Balance", new AutoBalance(m_robotMap.gyro, m_robotSwerveDrive));
playbackChooser = new PlaybackChooser(m_robotSwerveDrive)
.addOption("Balance", new AutoBalance(m_robotMap.gyro, m_robotSwerveDrive))
.buildDisplay();
}
@@ -137,9 +138,6 @@ public class RobotContainer {
"Blue1Path.txt"))
.onFalse(new InstantCommand());
// new JoystickButton(getDeadbandedDriverController(), XboxController.LEFT_BUMPER_BUTTON)
// .onTrue(new JoystickPlayback(m_robotSwerveDrive, "Blue1Path.txt"));
// * Operator Buttons
}
@@ -15,7 +15,7 @@ import frc4388.robot.subsystems.SwerveDrive;
public class PlaybackChooser {
private final ArrayList<SendableChooser<Command>> m_choosers = new ArrayList<>();
private final SendableChooser<Command> m_playback;
private SendableChooser<Command> m_playback = null;
private final HashMap<String, Command> m_commandPool = new HashMap<>();
private final File m_dir = new File("/home/lvuser/autos/");
@@ -26,21 +26,21 @@ public class PlaybackChooser {
public PlaybackChooser(SwerveDrive swerve, Object... pool) {
m_swerve = swerve;
}
for (int i = 0; i < pool.length; i += 2) {
if (!(pool[i] instanceof String) || !(pool[i + 1] instanceof Command)) {
throw new RuntimeException("Need (string, command)");
}
m_commandPool.put((String) pool[i], (Command) pool[i + 1]);
}
public PlaybackChooser addOption(String name, Command option) {
m_commandPool.put(name, option);
return this;
}
public PlaybackChooser buildDisplay() {
appendCommand();
m_playback = m_choosers.get(0);
Shuffleboard.getTab("Auto Chooser")
.add("Add Sequence", new InstantCommand(() -> appendCommand()))
.withPosition(4, 0);
return this;
}
// This will be bound to a button for the time being