added new condition: BlockFree
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
package de.srsoftware.web4rail.tiles;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.TreeSet;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.json.JSONArray;
|
||||
@@ -28,7 +30,7 @@ import de.srsoftware.web4rail.tags.Select;
|
||||
* @author Stephan Richter, SRSoftware
|
||||
*
|
||||
*/
|
||||
public abstract class Block extends StretchableTile{
|
||||
public abstract class Block extends StretchableTile implements Comparable<Block>{
|
||||
private static final String ALLOW_TURN = "allowTurn";
|
||||
private static final String NAME = "name";
|
||||
private static final String NO_TAG = "[default]";
|
||||
@@ -113,6 +115,11 @@ public abstract class Block extends StretchableTile{
|
||||
|
||||
|
||||
private Vector<WaitTime> waitTimes = new Vector<WaitTime>();
|
||||
|
||||
@Override
|
||||
public int compareTo(Block other) {
|
||||
return name.compareTo(other.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject config() {
|
||||
@@ -134,6 +141,12 @@ public abstract class Block extends StretchableTile{
|
||||
return this;
|
||||
}
|
||||
|
||||
public static Block get(String blockId) {
|
||||
Tile tile = plan.get(blockId, false);
|
||||
if (tile instanceof Block) return (Block) tile;
|
||||
return null;
|
||||
}
|
||||
|
||||
private WaitTime getWaitTime(String tag) {
|
||||
if (tag == null) return null;
|
||||
for (WaitTime wt : waitTimes) {
|
||||
@@ -273,6 +286,22 @@ public abstract class Block extends StretchableTile{
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public static Tag selector(Block preselected,Collection<Block> exclude) {
|
||||
if (isNull(exclude)) exclude = new Vector<Block>();
|
||||
Select select = new Select(Block.class.getSimpleName());
|
||||
new Tag("option").attr("value","0").content(t("unset")).addTo(select);
|
||||
TreeSet<Block> blocks = new TreeSet<Block>();
|
||||
for (Tile tile : plan.tiles.values()) {
|
||||
if (tile instanceof Block) blocks.add((Block) tile);
|
||||
}
|
||||
for (Block block : blocks) {
|
||||
if (exclude.contains(block)) continue;
|
||||
Tag opt = select.addOption(block.id(), block);
|
||||
if (block == preselected) opt.attr("selected", "selected");
|
||||
}
|
||||
return select;
|
||||
}
|
||||
|
||||
public abstract List<Connector> startPoints();
|
||||
|
||||
|
||||
@@ -106,7 +106,7 @@ public class Contact extends Tile{
|
||||
if (contact == null) return t("No contact with id {} found!",id);
|
||||
Tag propMenu = contact.propMenu();
|
||||
propMenu.children().insertElementAt(new Tag("div").content(t("Trigger a feedback sensor to assign it with this contact!")), 1);
|
||||
contact.plan.learn(contact);
|
||||
plan.learn(contact);
|
||||
return propMenu;
|
||||
}
|
||||
return t("Unknown action: {}",action);
|
||||
|
||||
@@ -59,7 +59,6 @@ public abstract class Tile extends BaseClass{
|
||||
private boolean disabled = false;
|
||||
private int length = DEFAUT_LENGTH;
|
||||
protected Direction oneWay = null;
|
||||
protected Plan plan = null;;
|
||||
protected Route route = null;
|
||||
private HashSet<Route> routes = new HashSet<>();
|
||||
protected HashSet<Shadow> shadows = new HashSet<>();
|
||||
@@ -113,7 +112,6 @@ public abstract class Tile extends BaseClass{
|
||||
private static void inflate(String clazz, JSONObject json, Plan plan) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, ClassNotFoundException, IOException {
|
||||
clazz = Tile.class.getName().replace(".Tile", "."+clazz);
|
||||
Tile tile = (Tile) Tile.class.getClassLoader().loadClass(clazz).getDeclaredConstructor().newInstance();
|
||||
tile.plan(plan);
|
||||
tile.load(json);
|
||||
plan.set(tile.x, tile.y, tile);
|
||||
}
|
||||
@@ -175,15 +173,6 @@ public abstract class Tile extends BaseClass{
|
||||
return this;
|
||||
}
|
||||
|
||||
public Plan plan() {
|
||||
return plan;
|
||||
}
|
||||
|
||||
public Tile plan(Plan plan) {
|
||||
this.plan = plan;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Tile position(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
||||
Reference in New Issue
Block a user