Browse Source

various bugfixes

lookup-tables
Stephan Richter 5 years ago
parent
commit
ad8375e7f4
  1. 2
      pom.xml
  2. 2
      src/main/java/de/srsoftware/web4rail/actions/ConditionalAction.java
  3. 2
      src/main/java/de/srsoftware/web4rail/conditions/TrainLength.java
  4. 106
      src/main/java/de/srsoftware/web4rail/moving/Train.java

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.6</version> <version>0.10.7</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>

2
src/main/java/de/srsoftware/web4rail/actions/ConditionalAction.java

@ -39,7 +39,7 @@ public class ConditionalAction extends Action {
if (!conditions.isEmpty()) { if (!conditions.isEmpty()) {
Tag list = new Tag("ul"); Tag list = new Tag("ul");
for (Condition condition : conditions) { for (Condition condition : conditions) {
link("li", Map.of(REALM,REALM_CONDITION,ID,id,ACTION,ACTION_PROPS,CONTEXT,params.get(CONTEXT)), condition).addTo(list); link("li", Map.of(REALM,REALM_CONDITION,ID,condition.id(),ACTION,ACTION_PROPS,CONTEXT,params.get(CONTEXT)), condition).addTo(list);
} }
list.addTo(fieldset); list.addTo(fieldset);
} }

2
src/main/java/de/srsoftware/web4rail/conditions/TrainLength.java

@ -33,7 +33,7 @@ public class TrainLength extends Condition {
@Override @Override
public Tag propForm(HashMap<String, String> params) { public Tag propForm(HashMap<String, String> params) {
return new Input(MAX_LENGTH, maxLength).addTo(new Label(t("Maximum train length:")+NBSP)).addTo(super.propForm(params)); return new Input(MAX_LENGTH, maxLength).numeric().addTo(new Label(t("Maximum train length:")+NBSP)).addTo(super.propForm(params));
} }
@Override @Override

106
src/main/java/de/srsoftware/web4rail/moving/Train.java

@ -152,6 +152,19 @@ public class Train extends BaseClass implements Comparable<Train> {
} }
return t("Unknown action: {}",params.get(ACTION)); return t("Unknown action: {}",params.get(ACTION));
} }
public void addToTrace(Vector<Tile> newTiles) {
boolean active = trace.isEmpty();
for (Tile tile : newTiles) {
if (active) {
trace.addFirst(tile);
} else {
Tile dummy = trace.getFirst();
if (dummy == tile) active = true;
}
}
showTrace();
}
private Route chooseRoute(Context context) { private Route chooseRoute(Context context) {
HashSet<Route> routes = block.routes(); HashSet<Route> routes = block.routes();
@ -270,10 +283,13 @@ public class Train extends BaseClass implements Comparable<Train> {
return props(); return props();
} }
public void dropTrace() {
while (!trace.isEmpty()) trace.removeFirst().set(null);
}
public static Train get(int id) { public static Train get(int id) {
return trains.get(id); return trains.get(id);
} }
public Train heading(Direction dir) { public Train heading(Direction dir) {
direction = dir; direction = dir;
@ -281,6 +297,10 @@ public class Train extends BaseClass implements Comparable<Train> {
return this; return this;
} }
public Tile headPos() {
return trace.getFirst();
}
private JSONObject json() { private JSONObject json() {
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
json.put(ID, id); json.put(ID, id);
@ -480,13 +500,6 @@ public class Train extends BaseClass implements Comparable<Train> {
return window; return window;
} }
public SortedSet<String> tags() {
TreeSet<String> list = new TreeSet<String>(tags);
for (Locomotive loco : locos) list.addAll(loco.tags());
for (Car car:cars) list.addAll(car.tags());
return list;
}
public Object quitAutopilot() { public Object quitAutopilot() {
if (isSet(autopilot)) { if (isSet(autopilot)) {
autopilot.stop = true; autopilot.stop = true;
@ -495,6 +508,10 @@ public class Train extends BaseClass implements Comparable<Train> {
} else return t("autopilot not active."); } else return t("autopilot not active.");
} }
private void reverseTrace() {
// TODO Auto-generated method stub
}
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));
for (Entry<Integer, Train> entry:trains.entrySet()) { for (Entry<Integer, Train> entry:trains.entrySet()) {
@ -516,12 +533,33 @@ public class Train extends BaseClass implements Comparable<Train> {
return select; return select;
} }
public void set(Block newBlock) {
block = newBlock;
if (isSet(block)) block.set(this);
}
public void setSpeed(int v) { public void setSpeed(int v) {
LOG.debug("Setting speed to {} kmh.",v); LOG.debug("Setting speed to {} kmh.",v);
for (Locomotive loco : locos) loco.setSpeed(v); for (Locomotive loco : locos) loco.setSpeed(v);
this.speed = v; this.speed = v;
} }
public void showTrace() {
int remainingLength = length();
if (remainingLength<1) remainingLength=1;
for (int i=0; i<trace.size(); i++) {
Tile tile = trace.get(i);
if (remainingLength>0) {
remainingLength-=tile.length();
tile.set(this);
} else {
tile.set(null);
trace.remove(i);
i--; // do not move to next index: remove shifted the next index towards us
}
}
}
public String start() throws IOException { public String start() throws IOException {
if (isNull(block)) return t("{} not in a block",this); if (isNull(block)) return t("{} not in a block",this);
Context context = isSet(route) ? new Context( route ) : new Context( this); Context context = isSet(route) ? new Context( route ) : new Context( this);
@ -558,6 +596,14 @@ public class Train extends BaseClass implements Comparable<Train> {
return Translation.get(Application.class, message, fills); return Translation.get(Application.class, message, fills);
} }
public SortedSet<String> tags() {
TreeSet<String> list = new TreeSet<String>(tags);
for (Locomotive loco : locos) list.addAll(loco.tags());
for (Car car:cars) list.addAll(car.tags());
return list;
}
@Override @Override
public String toString() { public String toString() {
return isSet(name) ? name : locos.firstElement().name(); return isSet(name) ? name : locos.firstElement().name();
@ -567,12 +613,13 @@ public class Train extends BaseClass implements Comparable<Train> {
LOG.debug("train.turn()"); LOG.debug("train.turn()");
if (isSet(direction)) { if (isSet(direction)) {
direction = direction.inverse(); direction = direction.inverse();
for (Locomotive loco : locos) loco.turn(); for (Locomotive loco : locos) loco.turn();
reverseTrace();
if (isSet(block)) plan.place(block);
} }
return t("{} turned.",this); return t("{} turned.",this);
} }
public Train update(HashMap<String, String> params) { public Train update(HashMap<String, String> params) {
LOG.debug("update({})",params); LOG.debug("update({})",params);
pushPull = params.containsKey(PUSH_PULL) && params.get(PUSH_PULL).equals("on"); pushPull = params.containsKey(PUSH_PULL) && params.get(PUSH_PULL).equals("on");
@ -589,47 +636,8 @@ public class Train extends BaseClass implements Comparable<Train> {
return this; return this;
} }
public void set(Block newBlock) {
block = newBlock;
if (isSet(block)) block.set(this);
}
public Tile headPos() {
return trace.getFirst();
}
public void addToTrace(Vector<Tile> newTiles) {
boolean active = trace.isEmpty();
for (Tile tile : newTiles) {
if (active) {
trace.addFirst(tile);
} else {
Tile dummy = trace.getFirst();
if (dummy == tile) active = true;
}
}
showTrace();
}
public void showTrace() {
int remainingLength = length();
if (remainingLength<1) remainingLength=1;
for (int i=0; i<trace.size(); i++) {
Tile tile = trace.get(i);
if (remainingLength>0) {
remainingLength-=tile.length();
tile.set(this);
} else {
tile.set(null);
trace.remove(i);
i--; // do not move to next index: remove shifted the next index towards us
}
}
}
public void dropTrace() {
while (!trace.isEmpty()) trace.removeFirst().set(null);
}
public void removeFromTrace(Tile tile) { public void removeFromTrace(Tile tile) {
trace.remove(tile); trace.remove(tile);

Loading…
Cancel
Save