preparing to make orientation of car reversible within train
This commit is contained in:
@@ -158,6 +158,7 @@ quit autopilot : Autopilot beenden
|
|||||||
Relay/Turnout : Relais/Weiche
|
Relay/Turnout : Relais/Weiche
|
||||||
Report Issue : Problem melden
|
Report Issue : Problem melden
|
||||||
reverse : rückwärts
|
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
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public class Car extends BaseClass implements Comparable<Car>{
|
|||||||
private Train train;
|
private Train train;
|
||||||
protected int maxSpeedForward = 0;
|
protected int maxSpeedForward = 0;
|
||||||
protected int maxSpeedReverse = 0;
|
protected int maxSpeedReverse = 0;
|
||||||
private boolean orientation = FORWARD;
|
protected boolean orientation = FORWARD;
|
||||||
|
|
||||||
public Car(String name) {
|
public Car(String name) {
|
||||||
this(name,null);
|
this(name,null);
|
||||||
@@ -95,6 +95,11 @@ 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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(Car o) {
|
||||||
|
return (stockId+":"+name).compareTo(o.stockId+":"+o.name);
|
||||||
|
}
|
||||||
|
|
||||||
public static Car get(Object id) {
|
public static Car get(Object id) {
|
||||||
return isNull(id) ? null : cars.get(new Id(""+id)); // try to get by id
|
return isNull(id) ? null : cars.get(new Id(""+id)); // try to get by id
|
||||||
@@ -269,8 +274,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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,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;
|
||||||
@@ -205,7 +204,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 +216,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);
|
||||||
}
|
}
|
||||||
@@ -265,7 +264,7 @@ public class Locomotive extends Car implements Constants,Device{
|
|||||||
|
|
||||||
private void queue() {
|
private void queue() {
|
||||||
int step = proto.steps * speed / (maxSpeedForward == 0 ? 100 : maxSpeedForward);
|
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) {
|
||||||
@@ -322,9 +321,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -209,7 +209,7 @@ 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);
|
locos.stream().map(loco -> loco.id()+":"+(reversed != loco.orientation?"r":"f")).forEach(carIds::add);
|
||||||
cars.stream().map(car -> ""+car.id()).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);
|
||||||
|
|||||||
Reference in New Issue
Block a user