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

@@ -175,3 +175,7 @@ svg.straight .right{
.occupied .block{
fill: yellow;
}
.active circle{
fill: #ffcc88;
}

View File

@@ -209,8 +209,8 @@ public class Route {
if (lastTile instanceof Turnout) addTurnout((Turnout) lastTile,state);
}
public Route setSignals() throws IOException {
for (Signal signal : signals) signal.state("go");
public Route setSignals(String state) throws IOException {
for (Signal signal : signals) signal.state(state == null ? "go" : state);
return this;
}
@@ -222,8 +222,9 @@ public class Route {
return Translation.get(Application.class, txt, fills);
}
public void unlock() {
public Route unlock() {
for (Tile tile : path) tile.unlock();
return this;
}
public void update(HashMap<String, String> params) {

View File

@@ -11,6 +11,7 @@ import de.srsoftware.web4rail.Application;
import de.srsoftware.web4rail.Route;
import de.srsoftware.web4rail.Window;
import de.srsoftware.web4rail.tiles.Block;
import de.srsoftware.web4rail.tiles.Signal;
import de.srsoftware.web4rail.tiles.Tile;
public class Train {
@@ -63,9 +64,9 @@ public class Train {
availableRoutes.add(route);
}
Random rand = new Random();
if (route != null) route.unlock();
if (route != null) route.unlock().setSignals(Signal.STOP);
int sel = rand.nextInt(availableRoutes.size());
route = availableRoutes.get(sel).lock(this).setSignals();
route = availableRoutes.get(sel).lock(this).setSignals(null);
return t("started {}",this);
}

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);
if (lockedBy != null) {
plan.stream(t("{} is locked by {}!",this,lockedBy));
} else {
state = (state == State.STRAIGHT) ? State.LEFT : State.STRAIGHT;
return tag(null);
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 {
if (lockedBy != null) {
plan.stream(t("{} is locked by {}!",this,lockedBy));
} else {
state = (state == State.STRAIGHT) ? State.RIGHT : State.STRAIGHT;
return tag(null);
plan.stream("place "+tag(null));
}
return propMenu();
}
}