refactored tiles data structure in plan

This commit is contained in:
Stephan Richter
2020-09-21 13:07:12 +02:00
parent 09a7c9f5b7
commit 67623f49bc
5 changed files with 85 additions and 85 deletions

View File

@@ -96,7 +96,11 @@ public abstract class Tile {
}
public String id() {
return x+":"+y;
return Tile.id(x, y);
}
public static String id(int x, int y) {
return x+"-"+y;
}
private static void inflate(String clazz, JSONObject json, Plan plan) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, ClassNotFoundException, IOException {
@@ -237,14 +241,11 @@ public abstract class Tile {
return routes;
}
public static void saveAll(HashMap<Integer, HashMap<Integer, Tile>> tiles ,String filename) throws IOException {
public static void saveAll(HashMap<String, Tile> tiles ,String filename) throws IOException {
BufferedWriter file = new BufferedWriter(new FileWriter(filename));
for (Entry<Integer, HashMap<Integer, Tile>> column : tiles.entrySet()) {
for (Entry<Integer, Tile> row : column.getValue().entrySet()) {
Tile tile = row.getValue();
if (tile == null || tile instanceof Shadow) continue;
file.append(tile.json()+"\n");
}
for (Tile tile : tiles.values()) {
if (tile == null || tile instanceof Shadow) continue;
file.append(tile.json()+"\n");
}
file.close();
}
@@ -261,7 +262,7 @@ public abstract class Tile {
replacements.put("%height%",height);
String style = "";
Tag svg = new Tag("svg")
.id((x!=-1 && y!=-1)?("tile-"+x+"-"+y):(getClass().getSimpleName()))
.id((x!=-1 && y!=-1)?(id()):(getClass().getSimpleName()))
.clazz(classes())
.size(100,100)
.attr("name", getClass().getSimpleName())