|
@@ -5,16 +5,15 @@ import me.hammerle.supersnuvi.tiles.Tile;
|
|
|
import me.hammerle.supersnuvi.util.CollisionObject;
|
|
|
import me.hammerle.supersnuvi.util.Pair;
|
|
|
|
|
|
-import java.util.HashSet;
|
|
|
-import java.util.Set;
|
|
|
+import java.util.*;
|
|
|
|
|
|
public class LevelPathParser {
|
|
|
|
|
|
- public static Set<Pair<Integer, Integer>> getCoordinatesOfCollisionTiles(Level lvl){
|
|
|
+ public static Map<Integer, List<Integer>> getCoordinatesOfCollisionTiles(Level lvl){
|
|
|
|
|
|
- Set<Pair<Integer, Integer>> res = new HashSet<>();
|
|
|
+ Map<Integer, List<Integer>> coordinates = new HashMap<>();
|
|
|
|
|
|
- if(lvl == null) return res;
|
|
|
+ if(lvl == null) return coordinates;
|
|
|
|
|
|
LevelData lvldata = lvl.getData();
|
|
|
|
|
@@ -30,12 +29,60 @@ public class LevelPathParser {
|
|
|
|
|
|
if(tile.getMovementBox(x, y, lvl) != CollisionObject.NULL_BOX){
|
|
|
|
|
|
- Pair<Integer, Integer> point = new Pair<>(x, y);
|
|
|
- res.add(point);
|
|
|
+ if(coordinates.get(x) == null)
|
|
|
+ coordinates.put(x, new ArrayList<>());
|
|
|
+
|
|
|
+ coordinates.get(x).add(y);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return res;
|
|
|
+ return coordinates;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static List<Pair<Integer, Integer>> getGraphCoordinates(Map<Integer, List<Integer>> collisionTileCoordinates){
|
|
|
+
|
|
|
+ List<Pair<Integer, Integer>> graphCoordinates = new ArrayList<>();
|
|
|
+
|
|
|
+ if(collisionTileCoordinates == null || collisionTileCoordinates.size() <= 0) return graphCoordinates;
|
|
|
+
|
|
|
+ for(int key : collisionTileCoordinates.keySet()){
|
|
|
+ Collections.sort(collisionTileCoordinates.get(key));
|
|
|
+ Collections.reverse(collisionTileCoordinates.get(key));
|
|
|
+
|
|
|
+ Stack<Integer> result = findGraphCoordinatesInRow(collisionTileCoordinates.get(key), new Stack<Integer>());
|
|
|
+ System.out.println(result);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return graphCoordinates;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * returns the y coordinates of a rows graph knots as a stack
|
|
|
+ * @param row (has to be ordered in ascending order)
|
|
|
+ * @param result (resulting stack of the y coordinates
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private static Stack<Integer> findGraphCoordinatesInRow(List<Integer> row, Stack<Integer> result){
|
|
|
+
|
|
|
+ if(row.isEmpty()) return result;
|
|
|
+
|
|
|
+ if(result.empty()){
|
|
|
+
|
|
|
+ result.push(row.get(0));
|
|
|
+ row.remove(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ int curr = result.pop();
|
|
|
+ if(row.get(0) < curr - 1){
|
|
|
+
|
|
|
+ result.push(curr);
|
|
|
+ }
|
|
|
+
|
|
|
+ result.push(row.get(0));
|
|
|
+ row.remove(0);
|
|
|
+
|
|
|
+ return LevelPathParser.findGraphCoordinatesInRow(row, result);
|
|
|
}
|
|
|
}
|