implementing train actions
This commit is contained in:
@@ -113,6 +113,7 @@ svg circle{
|
|||||||
right: 10px;
|
right: 10px;
|
||||||
background: yellow;
|
background: yellow;
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
|
overflow: scroll;
|
||||||
}
|
}
|
||||||
|
|
||||||
h2{
|
h2{
|
||||||
|
|||||||
@@ -15,12 +15,7 @@ function addMessage(txt){
|
|||||||
|
|
||||||
function addTile(x,y){
|
function addTile(x,y){
|
||||||
console.log("addTile:",selected.id,x,y);
|
console.log("addTile:",selected.id,x,y);
|
||||||
$.ajax({
|
return request({action:mode,tile:selected.id,x:x,y:y});
|
||||||
url : PLAN,
|
|
||||||
method: POST,
|
|
||||||
data : {action:mode,tile:selected.id,x:x,y:y},
|
|
||||||
success: addMessage
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function bodyClick(ev){
|
function bodyClick(ev){
|
||||||
@@ -97,12 +92,7 @@ function heartbeat(data){
|
|||||||
|
|
||||||
function moveTile(x,y){
|
function moveTile(x,y){
|
||||||
console.log("moveTile:",selected.id,x,y);
|
console.log("moveTile:",selected.id,x,y);
|
||||||
$.ajax({
|
return request({action:mode,direction:selected.id,x:x,y:y});
|
||||||
url : PLAN,
|
|
||||||
method: POST,
|
|
||||||
data : {action:mode,direction:selected.id,x:x,y:y},
|
|
||||||
success: addMessage
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function openRoute(id){
|
function openRoute(id){
|
||||||
@@ -136,17 +126,16 @@ function request(data){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function runAction(ev){
|
function runAction(ev){
|
||||||
console.log("runAction: ",ev.target.id);
|
console.log("runAction: ",ev.target.id);
|
||||||
$.ajax({
|
return request({action:ev.target.id,file:'default'}); // TODO: ask for name
|
||||||
url : PLAN,
|
}
|
||||||
method : POST,
|
|
||||||
data : {action:ev.target.id,file:'default'}, // TODO: ask for name
|
function train(x,y,action){
|
||||||
success: function(resp){ addMessage(resp);}
|
return request({action:action+"Train",x:x,y:y});
|
||||||
});
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function stream(ev){
|
function stream(ev){
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
import de.keawe.tools.translations.Translation;
|
import de.keawe.tools.translations.Translation;
|
||||||
import de.srsoftware.tools.Tag;
|
import de.srsoftware.tools.Tag;
|
||||||
|
import de.srsoftware.web4rail.moving.Train;
|
||||||
import de.srsoftware.web4rail.tiles.Block;
|
import de.srsoftware.web4rail.tiles.Block;
|
||||||
import de.srsoftware.web4rail.tiles.BlockH;
|
import de.srsoftware.web4rail.tiles.BlockH;
|
||||||
import de.srsoftware.web4rail.tiles.BlockV;
|
import de.srsoftware.web4rail.tiles.BlockV;
|
||||||
@@ -98,6 +99,7 @@ public class Plan {
|
|||||||
private static final String ID = "id";
|
private static final String ID = "id";
|
||||||
private static final String ROUTE = "route";
|
private static final String ROUTE = "route";
|
||||||
private static final HashMap<OutputStreamWriter,Integer> clients = new HashMap<OutputStreamWriter, Integer>();
|
private static final HashMap<OutputStreamWriter,Integer> clients = new HashMap<OutputStreamWriter, Integer>();
|
||||||
|
private static final String ACTION_SHOW_TRAIN = "showTrain";
|
||||||
|
|
||||||
private HashMap<Integer,HashMap<Integer,Tile>> tiles = new HashMap<Integer,HashMap<Integer,Tile>>();
|
private HashMap<Integer,HashMap<Integer,Tile>> tiles = new HashMap<Integer,HashMap<Integer,Tile>>();
|
||||||
private HashSet<Block> blocks = new HashSet<Block>();
|
private HashSet<Block> blocks = new HashSet<Block>();
|
||||||
@@ -183,6 +185,10 @@ public class Plan {
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Tile get(String x, String y,boolean resolveShadows) {
|
||||||
|
return get(Integer.parseInt(x),Integer.parseInt(y),resolveShadows);
|
||||||
|
}
|
||||||
|
|
||||||
public Tile get(int x, int y,boolean resolveShadows) {
|
public Tile get(int x, int y,boolean resolveShadows) {
|
||||||
HashMap<Integer, Tile> column = tiles.get(x);
|
HashMap<Integer, Tile> column = tiles.get(x);
|
||||||
Tile tile = (column == null) ? null : column.get(y);
|
Tile tile = (column == null) ? null : column.get(y);
|
||||||
@@ -366,11 +372,13 @@ public class Plan {
|
|||||||
case ACTION_MOVE:
|
case ACTION_MOVE:
|
||||||
return moveTile(params.get(DIRECTION),params.get(X),params.get(Y));
|
return moveTile(params.get(DIRECTION),params.get(X),params.get(Y));
|
||||||
case ACTION_PROPS:
|
case ACTION_PROPS:
|
||||||
return propMenu(params.get(X),params.get(Y));
|
return propMenu(get(params.get(X),params.get(Y),true));
|
||||||
case ACTION_ROUTE:
|
case ACTION_ROUTE:
|
||||||
return routeProperties(params.get(ID));
|
return routeProperties(params.get(ID));
|
||||||
case ACTION_SAVE:
|
case ACTION_SAVE:
|
||||||
return saveTo(params.get(FILE));
|
return saveTo(params.get(FILE));
|
||||||
|
case ACTION_SHOW_TRAIN:
|
||||||
|
return showTrain(get(params.get(X),params.get(Y),true));
|
||||||
case ACTION_UPDATE:
|
case ACTION_UPDATE:
|
||||||
return update(params);
|
return update(params);
|
||||||
default:
|
default:
|
||||||
@@ -390,12 +398,7 @@ public class Plan {
|
|||||||
return route.properties();
|
return route.properties();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Tag propMenu(String x, String y) {
|
private Tag propMenu(Tile tile) {
|
||||||
return propMenu(Integer.parseInt(x),Integer.parseInt(y));
|
|
||||||
}
|
|
||||||
|
|
||||||
private Tag propMenu(int x, int y) {
|
|
||||||
Tile tile = get(x, y,true);
|
|
||||||
if (tile == null) return null;
|
if (tile == null) return null;
|
||||||
return tile.propMenu();
|
return tile.propMenu();
|
||||||
}
|
}
|
||||||
@@ -405,8 +408,6 @@ public class Plan {
|
|||||||
routes.put(route.id(), route);
|
routes.put(route.id(), route);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void remove(Tile tile) {
|
private void remove(Tile tile) {
|
||||||
remove_intern(tile.x,tile.y);
|
remove_intern(tile.x,tile.y);
|
||||||
if (tile instanceof Block) blocks.remove(tile);
|
if (tile instanceof Block) blocks.remove(tile);
|
||||||
@@ -465,6 +466,15 @@ public class Plan {
|
|||||||
column.put(y,tile.position(x, y));
|
column.put(y,tile.position(x, y));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Object showTrain(Tile tile) {
|
||||||
|
if (tile instanceof Block) {
|
||||||
|
Block block = (Block) tile;
|
||||||
|
Train train = block.train();
|
||||||
|
if (train != null) return train.props();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private synchronized void stream(String data) {
|
private synchronized void stream(String data) {
|
||||||
data = data.replaceAll("\n", "").replaceAll("\r", "");
|
data = data.replaceAll("\n", "").replaceAll("\r", "");
|
||||||
LOG.debug("streaming: {}",data);
|
LOG.debug("streaming: {}",data);
|
||||||
|
|||||||
@@ -2,6 +2,11 @@ package de.srsoftware.web4rail.moving;
|
|||||||
|
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
|
import de.keawe.tools.translations.Translation;
|
||||||
|
import de.srsoftware.tools.Tag;
|
||||||
|
import de.srsoftware.web4rail.Application;
|
||||||
|
import de.srsoftware.web4rail.Window;
|
||||||
|
|
||||||
public class Train {
|
public class Train {
|
||||||
private Vector<Locomotive> locos = new Vector<Locomotive>();
|
private Vector<Locomotive> locos = new Vector<Locomotive>();
|
||||||
private Vector<Car> cars = new Vector<Car>();
|
private Vector<Car> cars = new Vector<Car>();
|
||||||
@@ -28,4 +33,14 @@ public class Train {
|
|||||||
public String name() {
|
public String name() {
|
||||||
return name != null ? name : locos.firstElement().name();
|
return name != null ? name : locos.firstElement().name();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Tag props() {
|
||||||
|
Window window = new Window("train-properties",t("Properties of {}",getClass().getSimpleName()));
|
||||||
|
|
||||||
|
return window;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String t(String message, Object...fills) {
|
||||||
|
return Translation.get(Application.class, message, fills);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,18 @@ public abstract class Block extends StretchableTile{
|
|||||||
return form;
|
return form;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Tag propMenu() {
|
||||||
|
Tag window = super.propMenu();
|
||||||
|
|
||||||
|
if (train != null) {
|
||||||
|
new Tag("h4").content(t("Train:")).addTo(window);
|
||||||
|
new Tag("span").clazz("link").attr("onclick","train("+x+","+y+",'show')").content(train.name()).addTo(window);
|
||||||
|
new Tag("span").clazz("link").attr("onclick","train("+x+","+y+",'start')").content(" - "+t("start")).addTo(window);
|
||||||
|
}
|
||||||
|
return window;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Tag tag(Map<String, Object> replacements) throws IOException {
|
public Tag tag(Map<String, Object> replacements) throws IOException {
|
||||||
if (replacements == null) replacements = new HashMap<String, Object>();
|
if (replacements == null) replacements = new HashMap<String, Object>();
|
||||||
@@ -64,4 +76,8 @@ public abstract class Block extends StretchableTile{
|
|||||||
public void setTrain(Train train) {
|
public void setTrain(Train train) {
|
||||||
this.train = train;
|
this.train = train;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Train train() {
|
||||||
|
return train;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,29 +70,29 @@ public abstract class Tile {
|
|||||||
new Tag("input").attr("type", "hidden").attr("name","action").attr("value", "update").addTo(form);
|
new Tag("input").attr("type", "hidden").attr("name","action").attr("value", "update").addTo(form);
|
||||||
new Tag("input").attr("type", "hidden").attr("name","x").attr("value", x).addTo(form);
|
new Tag("input").attr("type", "hidden").attr("name","x").attr("value", x).addTo(form);
|
||||||
new Tag("input").attr("type", "hidden").attr("name","y").attr("value", y).addTo(form);
|
new Tag("input").attr("type", "hidden").attr("name","y").attr("value", y).addTo(form);
|
||||||
|
|
||||||
if (!routes.isEmpty()) {
|
|
||||||
new Tag("h4").content(t("Routes using this tile:")).addTo(form);
|
|
||||||
Tag routeList = new Tag("ul");
|
|
||||||
for (Route route : routes) {
|
|
||||||
new Tag("li").clazz("link").attr("onclick","openRoute('"+route.id()+"')").content(route.name()).addTo(routeList);
|
|
||||||
}
|
|
||||||
routeList.addTo(form);
|
|
||||||
}
|
|
||||||
|
|
||||||
return form;
|
return form;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tag propMenu() {
|
public Tag propMenu() {
|
||||||
Window menu = new Window("tile-properties",t("Properties of {} @ ({},{})",getClass().getSimpleName(),x,y));
|
Window window = new Window("tile-properties",t("Properties of {} @ ({},{})",getClass().getSimpleName(),x,y));
|
||||||
Tag form = propForm();
|
Tag form = propForm();
|
||||||
if (form!=null) {
|
if (form!=null && form.children().size()>3) {
|
||||||
new Tag("button").attr("type", "submit").content(t("save")).addTo(form);
|
new Tag("button").attr("type", "submit").content(t("save")).addTo(form);
|
||||||
form.addTo(menu);
|
form.addTo(window);
|
||||||
} else {
|
} else {
|
||||||
menu.content(t("This tile ({}) has no properties",getClass().getSimpleName()));
|
window.content(t("This tile ({}) has no properties",getClass().getSimpleName()));
|
||||||
}
|
}
|
||||||
return menu;
|
|
||||||
|
if (!routes.isEmpty()) {
|
||||||
|
new Tag("h4").content(t("Routes using this tile:")).addTo(window);
|
||||||
|
Tag routeList = new Tag("ul");
|
||||||
|
for (Route route : routes) {
|
||||||
|
new Tag("li").clazz("link").attr("onclick","openRoute('"+route.id()+"')").content(route.name()).addTo(routeList);
|
||||||
|
}
|
||||||
|
routeList.addTo(window);
|
||||||
|
}
|
||||||
|
|
||||||
|
return window;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tag tag(Map<String,Object> replacements) throws IOException {
|
public Tag tag(Map<String,Object> replacements) throws IOException {
|
||||||
|
|||||||
Reference in New Issue
Block a user