working on route allocation
This commit is contained in:
@@ -86,7 +86,7 @@ public class Plan {
|
||||
private static final String ACTION_ADD = "add";
|
||||
private static final String ACTION_ANALYZE = "analyze";
|
||||
private static final String ACTION_MOVE = "move";
|
||||
private static final String ACTION_PROPS = "openProps";
|
||||
private static final String ACTION_CLICK = "click";
|
||||
private static final String ACTION_SAVE = "save";
|
||||
private static final String ACTION_UPDATE = "update";
|
||||
private static final String TILE = "tile";
|
||||
@@ -160,6 +160,11 @@ public class Plan {
|
||||
public Collection<Block> blocks() {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
private Object click(Tile tile) throws IOException {
|
||||
if (tile == null) return null;
|
||||
return tile.click();
|
||||
}
|
||||
|
||||
private Collection<Route> follow(Route route, Connector connector) {
|
||||
Tile tile = get(connector.x,connector.y,false);
|
||||
@@ -340,7 +345,7 @@ public class Plan {
|
||||
}
|
||||
|
||||
private boolean moveTile(int x, int y,int xstep,int ystep) throws IOException {
|
||||
LOG.error("moveTile({}+ {},{}+ {}) not implemented",x,xstep,y,ystep);
|
||||
LOG.error("moveTile({}+ {},{}+ {})",x,xstep,y,ystep);
|
||||
Stack<Tile> stack = new Stack<Tile>();
|
||||
Tile tile = get(x,y,false);
|
||||
while (tile != null) {
|
||||
@@ -368,12 +373,12 @@ public class Plan {
|
||||
switch (action) {
|
||||
case ACTION_ADD:
|
||||
return addTile(params.get(TILE),params.get(X),params.get(Y),null);
|
||||
case ACTION_CLICK:
|
||||
return click(get(params.get(X),params.get(Y),true));
|
||||
case ACTION_ANALYZE:
|
||||
return analyze();
|
||||
case ACTION_MOVE:
|
||||
return moveTile(params.get(DIRECTION),params.get(X),params.get(Y));
|
||||
case ACTION_PROPS:
|
||||
return propMenu(get(params.get(X),params.get(Y),true));
|
||||
case ACTION_ROUTE:
|
||||
return routeProperties(params.get(ID));
|
||||
case ACTION_SAVE:
|
||||
@@ -408,11 +413,6 @@ public class Plan {
|
||||
if (route == null) return t("Could not find route \"{}\"",routeId);
|
||||
return route.properties();
|
||||
}
|
||||
|
||||
private Tag propMenu(Tile tile) {
|
||||
if (tile == null) return null;
|
||||
return tile.propMenu();
|
||||
}
|
||||
|
||||
private void registerRoute(Route route) {
|
||||
for (Tile tile: route.path()) tile.add(route);
|
||||
@@ -482,7 +482,7 @@ public class Plan {
|
||||
return (train == null) ? null : train.props();
|
||||
}
|
||||
|
||||
private String start(Train train) {
|
||||
private String start(Train train) throws IOException {
|
||||
if (train == null) return null;
|
||||
return train.start();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.srsoftware.web4rail;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -111,7 +112,10 @@ public class Route {
|
||||
return props.toString();
|
||||
}
|
||||
|
||||
public Route lock(Train train) {
|
||||
public Route lock(Train train) throws IOException {
|
||||
for (Entry<Turnout, State> entry : turnouts.entrySet()) {
|
||||
entry.getKey().state(entry.getValue());
|
||||
}
|
||||
for (Tile tile : path) tile.lock(train);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.srsoftware.web4rail.moving;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Random;
|
||||
import java.util.Vector;
|
||||
@@ -55,7 +56,7 @@ public class Train {
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
public String start() {
|
||||
public String start() throws IOException {
|
||||
if (block == null) return t("{] not in a block",this);
|
||||
HashSet<Route> routes = block.routes();
|
||||
Vector<Route> availableRoutes = new Vector<Route>();
|
||||
|
||||
@@ -19,10 +19,10 @@ import de.srsoftware.web4rail.Application;
|
||||
import de.srsoftware.web4rail.Connector;
|
||||
import de.srsoftware.web4rail.Plan;
|
||||
import de.srsoftware.web4rail.Plan.Direction;
|
||||
import de.srsoftware.web4rail.tags.Form;
|
||||
import de.srsoftware.web4rail.Route;
|
||||
import de.srsoftware.web4rail.Window;
|
||||
import de.srsoftware.web4rail.moving.Train;
|
||||
import de.srsoftware.web4rail.tags.Form;
|
||||
|
||||
public abstract class Tile {
|
||||
|
||||
@@ -30,7 +30,7 @@ public abstract class Tile {
|
||||
protected HashSet<String> classes = new HashSet<>();
|
||||
protected HashSet<Shadow> shadows = new HashSet<>();
|
||||
private HashSet<Route> routes = new HashSet<>();
|
||||
private Plan plan;
|
||||
protected Plan plan;
|
||||
private Train lockedBy;
|
||||
|
||||
protected static Logger LOG = LoggerFactory.getLogger(Tile.class);
|
||||
@@ -48,6 +48,10 @@ public abstract class Tile {
|
||||
shadows.add(shadow);
|
||||
}
|
||||
|
||||
public Object click() throws IOException {
|
||||
return propMenu();
|
||||
}
|
||||
|
||||
public JSONObject config() {
|
||||
return new JSONObject();
|
||||
}
|
||||
@@ -69,6 +73,7 @@ public abstract class Tile {
|
||||
|
||||
public void lock(Train train) {
|
||||
lockedBy = train;
|
||||
classes.add("locked");
|
||||
plan.stream("addclass tile-"+x+"-"+y+" locked");
|
||||
}
|
||||
|
||||
@@ -190,6 +195,7 @@ public abstract class Tile {
|
||||
|
||||
public void unlock() {
|
||||
lockedBy = null;
|
||||
classes.remove("locked");
|
||||
plan.stream("dropclass tile-"+x+"-"+y+" locked");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,35 @@
|
||||
package de.srsoftware.web4rail.tiles;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
|
||||
public abstract class Turnout extends Tile {
|
||||
public static final String STATE = "state";
|
||||
public enum State{
|
||||
LEFT,STRAIGHT,RIGHT,UNDEF;
|
||||
}
|
||||
private boolean straight = true;
|
||||
protected State state = State.STRAIGHT;
|
||||
|
||||
public boolean toggle() {
|
||||
straight = !straight;
|
||||
return straight;
|
||||
public State state() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void state(State newState) throws IOException {
|
||||
state = newState;
|
||||
LOG.debug("Setting {} to {}",this,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).toLowerCase());
|
||||
return tag;
|
||||
}
|
||||
|
||||
public void toggle() {
|
||||
state = State.STRAIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
11
src/main/java/de/srsoftware/web4rail/tiles/TurnoutL.java
Normal file
11
src/main/java/de/srsoftware/web4rail/tiles/TurnoutL.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package de.srsoftware.web4rail.tiles;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class TurnoutL extends Turnout {
|
||||
@Override
|
||||
public Object click() throws IOException {
|
||||
state = (state == State.STRAIGHT) ? State.LEFT : State.STRAIGHT;
|
||||
return tag(null);
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import java.util.Map;
|
||||
import de.srsoftware.web4rail.Connector;
|
||||
import de.srsoftware.web4rail.Plan.Direction;
|
||||
|
||||
public class TurnoutLE extends Turnout{
|
||||
public class TurnoutLE extends TurnoutL{
|
||||
|
||||
@Override
|
||||
public Map<Connector, State> connections(Direction from) {
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.Map;
|
||||
import de.srsoftware.web4rail.Connector;
|
||||
import de.srsoftware.web4rail.Plan.Direction;
|
||||
|
||||
public class TurnoutLN extends Turnout{
|
||||
public class TurnoutLN extends TurnoutL{
|
||||
|
||||
@Override
|
||||
public Map<Connector, State> connections(Direction from) {
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.Map;
|
||||
import de.srsoftware.web4rail.Connector;
|
||||
import de.srsoftware.web4rail.Plan.Direction;
|
||||
|
||||
public class TurnoutLS extends Turnout{
|
||||
public class TurnoutLS extends TurnoutL{
|
||||
|
||||
@Override
|
||||
public Map<Connector, State> connections(Direction from) {
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.Map;
|
||||
import de.srsoftware.web4rail.Connector;
|
||||
import de.srsoftware.web4rail.Plan.Direction;
|
||||
|
||||
public class TurnoutLW extends Turnout{
|
||||
public class TurnoutLW extends TurnoutL{
|
||||
|
||||
@Override
|
||||
public Map<Connector, State> connections(Direction from) {
|
||||
|
||||
11
src/main/java/de/srsoftware/web4rail/tiles/TurnoutR.java
Normal file
11
src/main/java/de/srsoftware/web4rail/tiles/TurnoutR.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package de.srsoftware.web4rail.tiles;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import java.util.Map;
|
||||
import de.srsoftware.web4rail.Connector;
|
||||
import de.srsoftware.web4rail.Plan.Direction;
|
||||
|
||||
public class TurnoutRE extends Turnout{
|
||||
public class TurnoutRE extends TurnoutR{
|
||||
|
||||
@Override
|
||||
public Map<Connector, State> connections(Direction from) {
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.Map;
|
||||
import de.srsoftware.web4rail.Connector;
|
||||
import de.srsoftware.web4rail.Plan.Direction;
|
||||
|
||||
public class TurnoutRN extends Turnout{
|
||||
public class TurnoutRN extends TurnoutR{
|
||||
|
||||
@Override
|
||||
public Map<Connector, State> connections(Direction from) {
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.Map;
|
||||
import de.srsoftware.web4rail.Connector;
|
||||
import de.srsoftware.web4rail.Plan.Direction;
|
||||
|
||||
public class TurnoutRS extends Turnout{
|
||||
public class TurnoutRS extends TurnoutR{
|
||||
|
||||
@Override
|
||||
public Map<Connector, State> connections(Direction from) {
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.Map;
|
||||
import de.srsoftware.web4rail.Connector;
|
||||
import de.srsoftware.web4rail.Plan.Direction;
|
||||
|
||||
public class TurnoutRW extends Turnout{
|
||||
public class TurnoutRW extends TurnoutR{
|
||||
|
||||
@Override
|
||||
public Map<Connector, State> connections(Direction from) {
|
||||
|
||||
Reference in New Issue
Block a user