implemented directional speeds and turning of train
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -4,7 +4,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>de.srsoftware</groupId>
|
||||
<artifactId>web4rail</artifactId>
|
||||
<version>1.2.33</version>
|
||||
<version>1.2.34</version>
|
||||
<name>Web4Rail</name>
|
||||
<packaging>jar</packaging>
|
||||
<description>Java Model Railway Control</description>
|
||||
|
||||
@@ -76,6 +76,8 @@ public class Car extends BaseClass implements Comparable<Car>{
|
||||
return car.moveUp();
|
||||
case ACTION_PROPS:
|
||||
return car == null ? Car.manager() : car.properties();
|
||||
case ACTION_TURN:
|
||||
return car.turn();
|
||||
case ACTION_UPDATE:
|
||||
return car.update(params);
|
||||
}
|
||||
@@ -198,7 +200,7 @@ public class Car extends BaseClass implements Comparable<Car>{
|
||||
}
|
||||
|
||||
public int maxSpeed() {
|
||||
return maxSpeedForward;
|
||||
return orientation == FORWARD ? maxSpeedForward : maxSpeedReverse;
|
||||
}
|
||||
|
||||
protected Window moveUp() {
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.util.Map;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.BaseClass;
|
||||
import de.srsoftware.web4rail.Command;
|
||||
import de.srsoftware.web4rail.Constants;
|
||||
import de.srsoftware.web4rail.Device;
|
||||
@@ -232,13 +233,14 @@ public class Locomotive extends Car implements Constants,Device{
|
||||
new Tag("p").content(t("Click on a name to edit the entry.")).addTo(win);
|
||||
|
||||
Table table = new Table().addHead(t("Stock ID"),t("Name"),t("Max. Speed",speedUnit),t("Protocol"),t("Address"),t("Length"),t("Tags"));
|
||||
cars.values()
|
||||
.stream()
|
||||
.filter(car -> car instanceof Locomotive)
|
||||
.map(car -> (Locomotive)car)
|
||||
.sorted(Comparator.comparing(loco -> loco.address))
|
||||
.sorted(Comparator.comparing(loco -> loco.stockId))
|
||||
.forEach(loco -> table.addRow(loco.stockId,loco.link(),loco.maxSpeedForward == 0 ? "–":loco.maxSpeedForward+NBSP+speedUnit,loco.proto,loco.address,loco.length+NBSP+lengthUnit,String.join(", ", loco.tags())));
|
||||
List<Locomotive> locos = BaseClass.listElements(Locomotive.class);
|
||||
locos.sort(Comparator.comparing(loco -> loco.address));
|
||||
locos.sort(Comparator.comparing(loco -> loco.stockId));
|
||||
for (Locomotive loco : locos) {
|
||||
String maxSpeed = (loco.maxSpeedForward == 0 ? "–":""+loco.maxSpeedForward)+NBSP;
|
||||
if (loco.maxSpeedReverse != loco.maxSpeedForward) maxSpeed += "("+loco.maxSpeedReverse+")"+NBSP;
|
||||
table.addRow(loco.stockId,loco.link(),maxSpeed+speedUnit,loco.proto,loco.address,loco.length+NBSP+lengthUnit,String.join(", ", loco.tags()));
|
||||
}
|
||||
table.addTo(win);
|
||||
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
@@ -215,12 +216,12 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
Tag locoProp = new Tag("li").content(t("Locomotives and cars:"));
|
||||
Tag carList = new Tag("ul").clazz("carlist");
|
||||
|
||||
for (Car loco : this.cars) {
|
||||
for (Car car : this.cars) {
|
||||
Tag li = new Tag("li");
|
||||
loco.link(loco.name()+(loco.stockId.isEmpty() ? "" : " ("+loco.stockId+")")).addTo(li).content(NBSP);
|
||||
loco.button(t("turn within train"),Map.of(ACTION,ACTION_TURN)).addTo(li);
|
||||
loco.button("↑",Map.of(ACTION,ACTION_MOVE)).addTo(li);
|
||||
button(t("delete"),Map.of(ACTION,ACTION_DROP,LOCO_ID,loco.id().toString())).addTo(li);
|
||||
car.link(car.name()+(car.stockId.isEmpty() ? "" : " ("+car.stockId+")")).addTo(li).content(NBSP);
|
||||
car.button(t("turn within train"),Map.of(ACTION,ACTION_TURN)).addTo(li);
|
||||
car.button("↑",Map.of(ACTION,ACTION_MOVE)).addTo(li);
|
||||
button(t("delete"),Map.of(ACTION,ACTION_DROP,LOCO_ID,car.id().toString())).addTo(li);
|
||||
li.addTo(carList);
|
||||
}
|
||||
|
||||
@@ -769,6 +770,9 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
|
||||
public Tag turn() {
|
||||
LOG.debug("train.turn()");
|
||||
|
||||
for (Car car : cars) car.turn();
|
||||
Collections.reverse(cars);
|
||||
if (isSet(direction)) {
|
||||
direction = direction.inverse();
|
||||
reverseTrace();
|
||||
|
||||
Reference in New Issue
Block a user