implemented RouteEndBlock condition
This commit is contained in:
12
.gitignore
vendored
12
.gitignore
vendored
@@ -1,7 +1,11 @@
|
|||||||
/Debug/
|
|
||||||
*.pyc
|
*.pyc
|
||||||
*.log
|
*.log
|
||||||
/bin/
|
*.plan
|
||||||
/target/
|
*.cars
|
||||||
/default.*
|
*.cu
|
||||||
|
*.routes
|
||||||
|
*.trains
|
||||||
/backup
|
/backup
|
||||||
|
/bin/
|
||||||
|
/Debug/
|
||||||
|
/target/
|
||||||
|
|||||||
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.8</version>
|
<version>1.3.9</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>
|
||||||
|
|||||||
@@ -211,6 +211,9 @@ reverse : wenden
|
|||||||
Reversed {}. : {} umgedreht.
|
Reversed {}. : {} umgedreht.
|
||||||
RIGHT : rechts
|
RIGHT : rechts
|
||||||
Right port\: : Port für rechts
|
Right port\: : Port für rechts
|
||||||
|
RouteEndBlock : Routen-End-Block
|
||||||
|
Route does not end at {}. : Route endet nicht in {}.
|
||||||
|
Route ends at {}. : Route endet in {}.
|
||||||
Route properties : Routen-Eigenschaften
|
Route properties : Routen-Eigenschaften
|
||||||
Routes : Fahrstraßen
|
Routes : Fahrstraßen
|
||||||
Routes using this tile : Fahrstraßen, die diesen Abschnitt verwenden
|
Routes using this tile : Fahrstraßen, die diesen Abschnitt verwenden
|
||||||
|
|||||||
@@ -121,6 +121,7 @@ public abstract class Condition extends BaseClass {
|
|||||||
CarOrientation.class,
|
CarOrientation.class,
|
||||||
OrCondition.class,
|
OrCondition.class,
|
||||||
PushPullTrain.class,
|
PushPullTrain.class,
|
||||||
|
RouteEndBlock.class,
|
||||||
TrainHasTag.class,
|
TrainHasTag.class,
|
||||||
TrainLength.class,
|
TrainLength.class,
|
||||||
TrainSelect.class,
|
TrainSelect.class,
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
package de.srsoftware.web4rail.conditions;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import de.srsoftware.web4rail.BaseClass;
|
||||||
|
import de.srsoftware.web4rail.Route;
|
||||||
|
import de.srsoftware.web4rail.Window;
|
||||||
|
import de.srsoftware.web4rail.tags.Fieldset;
|
||||||
|
import de.srsoftware.web4rail.tiles.Block;
|
||||||
|
|
||||||
|
public class RouteEndBlock extends Condition{
|
||||||
|
|
||||||
|
private static final String BLOCK = Block.class.getSimpleName();
|
||||||
|
private Block block;
|
||||||
|
|
||||||
|
private RouteEndBlock block(Block block) {
|
||||||
|
this.block = block;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean fulfilledBy(Context context) {
|
||||||
|
if (isNull(context)) return false;
|
||||||
|
Route route = context.route();
|
||||||
|
if (isNull(route)) return false;
|
||||||
|
return route.endBlock() == block;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject json() {
|
||||||
|
return super.json().put(BLOCK, block.id());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Condition load(JSONObject json) {
|
||||||
|
super.load(json);
|
||||||
|
block(Block.get(new Id(json.getString(BLOCK))));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
||||||
|
formInputs.add(t("Select block"), Block.selector(block, null));
|
||||||
|
return super.properties(preForm, formInputs, postForm);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void removeChild(BaseClass child) {
|
||||||
|
if (child == block) block = null;
|
||||||
|
super.removeChild(child);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
if (block == null) return "["+t("Click here to select block!")+"]";
|
||||||
|
return t(inverted ? "Route does not end at {}.":"Route ends at {}.",block);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object update(HashMap<String, String> params) {
|
||||||
|
if (!params.containsKey(BLOCK)) return t("No block id passed to RouteEndBlock.update()!");
|
||||||
|
Id bid = new Id(params.get(BLOCK));
|
||||||
|
Block block = Block.get(bid);
|
||||||
|
if (block == null) return t("No block with id {} found!",bid);
|
||||||
|
this.block = block;
|
||||||
|
return super.update(params);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -158,7 +158,7 @@ public abstract class Block extends StretchableTile{
|
|||||||
if (!internalContacts.isEmpty()) {
|
if (!internalContacts.isEmpty()) {
|
||||||
Tag ul = new Tag("ul");
|
Tag ul = new Tag("ul");
|
||||||
for (BlockContact contact : internalContacts) {
|
for (BlockContact contact : internalContacts) {
|
||||||
Tag li = new Tag("li").content(contact.toString()+NBSP);
|
Tag li = contact.link("span", contact).content(NBSP).addTo(new Tag("li"));
|
||||||
contact.button(t("learn"),Map.of(ACTION,ACTION_ANALYZE)).addTo(li);
|
contact.button(t("learn"),Map.of(ACTION,ACTION_ANALYZE)).addTo(li);
|
||||||
contact.button(t("delete"),Map.of(ACTION,ACTION_DROP)).addTo(li);
|
contact.button(t("delete"),Map.of(ACTION,ACTION_DROP)).addTo(li);
|
||||||
li.addTo(ul);
|
li.addTo(ul);
|
||||||
@@ -224,10 +224,9 @@ public abstract class Block extends StretchableTile{
|
|||||||
json.put(WAIT_TIMES, jWaitTimes);
|
json.put(WAIT_TIMES, jWaitTimes);
|
||||||
JSONObject jContacts = null;
|
JSONObject jContacts = null;
|
||||||
for (BlockContact contact : internalContacts) {
|
for (BlockContact contact : internalContacts) {
|
||||||
int addr = contact.addr();
|
if (contact.addr() != 0) {
|
||||||
if (addr != 0) {
|
|
||||||
if (isNull(jContacts)) jContacts = new JSONObject();
|
if (isNull(jContacts)) jContacts = new JSONObject();
|
||||||
jContacts.put(contact.id().toString(), contact.addr());
|
jContacts.put(contact.id().toString(), contact.json());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isSet(jContacts)) json.put(CONTACT, jContacts);
|
if (isSet(jContacts)) json.put(CONTACT, jContacts);
|
||||||
@@ -260,7 +259,9 @@ public abstract class Block extends StretchableTile{
|
|||||||
}
|
}
|
||||||
if (json.has(CONTACT)) {
|
if (json.has(CONTACT)) {
|
||||||
JSONObject jContact = json.getJSONObject(CONTACT);
|
JSONObject jContact = json.getJSONObject(CONTACT);
|
||||||
for (String key : jContact.keySet()) new BlockContact(this).addr(jContact.getInt(key));
|
for (String key : jContact.keySet()) {
|
||||||
|
new BlockContact(this).load(jContact.getJSONObject(key));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return super.load(json);
|
return super.load(json);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import java.util.Map;
|
|||||||
|
|
||||||
import de.srsoftware.tools.Tag;
|
import de.srsoftware.tools.Tag;
|
||||||
import de.srsoftware.web4rail.Route;
|
import de.srsoftware.web4rail.Route;
|
||||||
import de.srsoftware.web4rail.Window;
|
|
||||||
|
|
||||||
public class BlockContact extends Contact {
|
public class BlockContact extends Contact {
|
||||||
|
|
||||||
@@ -28,11 +27,6 @@ public class BlockContact extends Contact {
|
|||||||
return new Id(block.name+":"+block.indexOf(this));
|
return new Id(block.name+":"+block.indexOf(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Window properties() {
|
|
||||||
return parent().properties();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Route route() {
|
public Route route() {
|
||||||
return ((Block)parent()).route();
|
return ((Block)parent()).route();
|
||||||
|
|||||||
@@ -171,6 +171,8 @@ public class Contact extends Tile{
|
|||||||
contact.remove();
|
contact.remove();
|
||||||
if (contact instanceof BlockContact) return contact.properties();
|
if (contact instanceof BlockContact) return contact.properties();
|
||||||
return t("Removed {}.",id);
|
return t("Removed {}.",id);
|
||||||
|
case ACTION_PROPS:
|
||||||
|
return contact.properties();
|
||||||
case ACTION_UPDATE:
|
case ACTION_UPDATE:
|
||||||
return plan.update(params);
|
return plan.update(params);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ public abstract class Tile extends BaseClass implements Comparable<Tile>{
|
|||||||
public JSONObject json() {
|
public JSONObject json() {
|
||||||
JSONObject json = super.json();
|
JSONObject json = super.json();
|
||||||
json.put(TYPE, getClass().getSimpleName());
|
json.put(TYPE, getClass().getSimpleName());
|
||||||
json.put(POS, new JSONObject(Map.of(X,x,Y,y)));
|
if (isSet(x) && isSet(y)) json.put(POS, new JSONObject(Map.of(X,x,Y,y)));
|
||||||
if (isSet(route)) json.put(ROUTE, route.id());
|
if (isSet(route)) json.put(ROUTE, route.id());
|
||||||
if (isSet(oneWay)) json.put(ONEW_WAY, oneWay);
|
if (isSet(oneWay)) json.put(ONEW_WAY, oneWay);
|
||||||
if (disabled) json.put(DISABLED, true);
|
if (disabled) json.put(DISABLED, true);
|
||||||
@@ -206,9 +206,11 @@ public abstract class Tile extends BaseClass implements Comparable<Tile>{
|
|||||||
public Tile load(JSONObject json) {
|
public Tile load(JSONObject json) {
|
||||||
if (json.has(ID)) json.remove(ID); // id should be created from cordinates
|
if (json.has(ID)) json.remove(ID); // id should be created from cordinates
|
||||||
super.load(json);
|
super.load(json);
|
||||||
JSONObject pos = json.getJSONObject(POS);
|
if (json.has(POS)) {
|
||||||
x = pos.getInt(X);
|
JSONObject pos = json.getJSONObject(POS);
|
||||||
y = pos.getInt(Y);
|
x = pos.getInt(X);
|
||||||
|
y = pos.getInt(Y);
|
||||||
|
}
|
||||||
if (json.has(DISABLED)) disabled = json.getBoolean(DISABLED);
|
if (json.has(DISABLED)) disabled = json.getBoolean(DISABLED);
|
||||||
if (json.has(LENGTH)) length = json.getInt(LENGTH);
|
if (json.has(LENGTH)) length = json.getInt(LENGTH);
|
||||||
if (json.has(ONEW_WAY)) oneWay = Direction.valueOf(json.getString(ONEW_WAY));
|
if (json.has(ONEW_WAY)) oneWay = Direction.valueOf(json.getString(ONEW_WAY));
|
||||||
|
|||||||
Reference in New Issue
Block a user