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