Merge branch 'directional-speeds-22'
This commit is contained in:
@@ -91,6 +91,7 @@ export : exportieren
|
|||||||
Faster (10 {}) : 10 {} schneller
|
Faster (10 {}) : 10 {} schneller
|
||||||
Firing {} : starte {}
|
Firing {} : starte {}
|
||||||
FinishRoute : Route abschließen
|
FinishRoute : Route abschließen
|
||||||
|
forward : vorwärts
|
||||||
Found {} routes. : {} Routen gefunden.
|
Found {} routes. : {} Routen gefunden.
|
||||||
FreeStartBlock : Start-Block freigeben
|
FreeStartBlock : Start-Block freigeben
|
||||||
Fullscreen : Vollbild
|
Fullscreen : Vollbild
|
||||||
@@ -156,6 +157,8 @@ quit autopilot : Autopilot beenden
|
|||||||
{} reached it`s destination! : {} ist am Ziel angekommen!
|
{} reached it`s destination! : {} ist am Ziel angekommen!
|
||||||
Relay/Turnout : Relais/Weiche
|
Relay/Turnout : Relais/Weiche
|
||||||
Report Issue : Problem melden
|
Report Issue : Problem melden
|
||||||
|
reverse : rückwärts
|
||||||
|
Reversed {}. : {} umgedreht.
|
||||||
RIGHT : rechts
|
RIGHT : rechts
|
||||||
Right port\: : Port für rechts
|
Right port\: : Port für rechts
|
||||||
Routes using this tile : Fahrstraßen, die diesen Abschnitt verwenden
|
Routes using this tile : Fahrstraßen, die diesen Abschnitt verwenden
|
||||||
@@ -210,7 +213,6 @@ STRAIGHT : gerade
|
|||||||
Switch power off : Strom ausschalten
|
Switch power off : Strom ausschalten
|
||||||
Switch power on : Strom anschalten
|
Switch power on : Strom anschalten
|
||||||
SYSTEM : Betriebssystem
|
SYSTEM : Betriebssystem
|
||||||
Tag : Markierung
|
|
||||||
Tags : Markierungen
|
Tags : Markierungen
|
||||||
Text to display on clients\: : Text, welcher auf den Clients angezeigt werden soll:
|
Text to display on clients\: : Text, welcher auf den Clients angezeigt werden soll:
|
||||||
Text to show on display\: : Text, welcher in der Anzeige dargestellt werden soll:
|
Text to show on display\: : Text, welcher in der Anzeige dargestellt werden soll:
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ import java.util.HashMap;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@@ -31,20 +31,24 @@ import de.srsoftware.web4rail.tags.Table;
|
|||||||
|
|
||||||
public class Car extends BaseClass implements Comparable<Car>{
|
public class Car extends BaseClass implements Comparable<Car>{
|
||||||
protected static final Logger LOG = LoggerFactory.getLogger(Car.class);
|
protected static final Logger LOG = LoggerFactory.getLogger(Car.class);
|
||||||
static HashMap<Id,Car> cars = new HashMap<Id, Car>();
|
|
||||||
|
|
||||||
public static final String NAME = "name";
|
public static final String NAME = "name";
|
||||||
|
public static boolean FORWARD = true;
|
||||||
|
public static boolean REVERSE = false;
|
||||||
private static final String LENGTH = "length";
|
private static final String LENGTH = "length";
|
||||||
private static final String STOCK_ID = "stock-id";
|
private static final String STOCK_ID = "stock-id";
|
||||||
private static final String TAGS = "tags";
|
private static final String TAGS = "tags";
|
||||||
private static final String MAX_SPEED = "max_speed";
|
private static final String MAX_SPEED = "max_speed";
|
||||||
|
private static final String MAX_SPEED_REVERSE = "max_speed_reverse";
|
||||||
protected HashSet<String> tags = new HashSet<String>();
|
protected HashSet<String> tags = new HashSet<String>();
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
public int length;
|
public int length;
|
||||||
protected String stockId = "";
|
protected String stockId = "";
|
||||||
private Train train;
|
private Train train;
|
||||||
protected int maxSpeed = 0;
|
protected int maxSpeedForward = 0;
|
||||||
|
protected int maxSpeedReverse = 0;
|
||||||
|
protected boolean orientation = FORWARD;
|
||||||
|
|
||||||
public Car(String name) {
|
public Car(String name) {
|
||||||
this(name,null);
|
this(name,null);
|
||||||
@@ -52,14 +56,13 @@ public class Car extends BaseClass implements Comparable<Car>{
|
|||||||
|
|
||||||
public Car(String name, Id id) {
|
public Car(String name, Id id) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
if (isNull(id)) id = new Id();
|
|
||||||
this.id = id;
|
this.id = id;
|
||||||
cars.put(id, this);
|
register();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object action(HashMap<String, String> params,Plan plan) throws IOException {
|
public static Object action(HashMap<String, String> params,Plan plan) throws IOException {
|
||||||
String id = params.get(ID);
|
String id = params.get(ID);
|
||||||
Car car = id == null ? null : Car.get(id);
|
Car car = id == null ? null : Car.get(new Id(id));
|
||||||
|
|
||||||
switch (params.get(ACTION)) {
|
switch (params.get(ACTION)) {
|
||||||
case ACTION_ADD:
|
case ACTION_ADD:
|
||||||
@@ -67,8 +70,12 @@ public class Car extends BaseClass implements Comparable<Car>{
|
|||||||
car.clone();
|
car.clone();
|
||||||
} else new Car(params.get(Car.NAME)).parent(plan);
|
} else new Car(params.get(Car.NAME)).parent(plan);
|
||||||
return Car.manager();
|
return Car.manager();
|
||||||
|
case ACTION_MOVE:
|
||||||
|
return car.moveUp();
|
||||||
case ACTION_PROPS:
|
case ACTION_PROPS:
|
||||||
return car == null ? Car.manager() : car.properties();
|
return car == null ? Car.manager() : car.properties();
|
||||||
|
case ACTION_TURN:
|
||||||
|
return car.turn();
|
||||||
case ACTION_UPDATE:
|
case ACTION_UPDATE:
|
||||||
return car.update(params);
|
return car.update(params);
|
||||||
}
|
}
|
||||||
@@ -78,7 +85,7 @@ public class Car extends BaseClass implements Comparable<Car>{
|
|||||||
|
|
||||||
public Car clone() {
|
public Car clone() {
|
||||||
Car clone = new Car(name);
|
Car clone = new Car(name);
|
||||||
clone.maxSpeed = maxSpeed;
|
clone.maxSpeedForward = maxSpeedForward;
|
||||||
clone.length = length;
|
clone.length = length;
|
||||||
clone.tags = new HashSet<String>(tags);
|
clone.tags = new HashSet<String>(tags);
|
||||||
clone.notes = notes;
|
clone.notes = notes;
|
||||||
@@ -90,16 +97,18 @@ public class Car extends BaseClass implements Comparable<Car>{
|
|||||||
private Button cloneButton() {
|
private Button cloneButton() {
|
||||||
return new Button(t("copy"),Map.of(REALM,REALM_CAR,ID,id(),ACTION,ACTION_ADD));
|
return new Button(t("copy"),Map.of(REALM,REALM_CAR,ID,id(),ACTION,ACTION_ADD));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Car get(Object id) {
|
|
||||||
return isNull(id) ? null : cars.get(new Id(""+id)); // try to get by id
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(Car o) {
|
||||||
|
return (stockId+":"+name).compareTo(o.stockId+":"+o.name);
|
||||||
|
}
|
||||||
|
|
||||||
public JSONObject json() {
|
public JSONObject json() {
|
||||||
JSONObject json = super.json();
|
JSONObject json = super.json();
|
||||||
json.put(NAME, name);
|
json.put(NAME, name);
|
||||||
json.put(LENGTH, length);
|
json.put(LENGTH, length);
|
||||||
if (maxSpeed != 0) json.put(MAX_SPEED, maxSpeed);
|
if (maxSpeedForward != 0) json.put(MAX_SPEED, maxSpeedForward);
|
||||||
|
if (maxSpeedReverse != 0) json.put(MAX_SPEED_REVERSE, maxSpeedReverse);
|
||||||
json.put(STOCK_ID, stockId);
|
json.put(STOCK_ID, stockId);
|
||||||
if (!tags.isEmpty()) json.put(TAGS, tags);
|
if (!tags.isEmpty()) json.put(TAGS, tags);
|
||||||
return json;
|
return json;
|
||||||
@@ -119,7 +128,6 @@ public class Car extends BaseClass implements Comparable<Car>{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void loadAll(String filename, Plan plan) throws IOException {
|
public static void loadAll(String filename, Plan plan) throws IOException {
|
||||||
cars.clear();
|
|
||||||
BufferedReader file = new BufferedReader(new FileReader(filename, UTF8));
|
BufferedReader file = new BufferedReader(new FileReader(filename, UTF8));
|
||||||
String line = file.readLine();
|
String line = file.readLine();
|
||||||
while (line != null) {
|
while (line != null) {
|
||||||
@@ -137,7 +145,11 @@ public class Car extends BaseClass implements Comparable<Car>{
|
|||||||
public Car load(JSONObject json) {
|
public Car load(JSONObject json) {
|
||||||
super.load(json);
|
super.load(json);
|
||||||
if (json.has(LENGTH)) length = json.getInt(LENGTH);
|
if (json.has(LENGTH)) length = json.getInt(LENGTH);
|
||||||
if (json.has(MAX_SPEED)) maxSpeed = json.getInt(MAX_SPEED);
|
if (json.has(MAX_SPEED)) {
|
||||||
|
maxSpeedForward = json.getInt(MAX_SPEED);
|
||||||
|
maxSpeedReverse = maxSpeedForward;
|
||||||
|
}
|
||||||
|
if (json.has(MAX_SPEED_REVERSE)) maxSpeedReverse = json.getInt(MAX_SPEED_REVERSE);
|
||||||
if (json.has(STOCK_ID)) stockId = json.getString(STOCK_ID);
|
if (json.has(STOCK_ID)) stockId = json.getString(STOCK_ID);
|
||||||
if (json.has(TAGS)) json.getJSONArray(TAGS).forEach(elem -> { tags.add(elem.toString()); });
|
if (json.has(TAGS)) json.getJSONArray(TAGS).forEach(elem -> { tags.add(elem.toString()); });
|
||||||
return this;
|
return this;
|
||||||
@@ -149,26 +161,30 @@ public class Car extends BaseClass implements Comparable<Car>{
|
|||||||
new Tag("p").content(t("Click on a name to edit the entry.")).addTo(win);
|
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("Length"),t("Train"),t("Tags"),t("Actions"));
|
Table table = new Table().addHead(t("Stock ID"),t("Name"),t("Max. Speed",speedUnit),t("Length"),t("Train"),t("Tags"),t("Actions"));
|
||||||
cars.values()
|
List<Car> cars = BaseClass.listElements(Car.class)
|
||||||
.stream()
|
.stream()
|
||||||
.filter(car -> !(car instanceof Locomotive))
|
.filter(car -> !(car instanceof Locomotive))
|
||||||
.sorted((c1,c2)->{
|
.sorted((c1,c2)->{
|
||||||
try {
|
try {
|
||||||
return Integer.parseInt(c1.stockId)-Integer.parseInt(c2.stockId);
|
return Integer.parseInt(c1.stockId)-Integer.parseInt(c2.stockId);
|
||||||
} catch (NumberFormatException nfe) {
|
} catch (NumberFormatException nfe) {
|
||||||
return c1.stockId.compareTo(c2.stockId);
|
return c1.stockId.compareTo(c2.stockId);
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
}).collect(Collectors.toList());
|
||||||
.forEach(car -> table.addRow(
|
for (Car car : cars) {
|
||||||
|
String maxSpeed = (car.maxSpeedForward == 0 ? "–":""+car.maxSpeedForward)+NBSP;
|
||||||
|
if (car.maxSpeedReverse != car.maxSpeedForward) maxSpeed += "("+car.maxSpeedReverse+")"+NBSP;
|
||||||
|
|
||||||
|
table.addRow(
|
||||||
car.stockId,
|
car.stockId,
|
||||||
car.link(),
|
car.link(),
|
||||||
car.maxSpeed == 0 ? "–":(car.maxSpeed+NBSP+speedUnit),
|
maxSpeed+speedUnit,
|
||||||
car.length+NBSP+lengthUnit,
|
car.length+NBSP+lengthUnit,
|
||||||
isSet(car.train) ? car.train.link("span", car.train) : "",
|
isSet(car.train) ? car.train.link("span", car.train) : "",
|
||||||
String.join(", ", car.tags()),
|
String.join(", ", car.tags()),
|
||||||
car.cloneButton()
|
car.cloneButton());
|
||||||
));
|
}
|
||||||
table.addTo(win);
|
table.addTo(win);
|
||||||
|
|
||||||
Form form = new Form("add-car-form");
|
Form form = new Form("add-car-form");
|
||||||
@@ -182,7 +198,12 @@ public class Car extends BaseClass implements Comparable<Car>{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int maxSpeed() {
|
public int maxSpeed() {
|
||||||
return maxSpeed;
|
return orientation == FORWARD ? maxSpeedForward : maxSpeedReverse;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Window moveUp() {
|
||||||
|
if (!isSet(train())) return properties();
|
||||||
|
return train().moveUp(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
String name(){
|
String name(){
|
||||||
@@ -194,8 +215,11 @@ public class Car extends BaseClass implements Comparable<Car>{
|
|||||||
formInputs.add(t("Name"),new Input(NAME,name));
|
formInputs.add(t("Name"),new Input(NAME,name));
|
||||||
formInputs.add(t("Stock ID"),new Input(STOCK_ID,stockId));
|
formInputs.add(t("Stock ID"),new Input(STOCK_ID,stockId));
|
||||||
formInputs.add(t("Length"),new Input(LENGTH,length).attr("type", "number").addTo(new Tag("span")).content(NBSP+lengthUnit));
|
formInputs.add(t("Length"),new Input(LENGTH,length).attr("type", "number").addTo(new Tag("span")).content(NBSP+lengthUnit));
|
||||||
formInputs.add(t("Tag"), new Input(TAGS,String.join(", ", tags)));
|
formInputs.add(t("Tags"), new Input(TAGS,String.join(", ", tags)));
|
||||||
formInputs.add(t("Maximum Speed"),new Input(MAX_SPEED, maxSpeed).numeric().addTo(new Tag("span")).content(NBSP+speedUnit));
|
Tag div = new Tag("div");
|
||||||
|
new Input(MAX_SPEED, maxSpeedForward).numeric().addTo(new Tag("p")).content(NBSP+speedUnit+NBSP+t("forward")).addTo(div);
|
||||||
|
new Input(MAX_SPEED_REVERSE, maxSpeedReverse).numeric().addTo(new Tag("p")).content(NBSP+speedUnit+NBSP+t("reverse")).addTo(div);
|
||||||
|
formInputs.add(t("Maximum Speed"),div);
|
||||||
|
|
||||||
Fieldset fieldset = new Fieldset(t("Train"));
|
Fieldset fieldset = new Fieldset(t("Train"));
|
||||||
if (train != null) train.link().addTo(fieldset);
|
if (train != null) train.link().addTo(fieldset);
|
||||||
@@ -214,7 +238,7 @@ public class Car extends BaseClass implements Comparable<Car>{
|
|||||||
|
|
||||||
public static void saveAll(String filename) throws IOException {
|
public static void saveAll(String filename) throws IOException {
|
||||||
BufferedWriter file = new BufferedWriter(new FileWriter(filename));
|
BufferedWriter file = new BufferedWriter(new FileWriter(filename));
|
||||||
for (Entry<Id, Car> entry: cars.entrySet()) file.write(entry.getValue().json()+"\n");
|
for (Car car : BaseClass.listElements(Car.class)) file.write(car.json()+"\n");
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,7 +267,8 @@ public class Car extends BaseClass implements Comparable<Car>{
|
|||||||
super.update(params);
|
super.update(params);
|
||||||
if (params.containsKey(NAME)) name = params.get(NAME).trim();
|
if (params.containsKey(NAME)) name = params.get(NAME).trim();
|
||||||
if (params.containsKey(LENGTH)) length = Integer.parseInt(params.get(LENGTH));
|
if (params.containsKey(LENGTH)) length = Integer.parseInt(params.get(LENGTH));
|
||||||
if (params.containsKey(MAX_SPEED)) maxSpeed = Integer.parseInt(params.get(MAX_SPEED));
|
if (params.containsKey(MAX_SPEED)) maxSpeedForward = Integer.parseInt(params.get(MAX_SPEED));
|
||||||
|
if (params.containsKey(MAX_SPEED_REVERSE)) maxSpeedReverse = Integer.parseInt(params.get(MAX_SPEED_REVERSE));
|
||||||
if (params.containsKey(STOCK_ID)) stockId = params.get(STOCK_ID);
|
if (params.containsKey(STOCK_ID)) stockId = params.get(STOCK_ID);
|
||||||
if (params.containsKey(TAGS)) {
|
if (params.containsKey(TAGS)) {
|
||||||
String[] parts = params.get(TAGS).replace(",", " ").split(" ");
|
String[] parts = params.get(TAGS).replace(",", " ").split(" ");
|
||||||
@@ -256,8 +281,8 @@ public class Car extends BaseClass implements Comparable<Car>{
|
|||||||
return properties();
|
return properties();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public String turn() {
|
||||||
public int compareTo(Car o) {
|
orientation = !orientation;
|
||||||
return (stockId+":"+name).compareTo(o.stockId+":"+o.name);
|
return t("Reversed {}.",this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import java.util.Map;
|
|||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import de.srsoftware.tools.Tag;
|
import de.srsoftware.tools.Tag;
|
||||||
|
import de.srsoftware.web4rail.BaseClass;
|
||||||
import de.srsoftware.web4rail.Command;
|
import de.srsoftware.web4rail.Command;
|
||||||
import de.srsoftware.web4rail.Constants;
|
import de.srsoftware.web4rail.Constants;
|
||||||
import de.srsoftware.web4rail.Device;
|
import de.srsoftware.web4rail.Device;
|
||||||
@@ -28,7 +29,6 @@ public class Locomotive extends Car implements Constants,Device{
|
|||||||
|
|
||||||
private static final String REVERSE = "reverse";
|
private static final String REVERSE = "reverse";
|
||||||
public static final String LOCOMOTIVE = "locomotive";
|
public static final String LOCOMOTIVE = "locomotive";
|
||||||
boolean reverse = false;
|
|
||||||
private Protocol proto = Protocol.DCC128;
|
private Protocol proto = Protocol.DCC128;
|
||||||
private int address = 3;
|
private int address = 3;
|
||||||
private int speed = 0;
|
private int speed = 0;
|
||||||
@@ -45,13 +45,15 @@ public class Locomotive extends Car implements Constants,Device{
|
|||||||
|
|
||||||
public static Object action(HashMap<String, String> params, Plan plan) throws IOException {
|
public static Object action(HashMap<String, String> params, Plan plan) throws IOException {
|
||||||
String id = params.get(ID);
|
String id = params.get(ID);
|
||||||
Locomotive loco = id == null ? null : Locomotive.get(id);
|
Locomotive loco = id == null ? null : BaseClass.get(new Id(id));
|
||||||
switch (params.get(ACTION)) {
|
switch (params.get(ACTION)) {
|
||||||
case ACTION_ADD:
|
case ACTION_ADD:
|
||||||
new Locomotive(params.get(Locomotive.NAME)).parent(plan).register();
|
new Locomotive(params.get(Locomotive.NAME)).parent(plan).register();
|
||||||
return Locomotive.manager();
|
return Locomotive.manager();
|
||||||
case ACTION_FASTER10:
|
case ACTION_FASTER10:
|
||||||
return loco.faster(10);
|
return loco.faster(10);
|
||||||
|
case ACTION_MOVE:
|
||||||
|
return loco.moveUp();
|
||||||
case ACTION_PROPS:
|
case ACTION_PROPS:
|
||||||
return loco == null ? Locomotive.manager() : loco.properties();
|
return loco == null ? Locomotive.manager() : loco.properties();
|
||||||
case ACTION_SLOWER10:
|
case ACTION_SLOWER10:
|
||||||
@@ -75,7 +77,7 @@ public class Locomotive extends Car implements Constants,Device{
|
|||||||
|
|
||||||
return t("Unknown action: {}",params.get(ACTION));
|
return t("Unknown action: {}",params.get(ACTION));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int address() {
|
public int address() {
|
||||||
return address;
|
return address;
|
||||||
@@ -161,12 +163,6 @@ public class Locomotive extends Car implements Constants,Device{
|
|||||||
return properties();
|
return properties();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Locomotive get(Object id) {
|
|
||||||
Car car = Car.get(id);
|
|
||||||
if (car instanceof Locomotive) return (Locomotive) car;
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void init() {
|
private void init() {
|
||||||
if (init) return;
|
if (init) return;
|
||||||
String proto = null;
|
String proto = null;
|
||||||
@@ -205,7 +201,7 @@ public class Locomotive extends Car implements Constants,Device{
|
|||||||
public JSONObject json() {
|
public JSONObject json() {
|
||||||
JSONObject json = super.json();
|
JSONObject json = super.json();
|
||||||
JSONObject loco = new JSONObject();
|
JSONObject loco = new JSONObject();
|
||||||
loco.put(REVERSE, reverse);
|
loco.put(REVERSE, orientation);
|
||||||
loco.put(PROTOCOL, proto);
|
loco.put(PROTOCOL, proto);
|
||||||
loco.put(ADDRESS, address);
|
loco.put(ADDRESS, address);
|
||||||
json.put(LOCOMOTIVE, loco);
|
json.put(LOCOMOTIVE, loco);
|
||||||
@@ -217,7 +213,7 @@ public class Locomotive extends Car implements Constants,Device{
|
|||||||
super.load(json);
|
super.load(json);
|
||||||
if (json.has(LOCOMOTIVE)) {
|
if (json.has(LOCOMOTIVE)) {
|
||||||
JSONObject loco = json.getJSONObject(LOCOMOTIVE);
|
JSONObject loco = json.getJSONObject(LOCOMOTIVE);
|
||||||
if (loco.has(REVERSE)) reverse = loco.getBoolean(REVERSE);
|
if (loco.has(REVERSE)) orientation = loco.getBoolean(REVERSE);
|
||||||
if (loco.has(PROTOCOL)) proto = Protocol.valueOf(loco.getString(PROTOCOL));
|
if (loco.has(PROTOCOL)) proto = Protocol.valueOf(loco.getString(PROTOCOL));
|
||||||
if (loco.has(ADDRESS)) address = loco.getInt(ADDRESS);
|
if (loco.has(ADDRESS)) address = loco.getInt(ADDRESS);
|
||||||
}
|
}
|
||||||
@@ -231,13 +227,14 @@ public class Locomotive extends Car implements Constants,Device{
|
|||||||
new Tag("p").content(t("Click on a name to edit the entry.")).addTo(win);
|
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"));
|
Table table = new Table().addHead(t("Stock ID"),t("Name"),t("Max. Speed",speedUnit),t("Protocol"),t("Address"),t("Length"),t("Tags"));
|
||||||
cars.values()
|
List<Locomotive> locos = BaseClass.listElements(Locomotive.class);
|
||||||
.stream()
|
locos.sort(Comparator.comparing(loco -> loco.address));
|
||||||
.filter(car -> car instanceof Locomotive)
|
locos.sort(Comparator.comparing(loco -> loco.stockId));
|
||||||
.map(car -> (Locomotive)car)
|
for (Locomotive loco : locos) {
|
||||||
.sorted(Comparator.comparing(loco -> loco.address))
|
String maxSpeed = (loco.maxSpeedForward == 0 ? "–":""+loco.maxSpeedForward)+NBSP;
|
||||||
.sorted(Comparator.comparing(loco -> loco.stockId))
|
if (loco.maxSpeedReverse != loco.maxSpeedForward) maxSpeed += "("+loco.maxSpeedReverse+")"+NBSP;
|
||||||
.forEach(loco -> table.addRow(loco.stockId,loco.link(),loco.maxSpeed == 0 ? "–":loco.maxSpeed+NBSP+speedUnit,loco.proto,loco.address,loco.length+NBSP+lengthUnit,String.join(", ", loco.tags())));
|
table.addRow(loco.stockId,loco.link(),maxSpeed+speedUnit,loco.proto,loco.address,loco.length+NBSP+lengthUnit,String.join(", ", loco.tags()));
|
||||||
|
}
|
||||||
table.addTo(win);
|
table.addTo(win);
|
||||||
|
|
||||||
|
|
||||||
@@ -264,8 +261,8 @@ public class Locomotive extends Car implements Constants,Device{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void queue() {
|
private void queue() {
|
||||||
int step = proto.steps * speed / (maxSpeed == 0 ? 100 : maxSpeed);
|
int step = proto.steps * speed / (maxSpeedForward == 0 ? 100 : maxSpeedForward);
|
||||||
plan.queue(new Command("SET {} GL "+address+" "+(reverse?1:0)+" "+step+" "+proto.steps+" "+(f1?1:0)+" "+(f2?1:0)+" "+(f3?1:0)+" "+(f4?1:0)) {
|
plan.queue(new Command("SET {} GL "+address+" "+(orientation == FORWARD ? 0 : 1)+" "+step+" "+proto.steps+" "+(f1?1:0)+" "+(f2?1:0)+" "+(f3?1:0)+" "+(f4?1:0)) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Reply reply) {
|
public void onFailure(Reply reply) {
|
||||||
@@ -284,7 +281,7 @@ public class Locomotive extends Car implements Constants,Device{
|
|||||||
LOG.debug(this.detail()+".setSpeed({})",newSpeed);
|
LOG.debug(this.detail()+".setSpeed({})",newSpeed);
|
||||||
init();
|
init();
|
||||||
speed = newSpeed;
|
speed = newSpeed;
|
||||||
if (speed > maxSpeed && maxSpeed > 0) speed = maxSpeed();
|
if (speed > maxSpeedForward && maxSpeedForward > 0) speed = maxSpeed();
|
||||||
if (speed < 0) speed = 0;
|
if (speed < 0) speed = 0;
|
||||||
|
|
||||||
queue();
|
queue();
|
||||||
@@ -322,9 +319,9 @@ public class Locomotive extends Car implements Constants,Device{
|
|||||||
return t("{} F{}",t(active?"Activated":"Deavtivated"),f);
|
return t("{} F{}",t(active?"Activated":"Deavtivated"),f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object turn() {
|
public String turn() {
|
||||||
reverse = !reverse;
|
|
||||||
stop();
|
stop();
|
||||||
|
super.turn();
|
||||||
return t("Stopped and reversed {}.",this);
|
return t("Stopped and reversed {}.",this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import java.io.FileWriter;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
@@ -65,10 +66,8 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
public boolean pushPull = false;
|
public boolean pushPull = false;
|
||||||
|
|
||||||
private static final String CARS = "cars";
|
private static final String CARS = "cars";
|
||||||
|
private static final String LOCOS = "locomotives";
|
||||||
private Vector<Car> cars = new Vector<Car>();
|
private Vector<Car> cars = new Vector<Car>();
|
||||||
|
|
||||||
private static final String LOCOS = "locomotives";
|
|
||||||
private Vector<Locomotive> locos = new Vector<Locomotive>();
|
|
||||||
|
|
||||||
private static final String TAGS = "tags";
|
private static final String TAGS = "tags";
|
||||||
|
|
||||||
@@ -179,8 +178,9 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
|
|
||||||
private Object addCar(HashMap<String, String> params) {
|
private Object addCar(HashMap<String, String> params) {
|
||||||
LOG.debug("addCar({})",params);
|
LOG.debug("addCar({})",params);
|
||||||
if (!params.containsKey(CAR_ID)) return t("No car id passed to Train.addCar!");
|
String carId = params.get(CAR_ID);
|
||||||
Car car = Car.get(params.get(CAR_ID));
|
if (isNull(carId)) return t("No car id passed to Train.addCar!");
|
||||||
|
Car car = BaseClass.get(new Id(carId));
|
||||||
if (isNull(car)) return t("No car with id \"{}\" known!",params.get(CAR_ID));
|
if (isNull(car)) return t("No car with id \"{}\" known!",params.get(CAR_ID));
|
||||||
add(car);
|
add(car);
|
||||||
return properties();
|
return properties();
|
||||||
@@ -188,9 +188,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
|
|
||||||
public void add(Car car) {
|
public void add(Car car) {
|
||||||
if (isNull(car)) return;
|
if (isNull(car)) return;
|
||||||
if (car instanceof Locomotive) {
|
cars.add(car);
|
||||||
locos.add((Locomotive) car);
|
|
||||||
} else cars.add(car);
|
|
||||||
car.train(this);
|
car.train(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,41 +207,54 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
|
|
||||||
public String brakeId(boolean reversed) {
|
public String brakeId(boolean reversed) {
|
||||||
TreeSet<String> carIds = new TreeSet<String>();
|
TreeSet<String> carIds = new TreeSet<String>();
|
||||||
locos.stream().map(loco -> loco.id()+":"+(reversed != loco.reverse?"r":"f")).forEach(carIds::add);
|
cars.stream().map(car -> car.id()+":"+(car.orientation == reversed ? "r":"f")).forEach(carIds::add);
|
||||||
cars.stream().map(car -> ""+car.id()).forEach(carIds::add);
|
|
||||||
String brakeId = md5sum(carIds);
|
String brakeId = md5sum(carIds);
|
||||||
LOG.debug("generated new brake id for {}: {}",this,brakeId);
|
LOG.debug("generated new brake id for {}: {}",this,brakeId);
|
||||||
return brakeId;
|
return brakeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Tag carList() {
|
private Tag carList() {
|
||||||
Tag locoProp = new Tag("li").content(t("Cars:"));
|
Tag locoProp = new Tag("li").content(t("Locomotives and cars:"));
|
||||||
Tag locoList = new Tag("ul").clazz("carlist").content("");
|
Tag carList = new Tag("ul").clazz("carlist");
|
||||||
|
|
||||||
for (Car car : this.cars) {
|
for (Car car : this.cars) {
|
||||||
Tag li = new Tag("li");
|
Tag li = new Tag("li");
|
||||||
car.link(car.name()+(car.stockId.isEmpty() ? "" : " ("+car.stockId+")")).addTo(li).content(NBSP);
|
car.link(car.name()+(car.stockId.isEmpty() ? "" : " ("+car.stockId+")")).addTo(li).content(NBSP);
|
||||||
button(t("delete"),Map.of(ACTION,ACTION_DROP,CAR_ID,car.id().toString())).addTo(li);
|
car.button(t("turn within train"),Map.of(ACTION,ACTION_TURN)).addTo(li);
|
||||||
li.addTo(locoList);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
Form addCarForm = new Form("append-car-form");
|
List<Locomotive> locos = BaseClass.listElements(Locomotive.class).stream().filter(loco -> isNull(loco.train())).collect(Collectors.toList());
|
||||||
addCarForm.content(t("add car:")+" ");
|
if (!locos.isEmpty()) {
|
||||||
new Input(REALM, REALM_TRAIN).hideIn(addCarForm);
|
Form addLocoForm = new Form("append-loco-form");
|
||||||
new Input(ACTION, ACTION_ADD).hideIn(addCarForm);
|
addLocoForm.content(t("add locomotive:")+" ");
|
||||||
new Input(ID,id).hideIn(addCarForm);
|
new Input(REALM, REALM_TRAIN).hideIn(addLocoForm);
|
||||||
Select select = new Select(CAR_ID);
|
new Input(ACTION, ACTION_ADD).hideIn(addLocoForm);
|
||||||
for (Car car : BaseClass.listElements(Car.class)) {
|
new Input(ID,id).hideIn(addLocoForm);
|
||||||
if (car instanceof Locomotive) continue;
|
Select select = new Select(CAR_ID);
|
||||||
if (isSet(car.train())) continue;
|
for (Car loco : locos) select.addOption(loco.id(), loco);
|
||||||
select.addOption(car.id(), car+(car.stockId.isEmpty()?"":" ("+car.stockId+")"));
|
select.addTo(addLocoForm);
|
||||||
|
new Button(t("add"),addLocoForm).addTo(addLocoForm);
|
||||||
|
addLocoForm.addTo(new Tag("li")).addTo(carList);
|
||||||
}
|
}
|
||||||
if (!select.children().isEmpty()) {
|
|
||||||
select.addTo(addCarForm);
|
List<Car> cars = BaseClass.listElements(Car.class).stream().filter(car -> !(car instanceof Locomotive)).filter(loco -> isNull(loco.train())).collect(Collectors.toList());
|
||||||
new Button(t("add"),addCarForm).addTo(addCarForm);
|
if (!cars.isEmpty()) {
|
||||||
addCarForm.addTo(new Tag("li")).addTo(locoList);
|
Form addCarForm = new Form("append-car-form");
|
||||||
}
|
addCarForm.content(t("add car:")+" ");
|
||||||
return locoList.addTo(locoProp);
|
new Input(REALM, REALM_TRAIN).hideIn(addCarForm);
|
||||||
|
new Input(ACTION, ACTION_ADD).hideIn(addCarForm);
|
||||||
|
new Input(ID,id).hideIn(addCarForm);
|
||||||
|
Select select = new Select(CAR_ID);
|
||||||
|
for (Car car : cars) select.addOption(car.id(), car+(car.stockId.isEmpty()?"":" ("+car.stockId+")"));
|
||||||
|
select.addTo(addCarForm);
|
||||||
|
new Button(t("add"),addCarForm).addTo(addCarForm);
|
||||||
|
addCarForm.addTo(new Tag("li")).addTo(carList);
|
||||||
|
}
|
||||||
|
return carList.addTo(locoProp);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Car> cars(){
|
public List<Car> cars(){
|
||||||
@@ -256,7 +267,9 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static Object create(HashMap<String, String> params, Plan plan) {
|
private static Object create(HashMap<String, String> params, Plan plan) {
|
||||||
Locomotive loco = (Locomotive) Locomotive.get(params.get(Train.LOCO_ID));
|
String locoId = params.get(Train.LOCO_ID);
|
||||||
|
if (isNull(locoId)) return t("Need loco id to create new train!");
|
||||||
|
Locomotive loco = BaseClass.get(new Id(locoId));
|
||||||
if (isNull(loco)) return t("unknown locomotive: {}",params.get(ID));
|
if (isNull(loco)) return t("unknown locomotive: {}",params.get(ID));
|
||||||
Train train = new Train(loco);
|
Train train = new Train(loco);
|
||||||
train.parent(plan);
|
train.parent(plan);
|
||||||
@@ -297,16 +310,13 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Object dropCar(HashMap<String, String> params) {
|
private Object dropCar(HashMap<String, String> params) {
|
||||||
Car car = Car.get(params.get(CAR_ID));
|
String carId = params.get(CAR_ID);
|
||||||
|
if (isNull(carId)) return t("Cannot drop car without car id!");
|
||||||
|
Car car = BaseClass.get(new Id(carId));
|
||||||
if (isSet(car)) {
|
if (isSet(car)) {
|
||||||
cars.remove(car);
|
cars.remove(car);
|
||||||
car.train(null);
|
car.train(null);
|
||||||
}
|
}
|
||||||
Locomotive loco = Locomotive.get(params.get(LOCO_ID));
|
|
||||||
if (isSet(loco)) {
|
|
||||||
locos.remove(loco);
|
|
||||||
loco.train(null);
|
|
||||||
}
|
|
||||||
return properties();
|
return properties();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -342,7 +352,6 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
if (isSet(route)) json.put(ROUTE, route.id());
|
if (isSet(route)) json.put(ROUTE, route.id());
|
||||||
if (isSet(direction)) json.put(DIRECTION, direction);
|
if (isSet(direction)) json.put(DIRECTION, direction);
|
||||||
|
|
||||||
json.put(LOCOS, locos.stream().map(l -> l.id().toString()).collect(Collectors.toList()));
|
|
||||||
json.put(CARS,cars.stream().map(c -> c.id().toString()).collect(Collectors.toList()));
|
json.put(CARS,cars.stream().map(c -> c.id().toString()).collect(Collectors.toList()));
|
||||||
json.put(TRACE, trace.stream().map(t -> t.id().toString()).collect(Collectors.toList()));
|
json.put(TRACE, trace.stream().map(t -> t.id().toString()).collect(Collectors.toList()));
|
||||||
|
|
||||||
@@ -352,7 +361,6 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
|
|
||||||
public int length() {
|
public int length() {
|
||||||
int result = 0;
|
int result = 0;
|
||||||
for (Locomotive loco : locos) result += loco.length;
|
|
||||||
for (Car car : cars) result += car.length;
|
for (Car car : cars) result += car.length;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -397,46 +405,14 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
if (json.has(TAGS)) json.getJSONArray(TAGS ).forEach(elem -> { tags.add(elem.toString()); });
|
if (json.has(TAGS)) json.getJSONArray(TAGS ).forEach(elem -> { tags.add(elem.toString()); });
|
||||||
if (json.has(TRACE)) json.getJSONArray(TRACE).forEach(elem -> { trace.add(plan.get(new Id(elem.toString()), false).set(this)); });
|
if (json.has(TRACE)) json.getJSONArray(TRACE).forEach(elem -> { trace.add(plan.get(new Id(elem.toString()), false).set(this)); });
|
||||||
if (json.has(BLOCK)) currentBlock = (Block) plan.get(new Id(json.getString(BLOCK)), false).set(this); // do not move this up! during set, other fields will be referenced!
|
if (json.has(BLOCK)) currentBlock = (Block) plan.get(new Id(json.getString(BLOCK)), false).set(this); // do not move this up! during set, other fields will be referenced!
|
||||||
for (Object id : json.getJSONArray(CARS)) add(Car.get(id));
|
if (json.has(LOCOS)) { // for downward compatibility
|
||||||
for (Object id : json.getJSONArray(LOCOS)) add((Locomotive) Car.get(id));
|
for (Object id : json.getJSONArray(LOCOS)) add(BaseClass.get(new Id(""+id)));
|
||||||
|
}
|
||||||
|
for (Object id : json.getJSONArray(CARS)) add(BaseClass.get(new Id(""+id)));
|
||||||
super.load(json);
|
super.load(json);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Tag locoList() {
|
|
||||||
Tag locoProp = new Tag("li").content(t("Locomotives:"));
|
|
||||||
Tag locoList = new Tag("ul").clazz("locolist");
|
|
||||||
|
|
||||||
for (Locomotive loco : this.locos) {
|
|
||||||
Tag li = new Tag("li");
|
|
||||||
loco.link(loco.name()+(loco.stockId.isEmpty() ? "" : " ("+loco.stockId+")")).addTo(li);
|
|
||||||
loco.button(t("turn within train"),Map.of(ACTION,ACTION_TURN)).addTo(li);
|
|
||||||
button(t("delete"),Map.of(ACTION,ACTION_DROP,LOCO_ID,loco.id().toString())).addTo(li);
|
|
||||||
li.addTo(locoList);
|
|
||||||
}
|
|
||||||
|
|
||||||
Form addLocoForm = new Form("append-loco-form");
|
|
||||||
addLocoForm.content(t("add locomotive:")+" ");
|
|
||||||
new Input(REALM, REALM_TRAIN).hideIn(addLocoForm);
|
|
||||||
new Input(ACTION, ACTION_ADD).hideIn(addLocoForm);
|
|
||||||
new Input(ID,id).hideIn(addLocoForm);
|
|
||||||
Select select = new Select(CAR_ID);
|
|
||||||
for (Car loco : BaseClass.listElements(Locomotive.class)) {
|
|
||||||
if (isNull(loco.train())) select.addOption(loco.id(), loco);
|
|
||||||
}
|
|
||||||
if (!select.children().isEmpty()) {
|
|
||||||
select.addTo(addLocoForm);
|
|
||||||
new Button(t("add"),addLocoForm).addTo(addLocoForm);
|
|
||||||
addLocoForm.addTo(new Tag("li")).addTo(locoList);
|
|
||||||
}
|
|
||||||
return locoList.addTo(locoProp);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Car> locos(){
|
|
||||||
return new Vector<Car>(locos);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static Object manager() {
|
public static Object manager() {
|
||||||
Window win = new Window("train-manager", t("Train manager"));
|
Window win = new Window("train-manager", t("Train manager"));
|
||||||
new Tag("h4").content(t("known trains")).addTo(win);
|
new Tag("h4").content(t("known trains")).addTo(win);
|
||||||
@@ -481,11 +457,6 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
|
|
||||||
private int maxSpeed() {
|
private int maxSpeed() {
|
||||||
int maxSpeed = Integer.MAX_VALUE;
|
int maxSpeed = Integer.MAX_VALUE;
|
||||||
for (Locomotive loco : locos) {
|
|
||||||
int max = loco.maxSpeed();
|
|
||||||
if (max == 0) continue;
|
|
||||||
maxSpeed = Math.min(max, maxSpeed);
|
|
||||||
}
|
|
||||||
for (Car car : cars) {
|
for (Car car : cars) {
|
||||||
int max = car.maxSpeed();
|
int max = car.maxSpeed();
|
||||||
if (max == 0) continue;
|
if (max == 0) continue;
|
||||||
@@ -493,9 +464,21 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
}
|
}
|
||||||
return maxSpeed;
|
return maxSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Window moveUp(Car car) {
|
||||||
|
for (int i = 1; i<cars.size(); i++) {
|
||||||
|
if (cars.get(i) == car) {
|
||||||
|
cars.remove(i);
|
||||||
|
cars.insertElementAt(car, i-1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return properties();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public String name() {
|
public String name() {
|
||||||
return (isSet(name) ? name : locos.firstElement().name());
|
return (isSet(name) ? name : cars.stream().filter(car -> isSet(car.name())).findFirst().get().name());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Train name(String newName) {
|
private Train name(String newName) {
|
||||||
@@ -513,7 +496,6 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
|
|
||||||
Tag propList = new Tag("ul").clazz("proplist");
|
Tag propList = new Tag("ul").clazz("proplist");
|
||||||
|
|
||||||
locoList().addTo(propList);
|
|
||||||
carList().addTo(propList);
|
carList().addTo(propList);
|
||||||
|
|
||||||
if (isSet(currentBlock)) currentBlock.button(currentBlock.toString()).addTo(new Tag("li").content(t("Current location:")+NBSP)).addTo(propList);
|
if (isSet(currentBlock)) currentBlock.button(currentBlock.toString()).addTo(new Tag("li").content(t("Current location:")+NBSP)).addTo(propList);
|
||||||
@@ -579,7 +561,6 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
if (child == currentBlock) currentBlock = null;
|
if (child == currentBlock) currentBlock = null;
|
||||||
if (child == destination) destination = null;
|
if (child == destination) destination = null;
|
||||||
cars.remove(child);
|
cars.remove(child);
|
||||||
locos.remove(child);
|
|
||||||
trace.remove(child);
|
trace.remove(child);
|
||||||
super.removeChild(child);
|
super.removeChild(child);
|
||||||
}
|
}
|
||||||
@@ -657,7 +638,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
public void setSpeed(int newSpeed) {
|
public void setSpeed(int newSpeed) {
|
||||||
speed = Math.min(newSpeed,maxSpeed());
|
speed = Math.min(newSpeed,maxSpeed());
|
||||||
if (speed < 0) speed = 0;
|
if (speed < 0) speed = 0;
|
||||||
for (Locomotive loco : locos) loco.setSpeed(speed);
|
cars.stream().filter(c -> c instanceof Locomotive).forEach(car -> ((Locomotive)car).setSpeed(speed));
|
||||||
plan.stream(t("Set {} to {} {}",this,speed,speedUnit));
|
plan.stream(t("Set {} to {} {}",this,speed,speedUnit));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -781,19 +762,21 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
|
|
||||||
public SortedSet<String> tags() {
|
public SortedSet<String> tags() {
|
||||||
TreeSet<String> list = new TreeSet<String>(tags);
|
TreeSet<String> list = new TreeSet<String>(tags);
|
||||||
for (Locomotive loco : locos) list.addAll(loco.tags());
|
//for (Locomotive loco : locos) list.addAll(loco.tags());
|
||||||
for (Car car:cars) list.addAll(car.tags());
|
for (Car car:cars) list.addAll(car.tags());
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return isSet(name) ? name : locos.firstElement().name();
|
return name();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tag turn() {
|
public Tag turn() {
|
||||||
LOG.debug("train.turn()");
|
LOG.debug("train.turn()");
|
||||||
for (Locomotive loco : locos) loco.turn();
|
|
||||||
|
for (Car car : cars) car.turn();
|
||||||
|
Collections.reverse(cars);
|
||||||
if (isSet(direction)) {
|
if (isSet(direction)) {
|
||||||
direction = direction.inverse();
|
direction = direction.inverse();
|
||||||
reverseTrace();
|
reverseTrace();
|
||||||
|
|||||||
Reference in New Issue
Block a user