From 1cd017f8cabf39069b03bed087beb3042e7f018c Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Fri, 3 Mar 2023 18:16:32 +0100 Subject: [PATCH] File Parser WIP: see comments Signed-off-by: Anthony Debucquoy --- app/src/main/java/school_project/MapParser.java | 15 ++++++++++++++- app/src/main/java/school_project/Shape.java | 17 +++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/school_project/MapParser.java b/app/src/main/java/school_project/MapParser.java index 0a366a9..2f0ac7a 100644 --- a/app/src/main/java/school_project/MapParser.java +++ b/app/src/main/java/school_project/MapParser.java @@ -27,9 +27,16 @@ public class MapParser { } } - byte[] map_data = Arrays.copyOfRange(bytes, start_position, end_position); //TODO tonitch cursor + byte[] level_data = Arrays.copyOfRange(bytes, start_position, end_position); + int width_map = level_data[0], height_map = level_data[1]; + byte[] map_data = Arrays.copyOfRange(level_data, 2, 2 + width_map * height_map / 8 + (height_map * width_map % 8 != 0 ? 1 : 0)); + byte piece_count = level_data[3 + width_map * height_map / 8 + (height_map * width_map % 8 != 0 ? 1 : 0)]; + byte[] pieces_datas = Arrays.copyOfRange(level_data, 4 + width_map * height_map / 8 + (height_map * width_map % 8 != 0 ? 1 : 0), level_data.length-1); + for (int piece_index = 0; piece_index < piece_count; piece_index++) { + + } fileStream.close(); return new Map(); //TODO: Send the parsed map } @@ -37,6 +44,12 @@ public class MapParser { // public static void SaveMapFile(File file){ // } + + private static boolean[][] BuildMatrixFromBytes(int map_width, int map_height, byte[] map_data){ + boolean[][] ret = new boolean[map_height][map_width]; + //TODO tonitch: cursor 2 + + } public static void main(String[] args) throws IOException, IllegalAccessException { ParseMapFile(new File("test.smap")); } diff --git a/app/src/main/java/school_project/Shape.java b/app/src/main/java/school_project/Shape.java index 7f52580..64f7bca 100644 --- a/app/src/main/java/school_project/Shape.java +++ b/app/src/main/java/school_project/Shape.java @@ -2,7 +2,7 @@ package school_project; public class Shape { - + protected boolean[][] matrix; protected int height, width; @@ -37,4 +37,17 @@ public class Shape { public boolean[][] getShape() { return matrix; } -} \ No newline at end of file + + @Override + public String toString() { + String ret = ""; + for (boolean[] row : matrix) { + for (boolean el : row) { + if(el) ret = ret.concat("⬛"); + else ret = ret.concat("⬜"); + } + ret = ret.concat("\n"); + } + return ret; + } +}