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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>de.srsoftware</groupId>
|
<groupId>de.srsoftware</groupId>
|
||||||
<artifactId>web4rail</artifactId>
|
<artifactId>web4rail</artifactId>
|
||||||
<version>1.3.37</version>
|
<version>1.3.38</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>
|
||||||
|
|||||||
@@ -227,7 +227,7 @@ public class Route extends BaseClass {
|
|||||||
return route.properties();
|
return route.properties();
|
||||||
case ACTION_START:
|
case ACTION_START:
|
||||||
route.set(new Context(route));
|
route.set(new Context(route));
|
||||||
route.fireSetupActions();
|
route.prepare();
|
||||||
route.context.clear();
|
route.context.clear();
|
||||||
|
|
||||||
return route.properties();
|
return route.properties();
|
||||||
@@ -490,9 +490,7 @@ public class Route extends BaseClass {
|
|||||||
LOG.debug("{} has no next route.",train);
|
LOG.debug("{} has no next route.",train);
|
||||||
if (isSet(brakeProcessor)) {
|
if (isSet(brakeProcessor)) {
|
||||||
brakeProcessor.finish();
|
brakeProcessor.finish();
|
||||||
} else {
|
} else train.setSpeed(0);
|
||||||
train.setSpeed(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
brakeProcessor = null;
|
brakeProcessor = null;
|
||||||
@@ -559,11 +557,25 @@ public class Route extends BaseClass {
|
|||||||
train = null;
|
train = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean fireSetupActions() {
|
public boolean free() {
|
||||||
LOG.debug("{}.firesSetupActions({})",this);
|
LOG.debug("{}.free()",this);
|
||||||
ActionList setupActions = triggeredActions.get(ROUTE_SETUP);
|
setSignals(Signal.RED);
|
||||||
if (isSet(setupActions) && !setupActions.fire(context)) return false;
|
for (Tile tile : path) try {
|
||||||
state = State.PREPARED;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -853,6 +865,14 @@ public class Route extends BaseClass {
|
|||||||
return result;
|
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() {
|
private Tag previewScript() {
|
||||||
Tag script = new Tag("script").attr("type", "text/javascript");
|
Tag script = new Tag("script").attr("type", "text/javascript");
|
||||||
for (Tile tile : path) {
|
for (Tile tile : path) {
|
||||||
@@ -919,30 +939,6 @@ public class Route extends BaseClass {
|
|||||||
super.removeChild(child);
|
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 {
|
public static void saveAll(String filename) throws IOException {
|
||||||
BufferedWriter file = new BufferedWriter(new FileWriter(filename));
|
BufferedWriter file = new BufferedWriter(new FileWriter(filename));
|
||||||
file.write("{\""+ROUTES+"\":[\n");
|
file.write("{\""+ROUTES+"\":[\n");
|
||||||
@@ -1052,11 +1048,6 @@ public class Route extends BaseClass {
|
|||||||
return win;
|
return win;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Route unlock() throws IOException {
|
|
||||||
// TODO
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Object update(HashMap<String, String> params,Plan plan) {
|
protected Object update(HashMap<String, String> params,Plan plan) {
|
||||||
LOG.debug("update({})",params);
|
LOG.debug("update({})",params);
|
||||||
String name = params.get(NAME);
|
String name = params.get(NAME);
|
||||||
|
|||||||
@@ -730,7 +730,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
|
|
||||||
public Object quitAutopilot() {
|
public Object quitAutopilot() {
|
||||||
if (isSet(nextRoute)) {
|
if (isSet(nextRoute)) {
|
||||||
nextRoute.reset();
|
nextRoute.free();
|
||||||
nextRoute = null;
|
nextRoute = null;
|
||||||
}
|
}
|
||||||
if (isSet(autopilot)) {
|
if (isSet(autopilot)) {
|
||||||
@@ -783,10 +783,10 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
}
|
}
|
||||||
nextRoute.set(context);
|
nextRoute.set(context);
|
||||||
boolean error = !nextRoute.lockIgnoring(route);
|
boolean error = !nextRoute.lockIgnoring(route);
|
||||||
error = error || !nextRoute.fireSetupActions();
|
error = error || !nextRoute.prepare();
|
||||||
|
|
||||||
if (error) {
|
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
|
route.lock(); // corrects unlocked tiles of nextRoute
|
||||||
} else {
|
} else {
|
||||||
this.nextRoute = nextRoute;
|
this.nextRoute = nextRoute;
|
||||||
@@ -981,7 +981,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
LOG.debug("{}.start()",this);
|
LOG.debug("{}.start()",this);
|
||||||
if (isNull(currentBlock)) return t("{} not in a block",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 (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;
|
String error = null;
|
||||||
if (isSet(nextRoute)) {
|
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 (isNull(route)) return t("No free routes from {}",currentBlock);
|
||||||
if (!route.lock()) error = t("Was not able to lock {}",route);
|
if (!route.lock()) error = t("Was not able to lock {}",route);
|
||||||
route.set(context);
|
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) && direction != route.startDirection) turn();
|
||||||
|
|
||||||
if (isNull(error) && !route.start(this)) error = t("Was not able to assign {} to {}!",this,route);
|
if (isNull(error) && !route.start(this)) error = t("Was not able to assign {} to {}!",this,route);
|
||||||
if (isSet(error)) {
|
if (isSet(error)) {
|
||||||
LOG.debug("{}.start:error = {}",this,error);
|
LOG.debug("{}.start:error = {}",this,error);
|
||||||
route.reset();
|
route.free();
|
||||||
route = null;
|
route = null;
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
@@ -1056,7 +1056,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
quitAutopilot();
|
quitAutopilot();
|
||||||
if (isSet(route)) {
|
if (isSet(route)) {
|
||||||
route.brakeCancel();
|
route.brakeCancel();
|
||||||
route.reset();
|
route.free();
|
||||||
route = null;
|
route = null;
|
||||||
}
|
}
|
||||||
setSpeed(0);
|
setSpeed(0);
|
||||||
|
|||||||
Reference in New Issue
Block a user