working on saving and loading of route actions
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -33,7 +33,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>de.srsoftware</groupId>
|
<groupId>de.srsoftware</groupId>
|
||||||
<artifactId>tools</artifactId>
|
<artifactId>tools</artifactId>
|
||||||
<version>1.1.7</version>
|
<version>1.1.8</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -262,6 +262,7 @@ public class Plan {
|
|||||||
actionMenu().addTo(menu);
|
actionMenu().addTo(menu);
|
||||||
moveMenu().addTo(menu);
|
moveMenu().addTo(menu);
|
||||||
tileMenu().addTo(menu);
|
tileMenu().addTo(menu);
|
||||||
|
trainMenu().addTo(menu);
|
||||||
return menu;
|
return menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -376,9 +377,13 @@ public class Plan {
|
|||||||
Object result = Train.action(params);
|
Object result = Train.action(params);
|
||||||
return result instanceof Train ? html() : result;
|
return result instanceof Train ? html() : result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Route route(int routeId) {
|
||||||
|
return routes.get(routeId);
|
||||||
|
}
|
||||||
|
|
||||||
private Object routeProperties(int id) {
|
private Object routeProperties(int id) {
|
||||||
Route route = routes.get(id);
|
Route route = route(id);
|
||||||
if (route == null) return t("Could not find route \"{}\"",id);
|
if (route == null) return t("Could not find route \"{}\"",id);
|
||||||
return route.properties();
|
return route.properties();
|
||||||
}
|
}
|
||||||
@@ -493,18 +498,24 @@ public class Plan {
|
|||||||
return new Tag("div").clazz("list").content(tiles.toString()).addTo(tileMenu);
|
return new Tag("div").clazz("list").content(tiles.toString()).addTo(tileMenu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Tag trainMenu() throws IOException {
|
||||||
|
Tag tileMenu = new Tag("div").clazz("trains").title(t("Manage trains")).content(t("Trains"));
|
||||||
|
|
||||||
|
StringBuffer tiles = new StringBuffer();
|
||||||
|
return new Tag("div").clazz("list").content(tiles.toString()).addTo(tileMenu);
|
||||||
|
}
|
||||||
|
|
||||||
private Object update(HashMap<String, String> params) throws IOException {
|
private Object update(HashMap<String, String> params) throws IOException {
|
||||||
if (params.containsKey(ROUTE)) {
|
if (params.containsKey(ROUTE)) {
|
||||||
Route route = routes.get(Integer.parseInt(params.get(ROUTE)));
|
Route route = routes.get(Integer.parseInt(params.get(ROUTE)));
|
||||||
if (route == null) return t("Unknown route: {}",params.get(ROUTE));
|
if (route == null) return t("Unknown route: {}",params.get(ROUTE));
|
||||||
route.update(params);
|
route.update(params);
|
||||||
} else update(Integer.parseInt(params.get("x")),Integer.parseInt(params.get("y")),params);
|
} else update(get(params.get(Tile.ID),true),params);
|
||||||
return this.html();
|
return this.html();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void update(int x,int y, HashMap<String, String> params) throws IOException {
|
private void update(Tile tile, HashMap<String, String> params) throws IOException {
|
||||||
Tile tile = get(Tile.id(x, y),true);
|
if (tile != null) place(tile.update(params));
|
||||||
if (tile != null) set(x,y,tile.update(params));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void warn(Contact contact) {
|
public void warn(Contact contact) {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import java.io.BufferedWriter;
|
|||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -13,6 +14,7 @@ import java.util.Map.Entry;
|
|||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -115,15 +117,15 @@ public class Route {
|
|||||||
|
|
||||||
public void complete() {
|
public void complete() {
|
||||||
if (contacts.size()>1) { // mindestens 2 Kontakte: erster Kontakt aktiviert Block, vorletzter Kontakt leitet Bremsung ein
|
if (contacts.size()>1) { // mindestens 2 Kontakte: erster Kontakt aktiviert Block, vorletzter Kontakt leitet Bremsung ein
|
||||||
addAction(contacts.firstElement().trigger(),new ActivateRoute(this));
|
addAction(contacts.firstElement().trigger(),new ActivateRoute(id()));
|
||||||
Contact nextToLastContact = contacts.get(contacts.size()-2);
|
Contact nextToLastContact = contacts.get(contacts.size()-2);
|
||||||
addAction(nextToLastContact.trigger(),new SpeedReduction(this,30));
|
addAction(nextToLastContact.trigger(),new SpeedReduction(id(),30));
|
||||||
addAction(nextToLastContact.trigger(),new SetSignalsToStop(this));
|
addAction(nextToLastContact.trigger(),new SetSignalsToStop(id()));
|
||||||
}
|
}
|
||||||
if (!contacts.isEmpty()) {
|
if (!contacts.isEmpty()) {
|
||||||
Contact lastContact = contacts.lastElement();
|
Contact lastContact = contacts.lastElement();
|
||||||
addAction(lastContact.trigger(), new SpeedReduction(this, 0));
|
addAction(lastContact.trigger(), new SpeedReduction(id(), 0));
|
||||||
addAction(lastContact.trigger(), new FinishRoute(this));
|
addAction(lastContact.trigger(), new FinishRoute(id()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,7 +139,7 @@ public class Route {
|
|||||||
Vector<Action> actions = triggers.get(contact.trigger());
|
Vector<Action> actions = triggers.get(contact.trigger());
|
||||||
for (Action action : actions) {
|
for (Action action : actions) {
|
||||||
try {
|
try {
|
||||||
action.fire();
|
action.fire(contact.plan());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOG.warn("Action did not fire properly: {}",action,e);
|
LOG.warn("Action did not fire properly: {}",action,e);
|
||||||
}
|
}
|
||||||
@@ -184,25 +186,25 @@ public class Route {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String json() {
|
public String json() {
|
||||||
JSONObject props = new JSONObject();
|
JSONObject json = new JSONObject();
|
||||||
|
|
||||||
props.put(ID, id());
|
json.put(ID, id());
|
||||||
Vector<String> tileIds = new Vector<String>();
|
Vector<String> tileIds = new Vector<String>();
|
||||||
for (Tile t : this.path) tileIds.add(t.id());
|
for (Tile t : this.path) tileIds.add(t.id());
|
||||||
props.put(PATH, tileIds);
|
json.put(PATH, tileIds);
|
||||||
|
|
||||||
Vector<String> signalIds = new Vector<String>(); // list all signals affecting this route
|
Vector<String> signalIds = new Vector<String>(); // list all signals affecting this route
|
||||||
for (Tile t : this.signals) signalIds.add(t.id());
|
for (Tile t : this.signals) signalIds.add(t.id());
|
||||||
props.put(SIGNALS, signalIds);
|
json.put(SIGNALS, signalIds);
|
||||||
|
|
||||||
JSONArray turnouts = new JSONArray();
|
JSONArray turnouts = new JSONArray();
|
||||||
for (Entry<Turnout, State> entry : this.turnouts.entrySet()) {
|
for (Entry<Turnout, State> entry : this.turnouts.entrySet()) {
|
||||||
Turnout t = entry.getKey();
|
Turnout t = entry.getKey();
|
||||||
turnouts.put(new JSONObject(Map.of(Turnout.ID,t.id(),Turnout.STATE,entry.getValue())));
|
turnouts.put(new JSONObject(Map.of(Turnout.ID,t.id(),Turnout.STATE,entry.getValue())));
|
||||||
}
|
}
|
||||||
props.put(TURNOUTS, turnouts);
|
json.put(TURNOUTS, turnouts);
|
||||||
props.put(START_DIRECTION, startDirection);
|
json.put(START_DIRECTION, startDirection);
|
||||||
props.put(END_DIRECTION, startDirection);
|
json.put(END_DIRECTION, endDirection);
|
||||||
|
|
||||||
JSONArray jTriggers = new JSONArray();
|
JSONArray jTriggers = new JSONArray();
|
||||||
for (Entry<String, Vector<Action>> entry : triggers.entrySet()) {
|
for (Entry<String, Vector<Action>> entry : triggers.entrySet()) {
|
||||||
@@ -218,12 +220,12 @@ public class Route {
|
|||||||
jTriggers.put(trigger);
|
jTriggers.put(trigger);
|
||||||
|
|
||||||
}
|
}
|
||||||
if (!jTriggers.isEmpty()) props.put(ACTIONS, jTriggers);
|
if (!jTriggers.isEmpty()) json.put(ACTIONS, jTriggers);
|
||||||
|
|
||||||
String name = name();
|
String name = name();
|
||||||
if (name != null) props.put(NAME, name);
|
if (name != null) json.put(NAME, name);
|
||||||
|
|
||||||
return props.toString();
|
return json.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Route load(JSONObject json,Plan plan) {
|
private Route load(JSONObject json,Plan plan) {
|
||||||
@@ -235,12 +237,46 @@ public class Route {
|
|||||||
Tile tile = plan.get((String) tileId,false);
|
Tile tile = plan.get((String) tileId,false);
|
||||||
if (startBlock == null) {
|
if (startBlock == null) {
|
||||||
start((Block) tile, startDirection);
|
start((Block) tile, startDirection);
|
||||||
} else add(tile, endDirection);
|
} else if (tile instanceof Block) { // make sure, endDirection is set on last block
|
||||||
|
add(tile,endDirection);
|
||||||
|
} else {
|
||||||
|
add(tile, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (json.has(NAME)) name(json.getString(NAME));
|
if (json.has(NAME)) name(json.getString(NAME));
|
||||||
|
if (json.has(TURNOUTS)) {
|
||||||
|
JSONArray turnouts = json.getJSONArray(TURNOUTS);
|
||||||
|
for (int i=0; i<turnouts.length();i++) {
|
||||||
|
JSONObject jTurnout = turnouts.getJSONObject(i);
|
||||||
|
Turnout turnout = (Turnout) plan.get(jTurnout.getString(Turnout.ID), false);
|
||||||
|
addTurnout(turnout, Turnout.State.valueOf(jTurnout.getString(Turnout.STATE)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (json.has(SIGNALS)) {
|
||||||
|
for (Object signalId : json.getJSONArray(SIGNALS)) addSignal((Signal) plan.get((String) signalId, false));
|
||||||
|
}
|
||||||
|
if (json.has(ACTIONS)) loadActions(json.getJSONArray(ACTIONS));
|
||||||
return plan.registerRoute(this);
|
return plan.registerRoute(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void loadActions(JSONArray arr) {
|
||||||
|
for (int i=0; i<arr.length(); i++) {
|
||||||
|
JSONObject json = arr.getJSONObject(i);
|
||||||
|
String trigger = json.getString(TRIGGER);
|
||||||
|
JSONArray actions = json.getJSONArray(ACTIONS);
|
||||||
|
for (int k=0; k<actions.length(); k++) {
|
||||||
|
try {
|
||||||
|
Action action = Action.load(actions.getJSONObject(k));
|
||||||
|
LOG.debug("Loaded {}",action);
|
||||||
|
addAction(trigger, action);
|
||||||
|
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException| InvocationTargetException | NoSuchMethodException | SecurityException | ClassNotFoundException | JSONException e) {
|
||||||
|
LOG.warn("Was not able to load action: ",e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void loadAll(String filename, Plan plan) throws IOException {
|
public static void loadAll(String filename, Plan plan) throws IOException {
|
||||||
BufferedReader file = new BufferedReader(new FileReader(filename));
|
BufferedReader file = new BufferedReader(new FileReader(filename));
|
||||||
String line = file.readLine();
|
String line = file.readLine();
|
||||||
|
|||||||
@@ -1,13 +1,16 @@
|
|||||||
package de.srsoftware.web4rail.actions;
|
package de.srsoftware.web4rail.actions;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import de.srsoftware.web4rail.Plan;
|
||||||
|
|
||||||
public abstract class Action {
|
public abstract class Action {
|
||||||
private static final String TYPE = "type";
|
private static final String TYPE = "type";
|
||||||
|
|
||||||
public abstract void fire() throws IOException;
|
public abstract void fire(Plan plan) throws IOException;
|
||||||
|
|
||||||
public JSONObject json() {
|
public JSONObject json() {
|
||||||
JSONObject json = new JSONObject();
|
JSONObject json = new JSONObject();
|
||||||
@@ -19,4 +22,19 @@ public abstract class Action {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return getClass().getSimpleName();
|
return getClass().getSimpleName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Action load(JSONObject json) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, ClassNotFoundException {
|
||||||
|
String clazz = json.getString(TYPE);
|
||||||
|
switch (clazz) {
|
||||||
|
case "ActivateRoute":
|
||||||
|
return new ActivateRoute(json.getInt(RouteAction.ROUTE));
|
||||||
|
case "FinishRoute":
|
||||||
|
return new FinishRoute(json.getInt(RouteAction.ROUTE));
|
||||||
|
case "SetSignalsToStop":
|
||||||
|
return new SetSignalsToStop(json.getInt(RouteAction.ROUTE));
|
||||||
|
case "SpeedReduction":
|
||||||
|
return new SpeedReduction(json.getInt(RouteAction.ROUTE), json.getInt(SpeedReduction.MAX_SPEED));
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,12 +7,12 @@ import de.srsoftware.web4rail.Route;
|
|||||||
public class ActivateRoute extends RouteAction {
|
public class ActivateRoute extends RouteAction {
|
||||||
|
|
||||||
|
|
||||||
public ActivateRoute(Route route) {
|
public ActivateRoute(int routeId) {
|
||||||
super(route);
|
super(routeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fire() throws IOException {
|
public void fire(Route route) throws IOException {
|
||||||
route.activate();
|
route.activate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,12 +6,12 @@ import de.srsoftware.web4rail.Route;
|
|||||||
|
|
||||||
public class FinishRoute extends RouteAction {
|
public class FinishRoute extends RouteAction {
|
||||||
|
|
||||||
public FinishRoute(Route route) {
|
public FinishRoute(int routeId) {
|
||||||
super(route);
|
super(routeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fire() throws IOException {
|
public void fire(Route route) throws IOException {
|
||||||
route.finish();
|
route.finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,32 @@
|
|||||||
package de.srsoftware.web4rail.actions;
|
package de.srsoftware.web4rail.actions;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import de.srsoftware.web4rail.Plan;
|
||||||
import de.srsoftware.web4rail.Route;
|
import de.srsoftware.web4rail.Route;
|
||||||
|
|
||||||
public abstract class RouteAction extends Action {
|
public abstract class RouteAction extends Action {
|
||||||
|
|
||||||
private static final String ROUTE = "route";
|
static final String ROUTE = "route";
|
||||||
protected Route route;
|
protected int routeId;
|
||||||
|
|
||||||
public RouteAction(Route route) {
|
public RouteAction(int routeId) {
|
||||||
this.route = route;
|
this.routeId = routeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JSONObject json() {
|
public JSONObject json() {
|
||||||
JSONObject json = super.json();
|
JSONObject json = super.json();
|
||||||
json.put(ROUTE, route.id());
|
json.put(ROUTE, routeId);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fire(Plan plan) throws IOException {
|
||||||
|
fire(plan.route(routeId));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void fire(Route route) throws IOException;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,12 +8,12 @@ import de.srsoftware.web4rail.tiles.Signal;
|
|||||||
public class SetSignalsToStop extends RouteAction {
|
public class SetSignalsToStop extends RouteAction {
|
||||||
|
|
||||||
|
|
||||||
public SetSignalsToStop(Route route) {
|
public SetSignalsToStop(int routeId) {
|
||||||
super(route);
|
super(routeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fire() throws IOException {
|
public void fire(Route route) throws IOException {
|
||||||
route.setSignals(Signal.STOP);
|
route.setSignals(Signal.STOP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,16 +7,16 @@ import de.srsoftware.web4rail.moving.Train;
|
|||||||
|
|
||||||
public class SpeedReduction extends RouteAction {
|
public class SpeedReduction extends RouteAction {
|
||||||
|
|
||||||
private static final String MAX_SPEED = "max_speed";
|
static final String MAX_SPEED = "max_speed";
|
||||||
private int maxSpeed;
|
private int maxSpeed;
|
||||||
|
|
||||||
public SpeedReduction(Route route, int kmh) {
|
public SpeedReduction(int routeId, int kmh) {
|
||||||
super(route);
|
super(routeId);
|
||||||
maxSpeed = kmh;
|
maxSpeed = kmh;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fire() {
|
public void fire(Route route) {
|
||||||
Train train = route.train;
|
Train train = route.train;
|
||||||
if (train != null && train.speed > maxSpeed) train.setSpeed(maxSpeed);
|
if (train != null && train.speed > maxSpeed) train.setSpeed(maxSpeed);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,13 +59,17 @@ public class Train {
|
|||||||
private Block block = null;
|
private Block block = null;
|
||||||
|
|
||||||
private class Autopilot extends Thread{
|
private class Autopilot extends Thread{
|
||||||
|
boolean stop = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
|
stop = false;
|
||||||
Vector<Tile> path = new Vector<Tile>();
|
Vector<Tile> path = new Vector<Tile>();
|
||||||
while (true) {
|
while (true) {
|
||||||
if (route == null) {
|
if (route == null) {
|
||||||
Thread.sleep(3000);
|
Thread.sleep(2000);
|
||||||
|
if (stop) return;
|
||||||
Train.this.start();
|
Train.this.start();
|
||||||
path = route == null ? new Vector<Tile>() : route.path();
|
path = route == null ? new Vector<Tile>() : route.path();
|
||||||
} else {
|
} else {
|
||||||
@@ -74,7 +78,7 @@ public class Train {
|
|||||||
if (t instanceof Contact) ((Contact)t).activate();
|
if (t instanceof Contact) ((Contact)t).activate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Thread.sleep(500);
|
Thread.sleep(250);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -87,6 +91,8 @@ public class Train {
|
|||||||
private static final String MODE_UPDATE = "update";
|
private static final String MODE_UPDATE = "update";
|
||||||
private static final String MODE_AUTO = "auto";
|
private static final String MODE_AUTO = "auto";
|
||||||
|
|
||||||
|
private static final String MODE_STOP = "stop";
|
||||||
|
|
||||||
public int speed = 0;
|
public int speed = 0;
|
||||||
private Autopilot autopilot = null;
|
private Autopilot autopilot = null;
|
||||||
|
|
||||||
@@ -133,6 +139,8 @@ public class Train {
|
|||||||
return train.props();
|
return train.props();
|
||||||
case MODE_START:
|
case MODE_START:
|
||||||
return train.start();
|
return train.start();
|
||||||
|
case MODE_STOP:
|
||||||
|
return train.stop();
|
||||||
case MODE_UPDATE:
|
case MODE_UPDATE:
|
||||||
return train.update(params);
|
return train.update(params);
|
||||||
default: return t("Unknown mode {} for {}",mode,train);
|
default: return t("Unknown mode {} for {}",mode,train);
|
||||||
@@ -235,7 +243,11 @@ public class Train {
|
|||||||
new Tag("li").content(t("Direction: heading {}",direction)).addTo(list);
|
new Tag("li").content(t("Direction: heading {}",direction)).addTo(list);
|
||||||
|
|
||||||
new Tag("li").clazz("link").attr("onclick","train("+id+",'"+MODE_START+"')").content(t("start")).addTo(list).addTo(window);
|
new Tag("li").clazz("link").attr("onclick","train("+id+",'"+MODE_START+"')").content(t("start")).addTo(list).addTo(window);
|
||||||
new Tag("li").clazz("link").attr("onclick","train("+id+",'"+MODE_AUTO+"')").content(t("auto")).addTo(list).addTo(window);
|
if (autopilot == null) {
|
||||||
|
new Tag("li").clazz("link").attr("onclick","train("+id+",'"+MODE_AUTO+"')").content(t("auto")).addTo(list).addTo(window);
|
||||||
|
} else {
|
||||||
|
new Tag("li").clazz("link").attr("onclick","train("+id+",'"+MODE_STOP+"')").content(t("stop")).addTo(list).addTo(window);
|
||||||
|
}
|
||||||
|
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
@@ -283,6 +295,12 @@ public class Train {
|
|||||||
return t("started {}",this);
|
return t("started {}",this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Object stop() {
|
||||||
|
autopilot.stop = true;
|
||||||
|
autopilot = null;
|
||||||
|
return t("{} stopping at next block {}");
|
||||||
|
}
|
||||||
|
|
||||||
private static String t(String message, Object...fills) {
|
private static String t(String message, Object...fills) {
|
||||||
return Translation.get(Application.class, message, fills);
|
return Translation.get(Application.class, message, fills);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -147,6 +147,7 @@ public abstract class Tile {
|
|||||||
JSONObject pos = json.getJSONObject(POS);
|
JSONObject pos = json.getJSONObject(POS);
|
||||||
x = pos.getInt(X);
|
x = pos.getInt(X);
|
||||||
y = pos.getInt(Y);
|
y = pos.getInt(Y);
|
||||||
|
if (json.has(ONEW_WAY)) oneWay = Direction.valueOf(json.getString(ONEW_WAY));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,6 +156,10 @@ public abstract class Tile {
|
|||||||
plan.place(this);
|
plan.place(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Plan plan() {
|
||||||
|
return plan;
|
||||||
|
}
|
||||||
|
|
||||||
public Tile plan(Plan plan) {
|
public Tile plan(Plan plan) {
|
||||||
this.plan = plan;
|
this.plan = plan;
|
||||||
return this;
|
return this;
|
||||||
@@ -173,8 +178,7 @@ public abstract class Tile {
|
|||||||
public Tag propForm() {
|
public Tag propForm() {
|
||||||
Form form = new Form();
|
Form form = new Form();
|
||||||
new Tag("input").attr("type", "hidden").attr("name","action").attr("value", "update").addTo(form);
|
new Tag("input").attr("type", "hidden").attr("name","action").attr("value", "update").addTo(form);
|
||||||
new Tag("input").attr("type", "hidden").attr("name","x").attr("value", x).addTo(form);
|
new Tag("input").attr("type", "hidden").attr("name",ID).attr("value", id()).addTo(form);
|
||||||
new Tag("input").attr("type", "hidden").attr("name","y").attr("value", y).addTo(form);
|
|
||||||
|
|
||||||
List<Direction> pd = possibleDirections();
|
List<Direction> pd = possibleDirections();
|
||||||
if (!pd.isEmpty()) {
|
if (!pd.isEmpty()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user