This commit is contained in:
Stephan Richter
2021-03-14 19:45:17 +01:00
parent 9c86955d8d
commit 3c53bd192f
3 changed files with 11 additions and 4 deletions

View File

@@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.srsoftware</groupId>
<artifactId>web4rail</artifactId>
<version>1.3.68</version>
<version>1.3.69</version>
<name>Web4Rail</name>
<packaging>jar</packaging>
<description>Java Model Railway Control</description>

View File

@@ -524,7 +524,10 @@ public class Train extends BaseClass implements Comparable<Train> {
public void afterLoad() {
if (json.has(TRACE)) json.getJSONArray(TRACE).forEach(elem -> {
Tile tile = plan.get(new Id(elem.toString()), false);
if (tile.setTrain(Train.this)) trace.add(tile);
if (tile instanceof Block) {
((Block)tile).add(Train.this, direction);
} else if (tile.setTrain(Train.this));
trace.add(tile);
});
if (json.has(BLOCK)) {// do not move this up! during set, other fields will be referenced!
currentBlock = (Block) plan.get(Id.from(json, BLOCK), false);
@@ -759,7 +762,10 @@ public class Train extends BaseClass implements Comparable<Train> {
public void set(Block newBlock) {
LOG.debug("{}.set({})",this,newBlock);
if (isSet(currentBlock)) currentBlock.free(this);
if (isSet(currentBlock)) {
if (newBlock == currentBlock) return;
currentBlock.free(this);
}
currentBlock = newBlock;
if (isSet(currentBlock)) {
currentBlock.setTrain(this);

View File

@@ -395,8 +395,9 @@ public abstract class Block extends StretchableTile{
Train train = BaseClass.get(tID);
Direction direction = to.has(DIRECTION) ? Direction.valueOf(to.getString(DIRECTION)) : null;
if (isSet(train)) {
trains.add(train, direction);
train.set(Block.this);
trains.add(train, direction);
status = Status.OCCUPIED;
}
}
}