fixed #23
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.2.35</version>
|
<version>1.2.36</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>
|
||||||
|
|||||||
@@ -142,8 +142,8 @@ public class Locomotive extends Car implements Constants,Device{
|
|||||||
}
|
}
|
||||||
direction.addTo(fieldset);
|
direction.addTo(fieldset);
|
||||||
|
|
||||||
Tag functions = new Tag("p");
|
Tag functions = new Tag("p");
|
||||||
Map.of("F1",ACTION_TOGGLE_F1,"F2",ACTION_TOGGLE_F2,"F3",ACTION_TOGGLE_F3,"F4",ACTION_TOGGLE_F4).entrySet().forEach(e -> {
|
Map.of("F1",ACTION_TOGGLE_F1,"F2",ACTION_TOGGLE_F2,"F3",ACTION_TOGGLE_F3,"F4",ACTION_TOGGLE_F4).entrySet().stream().sorted((e1,e2)->(e1.getKey().compareTo(e2.getKey()))).forEach(e -> {
|
||||||
params.put(ACTION, e.getValue());
|
params.put(ACTION, e.getValue());
|
||||||
new Button(t(e.getKey()),params).addTo(functions);
|
new Button(t(e.getKey()),params).addTo(functions);
|
||||||
});
|
});
|
||||||
@@ -262,6 +262,7 @@ public class Locomotive extends Car implements Constants,Device{
|
|||||||
|
|
||||||
private void queue() {
|
private void queue() {
|
||||||
int step = proto.steps * speed / (maxSpeedForward == 0 ? 100 : maxSpeedForward);
|
int step = proto.steps * speed / (maxSpeedForward == 0 ? 100 : maxSpeedForward);
|
||||||
|
init();
|
||||||
plan.queue(new Command("SET {} GL "+address+" "+(orientation == FORWARD ? 0 : 1)+" "+step+" "+proto.steps+" "+(f1?1:0)+" "+(f2?1:0)+" "+(f3?1:0)+" "+(f4?1:0)) {
|
plan.queue(new Command("SET {} GL "+address+" "+(orientation == FORWARD ? 0 : 1)+" "+step+" "+proto.steps+" "+(f1?1:0)+" "+(f2?1:0)+" "+(f3?1:0)+" "+(f4?1:0)) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -271,6 +272,27 @@ public class Locomotive extends Car implements Constants,Device{
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String setFunction(int num, boolean active) {
|
||||||
|
switch (num) {
|
||||||
|
case 1:
|
||||||
|
f1 = active;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
f2 = active;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
f3 = active;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
f4 = active;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return t("Unknown function: {}",num);
|
||||||
|
}
|
||||||
|
queue();
|
||||||
|
return t("{} F{}",t(active?"Activated":"Deavtivated"),num);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the speed of the locomotive to the given velocity in [plan.speedUnit]s
|
* Sets the speed of the locomotive to the given velocity in [plan.speedUnit]s
|
||||||
@@ -279,7 +301,6 @@ public class Locomotive extends Car implements Constants,Device{
|
|||||||
*/
|
*/
|
||||||
public String setSpeed(int newSpeed) {
|
public String setSpeed(int newSpeed) {
|
||||||
LOG.debug(this.detail()+".setSpeed({})",newSpeed);
|
LOG.debug(this.detail()+".setSpeed({})",newSpeed);
|
||||||
init();
|
|
||||||
speed = newSpeed;
|
speed = newSpeed;
|
||||||
if (speed > maxSpeedForward && maxSpeedForward > 0) speed = maxSpeed();
|
if (speed > maxSpeedForward && maxSpeedForward > 0) speed = maxSpeed();
|
||||||
if (speed < 0) speed = 0;
|
if (speed < 0) speed = 0;
|
||||||
@@ -293,30 +314,18 @@ public class Locomotive extends Car implements Constants,Device{
|
|||||||
return properties();
|
return properties();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object toggleFunction(int f) {
|
Object toggleFunction(int f) {
|
||||||
boolean active;
|
|
||||||
switch (f) {
|
switch (f) {
|
||||||
case 1:
|
case 1:
|
||||||
f1 =! f1;
|
return setFunction(1, !f1);
|
||||||
active = f1;
|
|
||||||
break;
|
|
||||||
case 2:
|
case 2:
|
||||||
f2 =! f2;
|
return setFunction(2, !f2);
|
||||||
active = f2;
|
|
||||||
break;
|
|
||||||
case 3:
|
case 3:
|
||||||
f3 =! f3;
|
return setFunction(3, !f3);
|
||||||
active = f3;
|
|
||||||
break;
|
|
||||||
case 4:
|
case 4:
|
||||||
f4 =! f4;
|
return setFunction(4, !f4);
|
||||||
active = f4;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return t("Unknown function: {}",f);
|
|
||||||
}
|
}
|
||||||
queue();
|
return t("Unknown function: {}",f);
|
||||||
return t("{} F{}",t(active?"Activated":"Deavtivated"),f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String turn() {
|
public String turn() {
|
||||||
@@ -329,7 +338,13 @@ public class Locomotive extends Car implements Constants,Device{
|
|||||||
protected Window update(HashMap<String, String> params) {
|
protected Window update(HashMap<String, String> params) {
|
||||||
super.update(params);
|
super.update(params);
|
||||||
if (params.containsKey(PROTOCOL)) proto = Protocol.valueOf(params.get(PROTOCOL));
|
if (params.containsKey(PROTOCOL)) proto = Protocol.valueOf(params.get(PROTOCOL));
|
||||||
if (params.containsKey(ADDRESS)) address = Integer.parseInt(params.get(ADDRESS));
|
if (params.containsKey(ADDRESS)) {
|
||||||
|
int newAddress = Integer.parseInt(params.get(ADDRESS));
|
||||||
|
if (newAddress != address) {
|
||||||
|
init = false;
|
||||||
|
address = newAddress;
|
||||||
|
}
|
||||||
|
}
|
||||||
return properties();
|
return properties();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
private static final String DESTINATION = "destination";
|
private static final String DESTINATION = "destination";
|
||||||
|
|
||||||
private HashSet<String> tags = new HashSet<String>();
|
private HashSet<String> tags = new HashSet<String>();
|
||||||
|
private boolean f1,f2,f3,f4;
|
||||||
|
|
||||||
private Block currentBlock,destination = null;
|
private Block currentBlock,destination = null;
|
||||||
LinkedList<Tile> trace = new LinkedList<Tile>();
|
LinkedList<Tile> trace = new LinkedList<Tile>();
|
||||||
@@ -141,6 +142,14 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
return train.automatic();
|
return train.automatic();
|
||||||
case ACTION_DROP:
|
case ACTION_DROP:
|
||||||
return train.dropCar(params);
|
return train.dropCar(params);
|
||||||
|
case ACTION_TOGGLE_F1:
|
||||||
|
return train.toggleFunction(1);
|
||||||
|
case ACTION_TOGGLE_F2:
|
||||||
|
return train.toggleFunction(2);
|
||||||
|
case ACTION_TOGGLE_F3:
|
||||||
|
return train.toggleFunction(3);
|
||||||
|
case ACTION_TOGGLE_F4:
|
||||||
|
return train.toggleFunction(4);
|
||||||
case ACTION_FASTER10:
|
case ACTION_FASTER10:
|
||||||
return train.faster(10);
|
return train.faster(10);
|
||||||
case ACTION_MOVE:
|
case ACTION_MOVE:
|
||||||
@@ -163,6 +172,37 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
return t("Unknown action: {}",params.get(ACTION));
|
return t("Unknown action: {}",params.get(ACTION));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Object toggleFunction(int f) {
|
||||||
|
boolean active;
|
||||||
|
switch (f) {
|
||||||
|
case 1:
|
||||||
|
f1 =! f1;
|
||||||
|
active = f1;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
f2 =! f2;
|
||||||
|
active = f2;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
f3 =! f3;
|
||||||
|
active = f3;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
f4 =! f4;
|
||||||
|
active = f4;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return t("Unknown function: {}",f);
|
||||||
|
}
|
||||||
|
for (Car car : cars) {
|
||||||
|
if (car instanceof Locomotive) {
|
||||||
|
Locomotive loco = (Locomotive) car;
|
||||||
|
loco.setFunction(f,active);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return properties();
|
||||||
|
}
|
||||||
|
|
||||||
public void addToTrace(Vector<Tile> newTiles) {
|
public void addToTrace(Vector<Tile> newTiles) {
|
||||||
boolean active = trace.isEmpty();
|
boolean active = trace.isEmpty();
|
||||||
for (Tile tile : newTiles) {
|
for (Tile tile : newTiles) {
|
||||||
@@ -222,7 +262,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
car.link(car.name()+(car.stockId.isEmpty() ? "" : " ("+car.stockId+")")).addTo(li).content(NBSP);
|
car.link(car.name()+(car.stockId.isEmpty() ? "" : " ("+car.stockId+")")).addTo(li).content(NBSP);
|
||||||
car.button(t("turn within train"),Map.of(ACTION,ACTION_TURN)).addTo(li);
|
car.button(t("turn within train"),Map.of(ACTION,ACTION_TURN)).addTo(li);
|
||||||
car.button("↑",Map.of(ACTION,ACTION_MOVE)).addTo(li);
|
car.button("↑",Map.of(ACTION,ACTION_MOVE)).addTo(li);
|
||||||
button(t("delete"),Map.of(ACTION,ACTION_DROP,LOCO_ID,car.id().toString())).addTo(li);
|
button(t("delete"),Map.of(ACTION,ACTION_DROP,CAR_ID,car.id().toString())).addTo(li);
|
||||||
li.addTo(carList);
|
li.addTo(carList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,7 +274,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
new Input(ACTION, ACTION_ADD).hideIn(addLocoForm);
|
new Input(ACTION, ACTION_ADD).hideIn(addLocoForm);
|
||||||
new Input(ID,id).hideIn(addLocoForm);
|
new Input(ID,id).hideIn(addLocoForm);
|
||||||
Select select = new Select(CAR_ID);
|
Select select = new Select(CAR_ID);
|
||||||
for (Car loco : locos) select.addOption(loco.id(), loco);
|
for (Car loco : locos) select.addOption(loco.id(), loco+(loco.stockId.isEmpty()?"":" ("+loco.stockId+")"));
|
||||||
select.addTo(addLocoForm);
|
select.addTo(addLocoForm);
|
||||||
new Button(t("add"),addLocoForm).addTo(addLocoForm);
|
new Button(t("add"),addLocoForm).addTo(addLocoForm);
|
||||||
addLocoForm.addTo(new Tag("li")).addTo(carList);
|
addLocoForm.addTo(new Tag("li")).addTo(carList);
|
||||||
@@ -797,7 +837,6 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
if (!tag.isEmpty()) tags.add(tag);
|
if (!tag.isEmpty()) tags.add(tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user