overhauled brake time processor

This commit is contained in:
Stephan Richter
2021-01-02 17:58:21 +01:00
parent 7b7980cc98
commit a74070ea80
7 changed files with 152 additions and 35 deletions

View File

@@ -93,6 +93,20 @@ public class ActionList extends Action implements Iterable<Action>{
return true;
}
public Integer getSpeed(Context context) {
Integer speed = null;
for (Action action : this) {
if (action instanceof SetSpeed) {
speed = ((SetSpeed)action).getSpeed();
}
if (action instanceof ActionList) {
Integer listSpeed = ((ActionList)action).getSpeed(context);
if (isSet(listSpeed)) speed = listSpeed;
}
}
return speed;
}
@Override
public Iterator<Action> iterator() {
return actions.iterator();

View File

@@ -34,6 +34,14 @@ public class ConditionalAction extends ActionList {
return super.fire(context.clone()); // actions, that happen within the conditional action list must not modify the global context.
}
@Override
public Integer getSpeed(Context context) {
for (Condition condition : conditions) {
if (!condition.fulfilledBy(context)) return null;
}
return super.getSpeed(context);
}
@Override
public JSONObject json() {
JSONObject json = super.json();

View File

@@ -51,6 +51,10 @@ public class SetSpeed extends Action{
return super.properties(preForm, formInputs, postForm);
}
public int getSpeed() {
return speed;
}
@Override
public String toString() {
return t("Set speed to {} {}",speed,speedUnit);