preparing to make orientation of car reversible within train
This commit is contained in:
@@ -49,7 +49,7 @@ public class Car extends BaseClass implements Comparable<Car>{
|
||||
private Train train;
|
||||
protected int maxSpeedForward = 0;
|
||||
protected int maxSpeedReverse = 0;
|
||||
private boolean orientation = FORWARD;
|
||||
protected boolean orientation = FORWARD;
|
||||
|
||||
public Car(String name) {
|
||||
this(name,null);
|
||||
@@ -95,6 +95,11 @@ public class Car extends BaseClass implements Comparable<Car>{
|
||||
private Button cloneButton() {
|
||||
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) {
|
||||
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();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Car o) {
|
||||
return (stockId+":"+name).compareTo(o.stockId+":"+o.name);
|
||||
public String turn() {
|
||||
orientation = !orientation;
|
||||
return t("Reversed {}.",this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ public class Locomotive extends Car implements Constants,Device{
|
||||
|
||||
private static final String REVERSE = "reverse";
|
||||
public static final String LOCOMOTIVE = "locomotive";
|
||||
boolean reverse = false;
|
||||
private Protocol proto = Protocol.DCC128;
|
||||
private int address = 3;
|
||||
private int speed = 0;
|
||||
@@ -205,7 +204,7 @@ public class Locomotive extends Car implements Constants,Device{
|
||||
public JSONObject json() {
|
||||
JSONObject json = super.json();
|
||||
JSONObject loco = new JSONObject();
|
||||
loco.put(REVERSE, reverse);
|
||||
loco.put(REVERSE, orientation);
|
||||
loco.put(PROTOCOL, proto);
|
||||
loco.put(ADDRESS, address);
|
||||
json.put(LOCOMOTIVE, loco);
|
||||
@@ -217,7 +216,7 @@ public class Locomotive extends Car implements Constants,Device{
|
||||
super.load(json);
|
||||
if (json.has(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(ADDRESS)) address = loco.getInt(ADDRESS);
|
||||
}
|
||||
@@ -265,7 +264,7 @@ public class Locomotive extends Car implements Constants,Device{
|
||||
|
||||
private void queue() {
|
||||
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
|
||||
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);
|
||||
}
|
||||
|
||||
public Object turn() {
|
||||
reverse = !reverse;
|
||||
public String turn() {
|
||||
stop();
|
||||
super.turn();
|
||||
return t("Stopped and reversed {}.",this);
|
||||
}
|
||||
|
||||
|
||||
@@ -209,7 +209,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
|
||||
public String brakeId(boolean reversed) {
|
||||
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);
|
||||
String brakeId = md5sum(carIds);
|
||||
LOG.debug("generated new brake id for {}: {}",this,brakeId);
|
||||
|
||||
Reference in New Issue
Block a user