renamed Route.reset to Route.free, Route.fireSetupActions to Route.prepare
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.3.37</version>
|
||||
<version>1.3.38</version>
|
||||
<name>Web4Rail</name>
|
||||
<packaging>jar</packaging>
|
||||
<description>Java Model Railway Control</description>
|
||||
|
||||
@@ -227,7 +227,7 @@ public class Route extends BaseClass {
|
||||
return route.properties();
|
||||
case ACTION_START:
|
||||
route.set(new Context(route));
|
||||
route.fireSetupActions();
|
||||
route.prepare();
|
||||
route.context.clear();
|
||||
|
||||
return route.properties();
|
||||
@@ -490,9 +490,7 @@ public class Route extends BaseClass {
|
||||
LOG.debug("{} has no next route.",train);
|
||||
if (isSet(brakeProcessor)) {
|
||||
brakeProcessor.finish();
|
||||
} else {
|
||||
train.setSpeed(0);
|
||||
}
|
||||
} else train.setSpeed(0);
|
||||
}
|
||||
}
|
||||
brakeProcessor = null;
|
||||
@@ -559,11 +557,25 @@ public class Route extends BaseClass {
|
||||
train = null;
|
||||
}
|
||||
|
||||
public boolean fireSetupActions() {
|
||||
LOG.debug("{}.firesSetupActions({})",this);
|
||||
ActionList setupActions = triggeredActions.get(ROUTE_SETUP);
|
||||
if (isSet(setupActions) && !setupActions.fire(context)) return false;
|
||||
state = State.PREPARED;
|
||||
public boolean free() {
|
||||
LOG.debug("{}.free()",this);
|
||||
setSignals(Signal.RED);
|
||||
for (Tile tile : path) try {
|
||||
tile.unset(this);
|
||||
} catch (IllegalArgumentException e) {}
|
||||
|
||||
Tile lastTile = path.lastElement();
|
||||
if (lastTile instanceof Contact) {
|
||||
lastTile.setTrain(null);
|
||||
if (isSet(train)) train.removeChild(lastTile);
|
||||
}
|
||||
if (isSet(train)) {
|
||||
train.set(startBlock);
|
||||
train.heading(startDirection);
|
||||
if (train.route() == this) train.route(null);
|
||||
train = null;
|
||||
}
|
||||
state = State.FREE;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -853,6 +865,14 @@ public class Route extends BaseClass {
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean prepare() {
|
||||
LOG.debug("{}.firesSetupActions({})",this);
|
||||
ActionList setupActions = triggeredActions.get(ROUTE_SETUP);
|
||||
if (isSet(setupActions) && !setupActions.fire(context)) return false;
|
||||
state = State.PREPARED;
|
||||
return true;
|
||||
}
|
||||
|
||||
private Tag previewScript() {
|
||||
Tag script = new Tag("script").attr("type", "text/javascript");
|
||||
for (Tile tile : path) {
|
||||
@@ -919,30 +939,6 @@ public class Route extends BaseClass {
|
||||
super.removeChild(child);
|
||||
}
|
||||
|
||||
public boolean reset() {
|
||||
LOG.debug("{}.reset()",this);
|
||||
setSignals(Signal.RED);
|
||||
for (Tile tile : path) {
|
||||
try {
|
||||
tile.unset(this);
|
||||
} catch (IllegalArgumentException e) {}
|
||||
}
|
||||
Tile lastTile = path.lastElement();
|
||||
if (lastTile instanceof Contact) {
|
||||
lastTile.setTrain(null);
|
||||
if (isSet(train)) train.removeChild(lastTile);
|
||||
}
|
||||
if (isSet(train)) {
|
||||
train.set(startBlock);
|
||||
train.heading(startDirection);
|
||||
if (train.route() == this) train.route(null);
|
||||
train = null;
|
||||
}
|
||||
LOG.debug("chlearing triggeredContacts of {}",this);
|
||||
state = State.FREE;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void saveAll(String filename) throws IOException {
|
||||
BufferedWriter file = new BufferedWriter(new FileWriter(filename));
|
||||
file.write("{\""+ROUTES+"\":[\n");
|
||||
@@ -1052,11 +1048,6 @@ public class Route extends BaseClass {
|
||||
return win;
|
||||
}
|
||||
|
||||
public Route unlock() throws IOException {
|
||||
// TODO
|
||||
return this;
|
||||
}
|
||||
|
||||
protected Object update(HashMap<String, String> params,Plan plan) {
|
||||
LOG.debug("update({})",params);
|
||||
String name = params.get(NAME);
|
||||
|
||||
@@ -730,7 +730,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
|
||||
public Object quitAutopilot() {
|
||||
if (isSet(nextRoute)) {
|
||||
nextRoute.reset();
|
||||
nextRoute.free();
|
||||
nextRoute = null;
|
||||
}
|
||||
if (isSet(autopilot)) {
|
||||
@@ -783,10 +783,10 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
}
|
||||
nextRoute.set(context);
|
||||
boolean error = !nextRoute.lockIgnoring(route);
|
||||
error = error || !nextRoute.fireSetupActions();
|
||||
error = error || !nextRoute.prepare();
|
||||
|
||||
if (error) {
|
||||
nextRoute.reset(); // may unlock tiles belonging to the current route.
|
||||
nextRoute.free(); // may unlock tiles belonging to the current route.
|
||||
route.lock(); // corrects unlocked tiles of nextRoute
|
||||
} else {
|
||||
this.nextRoute = nextRoute;
|
||||
@@ -981,7 +981,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
LOG.debug("{}.start()",this);
|
||||
if (isNull(currentBlock)) return t("{} not in a block",this);
|
||||
if (maxSpeed() == 0) return t("Train has maximum speed of 0 {}, cannot go!",speedUnit);
|
||||
if (isSet(route)) route.reset(); // reset route previously chosen
|
||||
if (isSet(route)) route.free(); // reset route previously chosen
|
||||
|
||||
String error = null;
|
||||
if (isSet(nextRoute)) {
|
||||
@@ -996,14 +996,14 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
if (isNull(route)) return t("No free routes from {}",currentBlock);
|
||||
if (!route.lock()) error = t("Was not able to lock {}",route);
|
||||
route.set(context);
|
||||
if (isNull(error) && !route.fireSetupActions()) error = t("Was not able to fire all setup actions of route!");
|
||||
if (isNull(error) && !route.prepare()) error = t("Was not able to fire all setup actions of route!");
|
||||
}
|
||||
if (isNull(error) && direction != route.startDirection) turn();
|
||||
|
||||
if (isNull(error) && !route.start(this)) error = t("Was not able to assign {} to {}!",this,route);
|
||||
if (isSet(error)) {
|
||||
LOG.debug("{}.start:error = {}",this,error);
|
||||
route.reset();
|
||||
route.free();
|
||||
route = null;
|
||||
return error;
|
||||
}
|
||||
@@ -1056,7 +1056,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
quitAutopilot();
|
||||
if (isSet(route)) {
|
||||
route.brakeCancel();
|
||||
route.reset();
|
||||
route.free();
|
||||
route = null;
|
||||
}
|
||||
setSpeed(0);
|
||||
|
||||
Reference in New Issue
Block a user