implemented AddDestination action and evaluation of destination tags of trains.
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -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.25</version>
|
<version>1.3.26</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>
|
||||||
|
|||||||
@@ -12,16 +12,18 @@ add action : Aktion hinzufügen
|
|||||||
Add action to action list : Aktion zur Liste hinzufügen
|
Add action to action list : Aktion zur Liste hinzufügen
|
||||||
add car : Waggon hinzufügen
|
add car : Waggon hinzufügen
|
||||||
Add condition : Bedingung hinzufügen
|
Add condition : Bedingung hinzufügen
|
||||||
|
AddDestination : Ziel hinzufügen
|
||||||
add locomotive : Lok hinzufügen
|
add locomotive : Lok hinzufügen
|
||||||
add new aspect : neues Signalbild hinzufügen
|
add new aspect : neues Signalbild hinzufügen
|
||||||
add new car : neuen Waggon anlegen
|
add new car : neuen Waggon anlegen
|
||||||
Add new custom field : neues benutzerdefiniertes Feld hinzufügen
|
Add new custom field : neues benutzerdefiniertes Feld hinzufügen
|
||||||
add new locomotive : neue Lok anlegen
|
add new locomotive : neue Lok anlegen
|
||||||
add new train : neuen Zug anlegen
|
add new train : neuen Zug anlegen
|
||||||
Add tag "{}" to train : Markierung "{}" zu Zug hinzufügen
|
|
||||||
Add tile : Kachel hinzufügen
|
|
||||||
AddRemoveTag : Markierung hinzufügen/entfernen
|
AddRemoveTag : Markierung hinzufügen/entfernen
|
||||||
Address : Adresse
|
Address : Adresse
|
||||||
|
Add tag "{}" to train : Markierung "{}" zu Zug hinzufügen
|
||||||
|
Add tile : Kachel hinzufügen
|
||||||
|
Add {} to destinations of train : {} zu den Zielen des Zugs hinzufügen
|
||||||
analyze : analysieren
|
analyze : analysieren
|
||||||
Analyze : analysieren
|
Analyze : analysieren
|
||||||
Analyze may overwrite these routes! : Durch die Analyse können diese Fahrstraßen überschrieben werden!
|
Analyze may overwrite these routes! : Durch die Analyse können diese Fahrstraßen überschrieben werden!
|
||||||
@@ -60,6 +62,8 @@ Car manager : Waggon-Verwaltung
|
|||||||
CarOrientation : Wagen-Laufrichtung
|
CarOrientation : Wagen-Laufrichtung
|
||||||
Cars : Waggons
|
Cars : Waggons
|
||||||
cars : Fahrzeugen teilen
|
cars : Fahrzeugen teilen
|
||||||
|
Clear destinations : Ziele löschen
|
||||||
|
Clear destinations of train : Ziele des Zugs löschen
|
||||||
Clicked tile is not a {}! : Angeklickte Kachel ist kein {}!
|
Clicked tile is not a {}! : Angeklickte Kachel ist kein {}!
|
||||||
Click here to add conditions : Hier klicken, um Bedingungen hinzuzufügen
|
Click here to add conditions : Hier klicken, um Bedingungen hinzuzufügen
|
||||||
Click here to select block! : Hier klicken, um Block auszuwählen!
|
Click here to select block! : Hier klicken, um Block auszuwählen!
|
||||||
@@ -336,8 +340,9 @@ Trigger a feedback sensor to assign it with this contact! : Rückmeldekontakt au
|
|||||||
TriggerContact : Kontakt auslösen
|
TriggerContact : Kontakt auslösen
|
||||||
Trigger contact to learn new contact : Kontakt auslösen, um neuen Kontakt zu lernen
|
Trigger contact to learn new contact : Kontakt auslösen, um neuen Kontakt zu lernen
|
||||||
Turn : Richtung wechseln
|
Turn : Richtung wechseln
|
||||||
turn train : Richtung des zuges Wechseln
|
turn train : Richtung des Zuges Wechseln
|
||||||
Turn allowed : Wenden erlaubt
|
Turn allowed : Wenden erlaubt
|
||||||
|
Turn at destination : Richtung am Ziel umkehren
|
||||||
{} turned. : {} gewendet.
|
{} turned. : {} gewendet.
|
||||||
Turnout : Weiche
|
Turnout : Weiche
|
||||||
TurnoutLE : WeicheLE
|
TurnoutLE : WeicheLE
|
||||||
|
|||||||
@@ -506,8 +506,33 @@ public class Route extends BaseClass {
|
|||||||
train.set(endBlock);
|
train.set(endBlock);
|
||||||
train.heading(endDirection);
|
train.heading(endDirection);
|
||||||
if (endBlock == train.destination()) {
|
if (endBlock == train.destination()) {
|
||||||
train.destination(null).quitAutopilot();
|
String destTag = null;
|
||||||
plan.stream(t("{} reached it`s destination!",train));
|
for (String tag : train.tags()) {
|
||||||
|
if (tag.startsWith("@")) {
|
||||||
|
destTag = tag;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
train.destination(null);
|
||||||
|
if (isSet(destTag)) {
|
||||||
|
String[] parts = destTag.split("@");
|
||||||
|
String destId = parts[1];
|
||||||
|
boolean turn = destId.endsWith("+turn");
|
||||||
|
if (turn) destId = destId.substring(0,destId.length()-5);
|
||||||
|
if (destId.equals(endBlock.id().toString())) {
|
||||||
|
if (turn) train.turn();
|
||||||
|
train.removeTag(destTag);
|
||||||
|
destTag = destTag.substring(parts[1].length()+1);
|
||||||
|
if (destTag.isEmpty()) { // no further destinations
|
||||||
|
destTag = null;
|
||||||
|
} else train.addTag(destTag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isNull(destTag)) {
|
||||||
|
train.quitAutopilot();
|
||||||
|
plan.stream(t("{} reached it`s destination!",train));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
train.setWaitTime(endBlock.getWaitTime(train,train.direction()));
|
train.setWaitTime(endBlock.getWaitTime(train,train.direction()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ public abstract class Action extends BaseClass {
|
|||||||
|
|
||||||
public static List<Class<? extends Action>> classes() {
|
public static List<Class<? extends Action>> classes() {
|
||||||
return List.of(
|
return List.of(
|
||||||
|
AddDestination.class,
|
||||||
AddRemoveTag.class,
|
AddRemoveTag.class,
|
||||||
AlterDirection.class,
|
AlterDirection.class,
|
||||||
BrakeCancel.class,
|
BrakeCancel.class,
|
||||||
|
|||||||
118
src/main/java/de/srsoftware/web4rail/actions/AddDestination.java
Normal file
118
src/main/java/de/srsoftware/web4rail/actions/AddDestination.java
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
package de.srsoftware.web4rail.actions;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import de.srsoftware.tools.Tag;
|
||||||
|
import de.srsoftware.web4rail.Application;
|
||||||
|
import de.srsoftware.web4rail.BaseClass;
|
||||||
|
import de.srsoftware.web4rail.Window;
|
||||||
|
import de.srsoftware.web4rail.moving.Train;
|
||||||
|
import de.srsoftware.web4rail.tags.Checkbox;
|
||||||
|
import de.srsoftware.web4rail.tags.Fieldset;
|
||||||
|
import de.srsoftware.web4rail.tiles.Block;
|
||||||
|
import de.srsoftware.web4rail.tiles.Tile;
|
||||||
|
|
||||||
|
public class AddDestination extends Action {
|
||||||
|
|
||||||
|
private static final String TURN = "turn";
|
||||||
|
private Block destination;
|
||||||
|
private boolean turnAtDestination;
|
||||||
|
|
||||||
|
public AddDestination(BaseClass parent) {
|
||||||
|
super(parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean fire(Context context) {
|
||||||
|
Train train = context.train();
|
||||||
|
if (isNull(train)) return false;
|
||||||
|
if (isNull(destination)) { // clear destinations!
|
||||||
|
Iterator<String> it = train.tags().iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
String tag = it.next();
|
||||||
|
if (tag.startsWith("@")) it = train.removeTag(tag);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
String dest = "@"+destination.id()+(turnAtDestination?"+turn":"");
|
||||||
|
for (String tag: train.tags()) {
|
||||||
|
if (tag.startsWith("@")) {
|
||||||
|
train.removeTag(tag);
|
||||||
|
dest = tag+dest;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
train.addTag(dest);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject json() {
|
||||||
|
JSONObject json = super.json();
|
||||||
|
if (isSet(destination)) json.put(Train.DESTINATION,destination.id().toString());
|
||||||
|
if (turnAtDestination) json.put(TURN,true);
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Action load(JSONObject json) {
|
||||||
|
if (json.has(TURN)) turnAtDestination = json.getBoolean(TURN);
|
||||||
|
if (json.has(Train.DESTINATION)) {
|
||||||
|
Id blockId = new Id(json.getString(Train.DESTINATION));
|
||||||
|
destination = BaseClass.get(blockId);
|
||||||
|
if (isNull(destination)) {
|
||||||
|
Application.threadPool.execute(new Thread() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
sleep(1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
destination = BaseClass.get(blockId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return super.load(json);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
||||||
|
Tag span = new Tag("span");
|
||||||
|
button(t("Select from plan"),Map.of(ACTION,ACTION_UPDATE,ASSIGN,Train.DESTINATION)).addTo(span);
|
||||||
|
button(t("Clear destinations"),Map.of(ACTION,ACTION_UPDATE,Train.DESTINATION,"0")).addTo(span);
|
||||||
|
formInputs.add(t("Destination")+": "+(isNull(destination) ? t("Clear destinations") : destination),span);
|
||||||
|
formInputs.add(t("Turn at destination"),new Checkbox(TURN, t("Turn"), turnAtDestination));
|
||||||
|
return super.properties(preForm, formInputs, postForm);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return isSet(destination) ? t("Add {} to destinations of train",destination) : t("Clear destinations of train");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object update(HashMap<String, String> params) {
|
||||||
|
if (params.containsKey(Train.DESTINATION)) {
|
||||||
|
String destId = params.get(Train.DESTINATION);
|
||||||
|
if ("0".equals(destId)) {
|
||||||
|
destination = null;
|
||||||
|
} else {
|
||||||
|
Tile tile = plan.get(new Id(destId), true);
|
||||||
|
if (tile instanceof Block) {
|
||||||
|
destination = (Block) tile;
|
||||||
|
} else {
|
||||||
|
return t("Clicked tile is not a {}!",t("block"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
turnAtDestination = "on".equals(params.get(TURN));
|
||||||
|
return context().properties();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package de.srsoftware.web4rail.actions;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
@@ -10,6 +11,7 @@ import de.srsoftware.web4rail.BaseClass;
|
|||||||
import de.srsoftware.web4rail.Window;
|
import de.srsoftware.web4rail.Window;
|
||||||
import de.srsoftware.web4rail.tags.Fieldset;
|
import de.srsoftware.web4rail.tags.Fieldset;
|
||||||
import de.srsoftware.web4rail.tiles.Block;
|
import de.srsoftware.web4rail.tiles.Block;
|
||||||
|
import de.srsoftware.web4rail.tiles.Tile;
|
||||||
|
|
||||||
public class DetermineTrainInBlock extends Action {
|
public class DetermineTrainInBlock extends Action {
|
||||||
|
|
||||||
@@ -57,7 +59,7 @@ public class DetermineTrainInBlock extends Action {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
||||||
formInputs.add(t("Select block"),Block.selector(block, null));
|
formInputs.add(t("Block")+": "+(isNull(block) ? t("unset") : block),button(t("Select from plan"),Map.of(ACTION,ACTION_UPDATE,ASSIGN,BLOCK)));
|
||||||
return super.properties(preForm, formInputs, postForm);
|
return super.properties(preForm, formInputs, postForm);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,8 +76,12 @@ public class DetermineTrainInBlock extends Action {
|
|||||||
@Override
|
@Override
|
||||||
protected Object update(HashMap<String, String> params) {
|
protected Object update(HashMap<String, String> params) {
|
||||||
LOG.debug("update: {}",params);
|
LOG.debug("update: {}",params);
|
||||||
Id blockId = Id.from(params,Block.class.getSimpleName());
|
if (params.containsKey(BLOCK)) {
|
||||||
if (isSet(blockId)) block = Block.get(blockId);
|
Tile tile = plan.get(new Id(params.get(BLOCK)), true);
|
||||||
return properties();
|
if (tile instanceof Block) {
|
||||||
|
block = (Block) tile;
|
||||||
|
} else return t("Clicked tile is not a {}!",t("block"));
|
||||||
|
}
|
||||||
|
return context().properties();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package de.srsoftware.web4rail.actions;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
@@ -11,6 +12,7 @@ import de.srsoftware.web4rail.Window;
|
|||||||
import de.srsoftware.web4rail.tags.Fieldset;
|
import de.srsoftware.web4rail.tags.Fieldset;
|
||||||
import de.srsoftware.web4rail.tags.Label;
|
import de.srsoftware.web4rail.tags.Label;
|
||||||
import de.srsoftware.web4rail.tiles.TextDisplay;
|
import de.srsoftware.web4rail.tiles.TextDisplay;
|
||||||
|
import de.srsoftware.web4rail.tiles.Tile;
|
||||||
|
|
||||||
public class SetDisplayText extends TextAction{
|
public class SetDisplayText extends TextAction{
|
||||||
|
|
||||||
@@ -29,7 +31,9 @@ public class SetDisplayText extends TextAction{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JSONObject json() {
|
public JSONObject json() {
|
||||||
return super.json().put(DISPLAY, display.id());
|
JSONObject json = super.json();
|
||||||
|
if (isSet(display)) json.put(DISPLAY, display.id());
|
||||||
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -60,7 +64,7 @@ public class SetDisplayText extends TextAction{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
||||||
formInputs.add(t("Select display"),TextDisplay.selector(display, null));
|
formInputs.add(t("Display")+": "+(isNull(display) ? t("unset") : display),button(t("Select from plan"),Map.of(ACTION,ACTION_UPDATE,ASSIGN,DISPLAY)));
|
||||||
return super.properties(preForm, formInputs, postForm);
|
return super.properties(preForm, formInputs, postForm);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,9 +74,14 @@ public class SetDisplayText extends TextAction{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Object update(HashMap<String, String> params) {
|
protected Object update(HashMap<String, String> params) {
|
||||||
String displayId = params.get(TextDisplay.class.getSimpleName());
|
if (params.containsKey(DISPLAY)) {
|
||||||
if (isSet(displayId)) display = (TextDisplay) plan.get(new Id(displayId), false);
|
Tile object = plan.get(new Id(params.get(DISPLAY)), true);
|
||||||
|
if (object instanceof TextDisplay) {
|
||||||
|
display = (TextDisplay) object;
|
||||||
|
} else return t("Clicked tile is not a {}!",t("display"));
|
||||||
|
|
||||||
|
}
|
||||||
return super.update(params);
|
return super.update(params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package de.srsoftware.web4rail.actions;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
@@ -73,8 +74,7 @@ public class SetTurnout extends Action {
|
|||||||
@Override
|
@Override
|
||||||
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
||||||
|
|
||||||
formInputs.add(t("Select turnout"),Turnout.selector(turnout,null));
|
formInputs.add(t("Turnout")+": "+(isNull(turnout) ? t("unset") : turnout),button(t("Select from plan"),Map.of(ACTION,ACTION_UPDATE,ASSIGN,TURNOUT)));
|
||||||
|
|
||||||
if (isSet(turnout)) {
|
if (isSet(turnout)) {
|
||||||
Select select = new Select(Turnout.STATE);
|
Select select = new Select(Turnout.STATE);
|
||||||
|
|
||||||
@@ -112,8 +112,12 @@ public class SetTurnout extends Action {
|
|||||||
@Override
|
@Override
|
||||||
protected Object update(HashMap<String, String> params) {
|
protected Object update(HashMap<String, String> params) {
|
||||||
LOG.debug("update: {}",params);
|
LOG.debug("update: {}",params);
|
||||||
Id turnoutId = new Id(params.get(TURNOUT));
|
if (params.containsKey(TURNOUT)) {
|
||||||
turnout = BaseClass.get(turnoutId);
|
BaseClass object = BaseClass.get(new Id(params.get(TURNOUT)));
|
||||||
|
if (object instanceof Turnout) {
|
||||||
|
turnout = (Turnout) object;
|
||||||
|
} else return t("Clicked tile is not a {}!",t("turnout"));
|
||||||
|
}
|
||||||
String st = params.get(Turnout.STATE);
|
String st = params.get(Turnout.STATE);
|
||||||
if (isSet(st)) state = Turnout.State.valueOf(st);
|
if (isSet(st)) state = Turnout.State.valueOf(st);
|
||||||
return super.update(params);
|
return super.update(params);
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public abstract class TextAction extends Action {
|
|||||||
@Override
|
@Override
|
||||||
protected Object update(HashMap<String, String> params) {
|
protected Object update(HashMap<String, String> params) {
|
||||||
LOG.debug("update: {}",params);
|
LOG.debug("update: {}",params);
|
||||||
text = params.get(TEXT);
|
if (params.containsKey(TEXT)) text = params.get(TEXT);
|
||||||
return super.update(params);
|
return super.update(params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,9 +77,7 @@ public class BlockFree extends Condition {
|
|||||||
@Override
|
@Override
|
||||||
protected Object update(HashMap<String, String> params) {
|
protected Object update(HashMap<String, String> params) {
|
||||||
if (!params.containsKey(BLOCK)) return t("No block id passed to BlockFree.update()!");
|
if (!params.containsKey(BLOCK)) return t("No block id passed to BlockFree.update()!");
|
||||||
Id bid = new Id(params.get(BLOCK));
|
Tile tile = plan.get(new Id(params.get(BLOCK)), true);
|
||||||
|
|
||||||
Tile tile = plan.get(bid, true);
|
|
||||||
if (tile instanceof Block) {
|
if (tile instanceof Block) {
|
||||||
block = (Block) tile;
|
block = (Block) tile;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package de.srsoftware.web4rail.conditions;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
@@ -11,6 +12,7 @@ import de.srsoftware.web4rail.Route;
|
|||||||
import de.srsoftware.web4rail.Window;
|
import de.srsoftware.web4rail.Window;
|
||||||
import de.srsoftware.web4rail.tags.Fieldset;
|
import de.srsoftware.web4rail.tags.Fieldset;
|
||||||
import de.srsoftware.web4rail.tiles.Block;
|
import de.srsoftware.web4rail.tiles.Block;
|
||||||
|
import de.srsoftware.web4rail.tiles.Tile;
|
||||||
|
|
||||||
public class RouteEndBlock extends Condition{
|
public class RouteEndBlock extends Condition{
|
||||||
|
|
||||||
@@ -58,7 +60,7 @@ public class RouteEndBlock extends Condition{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
||||||
formInputs.add(t("Select block"), Block.selector(block, null));
|
formInputs.add(t("Block")+": "+(isNull(block) ? t("unset") : block),button(t("Select from plan"),Map.of(ACTION,ACTION_UPDATE,ASSIGN,BLOCK)));
|
||||||
return super.properties(preForm, formInputs, postForm);
|
return super.properties(preForm, formInputs, postForm);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,11 +79,12 @@ public class RouteEndBlock extends Condition{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Object update(HashMap<String, String> params) {
|
protected Object update(HashMap<String, String> params) {
|
||||||
if (!params.containsKey(BLOCK)) return t("No block id passed to RouteEndBlock.update()!");
|
if (params.containsKey(BLOCK)) {
|
||||||
Id bid = new Id(params.get(BLOCK));
|
Tile tile = plan.get(new Id(params.get(BLOCK)), true);
|
||||||
Block block = Block.get(bid);
|
if (tile instanceof Block) {
|
||||||
if (block == null) return t("No block with id {} found!",bid);
|
block = (Block) tile;
|
||||||
this.block = block;
|
} else return t("Clicked tile is not a {}!",t("block"));
|
||||||
|
}
|
||||||
return super.update(params);
|
return super.update(params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import java.util.Collection;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -68,7 +69,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
|
|
||||||
private static final String TAGS = "tags";
|
private static final String TAGS = "tags";
|
||||||
|
|
||||||
private static final String DESTINATION = "destination";
|
public static final String DESTINATION = "destination";
|
||||||
|
|
||||||
private static final String ACTION_REVERSE = "reverse";
|
private static final String ACTION_REVERSE = "reverse";
|
||||||
|
|
||||||
@@ -172,6 +173,11 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
}
|
}
|
||||||
return t("Unknown action: {}",params.get(ACTION));
|
return t("Unknown action: {}",params.get(ACTION));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addTag(String tag) {
|
||||||
|
tags.add(tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void addToTrace(Vector<Tile> newTiles) {
|
public void addToTrace(Vector<Tile> newTiles) {
|
||||||
Route.LOG.debug("{}.addToTrace({})",this,newTiles);
|
Route.LOG.debug("{}.addToTrace({})",this,newTiles);
|
||||||
@@ -329,6 +335,22 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Block destination() {
|
public Block destination() {
|
||||||
|
if (isNull(destination)) {
|
||||||
|
String destTag = null;
|
||||||
|
for (String tag : tags) {
|
||||||
|
if (tag.startsWith("@")) {
|
||||||
|
destTag = tag;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isSet(destTag)) {
|
||||||
|
String[] parts = destTag.split("@");
|
||||||
|
destTag = parts[1];
|
||||||
|
if (destTag.endsWith("+turn")) destTag = destTag.substring(0,destTag.length()-5);
|
||||||
|
BaseClass object = BaseClass.get(new Id(destTag));
|
||||||
|
if (object instanceof Block) destination = (Block) object;
|
||||||
|
}
|
||||||
|
}
|
||||||
return destination;
|
return destination;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -663,6 +685,12 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
super.removeChild(child);
|
super.removeChild(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Iterator<String> removeTag(String tag) {
|
||||||
|
tags.remove(tag);
|
||||||
|
return tags().iterator();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void reserveNext() {
|
public void reserveNext() {
|
||||||
LOG.debug("{}.reserveNext()",this);
|
LOG.debug("{}.reserveNext()",this);
|
||||||
Context context = new Context(this).route(route).block(route.endBlock()).direction(route.endDirection);
|
Context context = new Context(this).route(route).block(route.endBlock()).direction(route.endDirection);
|
||||||
|
|||||||
@@ -243,6 +243,11 @@ public class Contact extends Tile{
|
|||||||
public String title() {
|
public String title() {
|
||||||
return t("Contact {} @ ({}, {})",addr,x,y);
|
return t("Contact {} @ ({}, {})",addr,x,y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return t("Contact")+"("+x+","+y+")";
|
||||||
|
}
|
||||||
|
|
||||||
public String trigger() {
|
public String trigger() {
|
||||||
if (trigger == null) trigger = getClass().getSimpleName()+"-"+id();
|
if (trigger == null) trigger = getClass().getSimpleName()+"-"+id();
|
||||||
|
|||||||
@@ -151,6 +151,12 @@ public abstract class Decoupler extends Tile implements Device{
|
|||||||
return select;
|
return select;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return t("Decoupler")+"("+x+","+y+")";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Tile update(HashMap<String, String> params) {
|
public Tile update(HashMap<String, String> params) {
|
||||||
if (params.containsKey(PROTOCOL)) protocol = Protocol.valueOf(params.get(PROTOCOL));
|
if (params.containsKey(PROTOCOL)) protocol = Protocol.valueOf(params.get(PROTOCOL));
|
||||||
|
|||||||
Reference in New Issue
Block a user