added action StopAllTrains, added null checks
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>0.10.13</version>
|
||||
<version>0.10.14</version>
|
||||
<name>Web4Rail</name>
|
||||
<packaging>jar</packaging>
|
||||
<description>Java Model Railway Control</description>
|
||||
|
||||
@@ -94,6 +94,7 @@ Setup actions : Aktivierungs-Aktionen
|
||||
Signals : Signale
|
||||
SOUTH : Süden
|
||||
Started {} : {} gestartet
|
||||
StopAllTrains : Alle Züge stoppen
|
||||
StopAuto : Automatikmodus abschalten
|
||||
Straight port\: : Port für gerade
|
||||
STRAIGHT : gerade
|
||||
|
||||
@@ -670,7 +670,7 @@ public class Plan extends BaseClass{
|
||||
|
||||
public void sensor(int addr, boolean active) {
|
||||
Contact contact = Contact.get(addr);
|
||||
LOG.debug("contact: {}",isSet(contact) ? contact : addr);
|
||||
LOG.debug("contact: {}",isSet(contact) ? addr+" / "+contact : addr);
|
||||
if (contact != null) {
|
||||
contact.activate(active);
|
||||
} else {
|
||||
|
||||
@@ -361,11 +361,13 @@ public class Route extends BaseClass{
|
||||
Tile lastTile = path.lastElement();
|
||||
if (lastTile instanceof Contact) {
|
||||
lastTile.set(null);
|
||||
train.removeFromTrace(lastTile);
|
||||
if (isSet(train)) train.removeFromTrace(lastTile);
|
||||
}
|
||||
if (isSet(train)) {
|
||||
train.set(endBlock);
|
||||
train.heading(endDirection.inverse());
|
||||
if (train.route == this) train.route = null;
|
||||
}
|
||||
train = null;
|
||||
triggeredContacts.clear();
|
||||
}
|
||||
|
||||
@@ -111,6 +111,7 @@ public abstract class Action extends BaseClass {
|
||||
FinishRoute.class,
|
||||
TriggerContact.class,
|
||||
TurnTrain.class,
|
||||
StopAllTrains.class,
|
||||
StopAuto.class,
|
||||
SetPower.class,
|
||||
SetRelay.class,
|
||||
|
||||
@@ -9,7 +9,7 @@ public class FinishRoute extends Action {
|
||||
@Override
|
||||
public boolean fire(Context context) throws IOException {
|
||||
Route route = context.route;
|
||||
if (route != null) route.finish();
|
||||
if (isSet(route)) route.finish();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package de.srsoftware.web4rail.actions;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import de.srsoftware.web4rail.moving.Train;
|
||||
|
||||
public class StopAllTrains extends Action {
|
||||
|
||||
@Override
|
||||
public boolean fire(Context context) throws IOException {
|
||||
Train.list().forEach(train -> train.stopNow());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -44,9 +44,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Train.class);
|
||||
|
||||
private static final String CAR_ID = "carId";
|
||||
public static final String HEAD = "train_head";
|
||||
public static final String LOCO_ID = "locoId";
|
||||
public static final String TAIL = "train_tile";
|
||||
private static final String TRACE = "trace";
|
||||
private static final HashMap<Integer, Train> trains = new HashMap<>();
|
||||
|
||||
@@ -179,7 +177,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
}
|
||||
}
|
||||
if (!rt.isFreeFor(this)) { // keine belegten Routen wählen
|
||||
LOG.debug("{} is not free!",rt);
|
||||
// LOG.debug("{} is not free!",rt);
|
||||
continue;
|
||||
}
|
||||
if (!rt.allowed(context)) continue;
|
||||
@@ -533,7 +531,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
|
||||
public static Select selector(Train preselected,Collection<Train> exclude) {
|
||||
if (isNull(exclude)) exclude = new Vector<Train>();
|
||||
Select select = new Select(Train.HEAD);
|
||||
Select select = new Select(Train.class.getSimpleName());
|
||||
new Tag("option").attr("value","0").content(t("unset")).addTo(select);
|
||||
for (Train train : Train.list()) {
|
||||
if (exclude.contains(train)) continue;
|
||||
@@ -594,7 +592,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
return t("Started {}",this);
|
||||
}
|
||||
|
||||
private Object stopNow() {
|
||||
public Object stopNow() {
|
||||
quitAutopilot();
|
||||
setSpeed(0);
|
||||
if (isSet(route)) route.reset();
|
||||
|
||||
@@ -90,8 +90,8 @@ public abstract class Block extends StretchableTile{
|
||||
@Override
|
||||
public Tile update(HashMap<String, String> params) throws IOException {
|
||||
if (params.containsKey(NAME)) name=params.get(NAME);
|
||||
if (params.containsKey(Train.HEAD)) {
|
||||
int trainId = Integer.parseInt(params.get(Train.HEAD));
|
||||
if (params.containsKey(Train.class.getSimpleName())) {
|
||||
int trainId = Integer.parseInt(params.get(Train.class.getSimpleName()));
|
||||
if (trainId == 0) {
|
||||
if (isSet(train)) train.dropTrace();
|
||||
train = null;
|
||||
|
||||
Reference in New Issue
Block a user