working on destination processing
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.5.28</version>
|
<version>1.5.29</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>
|
||||||
|
|||||||
@@ -99,6 +99,11 @@ svg.preview rect{
|
|||||||
fill:cyan;
|
fill:cyan;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
polygon.direction {
|
||||||
|
fill: rgba(0,0,0,0.4) !important;
|
||||||
|
stroke: none;
|
||||||
|
}
|
||||||
|
|
||||||
svg rect.sig_a,
|
svg rect.sig_a,
|
||||||
svg rect.sig_b{
|
svg rect.sig_b{
|
||||||
fill: inherit;
|
fill: inherit;
|
||||||
|
|||||||
@@ -196,6 +196,7 @@ Found {} routes. : {} Routen gefunden.
|
|||||||
free : frei machen
|
free : frei machen
|
||||||
FreeStartBlock : Start-Block freigeben
|
FreeStartBlock : Start-Block freigeben
|
||||||
Free tiles behind train : Kacheln hinter dem Zug freigeben
|
Free tiles behind train : Kacheln hinter dem Zug freigeben
|
||||||
|
{} from {} : {} von {}
|
||||||
Fullscreen : Vollbild
|
Fullscreen : Vollbild
|
||||||
Function : Funktion
|
Function : Funktion
|
||||||
Function {} : Funktion {}
|
Function {} : Funktion {}
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ package de.srsoftware.web4rail;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import de.srsoftware.web4rail.BaseClass.Id;
|
||||||
import de.srsoftware.web4rail.Plan.Direction;
|
import de.srsoftware.web4rail.Plan.Direction;
|
||||||
|
import de.srsoftware.web4rail.moving.Train;
|
||||||
import de.srsoftware.web4rail.tiles.Block;
|
import de.srsoftware.web4rail.tiles.Block;
|
||||||
|
|
||||||
public class Destination {
|
public class Destination {
|
||||||
@@ -12,7 +14,12 @@ public class Destination {
|
|||||||
private Direction enterDirection;
|
private Direction enterDirection;
|
||||||
public Block block;
|
public Block block;
|
||||||
|
|
||||||
|
private boolean shunting = false;
|
||||||
|
|
||||||
|
private boolean turn = false;
|
||||||
|
|
||||||
public Destination(Block block, Direction enterFrom) {
|
public Destination(Block block, Direction enterFrom) {
|
||||||
|
if (block == null) throw new NullPointerException();
|
||||||
this.block = block;
|
this.block = block;
|
||||||
this.enterDirection = enterFrom;
|
this.enterDirection = enterFrom;
|
||||||
}
|
}
|
||||||
@@ -34,10 +41,90 @@ public class Destination {
|
|||||||
return block.id().toString();
|
return block.id().toString();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public static String dropFirstFrom(String tag) {
|
||||||
|
if (BaseClass.isNull(tag)) return null;
|
||||||
|
|
||||||
|
String[] parts = tag.split(Train.DESTINATION_PREFIX,3);
|
||||||
|
if (parts.length<3) return null;
|
||||||
|
|
||||||
|
return Train.DESTINATION_PREFIX+parts[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
private Destination enterFrom(Direction enterFrom) {
|
||||||
|
this.enterDirection = enterFrom;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static Destination from(String tag) {
|
||||||
|
if (BaseClass.isNull(tag)) return null;
|
||||||
|
|
||||||
|
LOG.debug("→ processing \"{}\"...",tag);
|
||||||
|
String[] parts = tag.split(Train.DESTINATION_PREFIX,3);
|
||||||
|
if (parts.length<2) return null;
|
||||||
|
|
||||||
|
String firstTag = parts[1];
|
||||||
|
LOG.debug("processing first tag: {}",firstTag);
|
||||||
|
if (firstTag.length()<1) return null;
|
||||||
|
int pos = firstTag.indexOf(Train.FLAG_SEPARATOR);
|
||||||
|
String blockId = pos<0 ? firstTag : firstTag.substring(0,pos);
|
||||||
|
|
||||||
|
Block block = Block.get(new Id(blockId));
|
||||||
|
if (block == null) return null;
|
||||||
|
|
||||||
|
Destination destination = new Destination(block);
|
||||||
|
if (pos>0) {
|
||||||
|
String modifiers = firstTag.substring(pos+1);
|
||||||
|
for (int i=0; i<modifiers.length(); i++) {
|
||||||
|
switch (modifiers.charAt(i)) {
|
||||||
|
case Train.SHUNTING_FLAG: destination.shunting(true); break;
|
||||||
|
case Train.TURN_FLAG: destination.turn(true); break;
|
||||||
|
case '→': destination.enterFrom(Direction.WEST); break;
|
||||||
|
case '←': destination.enterFrom(Direction.EAST); break;
|
||||||
|
case '↓': destination.enterFrom(Direction.NORTH); break;
|
||||||
|
case '↑': destination.enterFrom(Direction.SOUTH); break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return destination;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Destination shunting(boolean enable) {
|
||||||
|
this.shunting = enable;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean shunting() {
|
||||||
|
return shunting;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return enterDirection == null ? block.toString() : BaseClass.t("{} from {}",block,enterDirection.inverse());
|
StringBuilder sb = new StringBuilder();
|
||||||
|
if (enterDirection == null) {
|
||||||
|
sb.append(block);
|
||||||
|
} else {
|
||||||
|
sb.append(BaseClass.t("{} from {}",block,enterDirection.inverse()));
|
||||||
|
}
|
||||||
|
if (shunting || turn) {
|
||||||
|
sb.append("(");
|
||||||
|
if (shunting) sb.append("shunting ");
|
||||||
|
if (turn) sb.append("turn ");
|
||||||
|
sb.append(")");
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void turn(boolean enable) {
|
||||||
|
this.turn = enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean turn() {
|
||||||
|
return turn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -174,7 +174,10 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addTag(String tag) {
|
public void addTag(String tag) {
|
||||||
tags.add(tag);
|
if (isSet(tag)) {
|
||||||
|
tags.add(tag);
|
||||||
|
LOG.debug("added tag \"{}\" to {}",tag,this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object addCar(Params params) {
|
private Object addCar(Params params) {
|
||||||
@@ -366,28 +369,11 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Destination destination(){
|
public Destination destination(){
|
||||||
//LOG.debug("{}.destination()",this);
|
|
||||||
if (isNull(destination)) {
|
if (isNull(destination)) {
|
||||||
String destTag = destinationTag();
|
destination = Destination.from(destinationTag());
|
||||||
LOG.debug("→ processing \"{}\"...",destTag);
|
LOG.debug("{}.destination() → {}",this,destination);
|
||||||
if (isSet(destTag)) {
|
if (isSet(destination)) shunting |= destination.shunting();
|
||||||
destTag = destTag.split(DESTINATION_PREFIX)[1];
|
}
|
||||||
LOG.debug("....processing \"{}\"…",destTag);
|
|
||||||
for (int i=destTag.length()-1; i>0; i--) {
|
|
||||||
switch (destTag.charAt(i)) {
|
|
||||||
case FLAG_SEPARATOR:
|
|
||||||
destTag = destTag.substring(0,i);
|
|
||||||
i=0;
|
|
||||||
break;
|
|
||||||
case SHUNTING_FLAG:
|
|
||||||
LOG.debug("....enabled shunting option");
|
|
||||||
shunting = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
destination = new Destination(BaseClass.get(new Id(destTag)));
|
|
||||||
}
|
|
||||||
}// else LOG.debug("→ heading towards {}",destination);
|
|
||||||
return destination;
|
return destination;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -471,37 +457,13 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
if (resetDest){
|
if (resetDest){
|
||||||
destination = null;
|
destination = null;
|
||||||
|
|
||||||
String destTag = destinationTag();
|
String destTag = destinationTag();
|
||||||
if (isSet(destTag)) {
|
Destination destinationFromTag = Destination.from(destTag);
|
||||||
LOG.debug("destination list: {}",destTag);
|
if (endedRoute.endsAt(destinationFromTag)) {
|
||||||
String[] parts = destTag.split(Train.DESTINATION_PREFIX);
|
if (destinationFromTag.turn()) turn();
|
||||||
for (int i=0; i<parts.length;i++) LOG.debug(" part {}: {}",i+1,parts[i]);
|
removeTag(destTag);
|
||||||
String destId = parts[1];
|
destTag = Destination.dropFirstFrom(destTag);
|
||||||
LOG.debug("destination tag: {}",destId);
|
addTag(destTag);
|
||||||
boolean turn = false;
|
|
||||||
|
|
||||||
for (int i=destId.length()-1; i>0; i--) {
|
|
||||||
switch (destId.charAt(i)) {
|
|
||||||
case Train.FLAG_SEPARATOR:
|
|
||||||
destId = destId.substring(0,i);
|
|
||||||
i=0;
|
|
||||||
break;
|
|
||||||
case Train.TURN_FLAG:
|
|
||||||
turn = true;
|
|
||||||
LOG.debug("Turn flag is set!");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (destId.equals(endBlock.id().toString())) {
|
|
||||||
if (turn) turn();
|
|
||||||
|
|
||||||
// update destination tag: remove and add altered tag:
|
|
||||||
removeTag(destTag);
|
|
||||||
destTag = destTag.substring(parts[1].length()+1);
|
|
||||||
if (destTag.isEmpty()) { // no further destinations
|
|
||||||
destTag = null;
|
|
||||||
} else addTag(destTag);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isNull(destTag)) {
|
if (isNull(destTag)) {
|
||||||
@@ -879,6 +841,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Iterator<String> removeTag(String tag) {
|
public Iterator<String> removeTag(String tag) {
|
||||||
|
LOG.debug("Removing tag \"{}\" from {}",tag,this);
|
||||||
tags.remove(tag);
|
tags.remove(tag);
|
||||||
return tags().iterator();
|
return tags().iterator();
|
||||||
}
|
}
|
||||||
@@ -1106,6 +1069,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
public SortedSet<String> tags() {
|
public SortedSet<String> tags() {
|
||||||
TreeSet<String> list = new TreeSet<String>(tags);
|
TreeSet<String> list = new TreeSet<String>(tags);
|
||||||
for (Car car:cars) list.addAll(car.tags());
|
for (Car car:cars) list.addAll(car.tags());
|
||||||
|
LOG.debug("{}.tags() → {}",this,list);
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -487,6 +487,11 @@ public abstract class Block extends StretchableTile{
|
|||||||
@Override
|
@Override
|
||||||
public String title() {
|
public String title() {
|
||||||
StringBuilder sb = new StringBuilder(name);
|
StringBuilder sb = new StringBuilder(name);
|
||||||
|
sb.append(" @ (");
|
||||||
|
sb.append(x);
|
||||||
|
sb.append(", ");
|
||||||
|
sb.append(y);
|
||||||
|
sb.append(")");
|
||||||
Train occupyingTrain = occupyingTrain();
|
Train occupyingTrain = occupyingTrain();
|
||||||
if (isSet(occupyingTrain)) sb.append(title(occupyingTrain));
|
if (isSet(occupyingTrain)) sb.append(title(occupyingTrain));
|
||||||
if (isSet(parkedTrains)) for (Train parked : parkedTrains.trains) sb.append(title(parked));
|
if (isSet(parkedTrains)) for (Train parked : parkedTrains.trains) sb.append(title(parked));
|
||||||
|
|||||||
Reference in New Issue
Block a user