fixed bug: orientation of cars has not been saved

This commit is contained in:
Stephan Richter
2021-02-16 09:12:30 +01:00
parent c3242cddcb
commit 8ab3b6d1a0
3 changed files with 4 additions and 4 deletions

View File

@@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>de.srsoftware</groupId> <groupId>de.srsoftware</groupId>
<artifactId>web4rail</artifactId> <artifactId>web4rail</artifactId>
<version>1.3.42</version> <version>1.3.43</version>
<name>Web4Rail</name> <name>Web4Rail</name>
<packaging>jar</packaging> <packaging>jar</packaging>
<description>Java Model Railway Control</description> <description>Java Model Railway Control</description>

View File

@@ -46,6 +46,7 @@ public class Car extends BaseClass implements Comparable<Car>{
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"; private static final String MAX_SPEED_REVERSE = "max_speed_reverse";
private static final String ORDER = "order"; private static final String ORDER = "order";
private static final String ORIENTATION = "orientation";
protected HashSet<String> tags = new HashSet<String>(); protected HashSet<String> tags = new HashSet<String>();
private String name; private String name;
@@ -122,6 +123,7 @@ public class Car extends BaseClass implements Comparable<Car>{
json.put(LENGTH, length); json.put(LENGTH, length);
if (maxSpeedForward != 0) json.put(MAX_SPEED, maxSpeedForward); if (maxSpeedForward != 0) json.put(MAX_SPEED, maxSpeedForward);
if (maxSpeedReverse != 0) json.put(MAX_SPEED_REVERSE, maxSpeedReverse); if (maxSpeedReverse != 0) json.put(MAX_SPEED_REVERSE, maxSpeedReverse);
json.put(ORIENTATION, orientation);
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;
@@ -165,6 +167,7 @@ public class Car extends BaseClass implements Comparable<Car>{
if (json.has(MAX_SPEED_REVERSE)) maxSpeedReverse = json.getInt(MAX_SPEED_REVERSE); 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()); });
if (json.has(ORIENTATION)) orientation=json.getBoolean(ORIENTATION);
return this; return this;
} }

View File

@@ -31,7 +31,6 @@ import de.srsoftware.web4rail.tiles.Block;
public class Locomotive extends Car implements Constants,Device{ public class Locomotive extends Car implements Constants,Device{
private static final String REVERSE = "reverse";
public static final String LOCOMOTIVE = "locomotive"; public static final String LOCOMOTIVE = "locomotive";
private static final Integer CV_ADDR = 1; private static final Integer CV_ADDR = 1;
private static final String CVS = "cvs"; private static final String CVS = "cvs";
@@ -243,7 +242,6 @@ 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, orientation);
loco.put(PROTOCOL, proto); loco.put(PROTOCOL, proto);
json.put(LOCOMOTIVE, loco); json.put(LOCOMOTIVE, loco);
loco.put(CVS, cvs); loco.put(CVS, cvs);
@@ -255,7 +253,6 @@ 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)) 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)) setAddress(loco.getInt(ADDRESS)); if (loco.has(ADDRESS)) setAddress(loco.getInt(ADDRESS));
if (loco.has(CVS)) { if (loco.has(CVS)) {