|
@@ -10,25 +10,41 @@ import me.hammerle.supersnuvi.util.Pair;
|
|
|
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
-public class LevelPathParser {
|
|
|
|
|
|
+public class LevelGraphBuilder {
|
|
|
|
|
|
- private final ILevel level;
|
|
|
|
- private final LevelData levelData;
|
|
|
|
-
|
|
|
|
- public LevelPathParser(Level level) {
|
|
|
|
- this.level = level;
|
|
|
|
- levelData = level.getData();
|
|
|
|
|
|
+ public LevelGraphBuilder() {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public LevelGraph getLevelAsGraph(Level lvl){
|
|
|
|
|
|
|
|
+ if(lvl == null) return null;
|
|
|
|
|
|
- public static Map<Integer, List<Integer>> getCoordinatesOfCollisionTiles(Level lvl){
|
|
|
|
|
|
+ LevelData lvlData = lvl.getData();
|
|
|
|
|
|
- Map<Integer, List<Integer>> coordinates = new HashMap<>();
|
|
|
|
|
|
+ if(lvlData == null) return null;
|
|
|
|
+
|
|
|
|
+ Map<Integer, List<Integer>> collisionTileCoordinates = getCoordinatesOfCollisionTiles(lvl, lvlData);
|
|
|
|
+
|
|
|
|
+ if(collisionTileCoordinates.size() == 0) return null;
|
|
|
|
+
|
|
|
|
+ List<Pair<Integer, Integer>> graphCoordinates = getListOfGraphCoordinates(collisionTileCoordinates);
|
|
|
|
|
|
- if(lvl == null) return coordinates;
|
|
|
|
|
|
+ if(graphCoordinates.size() == 0) return null;
|
|
|
|
|
|
- LevelData lvldata = lvl.getData();
|
|
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * returns coordinates of all tiles in the given level
|
|
|
|
+ * which can collide with entites (e.g ground tile)
|
|
|
|
+ *
|
|
|
|
+ * @param lvl
|
|
|
|
+ * @param lvldata
|
|
|
|
+ * @return coordinates of tiles as map (key = x coord, y = list of y coordinates)
|
|
|
|
+ */
|
|
|
|
+ private Map<Integer, List<Integer>> getCoordinatesOfCollisionTiles(Level lvl, LevelData lvldata){
|
|
|
|
+
|
|
|
|
+ Map<Integer, List<Integer>> coordinates = new HashMap<>();
|
|
|
|
|
|
int backgroundIndex = lvldata.getBackgroundIndex();
|
|
int backgroundIndex = lvldata.getBackgroundIndex();
|
|
int width = lvldata.getWidth();
|
|
int width = lvldata.getWidth();
|
|
@@ -53,18 +69,32 @@ public class LevelPathParser {
|
|
return coordinates;
|
|
return coordinates;
|
|
}
|
|
}
|
|
|
|
|
|
- public static List<Pair<Integer, Integer>> getGraphCoordinates(Map<Integer, List<Integer>> collisionTileCoordinates){
|
|
|
|
|
|
+ /**
|
|
|
|
+ * extracts from all collisiontiles a list of coordinates,
|
|
|
|
+ * which are used for the graph
|
|
|
|
+ *
|
|
|
|
+ * lists in the passed map will be emptied
|
|
|
|
+ *
|
|
|
|
+ * @param collisionTileCoordinates
|
|
|
|
+ * @return list of integer pairs
|
|
|
|
+ */
|
|
|
|
+ private List<Pair<Integer, Integer>> getListOfGraphCoordinates(Map<Integer, List<Integer>> collisionTileCoordinates){
|
|
|
|
|
|
List<Pair<Integer, Integer>> graphCoordinates = new ArrayList<>();
|
|
List<Pair<Integer, Integer>> graphCoordinates = new ArrayList<>();
|
|
|
|
|
|
if(collisionTileCoordinates == null || collisionTileCoordinates.size() <= 0) return graphCoordinates;
|
|
if(collisionTileCoordinates == null || collisionTileCoordinates.size() <= 0) return graphCoordinates;
|
|
|
|
|
|
for(int key : collisionTileCoordinates.keySet()){
|
|
for(int key : collisionTileCoordinates.keySet()){
|
|
|
|
+
|
|
Collections.sort(collisionTileCoordinates.get(key));
|
|
Collections.sort(collisionTileCoordinates.get(key));
|
|
Collections.reverse(collisionTileCoordinates.get(key));
|
|
Collections.reverse(collisionTileCoordinates.get(key));
|
|
|
|
|
|
- Stack<Integer> result = findGraphCoordinatesInRow(collisionTileCoordinates.get(key), new Stack<Integer>());
|
|
|
|
- System.out.println(result);
|
|
|
|
|
|
+ Stack<Integer> ycoordinates = findLowestIntegersInRow(collisionTileCoordinates.get(key), new Stack<Integer>());
|
|
|
|
+
|
|
|
|
+ while(!ycoordinates.isEmpty()){
|
|
|
|
+
|
|
|
|
+ graphCoordinates.add(new Pair<>(key, ycoordinates.pop()));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -72,12 +102,15 @@ public class LevelPathParser {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * returns the y coordinates of a rows graph knots as a stack
|
|
|
|
|
|
+ * recursively, searches for the lowest integers i in the given list
|
|
|
|
+ * if there is no (i+1) integer in the list
|
|
|
|
+ * e.g [10, 9, 5] will return [9, 5]
|
|
|
|
+ *
|
|
* @param row (has to be ordered in ascending order)
|
|
* @param row (has to be ordered in ascending order)
|
|
- * @param result (resulting stack of the y coordinates
|
|
|
|
- * @return
|
|
|
|
|
|
+ * @param result (resulting stack of the y coordinates)
|
|
|
|
+ * @return stack of y coordinates
|
|
*/
|
|
*/
|
|
- private static Stack<Integer> findGraphCoordinatesInRow(List<Integer> row, Stack<Integer> result){
|
|
|
|
|
|
+ private Stack<Integer> findLowestIntegersInRow(List<Integer> row, Stack<Integer> result){
|
|
|
|
|
|
if(row.isEmpty()) return result;
|
|
if(row.isEmpty()) return result;
|
|
|
|
|
|
@@ -96,6 +129,6 @@ public class LevelPathParser {
|
|
result.push(row.get(0));
|
|
result.push(row.get(0));
|
|
row.remove(0);
|
|
row.remove(0);
|
|
|
|
|
|
- return LevelPathParser.findGraphCoordinatesInRow(row, result);
|
|
|
|
|
|
+ return findLowestIntegersInRow(row, result);
|
|
}
|
|
}
|
|
}
|
|
}
|