13 changed files with 225 additions and 3 deletions
@ -0,0 +1,59 @@
@@ -0,0 +1,59 @@
|
||||
package de.srsoftware.web4rail.tiles; |
||||
|
||||
import java.io.IOException; |
||||
import java.util.Map; |
||||
|
||||
import de.srsoftware.tools.Tag; |
||||
import de.srsoftware.web4rail.Connector; |
||||
import de.srsoftware.web4rail.Window; |
||||
import de.srsoftware.web4rail.tags.Button; |
||||
import de.srsoftware.web4rail.tiles.Turnout.State; |
||||
|
||||
public abstract class Bridge extends Tile { |
||||
private static Bridge pendingConnection = null; |
||||
protected Bridge counterpart = null; |
||||
|
||||
@Override |
||||
public Object click() throws IOException { |
||||
if (pendingConnection != null) return connect(); |
||||
return super.click(); |
||||
} |
||||
|
||||
private Object connect() { |
||||
if (this == pendingConnection) return t("Cannot connect {} to itself!",this); |
||||
if (isSet(counterpart)) { |
||||
counterpart.counterpart = null; // drop other connection
|
||||
plan.place(counterpart); |
||||
} |
||||
counterpart = pendingConnection; |
||||
counterpart.counterpart = this; |
||||
pendingConnection = null; |
||||
plan.place(this); |
||||
plan.place(counterpart); |
||||
return t("Connected {} and {}.",this,counterpart); |
||||
} |
||||
|
||||
protected abstract Connector connector(); |
||||
|
||||
@Override |
||||
public Window propMenu() { |
||||
Window win = super.propMenu(); |
||||
Map<String, String> props = Map.of(REALM,REALM_PLAN,ID,id(),ACTION,ACTION_CONNECT); |
||||
new Tag("h4").content("Counterpart").addTo(win); |
||||
new Tag("p").content(isSet(counterpart) ? t("Connected to {}.",counterpart) : t("Not connected to other bridge part!")).addTo(win); |
||||
new Button(t("Select counterpart"), props).addTo(win); |
||||
return win; |
||||
} |
||||
|
||||
public Object requestConnect() { |
||||
pendingConnection = this; |
||||
return t("Click other bridge to connect to!"); |
||||
} |
||||
|
||||
@Override |
||||
public Tag tag(Map<String, Object> replacements) throws IOException { |
||||
Tag tag = super.tag(replacements); |
||||
if (isNull(counterpart)) tag.clazz(tag.get("class")+" disconnected"); |
||||
return tag; |
||||
} |
||||
} |
@ -0,0 +1,30 @@
@@ -0,0 +1,30 @@
|
||||
package de.srsoftware.web4rail.tiles; |
||||
|
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
import de.srsoftware.web4rail.Connector; |
||||
import de.srsoftware.web4rail.Plan.Direction; |
||||
import de.srsoftware.web4rail.tiles.Turnout.State; |
||||
|
||||
public class BridgeE extends Bridge { |
||||
@Override |
||||
public List<Direction> possibleDirections() { |
||||
return List.of(Direction.EAST); |
||||
} |
||||
|
||||
@Override |
||||
public Map<Connector, State> connections(Direction from) { |
||||
if (isSet(counterpart)) switch (from) { |
||||
case EAST: |
||||
return Map.of(counterpart.connector(),State.UNDEF); |
||||
default: |
||||
} |
||||
return super.connections(from); |
||||
} |
||||
|
||||
@Override |
||||
protected Connector connector() { |
||||
return new Connector(x+1, y, Direction.WEST); |
||||
} |
||||
} |
@ -0,0 +1,30 @@
@@ -0,0 +1,30 @@
|
||||
package de.srsoftware.web4rail.tiles; |
||||
|
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
import de.srsoftware.web4rail.Connector; |
||||
import de.srsoftware.web4rail.Plan.Direction; |
||||
import de.srsoftware.web4rail.tiles.Turnout.State; |
||||
|
||||
public class BridgeN extends Bridge { |
||||
@Override |
||||
public List<Direction> possibleDirections() { |
||||
return List.of(Direction.NORTH); |
||||
} |
||||
|
||||
@Override |
||||
public Map<Connector, State> connections(Direction from) { |
||||
if (isSet(counterpart)) switch (from) { |
||||
case NORTH: |
||||
return Map.of(counterpart.connector(),State.UNDEF); |
||||
default: |
||||
} |
||||
return super.connections(from); |
||||
} |
||||
|
||||
@Override |
||||
protected Connector connector() { |
||||
return new Connector(x, y-1, Direction.SOUTH); |
||||
} |
||||
} |
@ -0,0 +1,30 @@
@@ -0,0 +1,30 @@
|
||||
package de.srsoftware.web4rail.tiles; |
||||
|
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
import de.srsoftware.web4rail.Connector; |
||||
import de.srsoftware.web4rail.Plan.Direction; |
||||
import de.srsoftware.web4rail.tiles.Turnout.State; |
||||
|
||||
public class BridgeS extends Bridge { |
||||
@Override |
||||
public List<Direction> possibleDirections() { |
||||
return List.of(Direction.SOUTH); |
||||
} |
||||
|
||||
@Override |
||||
public Map<Connector, State> connections(Direction from) { |
||||
if (isSet(counterpart)) switch (from) { |
||||
case SOUTH: |
||||
return Map.of(counterpart.connector(),State.UNDEF); |
||||
default: |
||||
} |
||||
return super.connections(from); |
||||
} |
||||
|
||||
@Override |
||||
protected Connector connector() { |
||||
return new Connector(x, y+1, Direction.NORTH); |
||||
} |
||||
} |
@ -0,0 +1,31 @@
@@ -0,0 +1,31 @@
|
||||
package de.srsoftware.web4rail.tiles; |
||||
|
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
import de.srsoftware.web4rail.Connector; |
||||
import de.srsoftware.web4rail.Plan.Direction; |
||||
import de.srsoftware.web4rail.tiles.Turnout.State; |
||||
|
||||
public class BridgeW extends Bridge { |
||||
@Override |
||||
public List<Direction> possibleDirections() { |
||||
return List.of(Direction.WEST); |
||||
} |
||||
|
||||
@Override |
||||
public Map<Connector, State> connections(Direction from) { |
||||
if (isSet(counterpart)) |
||||
switch (from) { |
||||
case WEST: |
||||
return Map.of(counterpart.connector(), State.UNDEF); |
||||
default: |
||||
} |
||||
return super.connections(from); |
||||
} |
||||
|
||||
@Override |
||||
protected Connector connector() { |
||||
return new Connector(x - 1, y, Direction.EAST); |
||||
} |
||||
} |
Loading…
Reference in new issue