bugfixes + added new condition TrainWasInBlock
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.11</version>
|
<version>1.3.12</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>
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ BlockFree : Blockbelegung
|
|||||||
Block {} is free : Block {} ist frei
|
Block {} is free : Block {} ist frei
|
||||||
Block {} is occupied : Block {} ist belegt
|
Block {} is occupied : Block {} ist belegt
|
||||||
Block properties : Block-Eigenschaften
|
Block properties : Block-Eigenschaften
|
||||||
|
blocks of train : Blöcke des Zugs
|
||||||
{}bound : nach {}
|
{}bound : nach {}
|
||||||
BrakeCancel : Bremsvorgang abbrechen
|
BrakeCancel : Bremsvorgang abbrechen
|
||||||
BrakeStart : Bremsvorgang starten
|
BrakeStart : Bremsvorgang starten
|
||||||
@@ -139,6 +140,7 @@ known cars : bekannte Waggons
|
|||||||
known locomotives : bekannte Lokomotiven
|
known locomotives : bekannte Lokomotiven
|
||||||
known trains : bekannte Züge
|
known trains : bekannte Züge
|
||||||
Label for state {} : Beschriftung für Status {}
|
Label for state {} : Beschriftung für Status {}
|
||||||
|
Last blocks : Letzte Blöcke
|
||||||
learn : lernen
|
learn : lernen
|
||||||
LEFT : links
|
LEFT : links
|
||||||
Left port\: : Port für links
|
Left port\: : Port für links
|
||||||
@@ -173,6 +175,7 @@ NORTH : Norden
|
|||||||
Not connected to other bridge part! : Nicht mit anderem Brücken-Teil verbunden!
|
Not connected to other bridge part! : Nicht mit anderem Brücken-Teil verbunden!
|
||||||
Notes : Notizen
|
Notes : Notizen
|
||||||
No tile moved. : keine Kachel verschoben.
|
No tile moved. : keine Kachel verschoben.
|
||||||
|
{} not within last {} blocks of train : {} ist nicht in den letzten {} Blöcken des Zugs
|
||||||
{} now heading for {} : {} ist nun unterwegs nach {}
|
{} now heading for {} : {} ist nun unterwegs nach {}
|
||||||
{} now in auto-mode : {} ist nun im Automatikmodus
|
{} now in auto-mode : {} ist nun im Automatikmodus
|
||||||
Occupied area\: : Belegte Abschnitte:
|
Occupied area\: : Belegte Abschnitte:
|
||||||
@@ -221,6 +224,7 @@ Route will only be available, if all conditions are fulfilled. : Route ist nur v
|
|||||||
Save "{}" : „{}“ speichern
|
Save "{}" : „{}“ speichern
|
||||||
Save : speichern
|
Save : speichern
|
||||||
SavePlan : Plan speichern
|
SavePlan : Plan speichern
|
||||||
|
Seek in last : Durchsuche letzte
|
||||||
Select block : Block auswählen
|
Select block : Block auswählen
|
||||||
Select car : Fahrzeug auswählen
|
Select car : Fahrzeug auswählen
|
||||||
Select contact\: : Kotakt auswählen:
|
Select contact\: : Kotakt auswählen:
|
||||||
@@ -304,6 +308,7 @@ Trains\: : Züge:
|
|||||||
TrainSelect : Zug-Auswahl
|
TrainSelect : Zug-Auswahl
|
||||||
TrainSpeed : Zug-Geschwindigkeit
|
TrainSpeed : Zug-Geschwindigkeit
|
||||||
Train speed : Zug-Geschwindigkeit
|
Train speed : Zug-Geschwindigkeit
|
||||||
|
TrainWasInBlock : Zug war im Block
|
||||||
Trigger {} : {} betätigen
|
Trigger {} : {} betätigen
|
||||||
Trigger a feedback sensor to assign it with this contact! : Rückmeldekontakt auslösen, um ihn diesem Kontakt zuzuweisen!
|
Trigger a feedback sensor to assign it with this contact! : Rückmeldekontakt auslösen, um ihn diesem Kontakt zuzuweisen!
|
||||||
TriggerContact : Kontakt auslösen
|
TriggerContact : Kontakt auslösen
|
||||||
@@ -335,4 +340,5 @@ Was not able to set all signals! : Konnte nicht alle Signale stellen!
|
|||||||
Was not able to set all turnouts! : Konnte nicht alle Weichen stellen!
|
Was not able to set all turnouts! : Konnte nicht alle Weichen stellen!
|
||||||
WEST : Westen
|
WEST : Westen
|
||||||
Width : Breite
|
Width : Breite
|
||||||
|
{} within last {} blocks of train : {} ist in den letzten {} Blöcken des Zugs
|
||||||
Your plan currently has {} routes. : Ihr Plan hat im Moment {} Fahrstraßen.
|
Your plan currently has {} routes. : Ihr Plan hat im Moment {} Fahrstraßen.
|
||||||
@@ -32,7 +32,7 @@ public class BlockFree extends Condition {
|
|||||||
|
|
||||||
public Condition load(JSONObject json) {
|
public Condition load(JSONObject json) {
|
||||||
super.load(json);
|
super.load(json);
|
||||||
block(Block.get(new Id(json.getString(BLOCK))));
|
if (json.has(BLOCK)) block(Block.get(new Id(json.getString(BLOCK))));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,7 +60,7 @@ public class BlockFree extends Condition {
|
|||||||
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));
|
Id bid = new Id(params.get(BLOCK));
|
||||||
Block block = Block.get(bid);
|
Block block = Block.get(bid);
|
||||||
if (block == null) return t("No block with id {} found!",bid);
|
if (isNull(block)) return t("No block with id {} found!",bid);
|
||||||
this.block = block;
|
this.block = block;
|
||||||
return super.update(params);
|
return super.update(params);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -125,7 +125,8 @@ public abstract class Condition extends BaseClass {
|
|||||||
TrainHasTag.class,
|
TrainHasTag.class,
|
||||||
TrainLength.class,
|
TrainLength.class,
|
||||||
TrainSelect.class,
|
TrainSelect.class,
|
||||||
TrainSpeed.class);
|
TrainSpeed.class,
|
||||||
|
TrainWasInBlock.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Condition load(JSONObject json) {
|
public Condition load(JSONObject json) {
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
package de.srsoftware.web4rail.conditions;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import de.srsoftware.tools.Tag;
|
||||||
|
import de.srsoftware.web4rail.BaseClass;
|
||||||
|
import de.srsoftware.web4rail.Window;
|
||||||
|
import de.srsoftware.web4rail.moving.Train;
|
||||||
|
import de.srsoftware.web4rail.tags.Fieldset;
|
||||||
|
import de.srsoftware.web4rail.tags.Input;
|
||||||
|
import de.srsoftware.web4rail.tiles.Block;
|
||||||
|
|
||||||
|
public class TrainWasInBlock extends Condition {
|
||||||
|
|
||||||
|
private static final String BLOCK = Block.class.getSimpleName();
|
||||||
|
private static final String COUNT = "count";
|
||||||
|
private Block block;
|
||||||
|
private int count = 5;
|
||||||
|
|
||||||
|
private TrainWasInBlock block(Block block) {
|
||||||
|
this.block = block;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean fulfilledBy(Context context) {
|
||||||
|
Train train = context.train();
|
||||||
|
if (isNull(train)) return false;
|
||||||
|
return train.lastBlocks(count).contains(block) != inverted;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject json() {
|
||||||
|
return super.json().put(BLOCK, block.id()).put(COUNT, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Condition load(JSONObject json) {
|
||||||
|
super.load(json);
|
||||||
|
if (json.has(BLOCK)) block(Block.get(new Id(json.getString(BLOCK))));
|
||||||
|
if (json.has(COUNT)) count = json.getInt(COUNT);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
||||||
|
formInputs.add(t("Select block"), Block.selector(block, null));
|
||||||
|
formInputs.add(t("Seek in last"), new Input(COUNT, count).numeric().addTo(new Tag("span")).content(NBSP+t("blocks of train")));
|
||||||
|
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 ? "{} not within last {} blocks of train":"{} within last {} blocks of train",block,count);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object update(HashMap<String, String> params) {
|
||||||
|
if (!params.containsKey(BLOCK)) return t("No block id passed to TrainWasInBlock.update()!");
|
||||||
|
Id bid = new Id(params.get(BLOCK));
|
||||||
|
Block block = Block.get(bid);
|
||||||
|
if (isNull(block)) return t("No block with id {} found!",bid);
|
||||||
|
this.block = block;
|
||||||
|
if (params.containsKey(COUNT)) count=Integer.parseInt(params.get(COUNT));
|
||||||
|
return super.update(params);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -80,6 +80,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
|
|
||||||
private Block currentBlock,destination = null;
|
private Block currentBlock,destination = null;
|
||||||
LinkedList<Tile> trace = new LinkedList<Tile>();
|
LinkedList<Tile> trace = new LinkedList<Tile>();
|
||||||
|
private Vector<Block> lastBlocks = new Vector<Block>();
|
||||||
|
|
||||||
public int speed = 0;
|
public int speed = 0;
|
||||||
private Autopilot autopilot = null;
|
private Autopilot autopilot = null;
|
||||||
@@ -227,6 +228,16 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
return t("{} now in auto-mode",this);
|
return t("{} now in auto-mode",this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Fieldset blockHistory() {
|
||||||
|
Fieldset fieldset = new Fieldset(t("Last blocks"));
|
||||||
|
Tag list = new Tag("ol");
|
||||||
|
for (int i=lastBlocks.size(); i>0; i--) {
|
||||||
|
lastBlocks.get(i-1).link().addTo(new Tag("li")).addTo(list);
|
||||||
|
}
|
||||||
|
return list.addTo(fieldset);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public String brakeId() {
|
public String brakeId() {
|
||||||
return brakeId(false);
|
return brakeId(false);
|
||||||
}
|
}
|
||||||
@@ -405,6 +416,12 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
if (!tags.isEmpty()) json.put(TAGS, tags);
|
if (!tags.isEmpty()) json.put(TAGS, tags);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Collection<Block> lastBlocks(int count) {
|
||||||
|
Vector<Block> blocks = new Vector<Block>(count);
|
||||||
|
for (int i=0; i<count && i<lastBlocks.size(); i++) blocks.add(lastBlocks.get(i));
|
||||||
|
return blocks;
|
||||||
|
}
|
||||||
|
|
||||||
public int length() {
|
public int length() {
|
||||||
int result = 0;
|
int result = 0;
|
||||||
@@ -593,6 +610,8 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
preForm.add(Locomotive.cockpit(this));
|
preForm.add(Locomotive.cockpit(this));
|
||||||
postForm.add(otherTrainProps);
|
postForm.add(otherTrainProps);
|
||||||
postForm.add(brakeTimes());
|
postForm.add(brakeTimes());
|
||||||
|
postForm.add(blockHistory());
|
||||||
|
|
||||||
|
|
||||||
return super.properties(preForm, formInputs, postForm);
|
return super.properties(preForm, formInputs, postForm);
|
||||||
}
|
}
|
||||||
@@ -700,7 +719,11 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
public void set(Block newBlock) {
|
public void set(Block newBlock) {
|
||||||
LOG.debug("{}.set({})",this,newBlock);
|
LOG.debug("{}.set({})",this,newBlock);
|
||||||
currentBlock = newBlock;
|
currentBlock = newBlock;
|
||||||
if (isSet(currentBlock)) currentBlock.setTrain(this);
|
if (isSet(currentBlock)) {
|
||||||
|
currentBlock.setTrain(this);
|
||||||
|
lastBlocks.add(newBlock);
|
||||||
|
if (lastBlocks.size()>32) lastBlocks.remove(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String setDestination(HashMap<String, String> params) {
|
private String setDestination(HashMap<String, String> params) {
|
||||||
|
|||||||
Reference in New Issue
Block a user