working on signals on routes
This commit is contained in:
@@ -140,9 +140,12 @@ h2{
|
||||
stroke: red;
|
||||
}
|
||||
|
||||
.sig_a{
|
||||
.signal.stop .sig_a{
|
||||
fill: red;
|
||||
}
|
||||
.signal.go .sig_a{
|
||||
fill: lime;
|
||||
}
|
||||
|
||||
.sig_b{
|
||||
fill: black;
|
||||
@@ -168,3 +171,7 @@ svg.straight .left,
|
||||
svg.straight .right{
|
||||
fill: white !important;
|
||||
}
|
||||
|
||||
.occupied .block{
|
||||
fill: yellow;
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
@@ -52,7 +53,9 @@ public class Application {
|
||||
plan = new Plan();
|
||||
}
|
||||
Locomotive BR110 = new Locomotive("BR110");
|
||||
Block block = new Vector<>(plan.blocks()).lastElement();
|
||||
Vector<Block> blocks = new Vector<>(plan.blocks());
|
||||
Random rand = new Random();
|
||||
Block block = blocks.get(rand.nextInt(blocks.size()));
|
||||
if (block != null) block.train(new Train(BR110));
|
||||
Desktop.getDesktop().browse(URI.create("http://localhost:"+config.getInt(PORT)+"/plan"));
|
||||
}
|
||||
|
||||
@@ -209,6 +209,11 @@ public class Route {
|
||||
if (lastTile instanceof Turnout) addTurnout((Turnout) lastTile,state);
|
||||
}
|
||||
|
||||
public Route setSignals() throws IOException {
|
||||
for (Signal signal : signals) signal.state("go");
|
||||
return this;
|
||||
}
|
||||
|
||||
public Block startBlock() {
|
||||
return (Block) path.get(0);
|
||||
}
|
||||
|
||||
@@ -31,6 +31,10 @@ public class Train {
|
||||
} else cars.add(car);
|
||||
}
|
||||
|
||||
public void block(Block block) {
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
public int length() {
|
||||
int result = 0;
|
||||
for (Locomotive loco : locos) result += loco.length;
|
||||
@@ -48,14 +52,6 @@ public class Train {
|
||||
return window;
|
||||
}
|
||||
|
||||
private String t(String message, Object...fills) {
|
||||
return Translation.get(Application.class, message, fills);
|
||||
}
|
||||
|
||||
public void block(Block block) {
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
public String start() throws IOException {
|
||||
if (block == null) return t("{] not in a block",this);
|
||||
HashSet<Route> routes = block.routes();
|
||||
@@ -69,7 +65,16 @@ public class Train {
|
||||
Random rand = new Random();
|
||||
if (route != null) route.unlock();
|
||||
int sel = rand.nextInt(availableRoutes.size());
|
||||
route = availableRoutes.get(sel).lock(this);
|
||||
route = availableRoutes.get(sel).lock(this).setSignals();
|
||||
return t("started {}",this);
|
||||
}
|
||||
|
||||
private String t(String message, Object...fills) {
|
||||
return Translation.get(Application.class, message, fills);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,9 @@ public abstract class Block extends StretchableTile{
|
||||
public Tag tag(Map<String, Object> replacements) throws IOException {
|
||||
if (replacements == null) replacements = new HashMap<String, Object>();
|
||||
replacements.put("%text%",train == null ? name : train.name());
|
||||
return super.tag(replacements);
|
||||
Tag tag = super.tag(replacements);
|
||||
if (train != null) tag.clazz(tag.get("class")+" occupied");
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,13 +1,32 @@
|
||||
package de.srsoftware.web4rail.tiles;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.Plan.Direction;
|
||||
|
||||
public abstract class Signal extends Tile{
|
||||
|
||||
private static final String STOP = "stop";
|
||||
private String state = STOP;
|
||||
|
||||
public Signal() {
|
||||
super();
|
||||
classes.add("signal");
|
||||
}
|
||||
|
||||
public abstract boolean isAffectedFrom(Direction dir);
|
||||
|
||||
public void state(String state) throws IOException {
|
||||
this.state = state;
|
||||
plan.stream("place "+tag(null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag tag(Map<String, Object> replacements) throws IOException {
|
||||
Tag tag = super.tag(replacements);
|
||||
tag.clazz(tag.get("class")+" "+state);
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public abstract class Tile {
|
||||
protected HashSet<Shadow> shadows = new HashSet<>();
|
||||
private HashSet<Route> routes = new HashSet<>();
|
||||
protected Plan plan;
|
||||
private Train lockedBy;
|
||||
protected Train lockedBy;
|
||||
|
||||
protected static Logger LOG = LoggerFactory.getLogger(Tile.class);
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ 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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user