preparing trains
This commit is contained in:
@@ -15,6 +15,7 @@ import java.nio.charset.Charset;
|
|||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -24,6 +25,9 @@ import com.sun.net.httpserver.HttpServer;
|
|||||||
|
|
||||||
import de.keawe.localconfig.Configuration;
|
import de.keawe.localconfig.Configuration;
|
||||||
import de.keawe.tools.translations.Translation;
|
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 {
|
public class Application {
|
||||||
private static Plan plan;
|
private static Plan plan;
|
||||||
@@ -47,6 +51,9 @@ public class Application {
|
|||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
plan = new Plan();
|
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"));
|
Desktop.getDesktop().browse(URI.create("http://localhost:"+config.getInt(PORT)+"/plan"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -154,6 +154,10 @@ public class Plan {
|
|||||||
return t("Found {} routes.",routes.size());
|
return t("Found {} routes.",routes.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Collection<Block> blocks() {
|
||||||
|
return blocks;
|
||||||
|
}
|
||||||
|
|
||||||
private Collection<Route> follow(Route route, Connector connector) {
|
private Collection<Route> follow(Route route, Connector connector) {
|
||||||
Tile tile = get(connector.x,connector.y,false);
|
Tile tile = get(connector.x,connector.y,false);
|
||||||
Vector<Route> results = new Vector<>();
|
Vector<Route> results = new Vector<>();
|
||||||
@@ -201,7 +205,8 @@ public class Plan {
|
|||||||
for (Entry<Integer, Tile> row : column.getValue().entrySet()) {
|
for (Entry<Integer, Tile> row : column.getValue().entrySet()) {
|
||||||
int y = row.getKey();
|
int y = row.getKey();
|
||||||
Tile tile = row.getValue().position(x, y);
|
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
|
return page
|
||||||
@@ -213,6 +218,7 @@ public class Plan {
|
|||||||
.js("js/jquery-3.5.1.min.js")
|
.js("js/jquery-3.5.1.min.js")
|
||||||
.js("js/plan.js");
|
.js("js/plan.js");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Plan load(String filename) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
public static Plan load(String filename) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||||
Plan result = new Plan();
|
Plan result = new Plan();
|
||||||
File file = new File(filename+".plan");
|
File file = new File(filename+".plan");
|
||||||
@@ -403,6 +409,7 @@ public class Plan {
|
|||||||
|
|
||||||
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);
|
||||||
for (int i=1; i<tile.len(); i++) remove_intern(tile.x+i, tile.y); // remove shadow tiles
|
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
|
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);
|
if (tile != null) stream("remove tile-"+tile.x+"-"+tile.y);
|
||||||
@@ -442,6 +449,7 @@ public class Plan {
|
|||||||
|
|
||||||
public void set(int x,int y,Tile tile) throws IOException {
|
public void set(int x,int y,Tile tile) throws IOException {
|
||||||
if (tile == null) return;
|
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.len(); i++) set(x+i,y,new Shadow(tile));
|
||||||
for (int i=1; i<tile.height(); i++) set(x,y+i,new Shadow(tile));
|
for (int i=1; i<tile.height(); i++) set(x,y+i,new Shadow(tile));
|
||||||
set_intern(x,y,tile);
|
set_intern(x,y,tile);
|
||||||
|
|||||||
14
src/main/java/de/srsoftware/web4rail/moving/Car.java
Normal file
14
src/main/java/de/srsoftware/web4rail/moving/Car.java
Normal file
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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
Normal file
31
src/main/java/de/srsoftware/web4rail/moving/Train.java
Normal file
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,10 +9,12 @@ import org.json.JSONObject;
|
|||||||
|
|
||||||
import de.srsoftware.tools.Tag;
|
import de.srsoftware.tools.Tag;
|
||||||
import de.srsoftware.web4rail.Connector;
|
import de.srsoftware.web4rail.Connector;
|
||||||
|
import de.srsoftware.web4rail.moving.Train;
|
||||||
|
|
||||||
public abstract class Block extends StretchableTile{
|
public abstract class Block extends StretchableTile{
|
||||||
private static final String NAME = "name";
|
private static final String NAME = "name";
|
||||||
public String name = "Block";
|
public String name = "Block";
|
||||||
|
private Train train;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JSONObject config() {
|
public JSONObject config() {
|
||||||
@@ -43,7 +45,7 @@ public abstract class Block extends StretchableTile{
|
|||||||
@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>();
|
||||||
replacements.put("%text%",name);
|
replacements.put("%text%",train == null ? name : train.name());
|
||||||
return super.tag(replacements);
|
return super.tag(replacements);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,4 +60,8 @@ public abstract class Block extends StretchableTile{
|
|||||||
if (params.containsKey(NAME)) name=params.get(NAME);
|
if (params.containsKey(NAME)) name=params.get(NAME);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setTrain(Train train) {
|
||||||
|
this.train = train;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
72004
src/socket,sys,os
72004
src/socket,sys,os
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user