started implementing route properties
This commit is contained in:
@@ -105,7 +105,7 @@ svg circle{
|
||||
background: yellow;
|
||||
}
|
||||
|
||||
#tile-properties{
|
||||
.window{
|
||||
position: fixed;
|
||||
top: 10px;
|
||||
bottom: 10px;
|
||||
|
||||
@@ -71,6 +71,10 @@ function closeMenu(ev){
|
||||
return false;
|
||||
}
|
||||
|
||||
function closeWindows(){
|
||||
$('.window').remove();
|
||||
}
|
||||
|
||||
function enableAdding(ev){
|
||||
// console.log('enableAdding:',ev);
|
||||
if (selected != null) $(selected).css('border','');
|
||||
@@ -125,6 +129,21 @@ function moveTile(x,y){
|
||||
});
|
||||
}
|
||||
|
||||
function openRoute(id){
|
||||
closeWindows();
|
||||
$.ajax({
|
||||
url : PLAN,
|
||||
method : POST,
|
||||
data : {action:'openRoute',id:id},
|
||||
success: function(resp){
|
||||
if (resp.startsWith('<')){
|
||||
$('body').append($(resp));
|
||||
} else {
|
||||
addMessage(resp);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
function runAction(ev){
|
||||
console.log("runAction: ",ev.target.id);
|
||||
$.ajax({
|
||||
|
||||
@@ -2,9 +2,9 @@ package de.srsoftware.web4rail;
|
||||
|
||||
public class Connector {
|
||||
|
||||
private Plan.Direction from;
|
||||
private int y;
|
||||
private int x;
|
||||
public Plan.Direction from;
|
||||
public int y;
|
||||
public int x;
|
||||
|
||||
public Connector(int x, int y, Plan.Direction from) {
|
||||
this.x = x;
|
||||
@@ -12,18 +12,6 @@ public class Connector {
|
||||
this.from = from;
|
||||
}
|
||||
|
||||
public Plan.Direction from() {
|
||||
return from;
|
||||
}
|
||||
|
||||
public int x() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public int y() {
|
||||
return y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName()+"("+x+", "+y+", from "+from+")";
|
||||
|
||||
@@ -38,6 +38,7 @@ import de.srsoftware.web4rail.tiles.EndS;
|
||||
import de.srsoftware.web4rail.tiles.EndW;
|
||||
import de.srsoftware.web4rail.tiles.Eraser;
|
||||
import de.srsoftware.web4rail.tiles.Shadow;
|
||||
import de.srsoftware.web4rail.tiles.Signal;
|
||||
import de.srsoftware.web4rail.tiles.SignalE;
|
||||
import de.srsoftware.web4rail.tiles.SignalN;
|
||||
import de.srsoftware.web4rail.tiles.SignalS;
|
||||
@@ -71,9 +72,12 @@ public class Plan {
|
||||
private static final String Y = "y";
|
||||
private static final String FILE = "file";
|
||||
private static final String DIRECTION = "direction";
|
||||
private static final String ACTION_ROUTE = "openRoute";
|
||||
private static final String ID = "id";
|
||||
|
||||
private HashMap<Integer,HashMap<Integer,Tile>> tiles = new HashMap<Integer,HashMap<Integer,Tile>>();
|
||||
private HashSet<Block> blocks = new HashSet<Block>();
|
||||
private HashMap<String, Route> routes = new HashMap<String, Route>();
|
||||
|
||||
private Tag actionMenu() throws IOException {
|
||||
Tag tileMenu = new Tag("div").clazz("actions").content(t("Actions"));
|
||||
@@ -100,20 +104,25 @@ public class Plan {
|
||||
for (Block block : blocks) {
|
||||
for (Connector con : block.startPoints()) routes.addAll(follow(new Route().start(block),con));
|
||||
}
|
||||
this.routes.clear();
|
||||
for (Route route : routes) {
|
||||
route.start().add(route);
|
||||
LOG.debug("found route: {}",route);
|
||||
this.routes.put(route.id(), route);
|
||||
}
|
||||
return t("Found {} routes.",routes.size());
|
||||
}
|
||||
|
||||
private Collection<Route> follow(Route route, Connector con) {
|
||||
Tile tile = get(con.x(),con.y());
|
||||
Tile tile = get(con.x,con.y);
|
||||
Vector<Route> results = new Vector<>();
|
||||
if (tile == null) return results;
|
||||
Tile added = route.add(tile instanceof Shadow ? ((Shadow)tile).overlay() : tile);
|
||||
if (added instanceof Signal) {
|
||||
Signal signal = (Signal) added;
|
||||
if (signal.isAffectedFrom(con.from)) route.addSignal(signal);
|
||||
}
|
||||
if (added instanceof Block) return List.of(route);
|
||||
List<Connector> connectors = tile.connections(con.from());
|
||||
List<Connector> connectors = tile.connections(con.from);
|
||||
List<Route>routes = route.multiply(connectors.size());
|
||||
for (int i=0; i<connectors.size(); i++) results.addAll(follow(routes.get(i),connectors.get(i)));
|
||||
return results;
|
||||
@@ -247,6 +256,8 @@ public class Plan {
|
||||
return moveTile(params.get(DIRECTION),params.get(X),params.get(Y));
|
||||
case ACTION_PROPS:
|
||||
return propMenu(params.get(X),params.get(Y));
|
||||
case ACTION_ROUTE:
|
||||
return routeProperties(params.get(ID));
|
||||
case ACTION_SAVE:
|
||||
return saveTo(params.get(FILE));
|
||||
case ACTION_UPDATE:
|
||||
@@ -260,6 +271,12 @@ public class Plan {
|
||||
}
|
||||
}
|
||||
|
||||
private Object routeProperties(String routeId) {
|
||||
Route route = routes.get(routeId);
|
||||
if (route == null) return t("Could not find route \"{}\"",routeId);
|
||||
return route.properties();
|
||||
}
|
||||
|
||||
private Page update(HashMap<String, String> params) throws IOException {
|
||||
return update(Integer.parseInt(params.get("x")),Integer.parseInt(params.get("y")),params);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,10 @@ package de.srsoftware.web4rail;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
import de.keawe.tools.translations.Translation;
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.tiles.Block;
|
||||
import de.srsoftware.web4rail.tiles.Contact;
|
||||
import de.srsoftware.web4rail.tiles.Signal;
|
||||
import de.srsoftware.web4rail.tiles.Tile;
|
||||
|
||||
@@ -11,16 +14,25 @@ public class Route {
|
||||
|
||||
private Vector<Tile> path;
|
||||
private Vector<Signal> signals;
|
||||
private Vector<Contact> contacts;
|
||||
private String id;
|
||||
private String name;
|
||||
|
||||
public Tile add(Tile tile) {
|
||||
path.add(tile);
|
||||
if (tile instanceof Contact) contacts.add((Contact) tile);
|
||||
return tile;
|
||||
}
|
||||
|
||||
public Route addSignal(Signal signal) {
|
||||
signals.add(signal);
|
||||
return this;
|
||||
}
|
||||
|
||||
protected Route clone() {
|
||||
Route clone = new Route();
|
||||
clone.contacts = new Vector<Contact>(contacts);
|
||||
clone.signals = new Vector<Signal>(signals);
|
||||
clone.path = new Vector<>(path);
|
||||
return clone;
|
||||
}
|
||||
@@ -54,7 +66,22 @@ public class Route {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Window properties() {
|
||||
Window win = new Window("route-properties",t("Properties of {})",this));
|
||||
new Tag("h4").content(t("Signals")).addTo(win);
|
||||
Tag list = new Tag("ul");
|
||||
for (Signal s : signals) new Tag("li").content(s.toString()).addTo(list);
|
||||
list.addTo(win);
|
||||
new Tag("h4").content(t("Contacts")).addTo(win);
|
||||
list = new Tag("ul");
|
||||
for (Contact c : contacts) new Tag("li").content(c.toString()).addTo(list);
|
||||
list.addTo(win);
|
||||
return win;
|
||||
}
|
||||
|
||||
public Route start(Block block) {
|
||||
contacts = new Vector<Contact>();
|
||||
signals = new Vector<Signal>();
|
||||
path = new Vector<Tile>();
|
||||
path.add(block);
|
||||
return this;
|
||||
@@ -62,10 +89,14 @@ public class Route {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName()+"("+id()+")";
|
||||
return getClass().getSimpleName()+"("+name()+")";
|
||||
}
|
||||
|
||||
public Block start() {
|
||||
return (Block) path.get(0);
|
||||
}
|
||||
|
||||
protected static String t(String txt, Object...fills) {
|
||||
return Translation.get(Application.class, txt, fills);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ public class Window extends Tag{
|
||||
|
||||
public Window(String id, String title) {
|
||||
super("div");
|
||||
id(id);
|
||||
id(id).clazz("window");
|
||||
new Tag("h2")
|
||||
.clazz("title")
|
||||
.content(title).addTo(this);
|
||||
|
||||
@@ -52,7 +52,7 @@ public abstract class Block extends StretchableTile{
|
||||
new Tag("h4").content(t("Routes from here:")).addTo(form);
|
||||
Tag routeList = new Tag("ul");
|
||||
for (Route route : routes) {
|
||||
new Tag("li").content(route.id()).addTo(routeList);
|
||||
new Tag("li").content(route.id()).attr("onclick","openRoute('"+route.id()+"')").addTo(routeList);
|
||||
}
|
||||
routeList.addTo(form);
|
||||
|
||||
|
||||
@@ -9,5 +9,5 @@ public abstract class Signal extends Tile{
|
||||
classes.add("signal");
|
||||
}
|
||||
|
||||
abstract boolean isAffectedFrom(Direction dir);
|
||||
public abstract boolean isAffectedFrom(Direction dir);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public class SignalE extends Signal{
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean isAffectedFrom(Direction dir) {
|
||||
public boolean isAffectedFrom(Direction dir) {
|
||||
return dir == Direction.EAST;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public class SignalN extends Signal {
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean isAffectedFrom(Direction dir) {
|
||||
public boolean isAffectedFrom(Direction dir) {
|
||||
return dir == Direction.NORTH;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public class SignalS extends Signal{
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean isAffectedFrom(Direction dir) {
|
||||
public boolean isAffectedFrom(Direction dir) {
|
||||
return dir == Direction.SOUTH;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public class SignalW extends Signal{
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean isAffectedFrom(Direction dir) {
|
||||
public boolean isAffectedFrom(Direction dir) {
|
||||
return dir == Direction.WEST;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user