bugfixes
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -4,7 +4,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>de.srsoftware</groupId>
|
||||
<artifactId>web4rail</artifactId>
|
||||
<version>0.10.2</version>
|
||||
<version>0.10.3</version>
|
||||
<name>Web4Rail</name>
|
||||
<packaging>jar</packaging>
|
||||
<description>Java Model Railway Control</description>
|
||||
|
||||
@@ -67,7 +67,7 @@ public class Application implements Constants{
|
||||
server.setExecutor(java.util.concurrent.Executors.newCachedThreadPool());
|
||||
server.start();
|
||||
try {
|
||||
plan = Plan.load("default");
|
||||
plan = Plan.load(Plan.DEFAULT_NAME);
|
||||
} catch (FileNotFoundException e) {
|
||||
plan = new Plan();
|
||||
}
|
||||
|
||||
@@ -46,13 +46,14 @@ public interface Constants {
|
||||
public static final String REALM_PLAN = "plan";
|
||||
public static final String REALM_TRAIN = "train";
|
||||
|
||||
public static final String ID = "id";
|
||||
public static final String PORT = "port";
|
||||
public static final String BLOCK = "block";
|
||||
public static final String CONTACT = "contact";
|
||||
public static final String CONTEXT = "context";
|
||||
public static final String DISABLED = "disabled";
|
||||
public static final String GITHUB_URL = "https://github.com/srsoftware-de/Web4Rail";
|
||||
public static final String ID = "id";
|
||||
public static final String NBSP = " ";
|
||||
public static final String PORT = "port";
|
||||
public static final String TYPE = "type";
|
||||
public static final Charset UTF8 = StandardCharsets.UTF_8;
|
||||
public static final String CONTACT = "contact";
|
||||
public static final String TYPE = "type";
|
||||
public static final String NBSP = " ";
|
||||
public static final String CONTEXT = "context";
|
||||
public static final String GITHUB_URL = "https://github.com/srsoftware-de/Web4Rail";
|
||||
public static final String DISABLED = "disabled";
|
||||
}
|
||||
|
||||
@@ -106,14 +106,15 @@ public class Plan implements Constants{
|
||||
}
|
||||
|
||||
|
||||
private static final String TILE = "tile";
|
||||
private static final String ACTION_QR = "qrcode";
|
||||
public static final String DEFAULT_NAME = "default";
|
||||
private static final String DIRECTION = "direction";
|
||||
private static final String HELP = "help";
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Plan.class);
|
||||
private static final String TILE = "tile";
|
||||
private static final String X = "x";
|
||||
private static final String Y = "y";
|
||||
private static final String DIRECTION = "direction";
|
||||
private static final HashMap<OutputStreamWriter,Integer> clients = new HashMap<OutputStreamWriter, Integer>();
|
||||
private static final String ACTION_QR = "qrcode";
|
||||
private static final String HELP = "help";
|
||||
|
||||
public HashMap<String,Tile> tiles = new HashMap<String,Tile>(); // The list of tiles of this plan, i.e. the Track layout
|
||||
private HashSet<Block> blocks = new HashSet<Block>(); // the list of tiles, that are blocks
|
||||
@@ -152,7 +153,7 @@ public class Plan implements Constants{
|
||||
case ACTION_MOVE:
|
||||
return moveTile(params.get(DIRECTION),params.get(Tile.ID));
|
||||
case ACTION_SAVE:
|
||||
return saveTo("default");
|
||||
return saveTo(DEFAULT_NAME);
|
||||
case ACTION_UPDATE:
|
||||
return update(get(params.get(Tile.ID),true),params);
|
||||
}
|
||||
@@ -403,12 +404,12 @@ public class Plan implements Constants{
|
||||
} catch (Exception e) {
|
||||
LOG.warn("Was not able to load cars!",e);
|
||||
}
|
||||
Tile.loadAll(filename+".plan",plan);
|
||||
try {
|
||||
Train.loadAll(filename+".trains",plan);
|
||||
} catch (Exception e) {
|
||||
LOG.warn("Was not able to load trains!",e);
|
||||
}
|
||||
Tile.loadAll(filename+".plan",plan);
|
||||
try {
|
||||
Route.loadAll(filename+".routes",plan);
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -340,6 +340,8 @@ public class Route extends BaseClass{
|
||||
}
|
||||
train.set(endBlock);
|
||||
train.heading(endDirection.inverse());
|
||||
if (train.route == this) train.route = null;
|
||||
|
||||
}
|
||||
|
||||
public boolean fireSetupActions(Context context) {
|
||||
@@ -366,9 +368,9 @@ public class Route extends BaseClass{
|
||||
return id;
|
||||
}
|
||||
|
||||
public boolean isFree() {
|
||||
public boolean isFreeFor(Train newTrain) {
|
||||
for (int i=1; i<path.size(); i++) {
|
||||
if (!path.get(i).isFree()) return false;
|
||||
if (!path.get(i).isFreeFor(newTrain)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -542,8 +544,19 @@ public class Route extends BaseClass{
|
||||
}
|
||||
|
||||
public boolean reset() {
|
||||
// TODO
|
||||
return false;
|
||||
setSignals(Signal.STOP);
|
||||
for (Tile tile : path) tile.setRoute(null);
|
||||
Tile lastTile = path.lastElement();
|
||||
if (lastTile instanceof Contact) {
|
||||
lastTile.set(null);
|
||||
if (isSet(train)) train.removeFromTrace(lastTile);
|
||||
}
|
||||
if (isSet(train)) {
|
||||
train.set(startBlock);
|
||||
train.heading(startDirection);
|
||||
if (train.route == this) train.route = null;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void saveAll(Collection<Route> routes, String filename) throws IOException {
|
||||
|
||||
@@ -42,8 +42,11 @@ import de.srsoftware.web4rail.tiles.Tile;
|
||||
public class Train extends BaseClass implements Comparable<Train> {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Train.class);
|
||||
|
||||
public static final String HEAD = "train_head";
|
||||
public static final String TAIL = "train_tile";
|
||||
private static final String CAR_ID = "carId";
|
||||
public static final String HEAD = "train_head";
|
||||
public static final String LOCO_ID = "locoId";
|
||||
public static final String TAIL = "train_tile";
|
||||
private static final String TRACE = "trace";
|
||||
private static final HashMap<Integer, Train> trains = new HashMap<>();
|
||||
|
||||
public static final String ID = "id";
|
||||
@@ -96,9 +99,6 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
}
|
||||
}
|
||||
|
||||
public static final String LOCO_ID = "locoId";
|
||||
private static final String CAR_ID = "carId";
|
||||
|
||||
public int speed = 0;
|
||||
private Autopilot autopilot = null;
|
||||
|
||||
@@ -164,7 +164,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (!rt.isFree()) { // keine belegten Routen wählen
|
||||
if (!rt.isFreeFor(this)) { // keine belegten Routen wählen
|
||||
LOG.debug("{} is not free!",rt);
|
||||
continue;
|
||||
}
|
||||
@@ -280,17 +280,25 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
private JSONObject json() {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put(ID, id);
|
||||
json.put(NAME,name);
|
||||
json.put(PUSH_PULL, pushPull);
|
||||
|
||||
if (isSet(block)) json.put(BLOCK, block.id());
|
||||
if (isSet(name))json.put(NAME, name);
|
||||
if (isSet(route)) json.put(ROUTE, route.id());
|
||||
if (isSet(direction)) json.put(DIRECTION, direction);
|
||||
json.put(PUSH_PULL, pushPull);
|
||||
if (isSet(name))json.put(NAME, name);
|
||||
|
||||
Vector<Integer> locoIds = new Vector<Integer>();
|
||||
for (Locomotive loco : locos) locoIds.add(loco.id());
|
||||
json.put(LOCOS, locoIds);
|
||||
|
||||
Vector<Integer> carIds = new Vector<Integer>();
|
||||
for (Car car : cars) carIds.add(car.id());
|
||||
json.put(CARS,carIds);
|
||||
|
||||
Vector<String> tileIds = new Vector<String>();
|
||||
for (Tile tile : trace) tileIds.add(tile.id());
|
||||
json.put(TRACE, tileIds);
|
||||
|
||||
if (!tags.isEmpty()) json.put(TAGS, tags);
|
||||
return json;
|
||||
}
|
||||
@@ -319,7 +327,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
int id = json.getInt(ID);
|
||||
|
||||
Train train = new Train(null,id);
|
||||
train.load(json).plan(plan);
|
||||
train.plan(plan).load(json);
|
||||
|
||||
line = file.readLine();
|
||||
}
|
||||
@@ -328,11 +336,14 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
|
||||
private Train load(JSONObject json) {
|
||||
pushPull = json.getBoolean(PUSH_PULL);
|
||||
if (json.has(BLOCK)) block = (Block) plan.get(json.getString(BLOCK), false);
|
||||
if (json.has(DIRECTION)) direction = Direction.valueOf(json.getString(DIRECTION));
|
||||
if (json.has(NAME)) name = json.getString(NAME);
|
||||
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(elem.toString(), false).set(this)); });
|
||||
for (Object id : json.getJSONArray(CARS)) add(Car.get(id));
|
||||
for (Object id : json.getJSONArray(LOCOS)) add((Locomotive) Car.get(id));
|
||||
if (json.has(TAGS)) json.getJSONArray(TAGS).forEach(elem -> { tags.add(elem.toString()); });
|
||||
if (json.has(DIRECTION)) direction = Direction.valueOf(json.getString(DIRECTION));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -523,7 +534,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
private Object stopNow() {
|
||||
quitAutopilot();
|
||||
setSpeed(0);
|
||||
route = null;
|
||||
if (isSet(route)) route.reset();
|
||||
return t("Stopped {}.",this);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ import de.srsoftware.web4rail.tags.Button;
|
||||
import de.srsoftware.web4rail.tags.Checkbox;
|
||||
import de.srsoftware.web4rail.tags.Form;
|
||||
import de.srsoftware.web4rail.tags.Input;
|
||||
import de.srsoftware.web4rail.tags.Label;
|
||||
import de.srsoftware.web4rail.tags.Radio;
|
||||
|
||||
/**
|
||||
@@ -118,8 +119,11 @@ public abstract class Tile extends BaseClass{
|
||||
plan.set(tile.x, tile.y, tile);
|
||||
}
|
||||
|
||||
public boolean isFree() {
|
||||
return !(disabled || isSet(route) || isSet(train));
|
||||
public boolean isFreeFor(Train newTrain) {
|
||||
if (disabled) return false;
|
||||
if (isSet(route)) return false;
|
||||
if (isSet(train) && newTrain != train) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public JSONObject json() {
|
||||
@@ -169,7 +173,6 @@ public abstract class Tile extends BaseClass{
|
||||
if (json.has(DISABLED)) disabled = json.getBoolean(DISABLED);
|
||||
if (json.has(LENGTH)) length = json.getInt(LENGTH);
|
||||
if (json.has(ONEW_WAY)) oneWay = Direction.valueOf(json.getString(ONEW_WAY));
|
||||
if (json.has(REALM_TRAIN)) train = Train.get(json.getInt(REALM_TRAIN));
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -214,7 +217,7 @@ public abstract class Tile extends BaseClass{
|
||||
String formId = "tile-properties-"+id();
|
||||
Tag form = propForm(formId);
|
||||
new Tag("h4").content(t("Length")).addTo(form);
|
||||
new Input(LENGTH,length).numeric().addTo(form);
|
||||
new Input(LENGTH,length).numeric().addTo(new Label(t("Length")+":"+NBSP)).addTo(form);
|
||||
new Tag("h4").content(t("Availability")).addTo(form);
|
||||
new Checkbox(DISABLED, t("disabled"), disabled).addTo(form);
|
||||
new Button(t("Apply"),"submitForm('"+formId+"')").addTo(form);
|
||||
|
||||
@@ -93,6 +93,7 @@ public abstract class Turnout extends Tile implements Device{
|
||||
if (portB != 1) json.put(PORT_B, portB);
|
||||
if (address != 0) json.put(ADDRESS, address);
|
||||
json.put(PROTOCOL, protocol);
|
||||
json.put(STATE, state);
|
||||
return json;
|
||||
}
|
||||
|
||||
@@ -102,6 +103,7 @@ public abstract class Turnout extends Tile implements Device{
|
||||
if (json.has(PORT_A)) portA = json.getInt(PORT_A);
|
||||
if (json.has(PORT_B)) portB = json.getInt(PORT_B);
|
||||
if (json.has(PROTOCOL)) protocol = Protocol.valueOf(json.getString(PROTOCOL));
|
||||
if (json.has(STATE)) state = State.valueOf(json.getString(STATE));
|
||||
return super.load(json);
|
||||
}
|
||||
|
||||
@@ -139,9 +141,9 @@ public abstract class Turnout extends Tile implements Device{
|
||||
}
|
||||
|
||||
public Reply state(State newState) throws IOException {
|
||||
if (train != null && newState != state) return new Reply(415, t("{} locked by {}!",this,train));
|
||||
Reply reply = init();
|
||||
if (reply != null && !reply.succeeded()) return reply;
|
||||
LOG.debug("Setting {} to {}",this,newState);
|
||||
if (address == 0) {
|
||||
state = newState;
|
||||
plan.place(this);
|
||||
|
||||
Reference in New Issue
Block a user