diff --git a/pom.xml b/pom.xml
index dac6610..0545ca8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
4.0.0
de.srsoftware
web4rail
- 0.10.6
+ 0.10.7
Web4Rail
jar
Java Model Railway Control
diff --git a/src/main/java/de/srsoftware/web4rail/actions/ConditionalAction.java b/src/main/java/de/srsoftware/web4rail/actions/ConditionalAction.java
index 1f2cf62..a57f5d8 100644
--- a/src/main/java/de/srsoftware/web4rail/actions/ConditionalAction.java
+++ b/src/main/java/de/srsoftware/web4rail/actions/ConditionalAction.java
@@ -39,7 +39,7 @@ public class ConditionalAction extends Action {
if (!conditions.isEmpty()) {
Tag list = new Tag("ul");
for (Condition condition : conditions) {
- link("li", Map.of(REALM,REALM_CONDITION,ID,id,ACTION,ACTION_PROPS,CONTEXT,params.get(CONTEXT)), condition).addTo(list);
+ link("li", Map.of(REALM,REALM_CONDITION,ID,condition.id(),ACTION,ACTION_PROPS,CONTEXT,params.get(CONTEXT)), condition).addTo(list);
}
list.addTo(fieldset);
}
diff --git a/src/main/java/de/srsoftware/web4rail/conditions/TrainLength.java b/src/main/java/de/srsoftware/web4rail/conditions/TrainLength.java
index 81017d7..5a47803 100644
--- a/src/main/java/de/srsoftware/web4rail/conditions/TrainLength.java
+++ b/src/main/java/de/srsoftware/web4rail/conditions/TrainLength.java
@@ -33,7 +33,7 @@ public class TrainLength extends Condition {
@Override
public Tag propForm(HashMap params) {
- return new Input(MAX_LENGTH, maxLength).addTo(new Label(t("Maximum train length:")+NBSP)).addTo(super.propForm(params));
+ return new Input(MAX_LENGTH, maxLength).numeric().addTo(new Label(t("Maximum train length:")+NBSP)).addTo(super.propForm(params));
}
@Override
diff --git a/src/main/java/de/srsoftware/web4rail/moving/Train.java b/src/main/java/de/srsoftware/web4rail/moving/Train.java
index 1c57e91..28640ba 100644
--- a/src/main/java/de/srsoftware/web4rail/moving/Train.java
+++ b/src/main/java/de/srsoftware/web4rail/moving/Train.java
@@ -152,6 +152,19 @@ public class Train extends BaseClass implements Comparable {
}
return t("Unknown action: {}",params.get(ACTION));
}
+
+ public void addToTrace(Vector newTiles) {
+ boolean active = trace.isEmpty();
+ for (Tile tile : newTiles) {
+ if (active) {
+ trace.addFirst(tile);
+ } else {
+ Tile dummy = trace.getFirst();
+ if (dummy == tile) active = true;
+ }
+ }
+ showTrace();
+ }
private Route chooseRoute(Context context) {
HashSet routes = block.routes();
@@ -270,10 +283,13 @@ public class Train extends BaseClass implements Comparable {
return props();
}
+ public void dropTrace() {
+ while (!trace.isEmpty()) trace.removeFirst().set(null);
+ }
+
public static Train get(int id) {
return trains.get(id);
}
-
public Train heading(Direction dir) {
direction = dir;
@@ -281,6 +297,10 @@ public class Train extends BaseClass implements Comparable {
return this;
}
+ public Tile headPos() {
+ return trace.getFirst();
+ }
+
private JSONObject json() {
JSONObject json = new JSONObject();
json.put(ID, id);
@@ -480,13 +500,6 @@ public class Train extends BaseClass implements Comparable {
return window;
}
- public SortedSet tags() {
- TreeSet list = new TreeSet(tags);
- for (Locomotive loco : locos) list.addAll(loco.tags());
- for (Car car:cars) list.addAll(car.tags());
- return list;
- }
-
public Object quitAutopilot() {
if (isSet(autopilot)) {
autopilot.stop = true;
@@ -495,6 +508,10 @@ public class Train extends BaseClass implements Comparable {
} else return t("autopilot not active.");
}
+ private void reverseTrace() {
+ // TODO Auto-generated method stub
+ }
+
public static void saveAll(String filename) throws IOException {
BufferedWriter file = new BufferedWriter(new FileWriter(filename));
for (Entry entry:trains.entrySet()) {
@@ -516,12 +533,33 @@ public class Train extends BaseClass implements Comparable {
return select;
}
+ public void set(Block newBlock) {
+ block = newBlock;
+ if (isSet(block)) block.set(this);
+ }
+
public void setSpeed(int v) {
LOG.debug("Setting speed to {} kmh.",v);
for (Locomotive loco : locos) loco.setSpeed(v);
this.speed = v;
}
+ public void showTrace() {
+ int remainingLength = length();
+ if (remainingLength<1) remainingLength=1;
+ for (int i=0; i0) {
+ remainingLength-=tile.length();
+ tile.set(this);
+ } else {
+ tile.set(null);
+ trace.remove(i);
+ i--; // do not move to next index: remove shifted the next index towards us
+ }
+ }
+ }
+
public String start() throws IOException {
if (isNull(block)) return t("{} not in a block",this);
Context context = isSet(route) ? new Context( route ) : new Context( this);
@@ -558,6 +596,14 @@ public class Train extends BaseClass implements Comparable {
return Translation.get(Application.class, message, fills);
}
+
+ public SortedSet tags() {
+ TreeSet list = new TreeSet(tags);
+ for (Locomotive loco : locos) list.addAll(loco.tags());
+ for (Car car:cars) list.addAll(car.tags());
+ return list;
+ }
+
@Override
public String toString() {
return isSet(name) ? name : locos.firstElement().name();
@@ -567,12 +613,13 @@ public class Train extends BaseClass implements Comparable {
LOG.debug("train.turn()");
if (isSet(direction)) {
direction = direction.inverse();
- for (Locomotive loco : locos) loco.turn();
+ for (Locomotive loco : locos) loco.turn();
+ reverseTrace();
+ if (isSet(block)) plan.place(block);
}
return t("{} turned.",this);
}
-
public Train update(HashMap params) {
LOG.debug("update({})",params);
pushPull = params.containsKey(PUSH_PULL) && params.get(PUSH_PULL).equals("on");
@@ -589,47 +636,8 @@ public class Train extends BaseClass implements Comparable {
return this;
}
- public void set(Block newBlock) {
- block = newBlock;
- if (isSet(block)) block.set(this);
- }
-
- public Tile headPos() {
- return trace.getFirst();
- }
-
- public void addToTrace(Vector newTiles) {
- boolean active = trace.isEmpty();
- for (Tile tile : newTiles) {
- if (active) {
- trace.addFirst(tile);
- } else {
- Tile dummy = trace.getFirst();
- if (dummy == tile) active = true;
- }
- }
- showTrace();
- }
- public void showTrace() {
- int remainingLength = length();
- if (remainingLength<1) remainingLength=1;
- for (int i=0; i0) {
- remainingLength-=tile.length();
- tile.set(this);
- } else {
- tile.set(null);
- trace.remove(i);
- i--; // do not move to next index: remove shifted the next index towards us
- }
- }
- }
- public void dropTrace() {
- while (!trace.isEmpty()) trace.removeFirst().set(null);
- }
public void removeFromTrace(Tile tile) {
trace.remove(tile);