bugfixes after refactoring
This commit is contained in:
@@ -349,7 +349,7 @@ public abstract class Block extends StretchableTile implements Comparable<Block>
|
||||
if (params.containsKey(NAME)) name=params.get(NAME);
|
||||
if (params.containsKey(Train.class.getSimpleName())) {
|
||||
Id trainId = Id.from(params,Train.class.getSimpleName());
|
||||
if (trainId == null) { // TODO: this is rubbish
|
||||
if (trainId.equals(0)) { // TODO: this is rubbish
|
||||
if (isSet(train)) train.dropTrace();
|
||||
train = null;
|
||||
} else {
|
||||
|
||||
@@ -3,11 +3,16 @@ package de.srsoftware.web4rail.tiles;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.Connector;
|
||||
import de.srsoftware.web4rail.Route;
|
||||
import de.srsoftware.web4rail.Window;
|
||||
import de.srsoftware.web4rail.moving.Train;
|
||||
|
||||
public abstract class Bridge extends Tile {
|
||||
private static final String COUNTERPART = "counterpart";
|
||||
private static Bridge pendingConnection = null;
|
||||
protected Bridge counterpart = null;
|
||||
|
||||
@@ -32,6 +37,44 @@ public abstract class Bridge extends Tile {
|
||||
}
|
||||
|
||||
protected abstract Connector connector();
|
||||
|
||||
@Override
|
||||
public JSONObject json() {
|
||||
JSONObject json = super.json();
|
||||
if (isSet(counterpart)) json.put(COUNTERPART, counterpart.id().toString());
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Tile load(JSONObject json) throws IOException {
|
||||
if (json.has(COUNTERPART)) {
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
counterpart = (Bridge) plan.get(Id.from(json, COUNTERPART), false);
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
return super.load(json);
|
||||
}
|
||||
|
||||
public Tile set(Train train) {
|
||||
super.set(train);
|
||||
if (isSet(counterpart) && counterpart.train != train) counterpart.set(train);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tile setRoute(Route route) {
|
||||
super.setRoute(route);
|
||||
if (isSet(counterpart) && counterpart.route != route) counterpart.setRoute(route);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Window propMenu() {
|
||||
|
||||
@@ -122,7 +122,7 @@ public abstract class Tile extends BaseClass{
|
||||
}
|
||||
|
||||
public JSONObject json() {
|
||||
JSONObject json = new JSONObject();
|
||||
JSONObject json = super.json();
|
||||
json.put(TYPE, getClass().getSimpleName());
|
||||
JSONObject pos = new JSONObject(Map.of(X,x,Y,y));
|
||||
json.put(POS, pos);
|
||||
@@ -234,7 +234,7 @@ public abstract class Tile extends BaseClass{
|
||||
window.children().insertElementAt(new Tag("h4").content(t("Train:")), 1);
|
||||
}
|
||||
|
||||
if (isSet(route)) link("p",t("Locked by {}",route)).addTo(window);
|
||||
if (isSet(route)) route.link("p",t("Locked by {}",route)).addTo(window);
|
||||
|
||||
Form form = propForm("tile-properties-"+id());
|
||||
if (isTrack) {
|
||||
@@ -253,10 +253,8 @@ public abstract class Tile extends BaseClass{
|
||||
new Tag("h4").content(t("Routes using this tile:")).addTo(window);
|
||||
Tag routeList = new Tag("ol");
|
||||
for (Route route : routes) {
|
||||
String json = new JSONObject(Map.of(REALM,ROUTE,ID,route.id(),ACTION,ACTION_PROPS,CONTEXT,REALM_PLAN+":"+id())).toString().replace("\"", "'");
|
||||
Tag li = new Tag("span").attr("onclick","return request("+json+");").content(route.name()+(route.isDisabled()?" ["+t("disabled")+"]" : "")+NBSP).addTo(new Tag("li").clazz("link"));
|
||||
Map<String, Object> params = Map.of(REALM,REALM_ROUTE,ID,route.id(),ACTION,ACTION_DROP,Tile.class.getSimpleName(),id());
|
||||
new Button(t("delete route"),params).addTo(li);
|
||||
Tag li = route.link("span", route.name()+(route.isDisabled()?" ["+t("disabled")+"]" : "")+NBSP).addTo(new Tag("li").clazz("link"));
|
||||
route.button(t("delete route"),contextAction(ACTION_DROP)).addTo(li);
|
||||
li.addTo(routeList);
|
||||
}
|
||||
routeList.addTo(window);
|
||||
|
||||
Reference in New Issue
Block a user