vroious improvements

This commit is contained in:
Stephan Richter
2021-02-12 18:04:28 +01:00
parent 2973bd1432
commit c3242cddcb
10 changed files with 88 additions and 47 deletions

View File

@@ -81,12 +81,12 @@ public class ActionList extends Action implements Iterable<Action>{
}
public boolean fire(Context context) {
LOG.debug("{}.fire({})",this,context);
if (context.invalidated()) {
LOG.debug("Context has been invalidated, aborting {}",this);
return false;
}
if (!isEmpty()) LOG.debug(t("Firing {}"),actions);
if (!isEmpty()) LOG.debug("{}.fire({})",this,context);
for (Action action : actions) {
if (!action.fire(context)) return false;
}
@@ -94,12 +94,11 @@ public class ActionList extends Action implements Iterable<Action>{
}
public Integer getSpeed(Context context) {
LOG.debug("{}.getSpeed({})",this,context);
Integer speed = null;
for (Action action : this) {
if (action instanceof SetSpeed) {
speed = ((SetSpeed)action).getSpeed();
}
if (action instanceof ActionList) {
if (action instanceof SetSpeed) speed = ((SetSpeed)action).getSpeed();
if (isNull(speed) && action instanceof ActionList) {
Integer listSpeed = ((ActionList)action).getSpeed(context);
if (isSet(listSpeed)) speed = listSpeed;
}

View File

@@ -34,8 +34,9 @@ public class DelayedAction extends ActionList {
Application.threadPool.execute(new Thread() {
public void run() {
try {
Thread.sleep(min_delay + (min_delay < max_delay ? random.nextInt(max_delay - min_delay) : 0));
LOG.debug("{} ms passed by, firing actions:",min_delay);
int delay = min_delay + (min_delay < max_delay ? random.nextInt(max_delay - min_delay) : 0);
Thread.sleep(delay);
LOG.debug("{} ms passed by, firing actions:",delay);
} catch (InterruptedException e) {
LOG.warn("Interrupted Exception thrown while waiting:",e);
}

View File

@@ -4,6 +4,7 @@ import de.srsoftware.web4rail.BaseClass;
import de.srsoftware.web4rail.Range;
import de.srsoftware.web4rail.Route;
import de.srsoftware.web4rail.moving.Train;
import de.srsoftware.web4rail.tiles.Block;
public class PreserveRoute extends Action {
@@ -21,11 +22,12 @@ public class PreserveRoute extends Action {
// These are NOT errors:
if (!train.usesAutopilot()) return true; // do not reserve routes, when not in auto-mode
if (train.destination() == route.endBlock()) return true; // do not reserve routes, when destination has been reached
Block endBlock = route.endBlock();
if (train.destination() == endBlock) return true; // do not reserve routes, when destination has been reached
Range waitTime = route.endBlock().getWaitTime(train,route.endDirection);
Range waitTime = endBlock.getWaitTime(train,route.endDirection);
if (waitTime.max > 0) {
LOG.debug("Not preserving route, as train needs to stop in following block!");
LOG.debug("Not preserving route, as train needs to stop for {} ms at {}!",waitTime,endBlock);
return true; // train is expected to wait in next block.
}

View File

@@ -2,6 +2,7 @@ package de.srsoftware.web4rail.actions;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.json.JSONObject;
@@ -41,7 +42,7 @@ public class TriggerContact extends Action {
@Override
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
formInputs.add(t("Select contact"),Contact.selector(contact));
formInputs.add(t("Select contact")+": "+(isNull(contact) ? t("unset") : contact),button(t("Select from plan"),Map.of(ACTION,ACTION_UPDATE,ASSIGN,CONTACT)));
return super.properties(preForm, formInputs, postForm);
}