-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathSeriesAction.java
52 lines (41 loc) · 1.19 KB
/
SeriesAction.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.team254.frc2019.auto.actions;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Executes one action at a time. Useful as a member of {@link ParallelAction}
*/
public class SeriesAction implements Action {
private Action mCurrentAction;
private final ArrayList<Action> mRemainingActions;
public SeriesAction(List<Action> actions) {
mRemainingActions = new ArrayList<>(actions);
mCurrentAction = null;
}
public SeriesAction(Action... actions) {
this(Arrays.asList(actions));
}
@Override
public void start() {}
@Override
public void update() {
if (mCurrentAction == null) {
if (mRemainingActions.isEmpty()) {
return;
}
mCurrentAction = mRemainingActions.remove(0);
mCurrentAction.start();
}
mCurrentAction.update();
if (mCurrentAction.isFinished()) {
mCurrentAction.done();
mCurrentAction = null;
}
}
@Override
public boolean isFinished() {
return mRemainingActions.isEmpty() && mCurrentAction == null;
}
@Override
public void done() {}
}