working on contact and signal functions
This commit is contained in:
@@ -175,3 +175,7 @@ svg.straight .right{
|
|||||||
.occupied .block{
|
.occupied .block{
|
||||||
fill: yellow;
|
fill: yellow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.active circle{
|
||||||
|
fill: #ffcc88;
|
||||||
|
}
|
||||||
@@ -209,8 +209,8 @@ public class Route {
|
|||||||
if (lastTile instanceof Turnout) addTurnout((Turnout) lastTile,state);
|
if (lastTile instanceof Turnout) addTurnout((Turnout) lastTile,state);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Route setSignals() throws IOException {
|
public Route setSignals(String state) throws IOException {
|
||||||
for (Signal signal : signals) signal.state("go");
|
for (Signal signal : signals) signal.state(state == null ? "go" : state);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,8 +222,9 @@ public class Route {
|
|||||||
return Translation.get(Application.class, txt, fills);
|
return Translation.get(Application.class, txt, fills);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unlock() {
|
public Route unlock() {
|
||||||
for (Tile tile : path) tile.unlock();
|
for (Tile tile : path) tile.unlock();
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(HashMap<String, String> params) {
|
public void update(HashMap<String, String> params) {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import de.srsoftware.web4rail.Application;
|
|||||||
import de.srsoftware.web4rail.Route;
|
import de.srsoftware.web4rail.Route;
|
||||||
import de.srsoftware.web4rail.Window;
|
import de.srsoftware.web4rail.Window;
|
||||||
import de.srsoftware.web4rail.tiles.Block;
|
import de.srsoftware.web4rail.tiles.Block;
|
||||||
|
import de.srsoftware.web4rail.tiles.Signal;
|
||||||
import de.srsoftware.web4rail.tiles.Tile;
|
import de.srsoftware.web4rail.tiles.Tile;
|
||||||
|
|
||||||
public class Train {
|
public class Train {
|
||||||
@@ -63,9 +64,9 @@ public class Train {
|
|||||||
availableRoutes.add(route);
|
availableRoutes.add(route);
|
||||||
}
|
}
|
||||||
Random rand = new Random();
|
Random rand = new Random();
|
||||||
if (route != null) route.unlock();
|
if (route != null) route.unlock().setSignals(Signal.STOP);
|
||||||
int sel = rand.nextInt(availableRoutes.size());
|
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);
|
return t("started {}",this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,39 @@
|
|||||||
package de.srsoftware.web4rail.tiles;
|
package de.srsoftware.web4rail.tiles;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import de.srsoftware.tools.Tag;
|
||||||
|
|
||||||
public abstract class Contact extends Tile{
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import de.srsoftware.web4rail.Plan.Direction;
|
|||||||
|
|
||||||
public abstract class Signal extends Tile{
|
public abstract class Signal extends Tile{
|
||||||
|
|
||||||
private static final String STOP = "stop";
|
public static final String STOP = "stop";
|
||||||
private String state = STOP;
|
private String state = STOP;
|
||||||
|
|
||||||
public Signal() {
|
public Signal() {
|
||||||
|
|||||||
@@ -5,8 +5,12 @@ import java.io.IOException;
|
|||||||
public class TurnoutL extends Turnout {
|
public class TurnoutL extends Turnout {
|
||||||
@Override
|
@Override
|
||||||
public Object click() throws IOException {
|
public Object click() throws IOException {
|
||||||
if (lockedBy != null) return t("{} is locked by {}!",this,lockedBy);
|
if (lockedBy != null) {
|
||||||
state = (state == State.STRAIGHT) ? State.LEFT : State.STRAIGHT;
|
plan.stream(t("{} is locked by {}!",this,lockedBy));
|
||||||
return tag(null);
|
} else {
|
||||||
|
state = (state == State.STRAIGHT) ? State.LEFT : State.STRAIGHT;
|
||||||
|
plan.stream("place "+tag(null));
|
||||||
|
}
|
||||||
|
return propMenu();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,12 @@ import java.io.IOException;
|
|||||||
public class TurnoutR extends Turnout {
|
public class TurnoutR extends Turnout {
|
||||||
@Override
|
@Override
|
||||||
public Object click() throws IOException {
|
public Object click() throws IOException {
|
||||||
state = (state == State.STRAIGHT) ? State.RIGHT : State.STRAIGHT;
|
if (lockedBy != null) {
|
||||||
return tag(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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user