completed implementation of stopping times for trains in blocks
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.11.1</version>
|
||||
<version>0.11.2</version>
|
||||
<name>Web4Rail</name>
|
||||
<packaging>jar</packaging>
|
||||
<description>Java Model Railway Control</description>
|
||||
|
||||
@@ -15,6 +15,7 @@ Analyze : analysieren
|
||||
Apply : Übernehmen
|
||||
Availability : Verfügbarkeit
|
||||
Block properties : Block-Eigenschaften
|
||||
{}bound : nach {}
|
||||
Cars\: : Waggons:
|
||||
ConditionalAction : bedingte Aktion
|
||||
Conditions : Bedingungen
|
||||
@@ -30,6 +31,7 @@ DelayedAction : verzögerte Aktion
|
||||
delete : entfernen
|
||||
delete route : Route löschen
|
||||
Destination\: {} from {} : Ziel: {} von {}
|
||||
Direction : Richtung
|
||||
disabled : deaktiviert
|
||||
EAST : Osten
|
||||
editable train properties : veränderliche Zug-Eigenschaften
|
||||
@@ -53,9 +55,11 @@ Manage cars : Waggons verwalten
|
||||
Manage locos : Lokomotiven verwalten
|
||||
Manage trains : Züge verwalten
|
||||
Maximum train length\: : maximale Zug-Länge
|
||||
Minimum and maximum times (in Miliseconds) trains with the respective tag have to wait in this block. : Minamle und maximale Block-Haltezeit (in Millisekunden) für Züge mit der entsprchender Markierung.
|
||||
Move tiles : Kacheln verschieben
|
||||
name\: : Name:
|
||||
new locomotive : neue Lok
|
||||
new tag : neue Markierung
|
||||
new train : neuer Zug
|
||||
No : keine
|
||||
No free routes from {} : keine Route von {} frei
|
||||
@@ -96,10 +100,12 @@ SOUTH : Süden
|
||||
Started {} : {} gestartet
|
||||
StopAllTrains : Alle Züge stoppen
|
||||
StopAuto : Automatikmodus abschalten
|
||||
Stopsettings : Halte-Einstellungen
|
||||
Straight port\: : Port für gerade
|
||||
STRAIGHT : gerade
|
||||
Switch power off : Strom ausschalten
|
||||
Switch power on : Strom anschalten
|
||||
Tag : Markierung
|
||||
Tags : Markierungen
|
||||
Toggle : umschalten
|
||||
Toggle power : Stom umschalten
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.srsoftware.web4rail;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.json.JSONObject;
|
||||
@@ -20,4 +21,10 @@ public class BaseClass implements Constants{
|
||||
public static boolean isSet(Object o) {
|
||||
return o != null;
|
||||
}
|
||||
|
||||
public static HashMap<String, String> merged(Map<String, String> base, Map<String, String> overlay) {
|
||||
HashMap<String,String> merged = new HashMap<>(base);
|
||||
overlay.entrySet().stream().forEach(entry -> merged.put(entry.getKey(), entry.getValue()));
|
||||
return merged;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ public interface Constants {
|
||||
public static final String ACTION_SLOWER10 = "slower10";
|
||||
public static final String ACTION_START = "start";
|
||||
public static final String ACTION_STOP = "stop";
|
||||
public static final String ACTION_TIMES = "update_times";
|
||||
public static final String ACTION_TOGGLE_F1 = "f1";
|
||||
public static final String ACTION_TOGGLE_F2 = "f2";
|
||||
public static final String ACTION_TOGGLE_F3 = "f3";
|
||||
|
||||
@@ -148,13 +148,15 @@ public class Plan extends BaseClass{
|
||||
case ACTION_ANALYZE:
|
||||
return analyze();
|
||||
case ACTION_CLICK:
|
||||
return click(get(params.get(Tile.ID),true));
|
||||
return click(get(params.get(ID),true));
|
||||
case ACTION_MOVE:
|
||||
return moveTile(params.get(DIRECTION),params.get(Tile.ID));
|
||||
return moveTile(params.get(DIRECTION),params.get(ID));
|
||||
case ACTION_SAVE:
|
||||
return saveTo(DEFAULT_NAME);
|
||||
case ACTION_TIMES:
|
||||
return updateTimes(params);
|
||||
case ACTION_UPDATE:
|
||||
return update(get(params.get(Tile.ID),true),params);
|
||||
return update(get(params.get(ID),true),params);
|
||||
}
|
||||
return t("Unknown action: {}",params.get(ACTION));
|
||||
}
|
||||
@@ -813,6 +815,16 @@ public class Plan extends BaseClass{
|
||||
return tile == null ? null : tile.update(params);
|
||||
}
|
||||
|
||||
private Object updateTimes(HashMap<String, String> params) throws IOException {
|
||||
Tile tile = get(params.get(ID),false);
|
||||
if (tile instanceof Block) {
|
||||
Block block = (Block) tile;
|
||||
place(block.updateTimes(params));
|
||||
return tile.propMenu();
|
||||
}
|
||||
return t("updateTimes called on non-block tile!");
|
||||
}
|
||||
|
||||
/**
|
||||
* sends a Ghost train warning to the client
|
||||
* @param contact
|
||||
|
||||
@@ -33,8 +33,9 @@ public abstract class Block extends StretchableTile{
|
||||
private static final String NAME = "name";
|
||||
private static final String NO_TAG = "[default]";
|
||||
private static final String NEW_TAG = "new_tag";
|
||||
private static final String TAG = "tag";
|
||||
public static final String TAG = "tag";
|
||||
private static final String WAIT_TIMES = "wait_times";
|
||||
private static final String RAISE = "raise";
|
||||
|
||||
public String name = "Block";
|
||||
public boolean turnAllowed = false;
|
||||
@@ -123,6 +124,33 @@ public abstract class Block extends StretchableTile{
|
||||
public abstract Direction directionA();
|
||||
public abstract Direction directionB();
|
||||
|
||||
private Tile drop(String tag) {
|
||||
for (int i=0; i<waitTimes.size(); i++) {
|
||||
if (waitTimes.get(i).tag.equals(tag)) {
|
||||
waitTimes.remove(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
private WaitTime getWaitTime(String tag) {
|
||||
if (tag == null) return null;
|
||||
for (WaitTime wt : waitTimes) {
|
||||
if (wt.tag.equals(tag)) return wt;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Range getWaitTime(Train train) {
|
||||
for (WaitTime wt : waitTimes) {
|
||||
if (train.tags().contains(wt.tag)) {
|
||||
return wt.get(train.direction());
|
||||
}
|
||||
}
|
||||
return getWaitTime(NO_TAG).get(train.direction());
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject json() {
|
||||
JSONObject json = super.json();
|
||||
@@ -171,7 +199,9 @@ public abstract class Block extends StretchableTile{
|
||||
new Tag("h4").content(t("Stop settings")).addTo(win);
|
||||
new Input(REALM,REALM_PLAN).hideIn(form);
|
||||
new Input(ID,id()).hideIn(form);
|
||||
new Input(ACTION,ACTION_UPDATE).hideIn(form);
|
||||
new Input(ACTION,ACTION_TIMES).hideIn(form);
|
||||
|
||||
new Tag("div").content(t("Minimum and maximum times (in Miliseconds) trains with the respective tag have to wait in this block.")).addTo(form);
|
||||
|
||||
Direction dA = directionA();
|
||||
Direction dB = directionB();
|
||||
@@ -179,23 +209,40 @@ public abstract class Block extends StretchableTile{
|
||||
Tag table = new Tag("table");
|
||||
Tag row = new Tag("tr");
|
||||
new Tag("td").content(t("Direction")).addTo(row);
|
||||
new Tag("th").content(t("{}",dA)).attr("colspan", 2).addTo(row);
|
||||
new Tag("th").content(t("{}",dB)).attr("colspan", 2).addTo(row).addTo(table);
|
||||
new Tag("th").content(t("{}bound",dA)).attr("colspan", 2).addTo(row);
|
||||
new Tag("th").content(t("{}bound",dB)).attr("colspan", 2).addTo(row);
|
||||
new Tag("td").content("").addTo(row).addTo(table);
|
||||
|
||||
row = new Tag("tr");
|
||||
new Tag("th").content(t("Tag")).addTo(row);
|
||||
new Tag("th").content(t("min")).addTo(row);
|
||||
new Tag("th").content(t("max")).addTo(row);
|
||||
new Tag("th").content(t("min")).addTo(row);
|
||||
new Tag("th").content(t("max")).addTo(row).addTo(table);
|
||||
new Tag("th").content(t("max")).addTo(row);
|
||||
new Tag("th").content(t("Actions")).addTo(row).addTo(table);
|
||||
|
||||
int count = 0;
|
||||
for (WaitTime wt : waitTimes) {
|
||||
count++;
|
||||
row = new Tag("tr");
|
||||
new Tag("td").content(wt.tag).addTo(row);
|
||||
new Input("min."+wt.tag+"."+dA,wt.get(dA).min).numeric().addTo(new Tag("td")).addTo(row);
|
||||
new Input("max."+wt.tag+"."+dA,wt.get(dA).max).numeric().addTo(new Tag("td")).addTo(row);
|
||||
new Input("min."+wt.tag+"."+dB,wt.get(dB).min).numeric().addTo(new Tag("td")).addTo(row);
|
||||
new Input("max."+wt.tag+"."+dB,wt.get(dB).max).numeric().addTo(new Tag("td")).addTo(row).addTo(table);
|
||||
new Input("max."+wt.tag+"."+dB,wt.get(dB).max).numeric().addTo(new Tag("td")).addTo(row);
|
||||
Tag actions = new Tag("td");
|
||||
Map<String, String> props = Map.of(REALM,REALM_PLAN,ID,id(),ACTION,ACTION_TIMES);
|
||||
switch (count) {
|
||||
case 1:
|
||||
actions.content(""); break;
|
||||
case 2:
|
||||
new Button("-",merged(props,Map.of(ACTION_DROP,wt.tag))).addTo(actions);
|
||||
break;
|
||||
default:
|
||||
new Button("↑",merged(props,Map.of(RAISE,wt.tag))).addTo(actions);
|
||||
new Button("-",merged(props,Map.of(ACTION_DROP,wt.tag))).addTo(actions);
|
||||
}
|
||||
actions.addTo(row).addTo(table);
|
||||
|
||||
}
|
||||
|
||||
@@ -215,6 +262,18 @@ public abstract class Block extends StretchableTile{
|
||||
return win;
|
||||
}
|
||||
|
||||
public Tile raise(String tag) {
|
||||
for (int i=1; i<waitTimes.size(); i++) {
|
||||
WaitTime wt = waitTimes.get(i);
|
||||
if (wt.tag.equals(tag)) {
|
||||
waitTimes.remove(i);
|
||||
waitTimes.insertElementAt(wt, i-1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public abstract List<Connector> startPoints();
|
||||
|
||||
@Override
|
||||
@@ -258,7 +317,20 @@ public abstract class Block extends StretchableTile{
|
||||
}
|
||||
turnAllowed = params.containsKey(ALLOW_TURN) && params.get(ALLOW_TURN).equals("on");
|
||||
|
||||
return super.update(params);
|
||||
}
|
||||
|
||||
public Tile updateTimes(HashMap<String, String> params) throws IOException {
|
||||
String tag = params.get(ACTION_DROP);
|
||||
if (isSet(tag)) return drop(tag);
|
||||
tag = params.get(RAISE);
|
||||
if (isSet(tag)) return raise(tag);
|
||||
String newTag = params.get(NEW_TAG);
|
||||
if (isSet(newTag)) {
|
||||
newTag = newTag.replace(" ", "_").trim();
|
||||
if (newTag.isEmpty()) newTag = null;
|
||||
}
|
||||
|
||||
for (Entry<String, String> entry:params.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
String val = entry.getValue();
|
||||
@@ -266,7 +338,8 @@ public abstract class Block extends StretchableTile{
|
||||
if (key.startsWith("max.") || key.startsWith("min.")) {
|
||||
String[] parts = key.split("\\.");
|
||||
boolean isMin = parts[0].equals("min");
|
||||
String tag = parts[1].equals("new_tag") ? newTag : parts[1];
|
||||
tag = parts[1].equals("new_tag") ? newTag : parts[1];
|
||||
if (isNull(tag)) continue;
|
||||
Direction dir = Direction.valueOf(parts[2]);
|
||||
|
||||
WaitTime wt = getWaitTime(tag);
|
||||
@@ -280,23 +353,6 @@ public abstract class Block extends StretchableTile{
|
||||
}
|
||||
}
|
||||
|
||||
return super.update(params);
|
||||
}
|
||||
|
||||
private WaitTime getWaitTime(String tag) {
|
||||
if (tag == null) return null;
|
||||
for (WaitTime wt : waitTimes) {
|
||||
if (wt.tag.equals(tag)) return wt;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Range getWaitTime(Train train) {
|
||||
for (WaitTime wt : waitTimes) {
|
||||
if (train.tags().contains(wt.tag)) {
|
||||
return wt.get(train.direction());
|
||||
}
|
||||
}
|
||||
return getWaitTime(NO_TAG).get(train.direction());
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -46,7 +46,6 @@ public abstract class Tile extends BaseClass{
|
||||
protected static Logger LOG = LoggerFactory.getLogger(Tile.class);
|
||||
private static int DEFAUT_LENGTH = 5;
|
||||
|
||||
public static final String ID = "id";
|
||||
private static final String LENGTH = "length";
|
||||
private static final String LOCKED = "locked";
|
||||
private static final String OCCUPIED = "occupied";
|
||||
|
||||
Reference in New Issue
Block a user