Browse Source

preparing trains

lookup-tables
Stephan Richter 5 years ago
parent
commit
2f3251660d
  1. 7
      src/main/java/de/srsoftware/web4rail/Application.java
  2. 10
      src/main/java/de/srsoftware/web4rail/Plan.java
  3. 14
      src/main/java/de/srsoftware/web4rail/moving/Car.java
  4. 8
      src/main/java/de/srsoftware/web4rail/moving/Locomotive.java
  5. 31
      src/main/java/de/srsoftware/web4rail/moving/Train.java
  6. 8
      src/main/java/de/srsoftware/web4rail/tiles/Block.java
  7. 72004
      src/socket,sys,os

7
src/main/java/de/srsoftware/web4rail/Application.java

@ -15,6 +15,7 @@ import java.nio.charset.Charset; @@ -15,6 +15,7 @@ import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.Vector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -24,6 +25,9 @@ import com.sun.net.httpserver.HttpServer; @@ -24,6 +25,9 @@ import com.sun.net.httpserver.HttpServer;
import de.keawe.localconfig.Configuration;
import de.keawe.tools.translations.Translation;
import de.srsoftware.web4rail.moving.Locomotive;
import de.srsoftware.web4rail.moving.Train;
import de.srsoftware.web4rail.tiles.Block;
public class Application {
private static Plan plan;
@ -47,6 +51,9 @@ public class Application { @@ -47,6 +51,9 @@ public class Application {
} catch (FileNotFoundException e) {
plan = new Plan();
}
Locomotive BR110 = new Locomotive("BR110");
Block block = new Vector<>(plan.blocks()).firstElement();
if (block != null) block.setTrain(new Train(BR110));
Desktop.getDesktop().browse(URI.create("http://localhost:"+config.getInt(PORT)+"/plan"));
}

10
src/main/java/de/srsoftware/web4rail/Plan.java

@ -154,6 +154,10 @@ public class Plan { @@ -154,6 +154,10 @@ public class Plan {
return t("Found {} routes.",routes.size());
}
public Collection<Block> blocks() {
return blocks;
}
private Collection<Route> follow(Route route, Connector connector) {
Tile tile = get(connector.x,connector.y,false);
Vector<Route> results = new Vector<>();
@ -201,7 +205,8 @@ public class Plan { @@ -201,7 +205,8 @@ public class Plan {
for (Entry<Integer, Tile> row : column.getValue().entrySet()) {
int y = row.getKey();
Tile tile = row.getValue().position(x, y);
if (tile != null) page.append("\t\t"+tile.tag(null)+"\n");
if (tile == null) continue;
page.append("\t\t"+tile.tag(null)+"\n");
}
}
return page
@ -213,6 +218,7 @@ public class Plan { @@ -213,6 +218,7 @@ public class Plan {
.js("js/jquery-3.5.1.min.js")
.js("js/plan.js");
}
public static Plan load(String filename) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
Plan result = new Plan();
File file = new File(filename+".plan");
@ -403,6 +409,7 @@ public class Plan { @@ -403,6 +409,7 @@ public class Plan {
private void remove(Tile tile) {
remove_intern(tile.x,tile.y);
if (tile instanceof Block) blocks.remove(tile);
for (int i=1; i<tile.len(); i++) remove_intern(tile.x+i, tile.y); // remove shadow tiles
for (int i=1; i<tile.height(); i++) remove_intern(tile.x, tile.y+i); // remove shadow tiles
if (tile != null) stream("remove tile-"+tile.x+"-"+tile.y);
@ -442,6 +449,7 @@ public class Plan { @@ -442,6 +449,7 @@ public class Plan {
public void set(int x,int y,Tile tile) throws IOException {
if (tile == null) return;
if (tile instanceof Block) blocks.add((Block) tile);
for (int i=1; i<tile.len(); i++) set(x+i,y,new Shadow(tile));
for (int i=1; i<tile.height(); i++) set(x,y+i,new Shadow(tile));
set_intern(x,y,tile);

14
src/main/java/de/srsoftware/web4rail/moving/Car.java

@ -0,0 +1,14 @@ @@ -0,0 +1,14 @@
package de.srsoftware.web4rail.moving;
public class Car {
public int length;
private String name;
public Car(String name) {
this.name = name;
}
String name(){
return name;
}
}

8
src/main/java/de/srsoftware/web4rail/moving/Locomotive.java

@ -0,0 +1,8 @@ @@ -0,0 +1,8 @@
package de.srsoftware.web4rail.moving;
public class Locomotive extends Car {
public Locomotive(String name) {
super(name);
}
}

31
src/main/java/de/srsoftware/web4rail/moving/Train.java

@ -0,0 +1,31 @@ @@ -0,0 +1,31 @@
package de.srsoftware.web4rail.moving;
import java.util.Vector;
public class Train {
private Vector<Locomotive> locos = new Vector<Locomotive>();
private Vector<Car> cars = new Vector<Car>();
private String name = null;
public Train(Locomotive loco) {
add(loco);
}
public void add(Car car) {
if (car == null) return;
if (car instanceof Locomotive) {
locos.add((Locomotive) car);
} else cars.add(car);
}
public int length() {
int result = 0;
for (Locomotive loco : locos) result += loco.length;
for (Car car : cars) result += car.length;
return result;
}
public String name() {
return name != null ? name : locos.firstElement().name();
}
}

8
src/main/java/de/srsoftware/web4rail/tiles/Block.java

@ -9,10 +9,12 @@ import org.json.JSONObject; @@ -9,10 +9,12 @@ import org.json.JSONObject;
import de.srsoftware.tools.Tag;
import de.srsoftware.web4rail.Connector;
import de.srsoftware.web4rail.moving.Train;
public abstract class Block extends StretchableTile{
private static final String NAME = "name";
public String name = "Block";
private Train train;
@Override
public JSONObject config() {
@ -43,7 +45,7 @@ public abstract class Block extends StretchableTile{ @@ -43,7 +45,7 @@ public abstract class Block extends StretchableTile{
@Override
public Tag tag(Map<String, Object> replacements) throws IOException {
if (replacements == null) replacements = new HashMap<String, Object>();
replacements.put("%text%",name);
replacements.put("%text%",train == null ? name : train.name());
return super.tag(replacements);
}
@ -58,4 +60,8 @@ public abstract class Block extends StretchableTile{ @@ -58,4 +60,8 @@ public abstract class Block extends StretchableTile{
if (params.containsKey(NAME)) name=params.get(NAME);
return this;
}
public void setTrain(Train train) {
this.train = train;
}
}

72004
src/socket,sys,os

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save