added builder pattern instead of object pool

This commit is contained in:
66945
2023-02-25 21:14:25 -07:00
parent 94f38856d1
commit e43c44a28c
2 changed files with 11 additions and 13 deletions
@@ -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