working on contact and signal functions

This commit is contained in:
Stephan Richter
2020-09-19 14:36:32 +02:00
parent 0aa00ae065
commit ad1e4d2134
7 changed files with 60 additions and 11 deletions

View File

@@ -1,5 +1,39 @@
package de.srsoftware.web4rail.tiles;
import java.io.IOException;
import de.srsoftware.tools.Tag;
public abstract class Contact extends Tile{
private boolean active = false;
private void activate() throws IOException {
active = true;
stream();
new Thread() {
public void run() {
try {
sleep(200);
active=false;
stream();
} catch (Exception e) {}
}
}.start();
}
@Override
public Object click() throws IOException {
activate();
return super.click();
}
public void stream() throws IOException {
Tag tag = super.tag(null);
if (active) tag.clazz(tag.get("class")+" active");
plan.stream("place "+tag);
}
}

View File

@@ -8,7 +8,7 @@ import de.srsoftware.web4rail.Plan.Direction;
public abstract class Signal extends Tile{
private static final String STOP = "stop";
public static final String STOP = "stop";
private String state = STOP;
public Signal() {

View File

@@ -5,8 +5,12 @@ import java.io.IOException;
public class TurnoutL extends Turnout {
@Override
public Object click() throws IOException {
if (lockedBy != null) return t("{} is locked by {}!",this,lockedBy);
state = (state == State.STRAIGHT) ? State.LEFT : State.STRAIGHT;
return tag(null);
if (lockedBy != null) {
plan.stream(t("{} is locked by {}!",this,lockedBy));
} else {
state = (state == State.STRAIGHT) ? State.LEFT : State.STRAIGHT;
plan.stream("place "+tag(null));
}
return propMenu();
}
}

View File

@@ -5,7 +5,12 @@ import java.io.IOException;
public class TurnoutR extends Turnout {
@Override
public Object click() throws IOException {
state = (state == State.STRAIGHT) ? State.RIGHT : State.STRAIGHT;
return tag(null);
if (lockedBy != null) {
plan.stream(t("{} is locked by {}!",this,lockedBy));
} else {
state = (state == State.STRAIGHT) ? State.RIGHT : State.STRAIGHT;
plan.stream("place "+tag(null));
}
return propMenu();
}
}