implemented stop train

This commit is contained in:
Stephan Richter
2020-10-29 09:34:20 +01:00
parent 42536adc2a
commit 38bb612d97
5 changed files with 37 additions and 16 deletions

View File

@@ -135,10 +135,12 @@ public class Train implements Constants {
return train.automatic();
case ACTION_PROPS:
return train.props();
case ACTION_QUIT:
return train.quitAutopilot();
case ACTION_START:
return train.start();
case ACTION_STOP:
return train.stop();
return train.stopNow();
case ACTION_TURN:
return train.turn();
case ACTION_UPDATE:
@@ -147,7 +149,6 @@ public class Train implements Constants {
return t("Unknown action: {}",params.get(ACTION));
}
private Object addCar(HashMap<String, String> params) {
LOG.debug("addCar({})",params);
if (!params.containsKey(CAR_ID)) return t("No car id passed to Train.addCar!");
@@ -346,7 +347,7 @@ public class Train implements Constants {
if (autopilot == null) {
new Button(t("auto"),"train("+id+",'"+ACTION_AUTO+"')").addTo(actions);
} else {
new Button(t("stop"),"train("+id+",'"+ACTION_STOP+"')").addTo(actions);
new Button(t("quit autopilot"),"train("+id+",'"+ACTION_QUIT+"')").addTo(actions);
}
actions.addTo(propList);
@@ -361,6 +362,14 @@ public class Train implements Constants {
return window;
}
private Object quitAutopilot() {
if (autopilot != null) {
autopilot.stop = true;
autopilot = null;
return t("{} stopping at next block.",this);
} else return t("autopilot not active.");
}
public static void saveAll(String filename) throws IOException {
BufferedWriter file = new BufferedWriter(new FileWriter(filename));
for (Entry<Long, Train> entry:trains.entrySet()) {
@@ -414,10 +423,17 @@ public class Train implements Constants {
return error;
}
private Object stop() {
autopilot.stop = true;
autopilot = null;
return t("{} stopping at next block.",this);
private Object stopNow() {
setSpeed(0);
if (route != null) try {
route.unlock();
route.endBlock().train(null);
route.startBlock().train(this);
} catch (IOException e) {
e.printStackTrace();
}
route = null;
return t("Stopped {}.",this);
}
private static String t(String message, Object...fills) {