working on destination processing
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>1.5.28</version>
|
||||
<version>1.5.29</version>
|
||||
<name>Web4Rail</name>
|
||||
<packaging>jar</packaging>
|
||||
<description>Java Model Railway Control</description>
|
||||
|
||||
@@ -99,6 +99,11 @@ svg.preview rect{
|
||||
fill:cyan;
|
||||
}
|
||||
|
||||
polygon.direction {
|
||||
fill: rgba(0,0,0,0.4) !important;
|
||||
stroke: none;
|
||||
}
|
||||
|
||||
svg rect.sig_a,
|
||||
svg rect.sig_b{
|
||||
fill: inherit;
|
||||
|
||||
@@ -196,6 +196,7 @@ Found {} routes. : {} Routen gefunden.
|
||||
free : frei machen
|
||||
FreeStartBlock : Start-Block freigeben
|
||||
Free tiles behind train : Kacheln hinter dem Zug freigeben
|
||||
{} from {} : {} von {}
|
||||
Fullscreen : Vollbild
|
||||
Function : Funktion
|
||||
Function {} : Funktion {}
|
||||
|
||||
@@ -3,7 +3,9 @@ package de.srsoftware.web4rail;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import de.srsoftware.web4rail.BaseClass.Id;
|
||||
import de.srsoftware.web4rail.Plan.Direction;
|
||||
import de.srsoftware.web4rail.moving.Train;
|
||||
import de.srsoftware.web4rail.tiles.Block;
|
||||
|
||||
public class Destination {
|
||||
@@ -12,7 +14,12 @@ public class Destination {
|
||||
private Direction enterDirection;
|
||||
public Block block;
|
||||
|
||||
private boolean shunting = false;
|
||||
|
||||
private boolean turn = false;
|
||||
|
||||
public Destination(Block block, Direction enterFrom) {
|
||||
if (block == null) throw new NullPointerException();
|
||||
this.block = block;
|
||||
this.enterDirection = enterFrom;
|
||||
}
|
||||
@@ -34,10 +41,90 @@ public class Destination {
|
||||
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
|
||||
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) {
|
||||
tags.add(tag);
|
||||
if (isSet(tag)) {
|
||||
tags.add(tag);
|
||||
LOG.debug("added tag \"{}\" to {}",tag,this);
|
||||
}
|
||||
}
|
||||
|
||||
private Object addCar(Params params) {
|
||||
@@ -366,28 +369,11 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
}
|
||||
|
||||
public Destination destination(){
|
||||
//LOG.debug("{}.destination()",this);
|
||||
if (isNull(destination)) {
|
||||
String destTag = destinationTag();
|
||||
LOG.debug("→ processing \"{}\"...",destTag);
|
||||
if (isSet(destTag)) {
|
||||
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);
|
||||
destination = Destination.from(destinationTag());
|
||||
LOG.debug("{}.destination() → {}",this,destination);
|
||||
if (isSet(destination)) shunting |= destination.shunting();
|
||||
}
|
||||
return destination;
|
||||
}
|
||||
|
||||
@@ -471,37 +457,13 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
if (resetDest){
|
||||
destination = null;
|
||||
|
||||
String destTag = destinationTag();
|
||||
if (isSet(destTag)) {
|
||||
LOG.debug("destination list: {}",destTag);
|
||||
String[] parts = destTag.split(Train.DESTINATION_PREFIX);
|
||||
for (int i=0; i<parts.length;i++) LOG.debug(" part {}: {}",i+1,parts[i]);
|
||||
String destId = parts[1];
|
||||
LOG.debug("destination tag: {}",destId);
|
||||
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);
|
||||
}
|
||||
String destTag = destinationTag();
|
||||
Destination destinationFromTag = Destination.from(destTag);
|
||||
if (endedRoute.endsAt(destinationFromTag)) {
|
||||
if (destinationFromTag.turn()) turn();
|
||||
removeTag(destTag);
|
||||
destTag = Destination.dropFirstFrom(destTag);
|
||||
addTag(destTag);
|
||||
}
|
||||
|
||||
if (isNull(destTag)) {
|
||||
@@ -879,6 +841,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
}
|
||||
|
||||
public Iterator<String> removeTag(String tag) {
|
||||
LOG.debug("Removing tag \"{}\" from {}",tag,this);
|
||||
tags.remove(tag);
|
||||
return tags().iterator();
|
||||
}
|
||||
@@ -1106,6 +1069,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
public SortedSet<String> tags() {
|
||||
TreeSet<String> list = new TreeSet<String>(tags);
|
||||
for (Car car:cars) list.addAll(car.tags());
|
||||
LOG.debug("{}.tags() → {}",this,list);
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
@@ -487,6 +487,11 @@ public abstract class Block extends StretchableTile{
|
||||
@Override
|
||||
public String title() {
|
||||
StringBuilder sb = new StringBuilder(name);
|
||||
sb.append(" @ (");
|
||||
sb.append(x);
|
||||
sb.append(", ");
|
||||
sb.append(y);
|
||||
sb.append(")");
|
||||
Train occupyingTrain = occupyingTrain();
|
||||
if (isSet(occupyingTrain)) sb.append(title(occupyingTrain));
|
||||
if (isSet(parkedTrains)) for (Train parked : parkedTrains.trains) sb.append(title(parked));
|
||||
|
||||
Reference in New Issue
Block a user