From a1e36ccbc7a686aa13dbc62288571101ffad2565 Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Tue, 28 Feb 2023 07:13:50 +0100 Subject: [PATCH 01/25] wip map parser --- .../main/java/school_project/MapParser.java | 44 +++++++++++++++++++ .../main/java/school_project/Position.java | 2 - 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/school_project/MapParser.java delete mode 100644 app/src/main/java/school_project/Position.java diff --git a/app/src/main/java/school_project/MapParser.java b/app/src/main/java/school_project/MapParser.java new file mode 100644 index 0000000..0a366a9 --- /dev/null +++ b/app/src/main/java/school_project/MapParser.java @@ -0,0 +1,44 @@ +package school_project; + +import java.io.*; +import java.lang.reflect.Array; +import java.util.Arrays; + +public class MapParser { + public static Map ParseMapFile(File file) throws IllegalArgumentException, IllegalAccessException, IOException { + System.out.println(file.getAbsolutePath()); + FileInputStream fileStream = new FileInputStream(file); + if(!file.isFile()) throw new IllegalArgumentException("The argument should be a file"); + if(!file.canRead()) throw new IllegalAccessException("This file can't be read"); + + byte[] bytes = fileStream.readAllBytes(); + int start_position = 0, end_position = 0; + for (int i = 0; i < bytes.length; i++) { + if(bytes[i] == 83 && bytes[i+1] == 77 && bytes[i+2] == 83){ // SMS + start_position = i+3; + break; + } + } + + for (int i = start_position; i < bytes.length; i++) { + if(bytes[i] == 83 && bytes[i+1] == 77 && bytes[i+2] == 69){ // SME + end_position = i; + break; + } + } + + byte[] map_data = Arrays.copyOfRange(bytes, start_position, end_position); //TODO tonitch cursor + + + fileStream.close(); + return new Map(); //TODO: Send the parsed map + } + +// public static void SaveMapFile(File file){ +// } + + public static void main(String[] args) throws IOException, IllegalAccessException { + ParseMapFile(new File("test.smap")); + } + +} diff --git a/app/src/main/java/school_project/Position.java b/app/src/main/java/school_project/Position.java deleted file mode 100644 index a981709..0000000 --- a/app/src/main/java/school_project/Position.java +++ /dev/null @@ -1,2 +0,0 @@ -package school_project; - -- 2.46.0 From 1cd017f8cabf39069b03bed087beb3042e7f018c Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Fri, 3 Mar 2023 18:16:32 +0100 Subject: [PATCH 02/25] 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; + } +} -- 2.46.0 From e1d9a002e98754824a41ea5c19c18098521a1a9a Mon Sep 17 00:00:00 2001 From: "Debucquoy Anthony (tonitch)" Date: Sun, 5 Mar 2023 22:17:02 +0100 Subject: [PATCH 03/25] Finishing Parser, Have to finish Tests Signed-off-by: Anthony Debucquoy --- .../main/java/school_project/MapParser.java | 86 ++++++++++++++----- .../java/school_project/Utils/Bitwise.java | 30 +++++++ 2 files changed, 95 insertions(+), 21 deletions(-) create mode 100644 app/src/main/java/school_project/Utils/Bitwise.java diff --git a/app/src/main/java/school_project/MapParser.java b/app/src/main/java/school_project/MapParser.java index 2f0ac7a..adac1a4 100644 --- a/app/src/main/java/school_project/MapParser.java +++ b/app/src/main/java/school_project/MapParser.java @@ -1,16 +1,28 @@ package school_project; +import school_project.Utils.Bitwise; + import java.io.*; -import java.lang.reflect.Array; import java.util.Arrays; public class MapParser { + + /** + * Parse the file and create a Map with its shape and pieces setup + * @param file file to parse + * @return Map Object parsed with file data + * @see "TODO: Add Specification when done" + */ public static Map ParseMapFile(File file) throws IllegalArgumentException, IllegalAccessException, IOException { - System.out.println(file.getAbsolutePath()); + Map ret; + + // Get the file and check that this file exists and can be read FileInputStream fileStream = new FileInputStream(file); if(!file.isFile()) throw new IllegalArgumentException("The argument should be a file"); if(!file.canRead()) throw new IllegalAccessException("This file can't be read"); + // Read the file an array of byte, then look for the HEADER (SMS) and then the FOOTER (SME) + // Then Put everything that is in between in level_data[] byte[] bytes = fileStream.readAllBytes(); int start_position = 0, end_position = 0; for (int i = 0; i < bytes.length; i++) { @@ -26,32 +38,64 @@ public class MapParser { break; } } - 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); + + // Get the 2 first byte as the map width and height + // Then get the map data. This map data is every bit of the byte that represent either a true if it is a 1 or false if it is a 0 + int map_width = level_data[0], map_height = level_data[1]; + byte[] map_data = Arrays.copyOfRange(level_data, 2, 2 + map_width * map_height / 8 + (map_height * map_width % 8 != 0 ? 1 : 0)); + boolean[][] map_matrix = BuildMatrixFromBytes(map_width, map_height, map_data); + ret = new Map(map_matrix); + + // Get the amount of pieces + // For each of these pieces, get the size of the piece on 1 octet, 4 byte are for width then 4 byte are for height + // the same method as the map is used to get the piece shape. + byte piece_count = level_data[3 + map_width * map_height / 8 + (map_height * map_width % 8 != 0 ? 1 : 0)]; + byte[] pieces_data = Arrays.copyOfRange(level_data, 4 + map_width * map_height / 8 + (map_height * map_width % 8 != 0 ? 1 : 0), level_data.length-1); for (int piece_index = 0; piece_index < piece_count; piece_index++) { - - - + byte[] _piece_size = Bitwise.ByteToNible(pieces_data[piece_index]); + byte _piece_width = _piece_size[0], _piece_height = _piece_size[1]; + byte[] _piece_data = Arrays.copyOfRange(pieces_data, piece_index + 1, 1 + _piece_width * _piece_height / 8 + (_piece_height * _piece_width % 8 != 0 ? 1 : 0)); + boolean[][] _piece_matrix = BuildMatrixFromBytes(_piece_width, _piece_height, _piece_data); + Piece _piece = new Piece(_piece_matrix); + ret.AddShape(_piece); + piece_index = piece_index + _piece_width * _piece_height / 8 + (_piece_height * _piece_width % 8 != 0 ? 1 : 0); } + + // Close the file and return the generated map fileStream.close(); - return new Map(); //TODO: Send the parsed map + return ret; } -// public static void SaveMapFile(File file){ -// } + /** + * Build a boolean Matrix From a byte array + * Each Byte is composed of 8 bit, each bit is 1 or 0 + * if the bit is 0 then it's a false for this cell + * else it's true for this cell + * @param matrix_width width of the matrix + * @param matrix_height height of the matrix + * @param matrix_data byte array of the data to export + * @return boolean Matrix of the data decompiled + */ + private static boolean[][] BuildMatrixFromBytes(int matrix_width, int matrix_height, byte[] matrix_data){ + boolean[][] ret = new boolean[matrix_height][matrix_width]; + // Transforming the bit from matrix_data's byte into boolean array for better manipulation + boolean[] b_array = new boolean[matrix_height * matrix_width]; + int index = 0; + for(byte b: matrix_data){ + for (int i = 0; i < 8; i++) { // because 8 bit in a byte + b_array[index] = Bitwise.IsBitSetAt(b, i); + index++; + } + } - 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 - + // Transforming b_array to a 2D matrix + for (int x = 0; x < matrix_height; x++) { + for (int y = 0; y < matrix_width; y++) { + ret[x][y] = b_array[y + x * 8]; + } + } + return ret; } - public static void main(String[] args) throws IOException, IllegalAccessException { - ParseMapFile(new File("test.smap")); - } - } diff --git a/app/src/main/java/school_project/Utils/Bitwise.java b/app/src/main/java/school_project/Utils/Bitwise.java new file mode 100644 index 0000000..bc774c7 --- /dev/null +++ b/app/src/main/java/school_project/Utils/Bitwise.java @@ -0,0 +1,30 @@ +package school_project.Utils; + +public class Bitwise { + + /** + * Check if the bit at pos is 1 or 0 + * @param b byte to test + * @param pos position in b to check + * @return true if the bit at pos is 1 or false if it is 0 + */ + public static boolean IsBitSetAt(byte b, int pos){ + pos = 7 - pos; + return (b & (1 << pos))!= 0; + } + + /** + * Transform a byte (8 bit) to two Nible (4 bit) with a split in the middle + * Exemple: + * in = 01000101 (=69) + * out = { 00000100, 00000101 } (={4, 5}) + * @param in the byte to split + * @return an arrya of 2 byte ret[0] = left part; ret[1] = right part + */ + public static byte[] ByteToNible(byte in){ + byte[] ret = new byte[2]; + ret[0] = (byte) (in >> 4); + ret[1] = (byte) (in & 15); // apply the mask '00001111' + return ret; + } +} -- 2.46.0 From 0ea78295882275d106dd8bb5efd336261be4c0d6 Mon Sep 17 00:00:00 2001 From: "Debucquoy Anthony (tonitch)" Date: Sun, 5 Mar 2023 22:50:41 +0100 Subject: [PATCH 04/25] Adding Documentation for parser in jdb Signed-off-by: Anthony Debucquoy --- JournalDeBord/src/SUMMARY.md | 6 ++++- JournalDeBord/src/spec/FileParser.md | 38 ++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 JournalDeBord/src/spec/FileParser.md diff --git a/JournalDeBord/src/SUMMARY.md b/JournalDeBord/src/SUMMARY.md index 7c32410..da89d34 100644 --- a/JournalDeBord/src/SUMMARY.md +++ b/JournalDeBord/src/SUMMARY.md @@ -3,4 +3,8 @@ # Rapports - [Première entrevue](./rapports/130223.md) -- [Deuxième entrevue](./rapports/200223.md) \ No newline at end of file +- [Deuxième entrevue](./rapports/200223.md) + +# Specification + +- [File Parser](./spec/FileParser.md) \ No newline at end of file diff --git a/JournalDeBord/src/spec/FileParser.md b/JournalDeBord/src/spec/FileParser.md new file mode 100644 index 0000000..f34d0bc --- /dev/null +++ b/JournalDeBord/src/spec/FileParser.md @@ -0,0 +1,38 @@ +--- +title: File Parser +author: Debucquoy Anthony (tonitch) +date: 5 March 2023 +--- +# File Parser Specification + +For the Project, I wanted to challenge myself, I decided to do my own file parser with my own specification that would +have the special objective of being really small. + +## The File format + +The file would use the .level file extension. + +The file could contain anything, the used data is enclosed in between an header and a parser. +This could be used to add Music, images and other stuff in the level file for instance + +Only one Header and One Footer should be present in the file. +The parser will only read the first one it finds so to avoid problem, it is best practise to put the +level data at the top of the file. + +- The HEADER will be defined by the characters 'S', 'M', 'S' +- The FOOTER will be defined by the characters 'S', 'M', 'E' +- The bytes in between are the level data + - byte 1: Width of the map + - byte 2: Height of the map + - bytes 3 -> Width * Height (+1 if Width * Height % 8 is not 0) + - byte after Map Data: Pieces amount + - for each pieces + - 1 byte: size of the piece + - 4 first bits : width + - 4 last bits: height + - next bytes -> Width * Height (+1 if Width * Height % 8 is not 0) + +## Known Limitation + +1) by putting the piece size on one byte. We limit the maximum piece size to 15 x 15 (1111 | 1111) +I don't think we will ever need a piece larger than 5x5 so this is clearly a feature, not a bug! :-) \ No newline at end of file -- 2.46.0 From b9a6badadf9c0ab9f1f90913bdc2b8eb3de28e66 Mon Sep 17 00:00:00 2001 From: Debucquoy Date: Sun, 19 Mar 2023 22:24:59 +0100 Subject: [PATCH 05/25] WIP: Refactoring file parser --- app/build.gradle | 1 + .../BinaryParser.java} | 85 +++++++++++-------- .../school_project/Parsers/FileParser.java | 23 +++++ .../Parsers/FileParserFactory.java | 43 ++++++++++ .../school_project/Parsers/TxtParser.java | 13 +++ 5 files changed, 128 insertions(+), 37 deletions(-) rename app/src/main/java/school_project/{MapParser.java => Parsers/BinaryParser.java} (74%) create mode 100644 app/src/main/java/school_project/Parsers/FileParser.java create mode 100644 app/src/main/java/school_project/Parsers/FileParserFactory.java create mode 100644 app/src/main/java/school_project/Parsers/TxtParser.java diff --git a/app/build.gradle b/app/build.gradle index 3f8d793..52532f1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,6 +9,7 @@ plugins { // Apply the application plugin to add support for building a CLI application in Java. id 'application' + id 'checkstyle' id 'org.openjfx.javafxplugin' version '0.0.13' } diff --git a/app/src/main/java/school_project/MapParser.java b/app/src/main/java/school_project/Parsers/BinaryParser.java similarity index 74% rename from app/src/main/java/school_project/MapParser.java rename to app/src/main/java/school_project/Parsers/BinaryParser.java index adac1a4..0486f72 100644 --- a/app/src/main/java/school_project/MapParser.java +++ b/app/src/main/java/school_project/Parsers/BinaryParser.java @@ -1,52 +1,24 @@ -package school_project; +package school_project.Parsers; +import school_project.Map; +import school_project.Piece; import school_project.Utils.Bitwise; import java.io.*; import java.util.Arrays; -public class MapParser { +public class BinaryParser implements FileParser { - /** - * Parse the file and create a Map with its shape and pieces setup - * @param file file to parse - * @return Map Object parsed with file data - * @see "TODO: Add Specification when done" - */ - public static Map ParseMapFile(File file) throws IllegalArgumentException, IllegalAccessException, IOException { + public Map getLevel(File file) throws IOException { Map ret; - // Get the file and check that this file exists and can be read FileInputStream fileStream = new FileInputStream(file); - if(!file.isFile()) throw new IllegalArgumentException("The argument should be a file"); - if(!file.canRead()) throw new IllegalAccessException("This file can't be read"); - // Read the file an array of byte, then look for the HEADER (SMS) and then the FOOTER (SME) - // Then Put everything that is in between in level_data[] - byte[] bytes = fileStream.readAllBytes(); - int start_position = 0, end_position = 0; - for (int i = 0; i < bytes.length; i++) { - if(bytes[i] == 83 && bytes[i+1] == 77 && bytes[i+2] == 83){ // SMS - start_position = i+3; - break; - } - } + byte[] level_data = ExtractLevelData(fileStream); - for (int i = start_position; i < bytes.length; i++) { - if(bytes[i] == 83 && bytes[i+1] == 77 && bytes[i+2] == 69){ // SME - end_position = i; - break; - } - } - byte[] level_data = Arrays.copyOfRange(bytes, start_position, end_position); - - // Get the 2 first byte as the map width and height - // Then get the map data. This map data is every bit of the byte that represent either a true if it is a 1 or false if it is a 0 - int map_width = level_data[0], map_height = level_data[1]; - byte[] map_data = Arrays.copyOfRange(level_data, 2, 2 + map_width * map_height / 8 + (map_height * map_width % 8 != 0 ? 1 : 0)); - boolean[][] map_matrix = BuildMatrixFromBytes(map_width, map_height, map_data); - ret = new Map(map_matrix); + ret = new Map(ExtractMapFromLevelData(level_data)); + // TODO: 3/18/23 Cursor: have to make this into a method // Get the amount of pieces // For each of these pieces, get the size of the piece on 1 octet, 4 byte are for width then 4 byte are for height // the same method as the map is used to get the piece shape. @@ -67,6 +39,45 @@ public class MapParser { return ret; } + /** + * Get the Map Matrix out of the level data + * @param level_data full data of the level without header and footer + * @return boolean matrix of the map + */ + private static boolean[][] ExtractMapFromLevelData(byte[] level_data){ + int map_width = level_data[0], map_height = level_data[1]; + byte[] map_data = Arrays.copyOfRange(level_data, 2, 2 + map_width * map_height / 8 + (map_height * map_width % 8 != 0 ? 1 : 0)); + return BuildMatrixFromBytes(map_width, map_height, map_data); + } + + /** + * Extract Level data from file content + * @param fileStream + * @return Level data as an array of byte + * @throws IOException Expected if we can't read the file + */ + private static byte[] ExtractLevelData(FileInputStream fileStream) throws IOException { + + byte[] bytes = fileStream.readAllBytes(); + + int start_position = 0, end_position = 0; + for (int i = 0; i < bytes.length; i++) { + if(bytes[i] == 83 && bytes[i+1] == 77 && bytes[i+2] == 83){ // SMS + start_position = i+3; + break; + } + } + + for (int i = start_position; i < bytes.length; i++) { + if(bytes[i] == 83 && bytes[i+1] == 77 && bytes[i+2] == 69){ // SME + end_position = i; + break; + } + } + + return Arrays.copyOfRange(bytes, start_position, end_position); + } + /** * Build a boolean Matrix From a byte array * Each Byte is composed of 8 bit, each bit is 1 or 0 @@ -98,4 +109,4 @@ public class MapParser { } return ret; } -} +} \ No newline at end of file diff --git a/app/src/main/java/school_project/Parsers/FileParser.java b/app/src/main/java/school_project/Parsers/FileParser.java new file mode 100644 index 0000000..c0459f1 --- /dev/null +++ b/app/src/main/java/school_project/Parsers/FileParser.java @@ -0,0 +1,23 @@ +package school_project.Parsers; + +import school_project.Map; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; + +public interface FileParser { + + /** + * Parse the file and create a Map with its shape and pieces setup + * Ignore the rest of the file! (ie: save data) + * + * @param file file to parse + * @return Map Object parsed with file data + * @see "TODO: Add Specification when done" + */ + Map getLevel(File file) throws IOException; + + // TODO: 3/18/23 tonitch: Add getSavedData, for when piece could be added to map file + +} diff --git a/app/src/main/java/school_project/Parsers/FileParserFactory.java b/app/src/main/java/school_project/Parsers/FileParserFactory.java new file mode 100644 index 0000000..e50c1ee --- /dev/null +++ b/app/src/main/java/school_project/Parsers/FileParserFactory.java @@ -0,0 +1,43 @@ +package school_project.Parsers; + +import java.io.File; +import java.io.NotSerializableException; + +/** + * This is used to find the right parser to parser a save/level file. + * + *

+ * Mor file format can be added in the future by adding a new class that implement parser and making it recognisable by + * the CreateParser class + *

+ * + * @author tonitch + */ +public class FileParserFactory { + public static FileParser createParser(File file) throws NotSerializableException{ + if(isBinaryFile(file)) + return new BinaryParser(); + else if (isTextFile(file)) + return new TxtParser(); + else + throw new NotSerializableException("This file format is not supported"); + } + + /** + * Check if the file is a binary file suited for parsing + * @return true if it is a binary File + */ + private static boolean isBinaryFile(File file){ + // TODO: 3/18/23 + return false; + } + + /** + * Check if the file is a text file + * @return true if it is a text File + */ + private static boolean isTextFile(File file){ + return false; + // TODO: 3/18/23 + } +} diff --git a/app/src/main/java/school_project/Parsers/TxtParser.java b/app/src/main/java/school_project/Parsers/TxtParser.java new file mode 100644 index 0000000..aefd6f6 --- /dev/null +++ b/app/src/main/java/school_project/Parsers/TxtParser.java @@ -0,0 +1,13 @@ +package school_project.Parsers; + +import school_project.Map; + +import java.io.File; + +public class TxtParser implements FileParser{ + @Override + public Map getLevel(File file) { + return null; + // TODO: 3/18/23 + } +} -- 2.46.0 From dfb297525b4bcd5c10dbc2b14a4e3004ac1e9363 Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Sun, 19 Mar 2023 23:28:31 +0100 Subject: [PATCH 06/25] placing static function in their respective files & changing addShape to addPiece Signed-off-by: Anthony Debucquoy --- app/src/main/java/school_project/Map.java | 7 +++- .../school_project/Parsers/BinaryParser.java | 40 +++++++++++++------ .../Parsers/FileParserFactory.java | 21 +--------- .../school_project/Parsers/TxtParser.java | 9 +++++ 4 files changed, 44 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/school_project/Map.java b/app/src/main/java/school_project/Map.java index e9834c0..28008b0 100644 --- a/app/src/main/java/school_project/Map.java +++ b/app/src/main/java/school_project/Map.java @@ -14,7 +14,12 @@ public class Map extends Shape{ } // TODO: 2/27/23 Tests for Map - public void AddShape(Piece piece){ + public void addPiece(Piece piece){ pieces.add(piece); } + + public void addPiece(Piece[] pieces) { + for (Piece p : pieces) + this.addPiece(p); + } } diff --git a/app/src/main/java/school_project/Parsers/BinaryParser.java b/app/src/main/java/school_project/Parsers/BinaryParser.java index 0486f72..9a1a92b 100644 --- a/app/src/main/java/school_project/Parsers/BinaryParser.java +++ b/app/src/main/java/school_project/Parsers/BinaryParser.java @@ -9,6 +9,15 @@ import java.util.Arrays; public class BinaryParser implements FileParser { + /** + * Check if the file is a binary file suited for parsing + * @return true if it is a binary File + */ + static boolean isBinaryFile(File file){ + // TODO: 3/18/23 + return false; + } + public Map getLevel(File file) throws IOException { Map ret; @@ -18,24 +27,29 @@ public class BinaryParser implements FileParser { ret = new Map(ExtractMapFromLevelData(level_data)); - // TODO: 3/18/23 Cursor: have to make this into a method - // Get the amount of pieces - // For each of these pieces, get the size of the piece on 1 octet, 4 byte are for width then 4 byte are for height - // the same method as the map is used to get the piece shape. - byte piece_count = level_data[3 + map_width * map_height / 8 + (map_height * map_width % 8 != 0 ? 1 : 0)]; - byte[] pieces_data = Arrays.copyOfRange(level_data, 4 + map_width * map_height / 8 + (map_height * map_width % 8 != 0 ? 1 : 0), level_data.length-1); + ret.addPiece(ExtractPiecesFromLevelData(level_data)); + + fileStream.close(); + return ret; + } + + /** + * Get Pieces out of the level data + * @param levelData full data of the level without header and footer + * @return array of Piece from level data + */ + private static Piece[] ExtractPiecesFromLevelData(byte[] levelData) { + byte map_width = levelData[0], map_height = levelData[1]; + byte piece_count = levelData[3 + map_width * map_height / 8 + (map_height * map_width % 8 != 0 ? 1 : 0)]; + Piece[] ret = new Piece[piece_count]; + byte[] pieces_data = Arrays.copyOfRange(levelData, 4 + map_width * map_height / 8 + (map_height * map_width % 8 != 0 ? 1 : 0), levelData.length-1); for (int piece_index = 0; piece_index < piece_count; piece_index++) { byte[] _piece_size = Bitwise.ByteToNible(pieces_data[piece_index]); byte _piece_width = _piece_size[0], _piece_height = _piece_size[1]; byte[] _piece_data = Arrays.copyOfRange(pieces_data, piece_index + 1, 1 + _piece_width * _piece_height / 8 + (_piece_height * _piece_width % 8 != 0 ? 1 : 0)); boolean[][] _piece_matrix = BuildMatrixFromBytes(_piece_width, _piece_height, _piece_data); - Piece _piece = new Piece(_piece_matrix); - ret.AddShape(_piece); - piece_index = piece_index + _piece_width * _piece_height / 8 + (_piece_height * _piece_width % 8 != 0 ? 1 : 0); + ret[piece_index] = new Piece(_piece_matrix); } - - // Close the file and return the generated map - fileStream.close(); return ret; } @@ -52,7 +66,7 @@ public class BinaryParser implements FileParser { /** * Extract Level data from file content - * @param fileStream + * @param fileStream file stream to read extract data from * @return Level data as an array of byte * @throws IOException Expected if we can't read the file */ diff --git a/app/src/main/java/school_project/Parsers/FileParserFactory.java b/app/src/main/java/school_project/Parsers/FileParserFactory.java index e50c1ee..752af83 100644 --- a/app/src/main/java/school_project/Parsers/FileParserFactory.java +++ b/app/src/main/java/school_project/Parsers/FileParserFactory.java @@ -15,29 +15,12 @@ import java.io.NotSerializableException; */ public class FileParserFactory { public static FileParser createParser(File file) throws NotSerializableException{ - if(isBinaryFile(file)) + if(BinaryParser.isBinaryFile(file)) return new BinaryParser(); - else if (isTextFile(file)) + else if (TxtParser.isTextFile(file)) return new TxtParser(); else throw new NotSerializableException("This file format is not supported"); } - /** - * Check if the file is a binary file suited for parsing - * @return true if it is a binary File - */ - private static boolean isBinaryFile(File file){ - // TODO: 3/18/23 - return false; - } - - /** - * Check if the file is a text file - * @return true if it is a text File - */ - private static boolean isTextFile(File file){ - return false; - // TODO: 3/18/23 - } } diff --git a/app/src/main/java/school_project/Parsers/TxtParser.java b/app/src/main/java/school_project/Parsers/TxtParser.java index aefd6f6..485e081 100644 --- a/app/src/main/java/school_project/Parsers/TxtParser.java +++ b/app/src/main/java/school_project/Parsers/TxtParser.java @@ -5,6 +5,15 @@ import school_project.Map; import java.io.File; public class TxtParser implements FileParser{ + /** + * Check if the file is a text file + * @return true if it is a text File + */ + static boolean isTextFile(File file){ + return false; + // TODO: 3/18/23 + } + @Override public Map getLevel(File file) { return null; -- 2.46.0 From 43ef14abd851fedade4f4347351c5e16ef95794e Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Mon, 20 Mar 2023 20:08:50 +0100 Subject: [PATCH 07/25] finishing static functions for isBinary of isText Signed-off-by: Anthony Debucquoy --- .../school_project/Parsers/BinaryParser.java | 79 ++++++++++++------- .../Parsers/FileParserFactory.java | 3 +- .../school_project/Parsers/TxtParser.java | 6 +- 3 files changed, 55 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/school_project/Parsers/BinaryParser.java b/app/src/main/java/school_project/Parsers/BinaryParser.java index 9a1a92b..6cab224 100644 --- a/app/src/main/java/school_project/Parsers/BinaryParser.java +++ b/app/src/main/java/school_project/Parsers/BinaryParser.java @@ -5,6 +5,7 @@ import school_project.Piece; import school_project.Utils.Bitwise; import java.io.*; +import java.nio.file.Files; import java.util.Arrays; public class BinaryParser implements FileParser { @@ -13,8 +14,26 @@ public class BinaryParser implements FileParser { * Check if the file is a binary file suited for parsing * @return true if it is a binary File */ - static boolean isBinaryFile(File file){ - // TODO: 3/18/23 + static boolean isBinaryFile(File file) throws IOException { + // TODO: 3/20/23 Need more testing + if (Files.probeContentType(file.toPath()) != null) + return false; + + FileInputStream r_file = new FileInputStream(file); + byte[] content = r_file.readAllBytes(); + + boolean header_found = false; + for (int i = 0; i < content.length; i++) { + if (!header_found) { + if (content[i] == 'S' && content[i + 1] == 'M' && content[i + 2] == 'S') { + header_found = true; + } + } else { + if (content[i] == 'S' && content[i + 1] == 'M' && content[i + 2] == 'E') { + return true; + } + } + } return false; } @@ -33,6 +52,34 @@ public class BinaryParser implements FileParser { return ret; } + /** + * Extract Level data from file content + * @param fileStream file stream to read extract data from + * @return Level data as an array of byte + * @throws IOException Expected if we can't read the file + */ + private static byte[] ExtractLevelData(FileInputStream fileStream) throws IOException { + + byte[] bytes = fileStream.readAllBytes(); + + int start_position = 0, end_position = 0; + for (int i = 0; i < bytes.length; i++) { + if(bytes[i] == 83 && bytes[i+1] == 77 && bytes[i+2] == 83){ // SMS + start_position = i+3; + break; + } + } + + for (int i = start_position; i < bytes.length; i++) { + if(bytes[i] == 83 && bytes[i+1] == 77 && bytes[i+2] == 69){ // SME + end_position = i; + break; + } + } + + return Arrays.copyOfRange(bytes, start_position, end_position); + } + /** * Get Pieces out of the level data * @param levelData full data of the level without header and footer @@ -64,34 +111,6 @@ public class BinaryParser implements FileParser { return BuildMatrixFromBytes(map_width, map_height, map_data); } - /** - * Extract Level data from file content - * @param fileStream file stream to read extract data from - * @return Level data as an array of byte - * @throws IOException Expected if we can't read the file - */ - private static byte[] ExtractLevelData(FileInputStream fileStream) throws IOException { - - byte[] bytes = fileStream.readAllBytes(); - - int start_position = 0, end_position = 0; - for (int i = 0; i < bytes.length; i++) { - if(bytes[i] == 83 && bytes[i+1] == 77 && bytes[i+2] == 83){ // SMS - start_position = i+3; - break; - } - } - - for (int i = start_position; i < bytes.length; i++) { - if(bytes[i] == 83 && bytes[i+1] == 77 && bytes[i+2] == 69){ // SME - end_position = i; - break; - } - } - - return Arrays.copyOfRange(bytes, start_position, end_position); - } - /** * Build a boolean Matrix From a byte array * Each Byte is composed of 8 bit, each bit is 1 or 0 diff --git a/app/src/main/java/school_project/Parsers/FileParserFactory.java b/app/src/main/java/school_project/Parsers/FileParserFactory.java index 752af83..149ea97 100644 --- a/app/src/main/java/school_project/Parsers/FileParserFactory.java +++ b/app/src/main/java/school_project/Parsers/FileParserFactory.java @@ -1,6 +1,7 @@ package school_project.Parsers; import java.io.File; +import java.io.IOException; import java.io.NotSerializableException; /** @@ -14,7 +15,7 @@ import java.io.NotSerializableException; * @author tonitch */ public class FileParserFactory { - public static FileParser createParser(File file) throws NotSerializableException{ + public static FileParser createParser(File file) throws IOException { if(BinaryParser.isBinaryFile(file)) return new BinaryParser(); else if (TxtParser.isTextFile(file)) diff --git a/app/src/main/java/school_project/Parsers/TxtParser.java b/app/src/main/java/school_project/Parsers/TxtParser.java index 485e081..65683bc 100644 --- a/app/src/main/java/school_project/Parsers/TxtParser.java +++ b/app/src/main/java/school_project/Parsers/TxtParser.java @@ -3,14 +3,16 @@ package school_project.Parsers; import school_project.Map; import java.io.File; +import java.io.IOException; +import java.nio.file.Files; public class TxtParser implements FileParser{ /** * Check if the file is a text file * @return true if it is a text File */ - static boolean isTextFile(File file){ - return false; + static boolean isTextFile(File file) throws IOException { + return Files.probeContentType(file.toPath()).equals("text/plain"); // TODO: 3/18/23 } -- 2.46.0 From 29c2fd7a0b6f5dcc272931df9b07e6f1fa20ee8b Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Mon, 20 Mar 2023 23:18:59 +0100 Subject: [PATCH 08/25] begining save data methods Signed-off-by: Anthony Debucquoy --- .../school_project/Parsers/BinaryParser.java | 13 ++++-- .../school_project/Parsers/FileParser.java | 7 ++++ .../Parsers/FileParserFactory.java | 4 +- .../school_project/Parsers/JsonParser.java | 40 +++++++++++++++++++ .../school_project/Parsers/TxtParser.java | 24 ----------- 5 files changed, 58 insertions(+), 30 deletions(-) create mode 100644 app/src/main/java/school_project/Parsers/JsonParser.java delete mode 100644 app/src/main/java/school_project/Parsers/TxtParser.java diff --git a/app/src/main/java/school_project/Parsers/BinaryParser.java b/app/src/main/java/school_project/Parsers/BinaryParser.java index 6cab224..fee1c7d 100644 --- a/app/src/main/java/school_project/Parsers/BinaryParser.java +++ b/app/src/main/java/school_project/Parsers/BinaryParser.java @@ -10,14 +10,19 @@ import java.util.Arrays; public class BinaryParser implements FileParser { + @Override + public void saveLevelData(File file, Map levelData) throws IOException { + // TODO: 3/20/23 + } + /** - * Check if the file is a binary file suited for parsing + * check if the file is a binary file suited for parsing * @return true if it is a binary File */ - static boolean isBinaryFile(File file) throws IOException { - // TODO: 3/20/23 Need more testing + public static boolean isBinaryFile(File file) throws IOException { + // TODO: 3/20/23 Need more testing if (Files.probeContentType(file.toPath()) != null) - return false; + return false ; FileInputStream r_file = new FileInputStream(file); byte[] content = r_file.readAllBytes(); diff --git a/app/src/main/java/school_project/Parsers/FileParser.java b/app/src/main/java/school_project/Parsers/FileParser.java index c0459f1..7df3566 100644 --- a/app/src/main/java/school_project/Parsers/FileParser.java +++ b/app/src/main/java/school_project/Parsers/FileParser.java @@ -18,6 +18,13 @@ public interface FileParser { */ Map getLevel(File file) throws IOException; + /** + * Save Map to a file with all it's data + * @param file the file where to save + * @param levelData the map to save + */ + void saveLevelData(File file, Map levelData) throws IOException; + // TODO: 3/18/23 tonitch: Add getSavedData, for when piece could be added to map file } diff --git a/app/src/main/java/school_project/Parsers/FileParserFactory.java b/app/src/main/java/school_project/Parsers/FileParserFactory.java index 149ea97..a5501b1 100644 --- a/app/src/main/java/school_project/Parsers/FileParserFactory.java +++ b/app/src/main/java/school_project/Parsers/FileParserFactory.java @@ -18,8 +18,8 @@ public class FileParserFactory { public static FileParser createParser(File file) throws IOException { if(BinaryParser.isBinaryFile(file)) return new BinaryParser(); - else if (TxtParser.isTextFile(file)) - return new TxtParser(); + else if (JsonParser.isJsonFile(file)) + return new JsonParser(); else throw new NotSerializableException("This file format is not supported"); } diff --git a/app/src/main/java/school_project/Parsers/JsonParser.java b/app/src/main/java/school_project/Parsers/JsonParser.java new file mode 100644 index 0000000..4331b0c --- /dev/null +++ b/app/src/main/java/school_project/Parsers/JsonParser.java @@ -0,0 +1,40 @@ +package school_project.Parsers; + +import school_project.Map; + +import java.io.*; +import java.nio.file.Files; + +public class JsonParser implements FileParser{ + + @Override + public void saveLevelData(File file, Map levelData) throws IOException { + FileOutputStream fileStream = new FileOutputStream(file); + ObjectOutputStream objectStream = new ObjectOutputStream(fileStream); + objectStream.writeObject(levelData); + + objectStream.close(); + fileStream.close(); + } + + /** + * Check if the file is a text file + * @return true if it is a text File + */ + public static boolean isJsonFile(File file) throws IOException { + System.out.println(Files.probeContentType(file.toPath())); + return Files.probeContentType(file.toPath()).equals("application/json"); + } + + @Override + public Map getLevel(File file) throws IOException { + FileInputStream fileStream = new FileInputStream(file); + ObjectInputStream objectStream = new ObjectInputStream(fileStream); + try { + return (Map) objectStream.readObject(); + } catch (ClassNotFoundException e) { + throw new RuntimeException(e); + } + } + +} diff --git a/app/src/main/java/school_project/Parsers/TxtParser.java b/app/src/main/java/school_project/Parsers/TxtParser.java deleted file mode 100644 index 65683bc..0000000 --- a/app/src/main/java/school_project/Parsers/TxtParser.java +++ /dev/null @@ -1,24 +0,0 @@ -package school_project.Parsers; - -import school_project.Map; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; - -public class TxtParser implements FileParser{ - /** - * Check if the file is a text file - * @return true if it is a text File - */ - static boolean isTextFile(File file) throws IOException { - return Files.probeContentType(file.toPath()).equals("text/plain"); - // TODO: 3/18/23 - } - - @Override - public Map getLevel(File file) { - return null; - // TODO: 3/18/23 - } -} -- 2.46.0 From 7cd61c50e667b425b819716a7509b3f0babe3605 Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Mon, 20 Mar 2023 23:23:43 +0100 Subject: [PATCH 09/25] Should not have done this there, I will do on another branch another time Signed-off-by: Anthony Debucquoy --- app/build.gradle | 1 - 1 file changed, 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 52532f1..3f8d793 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,7 +9,6 @@ plugins { // Apply the application plugin to add support for building a CLI application in Java. id 'application' - id 'checkstyle' id 'org.openjfx.javafxplugin' version '0.0.13' } -- 2.46.0 From 1771fd1d42c6026b6de7c2a99fc3ed0515d31012 Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Tue, 21 Mar 2023 23:58:59 +0100 Subject: [PATCH 10/25] Testing + Wip Signed-off-by: Anthony Debucquoy --- app/src/main/java/school_project/Map.java | 2 ++ .../school_project/Parsers/JsonParser.java | 1 - app/src/main/java/school_project/Shape.java | 4 ++- .../Parsers/JsonParserTest.java | 34 +++++++++++++++++++ 4 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 app/src/test/java/school_project/Parsers/JsonParserTest.java diff --git a/app/src/main/java/school_project/Map.java b/app/src/main/java/school_project/Map.java index e67944a..418a7f2 100644 --- a/app/src/main/java/school_project/Map.java +++ b/app/src/main/java/school_project/Map.java @@ -42,6 +42,8 @@ public class Map extends Shape{ } for (Piece p : pieces) { + if(p.getPosition() == null) + continue; for(int x = 0; x < p.height; x++){ for(int y = 0; y < p.width; y++){ if (p.getShape()[x][y]){ diff --git a/app/src/main/java/school_project/Parsers/JsonParser.java b/app/src/main/java/school_project/Parsers/JsonParser.java index 4331b0c..14d56d8 100644 --- a/app/src/main/java/school_project/Parsers/JsonParser.java +++ b/app/src/main/java/school_project/Parsers/JsonParser.java @@ -22,7 +22,6 @@ public class JsonParser implements FileParser{ * @return true if it is a text File */ public static boolean isJsonFile(File file) throws IOException { - System.out.println(Files.probeContentType(file.toPath())); return Files.probeContentType(file.toPath()).equals("application/json"); } diff --git a/app/src/main/java/school_project/Shape.java b/app/src/main/java/school_project/Shape.java index 7061bc2..401fdcf 100644 --- a/app/src/main/java/school_project/Shape.java +++ b/app/src/main/java/school_project/Shape.java @@ -1,11 +1,13 @@ package school_project; +import java.io.Serializable; + /** * Base class for everything that is a shape kind, like map and pieces * it contain a matrix of boolean where the shape is defined by the true's */ -public class Shape { +public class Shape implements Serializable { protected boolean[][] matrix; protected int height, width; diff --git a/app/src/test/java/school_project/Parsers/JsonParserTest.java b/app/src/test/java/school_project/Parsers/JsonParserTest.java new file mode 100644 index 0000000..08f2185 --- /dev/null +++ b/app/src/test/java/school_project/Parsers/JsonParserTest.java @@ -0,0 +1,34 @@ +package school_project.Parsers; + +import org.junit.jupiter.api.Test; +import school_project.Map; +import school_project.Piece; + +import java.io.File; +import java.io.IOException; + +import static org.junit.jupiter.api.Assertions.*; + +class JsonParserTest { + + @Test + void saveLevelData() throws IOException { + boolean[][] map_matrix = { + {true, true, true}, + {false, true, false}, + {true, true, true}, + }; + Map map = new Map(map_matrix); + boolean[][] piece1 = {{true, true, true}}; + boolean[][] piece2 = {{false, true, false}, {true, true, true}}; + map.addPiece(new Piece(piece1)); + map.addPiece(new Piece(piece2)); + JsonParser parser = new JsonParser(); + parser.saveLevelData(new File("test.json"), map); + + FileParser p2 = FileParserFactory.createParser(new File("test.json")); + Map map2 = p2.getLevel(new File("test.json")); + assertArrayEquals(map2.getShape(), map.getShape()); + assertArrayEquals(map2.getUsedSpace(), map.getUsedSpace()); + } +} \ No newline at end of file -- 2.46.0 From e54fab4c2f8caaee5cb4d8d0f2305c9e77d95515 Mon Sep 17 00:00:00 2001 From: Debucquoy Date: Thu, 23 Mar 2023 12:38:12 +0100 Subject: [PATCH 11/25] WIP: adding save data --- JournalDeBord/src/spec/FileParser.md | 3 ++ app/src/main/java/school_project/Map.java | 4 ++ .../school_project/Parsers/BinaryParser.java | 38 +++++++++++++++- .../school_project/Parsers/FileParser.java | 14 +++++- .../school_project/Parsers/JsonParser.java | 10 +++++ .../Parsers/BinaryParserTest.java | 43 +++++++++++++++++++ 6 files changed, 108 insertions(+), 4 deletions(-) create mode 100644 app/src/test/java/school_project/Parsers/BinaryParserTest.java diff --git a/JournalDeBord/src/spec/FileParser.md b/JournalDeBord/src/spec/FileParser.md index f34d0bc..eed995a 100644 --- a/JournalDeBord/src/spec/FileParser.md +++ b/JournalDeBord/src/spec/FileParser.md @@ -31,6 +31,9 @@ level data at the top of the file. - 4 first bits : width - 4 last bits: height - next bytes -> Width * Height (+1 if Width * Height % 8 is not 0) + - Position ( only for saved file ) + - 'F' if the piece is in float state ( not placed) + - x and y on 2 bytes for position if the piece is placed ## Known Limitation diff --git a/app/src/main/java/school_project/Map.java b/app/src/main/java/school_project/Map.java index 418a7f2..30568e5 100644 --- a/app/src/main/java/school_project/Map.java +++ b/app/src/main/java/school_project/Map.java @@ -54,4 +54,8 @@ public class Map extends Shape{ } return used; } + + public ArrayList getPieces() { + return pieces; + } } diff --git a/app/src/main/java/school_project/Parsers/BinaryParser.java b/app/src/main/java/school_project/Parsers/BinaryParser.java index fee1c7d..d26a708 100644 --- a/app/src/main/java/school_project/Parsers/BinaryParser.java +++ b/app/src/main/java/school_project/Parsers/BinaryParser.java @@ -10,9 +10,14 @@ import java.util.Arrays; public class BinaryParser implements FileParser { + @Override + public Map getSavedData(File file) { + return null; + } + @Override public void saveLevelData(File file, Map levelData) throws IOException { - // TODO: 3/20/23 + } /** @@ -20,7 +25,6 @@ public class BinaryParser implements FileParser { * @return true if it is a binary File */ public static boolean isBinaryFile(File file) throws IOException { - // TODO: 3/20/23 Need more testing if (Files.probeContentType(file.toPath()) != null) return false ; @@ -42,6 +46,7 @@ public class BinaryParser implements FileParser { return false; } + @Override public Map getLevel(File file) throws IOException { Map ret; @@ -57,6 +62,11 @@ public class BinaryParser implements FileParser { return ret; } + @Override + public void saveLevel(File file, Map levelData) throws FileNotFoundException { +// byte[] data = new byte[]; + } + /** * Extract Level data from file content * @param fileStream file stream to read extract data from @@ -147,4 +157,28 @@ public class BinaryParser implements FileParser { } return ret; } + + /** + * give the amount of byte needed to store the given Map + * following the binary file format + * @param level the map to check + * @param data should add save data or only level data + * @return integer of the ammount of byte needed + */ + public static int getByteSizeForMap(Map level, boolean data){ + int ret = 6; // header + footer + ret += 2; //size of the piece + ret += ((level.getWidth() * level.getHeight()) / 8); // size of the map + ret += level.getHeight() * level.getWidth() % 8 == 0 ? 0 : 1; // Add 1 if the size of map is not a mult of 8 + ret += 1; // amount of pieces + for(Piece p: level.getPieces()){ + ret += 1; // size of the piece + ret += p.getHeight() * p.getWidth() / 8; + ret += p.getHeight() * p.getWidth() % 8 == 0 ? 0 : 1; // add 1 if the size of the piece is not mult of 8 + if(data){ + ret += p.getPosition() != null ? 2: 1; // if the piece is not placed, only one byte else 2 + } + } + return ret; + } } \ No newline at end of file diff --git a/app/src/main/java/school_project/Parsers/FileParser.java b/app/src/main/java/school_project/Parsers/FileParser.java index 7df3566..f77ac14 100644 --- a/app/src/main/java/school_project/Parsers/FileParser.java +++ b/app/src/main/java/school_project/Parsers/FileParser.java @@ -10,13 +10,21 @@ public interface FileParser { /** * Parse the file and create a Map with its shape and pieces setup - * Ignore the rest of the file! (ie: save data) * * @param file file to parse + * @param saved_data does the saved data should be added to the map * @return Map Object parsed with file data * @see "TODO: Add Specification when done" */ - Map getLevel(File file) throws IOException; + Map getLevel(File file, boolean saved_data) throws IOException; + + /** + * Save Map to a file without all it's data + * Could be used for generating level file. might not be used in game. + * @param file the file where to save + * @param levelData the map to save + */ + void saveLevel(File file, Map levelData) throws FileNotFoundException; /** * Save Map to a file with all it's data @@ -25,6 +33,8 @@ public interface FileParser { */ void saveLevelData(File file, Map levelData) throws IOException; + + // TODO: 3/18/23 tonitch: Add getSavedData, for when piece could be added to map file } diff --git a/app/src/main/java/school_project/Parsers/JsonParser.java b/app/src/main/java/school_project/Parsers/JsonParser.java index 14d56d8..0e15404 100644 --- a/app/src/main/java/school_project/Parsers/JsonParser.java +++ b/app/src/main/java/school_project/Parsers/JsonParser.java @@ -7,6 +7,16 @@ import java.nio.file.Files; public class JsonParser implements FileParser{ + @Override + public Map getSavedData(File file) { + return null; + } + + @Override + public void saveLevel(File file, Map levelData) throws FileNotFoundException { + + } + @Override public void saveLevelData(File file, Map levelData) throws IOException { FileOutputStream fileStream = new FileOutputStream(file); diff --git a/app/src/test/java/school_project/Parsers/BinaryParserTest.java b/app/src/test/java/school_project/Parsers/BinaryParserTest.java new file mode 100644 index 0000000..a34dff2 --- /dev/null +++ b/app/src/test/java/school_project/Parsers/BinaryParserTest.java @@ -0,0 +1,43 @@ +package school_project.Parsers; + +import org.junit.jupiter.api.Test; +import school_project.Map; +import school_project.Piece; +import school_project.Vec2; + +import static org.junit.jupiter.api.Assertions.*; + +class BinaryParserTest { + + @Test + void getByteSizeForMap() { + boolean[][] map_shape = { + { true, true, true }, + { true, false, true }, + { true, true, true }, + + }; + boolean[][] piece1_shape = { + { true, true }, + { true, false }, + { true, true }, + + }; + boolean[][] piece2_shape = { + { true }, + { true }, + { true }, + + }; + Map map = new Map(map_shape); + Piece piece1 = new Piece(piece1_shape); + Piece piece2 = new Piece(piece2_shape); + + map.addPiece(new Piece[]{piece1, piece2}); + piece2.setPosition(new Vec2(0, 2)); + + + assertEquals(15, BinaryParser.getByteSizeForMap(map, false)); + assertEquals(18, BinaryParser.getByteSizeForMap(map, true)); + } +} \ No newline at end of file -- 2.46.0 From ad301ca7fbb4a1d219931b4e971236a0cacb1958 Mon Sep 17 00:00:00 2001 From: Debucquoy Date: Thu, 23 Mar 2023 15:17:54 +0100 Subject: [PATCH 12/25] Finishing SaveLevel without saved data --- JournalDeBord/src/spec/FileParser.md | 2 +- .../school_project/Parsers/BinaryParser.java | 61 +++++++++++++++---- .../school_project/Parsers/FileParser.java | 14 +---- .../java/school_project/Utils/Bitwise.java | 10 +++ 4 files changed, 60 insertions(+), 27 deletions(-) diff --git a/JournalDeBord/src/spec/FileParser.md b/JournalDeBord/src/spec/FileParser.md index eed995a..e01a64e 100644 --- a/JournalDeBord/src/spec/FileParser.md +++ b/JournalDeBord/src/spec/FileParser.md @@ -38,4 +38,4 @@ level data at the top of the file. ## Known Limitation 1) by putting the piece size on one byte. We limit the maximum piece size to 15 x 15 (1111 | 1111) -I don't think we will ever need a piece larger than 5x5 so this is clearly a feature, not a bug! :-) \ No newline at end of file +I don't think we will ever need a piece larger than 5x5 so this is clearly a feature, not a bug! :-) diff --git a/app/src/main/java/school_project/Parsers/BinaryParser.java b/app/src/main/java/school_project/Parsers/BinaryParser.java index d26a708..e7d644d 100644 --- a/app/src/main/java/school_project/Parsers/BinaryParser.java +++ b/app/src/main/java/school_project/Parsers/BinaryParser.java @@ -10,16 +10,6 @@ import java.util.Arrays; public class BinaryParser implements FileParser { - @Override - public Map getSavedData(File file) { - return null; - } - - @Override - public void saveLevelData(File file, Map levelData) throws IOException { - - } - /** * check if the file is a binary file suited for parsing * @return true if it is a binary File @@ -47,7 +37,7 @@ public class BinaryParser implements FileParser { } @Override - public Map getLevel(File file) throws IOException { + public Map getLevel(File file, boolean saved_data) throws IOException { Map ret; FileInputStream fileStream = new FileInputStream(file); @@ -57,14 +47,35 @@ public class BinaryParser implements FileParser { ret = new Map(ExtractMapFromLevelData(level_data)); ret.addPiece(ExtractPiecesFromLevelData(level_data)); + + if(saved_data) + // TODO: 3/23/23 getSavedDat fileStream.close(); return ret; } @Override - public void saveLevel(File file, Map levelData) throws FileNotFoundException { -// byte[] data = new byte[]; + public void saveLevel(File file, Map level_data, boolean save_data) throws FileNotFoundException { + int byteSize = getByteSizeForMap(level_data, false); + byte[] data = new byte[byteSize]; + int i = 0; + data[i++] = 'S'; data[i++] = 'M'; data[i++] = 'S'; + data[i++] = (byte) level_data.getWidth(); data[i++] = (byte) level_data.getHeight(); + for(byte b : BuildByteFromMatrix(level_data.getShape())){ + data[i++] = b; + } + data[i++] = (byte) level_data.getPieces().size(); + for (Piece p : level_data.getPieces()) { + data[i++] = Bitwise.NibbleToByte((byte) p.getWidth(), (byte) p.getHeight()); + for(byte b : BuildByteFromMatrix(p.getShape())){ + data[i++] = b; + } + } + if (save_data){ + // TODO: 3/23/23 Save Data + } + data[i++] = 'S'; data[i++] = 'M'; data[i++] = 'E'; } /** @@ -126,6 +137,30 @@ public class BinaryParser implements FileParser { return BuildMatrixFromBytes(map_width, map_height, map_data); } + /** + * take a boolean matrix and build an array of byte following the specs of the parser + * @param shape bolean matrix where true are 1 and false are 0 + * @return byte array with each element compiled for file format + */ + private static byte[] BuildByteFromMatrix(boolean[][] shape){ + int width = shape[0].length , height = shape.length; + boolean[] list = new boolean[width * height]; + for (int x = 0; x < shape.length; x++) { + for (int y = 0; y < shape[x].length; y++) { + list[x * shape[x].length + y] = shape[x][y]; + } + } + byte[] ret = new byte[width * height / 8 + width * height % 8 == 0 ? 0 : 1 ]; + for (int i = 0; i < ret.length; i++) { + byte b = 0; + for (int b_count = i * 8; b_count < i * 8 + 8; b_count++) { + b = (byte) ((b << 1) | (list[b_count] ? 1 : 0)); + } + ret[i] = b; + } + return ret; + } + /** * Build a boolean Matrix From a byte array * Each Byte is composed of 8 bit, each bit is 1 or 0 diff --git a/app/src/main/java/school_project/Parsers/FileParser.java b/app/src/main/java/school_project/Parsers/FileParser.java index f77ac14..f1c7015 100644 --- a/app/src/main/java/school_project/Parsers/FileParser.java +++ b/app/src/main/java/school_project/Parsers/FileParser.java @@ -24,17 +24,5 @@ public interface FileParser { * @param file the file where to save * @param levelData the map to save */ - void saveLevel(File file, Map levelData) throws FileNotFoundException; - - /** - * Save Map to a file with all it's data - * @param file the file where to save - * @param levelData the map to save - */ - void saveLevelData(File file, Map levelData) throws IOException; - - - - // TODO: 3/18/23 tonitch: Add getSavedData, for when piece could be added to map file - + void saveLevel(File file, Map levelData, boolean save_data) throws FileNotFoundException; } diff --git a/app/src/main/java/school_project/Utils/Bitwise.java b/app/src/main/java/school_project/Utils/Bitwise.java index bc774c7..b1a8cd4 100644 --- a/app/src/main/java/school_project/Utils/Bitwise.java +++ b/app/src/main/java/school_project/Utils/Bitwise.java @@ -27,4 +27,14 @@ public class Bitwise { ret[1] = (byte) (in & 15); // apply the mask '00001111' return ret; } + + /** + * Transform 2 byte into 1 with a left part ( 4 bits ) and a right part ( 4 bits) + * @param left first 4 bits + * @param right last 4 bits + * @return concatenated byte + */ + public static byte NibbleToByte(byte left, byte right){ + return (byte) ((left << 4) | right); + } } -- 2.46.0 From 194de024ffafb72b547249ec12558220c0cb0ad1 Mon Sep 17 00:00:00 2001 From: Debucquoy Date: Thu, 23 Mar 2023 15:24:59 +0100 Subject: [PATCH 13/25] small correction --- .../java/school_project/Parsers/FileParser.java | 3 +-- .../java/school_project/Parsers/JsonParser.java | 14 ++------------ .../school_project/Parsers/JsonParserTest.java | 4 ++-- 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/school_project/Parsers/FileParser.java b/app/src/main/java/school_project/Parsers/FileParser.java index f1c7015..20182bf 100644 --- a/app/src/main/java/school_project/Parsers/FileParser.java +++ b/app/src/main/java/school_project/Parsers/FileParser.java @@ -3,7 +3,6 @@ package school_project.Parsers; import school_project.Map; import java.io.File; -import java.io.FileNotFoundException; import java.io.IOException; public interface FileParser { @@ -24,5 +23,5 @@ public interface FileParser { * @param file the file where to save * @param levelData the map to save */ - void saveLevel(File file, Map levelData, boolean save_data) throws FileNotFoundException; + void saveLevel(File file, Map levelData, boolean save_data) throws IOException; } diff --git a/app/src/main/java/school_project/Parsers/JsonParser.java b/app/src/main/java/school_project/Parsers/JsonParser.java index 0e15404..12b350f 100644 --- a/app/src/main/java/school_project/Parsers/JsonParser.java +++ b/app/src/main/java/school_project/Parsers/JsonParser.java @@ -8,17 +8,7 @@ import java.nio.file.Files; public class JsonParser implements FileParser{ @Override - public Map getSavedData(File file) { - return null; - } - - @Override - public void saveLevel(File file, Map levelData) throws FileNotFoundException { - - } - - @Override - public void saveLevelData(File file, Map levelData) throws IOException { + public void saveLevel(File file, Map levelData, boolean save_data) throws IOException { FileOutputStream fileStream = new FileOutputStream(file); ObjectOutputStream objectStream = new ObjectOutputStream(fileStream); objectStream.writeObject(levelData); @@ -36,7 +26,7 @@ public class JsonParser implements FileParser{ } @Override - public Map getLevel(File file) throws IOException { + public Map getLevel(File file, boolean saved_data) throws IOException { FileInputStream fileStream = new FileInputStream(file); ObjectInputStream objectStream = new ObjectInputStream(fileStream); try { diff --git a/app/src/test/java/school_project/Parsers/JsonParserTest.java b/app/src/test/java/school_project/Parsers/JsonParserTest.java index 08f2185..8273a0d 100644 --- a/app/src/test/java/school_project/Parsers/JsonParserTest.java +++ b/app/src/test/java/school_project/Parsers/JsonParserTest.java @@ -24,10 +24,10 @@ class JsonParserTest { map.addPiece(new Piece(piece1)); map.addPiece(new Piece(piece2)); JsonParser parser = new JsonParser(); - parser.saveLevelData(new File("test.json"), map); + parser.saveLevel(new File("test.json"), map, false); FileParser p2 = FileParserFactory.createParser(new File("test.json")); - Map map2 = p2.getLevel(new File("test.json")); + Map map2 = p2.getLevel(new File("test.json"), false); assertArrayEquals(map2.getShape(), map.getShape()); assertArrayEquals(map2.getUsedSpace(), map.getUsedSpace()); } -- 2.46.0 From eb2c293d2a37dc436ee5280ef9dff574153d8ba0 Mon Sep 17 00:00:00 2001 From: Debucquoy Date: Sat, 25 Mar 2023 10:33:07 +0100 Subject: [PATCH 14/25] . --- JournalDeBord/src/spec/FileParser.md | 10 +++++----- .../java/school_project/Parsers/BinaryParser.java | 15 ++++++++------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/JournalDeBord/src/spec/FileParser.md b/JournalDeBord/src/spec/FileParser.md index e01a64e..0b79137 100644 --- a/JournalDeBord/src/spec/FileParser.md +++ b/JournalDeBord/src/spec/FileParser.md @@ -12,15 +12,15 @@ have the special objective of being really small. The file would use the .level file extension. -The file could contain anything, the used data is enclosed in between an header and a parser. -This could be used to add Music, images and other stuff in the level file for instance +The file can contain anything, the used data is enclosed between a header and a footer. +This could be used to add: musics, images and other stuff in the level file itself Only one Header and One Footer should be present in the file. The parser will only read the first one it finds so to avoid problem, it is best practise to put the level data at the top of the file. -- The HEADER will be defined by the characters 'S', 'M', 'S' -- The FOOTER will be defined by the characters 'S', 'M', 'E' +- The HEADER will be defined by the succesion of the characters 'S', 'M' then 'S' +- The FOOTER will be defined by the succesion of the characters 'S', 'M', then 'E' - The bytes in between are the level data - byte 1: Width of the map - byte 2: Height of the map @@ -32,7 +32,7 @@ level data at the top of the file. - 4 last bits: height - next bytes -> Width * Height (+1 if Width * Height % 8 is not 0) - Position ( only for saved file ) - - 'F' if the piece is in float state ( not placed) + - 'F' and 'L' on 2 bytes for floating positions when the piece is not placed - x and y on 2 bytes for position if the piece is placed ## Known Limitation diff --git a/app/src/main/java/school_project/Parsers/BinaryParser.java b/app/src/main/java/school_project/Parsers/BinaryParser.java index e7d644d..6688030 100644 --- a/app/src/main/java/school_project/Parsers/BinaryParser.java +++ b/app/src/main/java/school_project/Parsers/BinaryParser.java @@ -46,11 +46,8 @@ public class BinaryParser implements FileParser { ret = new Map(ExtractMapFromLevelData(level_data)); - ret.addPiece(ExtractPiecesFromLevelData(level_data)); + ret.addPiece(ExtractPiecesFromLevelData(level_data, saved_data)); - if(saved_data) - // TODO: 3/23/23 getSavedDat - fileStream.close(); return ret; } @@ -108,18 +105,22 @@ public class BinaryParser implements FileParser { /** * Get Pieces out of the level data - * @param levelData full data of the level without header and footer + * + * @param levelData full data of the level without header and footer + * @param saved_data * @return array of Piece from level data */ - private static Piece[] ExtractPiecesFromLevelData(byte[] levelData) { + private static Piece[] ExtractPiecesFromLevelData(byte[] levelData, boolean saved_data) { byte map_width = levelData[0], map_height = levelData[1]; byte piece_count = levelData[3 + map_width * map_height / 8 + (map_height * map_width % 8 != 0 ? 1 : 0)]; Piece[] ret = new Piece[piece_count]; - byte[] pieces_data = Arrays.copyOfRange(levelData, 4 + map_width * map_height / 8 + (map_height * map_width % 8 != 0 ? 1 : 0), levelData.length-1); + byte[] pieces_data = Arrays.copyOfRange(levelData, 4 + map_width * map_height / 8 + (map_height * map_width % 8 != 0 ? 1 : 0), levelData.length - 1); for (int piece_index = 0; piece_index < piece_count; piece_index++) { + // TODO: 3/24/23 BUG! this should not check every byte linearly like this... data are not next to each other... byte[] _piece_size = Bitwise.ByteToNible(pieces_data[piece_index]); byte _piece_width = _piece_size[0], _piece_height = _piece_size[1]; byte[] _piece_data = Arrays.copyOfRange(pieces_data, piece_index + 1, 1 + _piece_width * _piece_height / 8 + (_piece_height * _piece_width % 8 != 0 ? 1 : 0)); + byte[] _piece_save_data = Arrays.copyOfRange(pieces_data, ) boolean[][] _piece_matrix = BuildMatrixFromBytes(_piece_width, _piece_height, _piece_data); ret[piece_index] = new Piece(_piece_matrix); } -- 2.46.0 From acf1faba49ca996f03dbcf496aaa0073dbd33a7f Mon Sep 17 00:00:00 2001 From: "Debucquoy Anthony (tonitch)" Date: Sat, 25 Mar 2023 13:32:48 +0100 Subject: [PATCH 15/25] Fixing BinaryParser Loader --- JournalDeBord/src/spec/FileParser.md | 15 +++++++++--- .../school_project/Parsers/BinaryParser.java | 24 +++++++++++++------ .../school_project/Parsers/FileParser.java | 1 + .../java/school_project/Utils/Bitwise.java | 15 +++++++----- 4 files changed, 39 insertions(+), 16 deletions(-) diff --git a/JournalDeBord/src/spec/FileParser.md b/JournalDeBord/src/spec/FileParser.md index 0b79137..f7b2942 100644 --- a/JournalDeBord/src/spec/FileParser.md +++ b/JournalDeBord/src/spec/FileParser.md @@ -31,11 +31,20 @@ level data at the top of the file. - 4 first bits : width - 4 last bits: height - next bytes -> Width * Height (+1 if Width * Height % 8 is not 0) - - Position ( only for saved file ) - - 'F' and 'L' on 2 bytes for floating positions when the piece is not placed - - x and y on 2 bytes for position if the piece is placed + +### Saved file + +For saved file, the extension will be .slevel +The only difference is that at the end of the map data (after the pieces and before the +Footer. there will be the position of each pieces from their top-left corner in the map. +following this pattern for each pieces + + - 'F' and 'L' on 2 bytes for floating positions when the piece is not placed + - x and y on 2 bytes for position if the piece is placed ## Known Limitation 1) by putting the piece size on one byte. We limit the maximum piece size to 15 x 15 (1111 | 1111) I don't think we will ever need a piece larger than 5x5 so this is clearly a feature, not a bug! :-) +We might use the same methods for the pieces positions but there could be a posibility to have +larger map if I use 2 bytes for the positions. diff --git a/app/src/main/java/school_project/Parsers/BinaryParser.java b/app/src/main/java/school_project/Parsers/BinaryParser.java index 6688030..92a208e 100644 --- a/app/src/main/java/school_project/Parsers/BinaryParser.java +++ b/app/src/main/java/school_project/Parsers/BinaryParser.java @@ -3,6 +3,7 @@ package school_project.Parsers; import school_project.Map; import school_project.Piece; import school_project.Utils.Bitwise; +import school_project.Vec2; import java.io.*; import java.nio.file.Files; @@ -115,14 +116,23 @@ public class BinaryParser implements FileParser { byte piece_count = levelData[3 + map_width * map_height / 8 + (map_height * map_width % 8 != 0 ? 1 : 0)]; Piece[] ret = new Piece[piece_count]; byte[] pieces_data = Arrays.copyOfRange(levelData, 4 + map_width * map_height / 8 + (map_height * map_width % 8 != 0 ? 1 : 0), levelData.length - 1); + byte[] pieces_positions = saved_data ? Arrays.copyOfRange(levelData, levelData.length - 1 - piece_count,levelData.length - 1): null; + int piece_offset = 0; for (int piece_index = 0; piece_index < piece_count; piece_index++) { - // TODO: 3/24/23 BUG! this should not check every byte linearly like this... data are not next to each other... - byte[] _piece_size = Bitwise.ByteToNible(pieces_data[piece_index]); - byte _piece_width = _piece_size[0], _piece_height = _piece_size[1]; - byte[] _piece_data = Arrays.copyOfRange(pieces_data, piece_index + 1, 1 + _piece_width * _piece_height / 8 + (_piece_height * _piece_width % 8 != 0 ? 1 : 0)); - byte[] _piece_save_data = Arrays.copyOfRange(pieces_data, ) - boolean[][] _piece_matrix = BuildMatrixFromBytes(_piece_width, _piece_height, _piece_data); + Vec2 _piece_size = Bitwise.ByteToNible(pieces_data[piece_index + piece_offset]); + + byte[] _piece_data = Arrays.copyOfRange(pieces_data, piece_index + piece_offset + 1, piece_index + piece_offset + 1 + _piece_size.x * _piece_size.y / 8 + (_piece_size.x * _piece_size.y % 8 != 0 ? 1 : 0)); + + boolean[][] _piece_matrix = BuildMatrixFromBytes(_piece_size.x, _piece_size.y, _piece_data); + ret[piece_index] = new Piece(_piece_matrix); + + if(saved_data){ + Vec2 _piece_pos = new Vec2(pieces_positions[piece_index*2], pieces_positions[piece_index*2 + 1]); + ret[piece_index].setPosition(_piece_pos); + } + + piece_offset += _piece_size.x * _piece_size.y / 8 + (_piece_size.x * _piece_size.y % 8 != 0 ? 1 : 0); } return ret; } @@ -212,7 +222,7 @@ public class BinaryParser implements FileParser { ret += p.getHeight() * p.getWidth() / 8; ret += p.getHeight() * p.getWidth() % 8 == 0 ? 0 : 1; // add 1 if the size of the piece is not mult of 8 if(data){ - ret += p.getPosition() != null ? 2: 1; // if the piece is not placed, only one byte else 2 + ret += 2; // if the piece is not placed, only one byte else 2 } } return ret; diff --git a/app/src/main/java/school_project/Parsers/FileParser.java b/app/src/main/java/school_project/Parsers/FileParser.java index 20182bf..e590194 100644 --- a/app/src/main/java/school_project/Parsers/FileParser.java +++ b/app/src/main/java/school_project/Parsers/FileParser.java @@ -22,6 +22,7 @@ public interface FileParser { * Could be used for generating level file. might not be used in game. * @param file the file where to save * @param levelData the map to save + * @param save_data should save the map data (need to be false only in development I think) */ void saveLevel(File file, Map levelData, boolean save_data) throws IOException; } diff --git a/app/src/main/java/school_project/Utils/Bitwise.java b/app/src/main/java/school_project/Utils/Bitwise.java index b1a8cd4..1e808b2 100644 --- a/app/src/main/java/school_project/Utils/Bitwise.java +++ b/app/src/main/java/school_project/Utils/Bitwise.java @@ -1,5 +1,7 @@ package school_project.Utils; +import school_project.Vec2; + public class Bitwise { /** @@ -16,15 +18,16 @@ public class Bitwise { /** * Transform a byte (8 bit) to two Nible (4 bit) with a split in the middle * Exemple: - * in = 01000101 (=69) - * out = { 00000100, 00000101 } (={4, 5}) + * in = 01000101 (=69) + * out = { 00000100, 00000101 } (={4, 5}) + * * @param in the byte to split * @return an arrya of 2 byte ret[0] = left part; ret[1] = right part */ - public static byte[] ByteToNible(byte in){ - byte[] ret = new byte[2]; - ret[0] = (byte) (in >> 4); - ret[1] = (byte) (in & 15); // apply the mask '00001111' + public static Vec2 ByteToNible(byte in){ + Vec2 ret = new Vec2(); + ret.x = (byte) (in >> 4); + ret.y = (byte) (in & 15); // apply the mask '00001111' return ret; } -- 2.46.0 From 4b7133975867e3787047380941a23dbfc60e8ca0 Mon Sep 17 00:00:00 2001 From: "Debucquoy Anthony (tonitch)" Date: Sat, 25 Mar 2023 15:44:26 +0100 Subject: [PATCH 16/25] Finishing Parser save TODO: - Tests - Clasical Parser - Recognise file by file extension instead of guessing type --- .../school_project/Parsers/BinaryParser.java | 18 +++++++++++++----- .../Parsers/BinaryParserTest.java | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/school_project/Parsers/BinaryParser.java b/app/src/main/java/school_project/Parsers/BinaryParser.java index 92a208e..02fcb83 100644 --- a/app/src/main/java/school_project/Parsers/BinaryParser.java +++ b/app/src/main/java/school_project/Parsers/BinaryParser.java @@ -54,8 +54,8 @@ public class BinaryParser implements FileParser { } @Override - public void saveLevel(File file, Map level_data, boolean save_data) throws FileNotFoundException { - int byteSize = getByteSizeForMap(level_data, false); + public void saveLevel(File file, Map level_data, boolean save_data) throws IOException { + int byteSize = getByteSizeForMap(level_data, save_data); byte[] data = new byte[byteSize]; int i = 0; data[i++] = 'S'; data[i++] = 'M'; data[i++] = 'S'; @@ -71,9 +71,17 @@ public class BinaryParser implements FileParser { } } if (save_data){ - // TODO: 3/23/23 Save Data + for (Piece p : level_data.getPieces()) { + Vec2 _piece_pos = p.getPosition(); + data[i++] = (byte) _piece_pos.x; + data[i++] = (byte) _piece_pos.y; + } } - data[i++] = 'S'; data[i++] = 'M'; data[i++] = 'E'; + data[i++] = 'S'; data[i++] = 'M'; data[++i] = 'E'; + FileOutputStream save_file = new FileOutputStream(file); + save_file.write(data); + save_file.flush(); + save_file.close(); } /** @@ -108,7 +116,7 @@ public class BinaryParser implements FileParser { * Get Pieces out of the level data * * @param levelData full data of the level without header and footer - * @param saved_data + * @param saved_data Should extract saved data and included it in the pieces * @return array of Piece from level data */ private static Piece[] ExtractPiecesFromLevelData(byte[] levelData, boolean saved_data) { diff --git a/app/src/test/java/school_project/Parsers/BinaryParserTest.java b/app/src/test/java/school_project/Parsers/BinaryParserTest.java index a34dff2..7243485 100644 --- a/app/src/test/java/school_project/Parsers/BinaryParserTest.java +++ b/app/src/test/java/school_project/Parsers/BinaryParserTest.java @@ -38,6 +38,6 @@ class BinaryParserTest { assertEquals(15, BinaryParser.getByteSizeForMap(map, false)); - assertEquals(18, BinaryParser.getByteSizeForMap(map, true)); + assertEquals(19, BinaryParser.getByteSizeForMap(map, true)); } } \ No newline at end of file -- 2.46.0 From a70f6589529036672fed9ccbc745ae6ae1b82bf7 Mon Sep 17 00:00:00 2001 From: "Debucquoy Anthony (tonitch)" Date: Sat, 25 Mar 2023 16:59:25 +0100 Subject: [PATCH 17/25] JavaDocs improvement --- .../school_project/Parsers/BinaryParser.java | 26 ------- .../school_project/Parsers/FileParser.java | 5 ++ .../Parsers/FileParserFactory.java | 76 ++++++++++++++++--- .../{JsonParser.java => SerializeParser.java} | 2 +- .../Parsers/JsonParserTest.java | 34 --------- 5 files changed, 72 insertions(+), 71 deletions(-) rename app/src/main/java/school_project/Parsers/{JsonParser.java => SerializeParser.java} (95%) delete mode 100644 app/src/test/java/school_project/Parsers/JsonParserTest.java diff --git a/app/src/main/java/school_project/Parsers/BinaryParser.java b/app/src/main/java/school_project/Parsers/BinaryParser.java index 02fcb83..0e61870 100644 --- a/app/src/main/java/school_project/Parsers/BinaryParser.java +++ b/app/src/main/java/school_project/Parsers/BinaryParser.java @@ -11,32 +11,6 @@ import java.util.Arrays; public class BinaryParser implements FileParser { - /** - * check if the file is a binary file suited for parsing - * @return true if it is a binary File - */ - public static boolean isBinaryFile(File file) throws IOException { - if (Files.probeContentType(file.toPath()) != null) - return false ; - - FileInputStream r_file = new FileInputStream(file); - byte[] content = r_file.readAllBytes(); - - boolean header_found = false; - for (int i = 0; i < content.length; i++) { - if (!header_found) { - if (content[i] == 'S' && content[i + 1] == 'M' && content[i + 2] == 'S') { - header_found = true; - } - } else { - if (content[i] == 'S' && content[i + 1] == 'M' && content[i + 2] == 'E') { - return true; - } - } - } - return false; - } - @Override public Map getLevel(File file, boolean saved_data) throws IOException { Map ret; diff --git a/app/src/main/java/school_project/Parsers/FileParser.java b/app/src/main/java/school_project/Parsers/FileParser.java index e590194..c20d0bc 100644 --- a/app/src/main/java/school_project/Parsers/FileParser.java +++ b/app/src/main/java/school_project/Parsers/FileParser.java @@ -3,6 +3,7 @@ package school_project.Parsers; import school_project.Map; import java.io.File; +import java.io.FileNotFoundException; import java.io.IOException; public interface FileParser { @@ -14,6 +15,8 @@ public interface FileParser { * @param saved_data does the saved data should be added to the map * @return Map Object parsed with file data * @see "TODO: Add Specification when done" + * @throws FileNotFoundException if the file was not found or was not accessible + * @throws IOException if an I/O occurs */ Map getLevel(File file, boolean saved_data) throws IOException; @@ -23,6 +26,8 @@ public interface FileParser { * @param file the file where to save * @param levelData the map to save * @param save_data should save the map data (need to be false only in development I think) + * @throws FileNotFoundException The file could not be created + * @throws IOException if an I/O occurs */ void saveLevel(File file, Map levelData, boolean save_data) throws IOException; } diff --git a/app/src/main/java/school_project/Parsers/FileParserFactory.java b/app/src/main/java/school_project/Parsers/FileParserFactory.java index a5501b1..a7f4f68 100644 --- a/app/src/main/java/school_project/Parsers/FileParserFactory.java +++ b/app/src/main/java/school_project/Parsers/FileParserFactory.java @@ -1,27 +1,83 @@ package school_project.Parsers; +import javafx.util.Pair; +import school_project.Map; + import java.io.File; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.NotSerializableException; /** * This is used to find the right parser to parser a save/level file. + * This should be the only right way to save/load a file! you can just use `Map loadMapFromFile(File)` to load a file + * and `void saveFileFromMap(File, Map)` to save a file * *

- * Mor file format can be added in the future by adding a new class that implement parser and making it recognisable by - * the CreateParser class + * there is currently 2 file format with 2 variation each (save file or level file) + * - BinaryParser + * - ".level" + * - ".slevel" + * - SerializeParser + * - ".serialized" + * - ".sserialized" + *

+ * + *

+ * More file format can be added in the future by adding a new class that implement parser + * and adding it to this file *

* * @author tonitch */ public class FileParserFactory { - public static FileParser createParser(File file) throws IOException { - if(BinaryParser.isBinaryFile(file)) - return new BinaryParser(); - else if (JsonParser.isJsonFile(file)) - return new JsonParser(); - else - throw new NotSerializableException("This file format is not supported"); + /** + * Load a file and return a map + * If this is a save map, return the map with its save data + * @param file file to get data from + * @return Map generated from the file + * @throws FileNotFoundException if the file was not found or was not accessible + * @throws IOException if an I/O occurs + */ + public static Map loadMapFromFile(File file) throws IOException { + Pair parser= getFileParser(file); + return parser.getKey().getLevel(file, parser.getValue()); } -} + /** + * Save a file in a specific format, this format is defined by the file extension + * This file extention could be: ".level", ".slevel", ".serialized", ".sserialized" + * for save file use the .s variations + * @param file file name to be saved to with the right extension + * @param map map file to save + * @throws NotSerializableException the file extension is not recognised + * @throws FileNotFoundException The file could not be created + * @throws IOException if an I/O occurs + */ + public static void saveFileFromMap(File file, Map map) throws IOException { + Pair parser= getFileParser(file); + parser.getKey().saveLevel(file, map, parser.getValue()); + } + + private static Pair getFileParser(File file) throws NotSerializableException { + FileParser fileParser; + boolean save_data; + + if (file.toString().toLowerCase().endsWith(".level")){ + fileParser = new BinaryParser(); + save_data = false; + }else if(file.toString().toLowerCase().endsWith(".slevel")){ + fileParser = new BinaryParser(); + save_data = true; + }else if(file.toString().toLowerCase().endsWith(".serialized")){ + fileParser = new SerializeParser(); + save_data = false; + }else if(file.toString().toLowerCase().endsWith(".sserialized")) { + fileParser = new SerializeParser(); + save_data = true; + }else { + throw new NotSerializableException("This file format is not supported"); + } + return new Pair(fileParser, save_data); + } +} \ No newline at end of file diff --git a/app/src/main/java/school_project/Parsers/JsonParser.java b/app/src/main/java/school_project/Parsers/SerializeParser.java similarity index 95% rename from app/src/main/java/school_project/Parsers/JsonParser.java rename to app/src/main/java/school_project/Parsers/SerializeParser.java index 12b350f..ed627ff 100644 --- a/app/src/main/java/school_project/Parsers/JsonParser.java +++ b/app/src/main/java/school_project/Parsers/SerializeParser.java @@ -5,7 +5,7 @@ import school_project.Map; import java.io.*; import java.nio.file.Files; -public class JsonParser implements FileParser{ +public class SerializeParser implements FileParser{ @Override public void saveLevel(File file, Map levelData, boolean save_data) throws IOException { diff --git a/app/src/test/java/school_project/Parsers/JsonParserTest.java b/app/src/test/java/school_project/Parsers/JsonParserTest.java deleted file mode 100644 index 8273a0d..0000000 --- a/app/src/test/java/school_project/Parsers/JsonParserTest.java +++ /dev/null @@ -1,34 +0,0 @@ -package school_project.Parsers; - -import org.junit.jupiter.api.Test; -import school_project.Map; -import school_project.Piece; - -import java.io.File; -import java.io.IOException; - -import static org.junit.jupiter.api.Assertions.*; - -class JsonParserTest { - - @Test - void saveLevelData() throws IOException { - boolean[][] map_matrix = { - {true, true, true}, - {false, true, false}, - {true, true, true}, - }; - Map map = new Map(map_matrix); - boolean[][] piece1 = {{true, true, true}}; - boolean[][] piece2 = {{false, true, false}, {true, true, true}}; - map.addPiece(new Piece(piece1)); - map.addPiece(new Piece(piece2)); - JsonParser parser = new JsonParser(); - parser.saveLevel(new File("test.json"), map, false); - - FileParser p2 = FileParserFactory.createParser(new File("test.json")); - Map map2 = p2.getLevel(new File("test.json"), false); - assertArrayEquals(map2.getShape(), map.getShape()); - assertArrayEquals(map2.getUsedSpace(), map.getUsedSpace()); - } -} \ No newline at end of file -- 2.46.0 From 746546fbfc54bef277e68f8d2191582ca7cc66e6 Mon Sep 17 00:00:00 2001 From: "Debucquoy Anthony (tonitch)" Date: Sat, 25 Mar 2023 17:18:47 +0100 Subject: [PATCH 18/25] Finishing SerializeParser --- app/src/main/java/school_project/Map.java | 14 ++++++++ .../Parsers/SerializeParser.java | 33 ++++++++----------- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/school_project/Map.java b/app/src/main/java/school_project/Map.java index 30568e5..2beea88 100644 --- a/app/src/main/java/school_project/Map.java +++ b/app/src/main/java/school_project/Map.java @@ -58,4 +58,18 @@ public class Map extends Shape{ public ArrayList getPieces() { return pieces; } + + /** + * return a new Clean Map without any pieces on it for saving purpose + * @return a New Map Object without any pieces or saved data + */ + public Map getCleanedMap() { + try { + Map ret = (Map) this.clone(); + ret.getPieces().clear(); + return ret; + } catch (CloneNotSupportedException e) { + throw new RuntimeException(e); + } + } } diff --git a/app/src/main/java/school_project/Parsers/SerializeParser.java b/app/src/main/java/school_project/Parsers/SerializeParser.java index ed627ff..d49abbd 100644 --- a/app/src/main/java/school_project/Parsers/SerializeParser.java +++ b/app/src/main/java/school_project/Parsers/SerializeParser.java @@ -3,37 +3,30 @@ package school_project.Parsers; import school_project.Map; import java.io.*; -import java.nio.file.Files; public class SerializeParser implements FileParser{ - @Override - public void saveLevel(File file, Map levelData, boolean save_data) throws IOException { - FileOutputStream fileStream = new FileOutputStream(file); - ObjectOutputStream objectStream = new ObjectOutputStream(fileStream); - objectStream.writeObject(levelData); - - objectStream.close(); - fileStream.close(); - } - - /** - * Check if the file is a text file - * @return true if it is a text File - */ - public static boolean isJsonFile(File file) throws IOException { - return Files.probeContentType(file.toPath()).equals("application/json"); - } - @Override public Map getLevel(File file, boolean saved_data) throws IOException { + // saved_data is ignored in this case because the file is serialized data and it already knows if should have saved_data or not at this point FileInputStream fileStream = new FileInputStream(file); ObjectInputStream objectStream = new ObjectInputStream(fileStream); try { return (Map) objectStream.readObject(); } catch (ClassNotFoundException e) { - throw new RuntimeException(e); + throw new IOException("the serialized file format has not found any object in the file"); } } + @Override + public void saveLevel(File file, Map levelData, boolean save_data) throws IOException { + FileOutputStream fileStream = new FileOutputStream(file); + ObjectOutputStream objectStream = new ObjectOutputStream(fileStream); + objectStream.writeObject(save_data ? levelData : levelData.getCleanedMap()); + + objectStream.close(); + fileStream.close(); + } + + } -- 2.46.0 From 0188fd84202831396ac82027680f0b7d42d9002b Mon Sep 17 00:00:00 2001 From: "Debucquoy Anthony (tonitch)" Date: Sat, 25 Mar 2023 19:08:34 +0100 Subject: [PATCH 19/25] Fixing Test: WIP ERROR at BinaryParser.java#188 to fix --- .../school_project/Parsers/BinaryParser.java | 13 ++- app/src/main/java/school_project/Piece.java | 10 ++ app/src/main/java/school_project/Shape.java | 2 +- .../Parsers/FileParserFactoryTest.java | 94 +++++++++++++++++++ 4 files changed, 114 insertions(+), 5 deletions(-) create mode 100644 app/src/test/java/school_project/Parsers/FileParserFactoryTest.java diff --git a/app/src/main/java/school_project/Parsers/BinaryParser.java b/app/src/main/java/school_project/Parsers/BinaryParser.java index 0e61870..8c78677 100644 --- a/app/src/main/java/school_project/Parsers/BinaryParser.java +++ b/app/src/main/java/school_project/Parsers/BinaryParser.java @@ -47,11 +47,16 @@ public class BinaryParser implements FileParser { if (save_data){ for (Piece p : level_data.getPieces()) { Vec2 _piece_pos = p.getPosition(); - data[i++] = (byte) _piece_pos.x; - data[i++] = (byte) _piece_pos.y; + if(_piece_pos == null){ + data[i++] = 'F'; + data[i++] = 'L'; + }else{ + data[i++] = (byte) _piece_pos.x; + data[i++] = (byte) _piece_pos.y; + } } } - data[i++] = 'S'; data[i++] = 'M'; data[++i] = 'E'; + data[i++] = 'S'; data[i++] = 'M'; data[i++] = 'E'; FileOutputStream save_file = new FileOutputStream(file); save_file.write(data); save_file.flush(); @@ -146,7 +151,7 @@ public class BinaryParser implements FileParser { byte[] ret = new byte[width * height / 8 + width * height % 8 == 0 ? 0 : 1 ]; for (int i = 0; i < ret.length; i++) { byte b = 0; - for (int b_count = i * 8; b_count < i * 8 + 8; b_count++) { + for (int b_count = i * 8; b_count < (i * 8 + 8) % (i * 8 - ret.length); b_count++) { b = (byte) ((b << 1) | (list[b_count] ? 1 : 0)); } ret[i] = b; diff --git a/app/src/main/java/school_project/Piece.java b/app/src/main/java/school_project/Piece.java index a358dd2..8d9c0e7 100644 --- a/app/src/main/java/school_project/Piece.java +++ b/app/src/main/java/school_project/Piece.java @@ -56,4 +56,14 @@ public class Piece extends Shape{ matrix = temp_matrix; } } + + @Override + public boolean equals(Object obj) { + if(obj instanceof Piece pieceObj){ + if( pieceObj.getPosition().equals(this.getPosition()) && pieceObj.getShape().equals(getShape())) { + return true; + } + } + return false; + } } \ No newline at end of file diff --git a/app/src/main/java/school_project/Shape.java b/app/src/main/java/school_project/Shape.java index 401fdcf..3a436d6 100644 --- a/app/src/main/java/school_project/Shape.java +++ b/app/src/main/java/school_project/Shape.java @@ -7,7 +7,7 @@ import java.io.Serializable; * Base class for everything that is a shape kind, like map and pieces * it contain a matrix of boolean where the shape is defined by the true's */ -public class Shape implements Serializable { +public class Shape implements Serializable, Cloneable{ protected boolean[][] matrix; protected int height, width; diff --git a/app/src/test/java/school_project/Parsers/FileParserFactoryTest.java b/app/src/test/java/school_project/Parsers/FileParserFactoryTest.java new file mode 100644 index 0000000..7a08e67 --- /dev/null +++ b/app/src/test/java/school_project/Parsers/FileParserFactoryTest.java @@ -0,0 +1,94 @@ +package school_project.Parsers; + +import org.junit.jupiter.api.*; +import school_project.Map; +import school_project.Piece; + +import java.io.File; +import java.io.IOException; + +import static org.junit.jupiter.api.Assertions.*; + +@TestMethodOrder(value = MethodOrderer.OrderAnnotation.class) +class FileParserFactoryTest { + + static Map generateMapTest(){ + boolean[][] map_shape = { + {true, true, true, true}, + {true, false, true, true}, + {true, true, false, true}, + {true, true, false, false}, + }; + boolean[][] piece1_shape = { + {true, true}, + {true, false}, + {true, true}, + {true, true}, + }; + boolean[][] piece2_shape = { + {true, true}, + }; + boolean[][] piece3_shape = { + {true, true}, + {false, true}, + }; + Piece[] pieces = { new Piece(piece1_shape), new Piece(piece2_shape), new Piece(piece3_shape) }; + Map map = new Map(map_shape); + map.addPiece(pieces); + return map; + } + + @Test + void saveFileFromMap_Binary() throws IOException { + Map map = generateMapTest(); + FileParserFactory.saveFileFromMap(new File("TestBinaryLevel.level"), map); + } + + @Test + void saveFileFromMap_save_Binary() throws IOException { + Map map = generateMapTest(); + FileParserFactory.saveFileFromMap(new File("TestBinarySave.slevel"), map); + } + @Test + void saveFileFromMap_Serialized() throws IOException { + Map map = generateMapTest(); + FileParserFactory.saveFileFromMap(new File("TestSerializedLevel.serialized"), map); + } + + @Test + void saveFileFromMap_save_Serialized() throws IOException{ + Map map = generateMapTest(); + FileParserFactory.saveFileFromMap(new File("TestSerializedSave.sserialized"), map); + } + + @Test + void loadMapFromFile_Binary() throws IOException { + Map map = generateMapTest(); + Map testMap = FileParserFactory.loadMapFromFile(new File("src/test/resources/saveFileExamples/TestBinaryLevel.level")); + assertArrayEquals(map.getCleanedMap().getShape(), testMap.getShape()); + assertTrue(map.getCleanedMap().getPieces().equals(testMap.getPieces())); + } + + @Test + void loadMapFromFile_saved_Binary() throws IOException { + Map map = generateMapTest(); + Map testMap = FileParserFactory.loadMapFromFile(new File("src/test/resources/saveFileExamples/TestBinarySave.slevel")); + assertArrayEquals(map.getShape(), testMap.getShape()); + assert(map.getPieces().equals(testMap.getPieces())); + } + @Test + void loadMapFromFile_Serialized() throws IOException { + Map map = generateMapTest(); + Map testMap = FileParserFactory.loadMapFromFile(new File("src/test/resources/saveFileExamples/TestSerializedLevel.serialized")); + assertArrayEquals(map.getCleanedMap().getShape(), testMap.getShape()); + assert(map.getCleanedMap().getPieces().equals(testMap.getPieces())); + } + + @Test + void loadMapFromFile_saved_Serialized() throws IOException { + Map map = generateMapTest(); + Map testMap = FileParserFactory.loadMapFromFile(new File("src/test/resources/saveFileExamples/TestSerializedSave.sserialized")); + assertArrayEquals(map.getShape(), testMap.getShape()); + assertTrue(map.getPieces().equals(testMap.getPieces())); + } +} \ No newline at end of file -- 2.46.0 From 4a14c5d2e6455cfa7c0a999e31437092196cd43d Mon Sep 17 00:00:00 2001 From: Debucquoy Date: Wed, 29 Mar 2023 08:49:25 +0200 Subject: [PATCH 20/25] wip tests: build matrixtobytes --- .../school_project/Parsers/BinaryParser.java | 11 +-- .../Parsers/BinaryParserTest.java | 82 +++++++++++++++++++ 2 files changed, 88 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/school_project/Parsers/BinaryParser.java b/app/src/main/java/school_project/Parsers/BinaryParser.java index 8c78677..9e2f64e 100644 --- a/app/src/main/java/school_project/Parsers/BinaryParser.java +++ b/app/src/main/java/school_project/Parsers/BinaryParser.java @@ -6,7 +6,6 @@ import school_project.Utils.Bitwise; import school_project.Vec2; import java.io.*; -import java.nio.file.Files; import java.util.Arrays; public class BinaryParser implements FileParser { @@ -129,7 +128,7 @@ public class BinaryParser implements FileParser { * @param level_data full data of the level without header and footer * @return boolean matrix of the map */ - private static boolean[][] ExtractMapFromLevelData(byte[] level_data){ + static boolean[][] ExtractMapFromLevelData(byte[] level_data){ int map_width = level_data[0], map_height = level_data[1]; byte[] map_data = Arrays.copyOfRange(level_data, 2, 2 + map_width * map_height / 8 + (map_height * map_width % 8 != 0 ? 1 : 0)); return BuildMatrixFromBytes(map_width, map_height, map_data); @@ -140,7 +139,7 @@ public class BinaryParser implements FileParser { * @param shape bolean matrix where true are 1 and false are 0 * @return byte array with each element compiled for file format */ - private static byte[] BuildByteFromMatrix(boolean[][] shape){ + static byte[] BuildByteFromMatrix(boolean[][] shape){ int width = shape[0].length , height = shape.length; boolean[] list = new boolean[width * height]; for (int x = 0; x < shape.length; x++) { @@ -169,7 +168,7 @@ public class BinaryParser implements FileParser { * @param matrix_data byte array of the data to export * @return boolean Matrix of the data decompiled */ - private static boolean[][] BuildMatrixFromBytes(int matrix_width, int matrix_height, byte[] matrix_data){ + static boolean[][] BuildMatrixFromBytes(int matrix_width, int matrix_height, byte[] matrix_data){ boolean[][] ret = new boolean[matrix_height][matrix_width]; // Transforming the bit from matrix_data's byte into boolean array for better manipulation @@ -179,13 +178,15 @@ public class BinaryParser implements FileParser { for (int i = 0; i < 8; i++) { // because 8 bit in a byte b_array[index] = Bitwise.IsBitSetAt(b, i); index++; + if(index <= matrix_height * matrix_width) + break; } } // Transforming b_array to a 2D matrix for (int x = 0; x < matrix_height; x++) { for (int y = 0; y < matrix_width; y++) { - ret[x][y] = b_array[y + x * 8]; + ret[x][y] = b_array[y + x * matrix_width]; } } return ret; diff --git a/app/src/test/java/school_project/Parsers/BinaryParserTest.java b/app/src/test/java/school_project/Parsers/BinaryParserTest.java index 7243485..a8db7a9 100644 --- a/app/src/test/java/school_project/Parsers/BinaryParserTest.java +++ b/app/src/test/java/school_project/Parsers/BinaryParserTest.java @@ -5,10 +5,23 @@ import school_project.Map; import school_project.Piece; import school_project.Vec2; +import java.util.Arrays; + import static org.junit.jupiter.api.Assertions.*; class BinaryParserTest { + static byte[] file_data = { + 'S', 'M', 'S', + 6, 4, (byte) 0x31, (byte) 0xEC, (byte) 0xF3, (byte) 0xFC, + 4, + (byte) 0x22, (byte) 0x70, + (byte) 0x33, (byte) 0x99, (byte) 0x80, + (byte) 0x32, (byte) 0x7C, + (byte) 0x33, (byte) 0xDB, (byte) 0x80, + 'S', 'M', 'S' + }; + @Test void getByteSizeForMap() { boolean[][] map_shape = { @@ -40,4 +53,73 @@ class BinaryParserTest { assertEquals(15, BinaryParser.getByteSizeForMap(map, false)); assertEquals(19, BinaryParser.getByteSizeForMap(map, true)); } + +// @Test +// void ExtractLevelData(){ +// boolean[][] expected_map_shape = { +// {false, false, true, true, false, false}, +// {false, true, true, true, true, false}, +// {true, true, false, false, true, true}, +// {true, true, false, false, true, true}, +// {true, true, true, true, true, true}, +// }; +// +// boolean[][] map = BinaryParser.ExtractMapFromLevelData(file_data); +// assertArrayEquals(expected_map_shape, map); +// } + + @Test + void BuildMatrixFromByte_map(){ + byte[] map_data = Arrays.copyOfRange(file_data, 5, 9); + boolean[][] map_shape = { + {false, false, true, true, false, false}, + {false, true, true, true, true, false}, + {true, true, false, false, true, true}, + {true, true, false, false, true, true}, + {true, true, true, true, true, true}, + }; + assertEquals(map_shape, BinaryParser.BuildMatrixFromBytes(6, 5, map_data)); + } + + @Test + void BuildMatrixFromByte_piece1(){ + byte[] piece1_data = Arrays.copyOfRange(file_data, 11, 12); + boolean[][] piece1_shape = { + {false, true}, + {true, true}, + }; + assertArrayEquals(piece1_shape, BinaryParser.BuildMatrixFromBytes(2, 2, piece1_data)); + } + + @Test + void BuildMatrixFromByte_piece2(){ + byte[] piece2_data = Arrays.copyOfRange(file_data, 13, 15); + boolean[][] piece2_shape = { + {true, false, false}, + {true, true, false}, + {false, true, true}, + }; + assertArrayEquals(piece2_shape, BinaryParser.BuildMatrixFromBytes(3, 3, piece2_data)); + } + + @Test + void BuildMatrixFromByte_piece3(){ + byte[] piece3_data = Arrays.copyOfRange(file_data, 16, 17); + boolean[][] piece3_shape = { + {false, true, true}, + {true, true, false}, + }; + assertArrayEquals(piece3_shape, BinaryParser.BuildMatrixFromBytes(3, 2, piece3_data)); + } + + @Test + void BuildMatrixFromByte_piece4(){ + byte[] piece4_data = Arrays.copyOfRange(file_data, 18, 20); + boolean[][] piece4_shape = { + {true, true, false}, + {true, true, false}, + {true, true, true}, + }; + assertArrayEquals(piece4_shape, BinaryParser.BuildMatrixFromBytes(3, 3, piece4_data)); + } } \ No newline at end of file -- 2.46.0 From 3ce26796a8ee12799247133b93af4ddbffcbde57 Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Wed, 29 Mar 2023 10:13:34 +0200 Subject: [PATCH 21/25] Fixing BuildMatrixFromByte Finish Signed-off-by: Anthony Debucquoy --- app/src/main/java/school_project/Parsers/BinaryParser.java | 5 +++-- .../test/java/school_project/Parsers/BinaryParserTest.java | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/school_project/Parsers/BinaryParser.java b/app/src/main/java/school_project/Parsers/BinaryParser.java index 9e2f64e..019daf7 100644 --- a/app/src/main/java/school_project/Parsers/BinaryParser.java +++ b/app/src/main/java/school_project/Parsers/BinaryParser.java @@ -140,6 +140,7 @@ public class BinaryParser implements FileParser { * @return byte array with each element compiled for file format */ static byte[] BuildByteFromMatrix(boolean[][] shape){ + // TODO: 3/27/23 Problem with this function to investigate int width = shape[0].length , height = shape.length; boolean[] list = new boolean[width * height]; for (int x = 0; x < shape.length; x++) { @@ -178,7 +179,7 @@ public class BinaryParser implements FileParser { for (int i = 0; i < 8; i++) { // because 8 bit in a byte b_array[index] = Bitwise.IsBitSetAt(b, i); index++; - if(index <= matrix_height * matrix_width) + if(index >= matrix_height * matrix_width) break; } } @@ -215,4 +216,4 @@ public class BinaryParser implements FileParser { } return ret; } -} \ No newline at end of file +} diff --git a/app/src/test/java/school_project/Parsers/BinaryParserTest.java b/app/src/test/java/school_project/Parsers/BinaryParserTest.java index a8db7a9..defc63a 100644 --- a/app/src/test/java/school_project/Parsers/BinaryParserTest.java +++ b/app/src/test/java/school_project/Parsers/BinaryParserTest.java @@ -78,7 +78,7 @@ class BinaryParserTest { {true, true, false, false, true, true}, {true, true, true, true, true, true}, }; - assertEquals(map_shape, BinaryParser.BuildMatrixFromBytes(6, 5, map_data)); + assertArrayEquals(map_shape, BinaryParser.BuildMatrixFromBytes(6, 5, map_data)); } @Test @@ -107,7 +107,7 @@ class BinaryParserTest { byte[] piece3_data = Arrays.copyOfRange(file_data, 16, 17); boolean[][] piece3_shape = { {false, true, true}, - {true, true, false}, + {true, true, true}, }; assertArrayEquals(piece3_shape, BinaryParser.BuildMatrixFromBytes(3, 2, piece3_data)); } -- 2.46.0 From c7511827fbc5f1b940900dae7b04cb33b2c81957 Mon Sep 17 00:00:00 2001 From: Debucquoy Date: Wed, 29 Mar 2023 22:32:38 +0200 Subject: [PATCH 22/25] Extraction Tests --- .../school_project/Parsers/BinaryParser.java | 10 +-- .../Parsers/BinaryParserTest.java | 69 +++++++++++++++---- 2 files changed, 59 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/school_project/Parsers/BinaryParser.java b/app/src/main/java/school_project/Parsers/BinaryParser.java index 019daf7..7e672c5 100644 --- a/app/src/main/java/school_project/Parsers/BinaryParser.java +++ b/app/src/main/java/school_project/Parsers/BinaryParser.java @@ -68,7 +68,7 @@ public class BinaryParser implements FileParser { * @return Level data as an array of byte * @throws IOException Expected if we can't read the file */ - private static byte[] ExtractLevelData(FileInputStream fileStream) throws IOException { + static byte[] ExtractLevelData(InputStream fileStream) throws IOException { byte[] bytes = fileStream.readAllBytes(); @@ -80,7 +80,7 @@ public class BinaryParser implements FileParser { } } - for (int i = start_position; i < bytes.length; i++) { + for (int i = start_position; i < bytes.length - 2; i++) { if(bytes[i] == 83 && bytes[i+1] == 77 && bytes[i+2] == 69){ // SME end_position = i; break; @@ -97,11 +97,11 @@ public class BinaryParser implements FileParser { * @param saved_data Should extract saved data and included it in the pieces * @return array of Piece from level data */ - private static Piece[] ExtractPiecesFromLevelData(byte[] levelData, boolean saved_data) { + static Piece[] ExtractPiecesFromLevelData(byte[] levelData, boolean saved_data) { byte map_width = levelData[0], map_height = levelData[1]; - byte piece_count = levelData[3 + map_width * map_height / 8 + (map_height * map_width % 8 != 0 ? 1 : 0)]; + byte piece_count = levelData[2 + map_width * map_height / 8 + (map_height * map_width % 8 != 0 ? 1 : 0)]; Piece[] ret = new Piece[piece_count]; - byte[] pieces_data = Arrays.copyOfRange(levelData, 4 + map_width * map_height / 8 + (map_height * map_width % 8 != 0 ? 1 : 0), levelData.length - 1); + byte[] pieces_data = Arrays.copyOfRange(levelData, 3 + map_width * map_height / 8 + (map_height * map_width % 8 != 0 ? 1 : 0), levelData.length); byte[] pieces_positions = saved_data ? Arrays.copyOfRange(levelData, levelData.length - 1 - piece_count,levelData.length - 1): null; int piece_offset = 0; for (int piece_index = 0; piece_index < piece_count; piece_index++) { diff --git a/app/src/test/java/school_project/Parsers/BinaryParserTest.java b/app/src/test/java/school_project/Parsers/BinaryParserTest.java index defc63a..4f52c12 100644 --- a/app/src/test/java/school_project/Parsers/BinaryParserTest.java +++ b/app/src/test/java/school_project/Parsers/BinaryParserTest.java @@ -5,6 +5,8 @@ import school_project.Map; import school_project.Piece; import school_project.Vec2; +import java.io.ByteArrayInputStream; +import java.io.IOException; import java.util.Arrays; import static org.junit.jupiter.api.Assertions.*; @@ -13,13 +15,13 @@ class BinaryParserTest { static byte[] file_data = { 'S', 'M', 'S', - 6, 4, (byte) 0x31, (byte) 0xEC, (byte) 0xF3, (byte) 0xFC, + 6, 5, (byte) 0x31, (byte) 0xEC, (byte) 0xF3, (byte) 0xFC, 4, (byte) 0x22, (byte) 0x70, (byte) 0x33, (byte) 0x99, (byte) 0x80, (byte) 0x32, (byte) 0x7C, (byte) 0x33, (byte) 0xDB, (byte) 0x80, - 'S', 'M', 'S' + 'S', 'M', 'E' }; @Test @@ -54,19 +56,6 @@ class BinaryParserTest { assertEquals(19, BinaryParser.getByteSizeForMap(map, true)); } -// @Test -// void ExtractLevelData(){ -// boolean[][] expected_map_shape = { -// {false, false, true, true, false, false}, -// {false, true, true, true, true, false}, -// {true, true, false, false, true, true}, -// {true, true, false, false, true, true}, -// {true, true, true, true, true, true}, -// }; -// -// boolean[][] map = BinaryParser.ExtractMapFromLevelData(file_data); -// assertArrayEquals(expected_map_shape, map); -// } @Test void BuildMatrixFromByte_map(){ @@ -122,4 +111,54 @@ class BinaryParserTest { }; assertArrayEquals(piece4_shape, BinaryParser.BuildMatrixFromBytes(3, 3, piece4_data)); } + + @Test + void ExtractLevelData() throws IOException { + boolean[][] expected_map_shape = { + {false, false, true, true, false, false}, + {false, true, true, true, true, false}, + {true, true, false, false, true, true}, + {true, true, false, false, true, true}, + {true, true, true, true, true, true}, + }; + + byte[] level_data = BinaryParser.ExtractLevelData(new ByteArrayInputStream(file_data)); + boolean[][] map = BinaryParser.ExtractMapFromLevelData(level_data); + + assertArrayEquals(expected_map_shape, map); + } + + @Test + void ExtractPiecesFronLevelDataTest() throws IOException { + boolean[][] piece1_shape = { + {false, true}, + {true, true}, + }; + boolean[][] piece2_shape = { + {true, false, false}, + {true, true, false}, + {false, true, true}, + }; + boolean[][] piece3_shape = { + {false, true, true}, + {true, true, true}, + }; + boolean[][] piece4_shape = { + {true, true, false}, + {true, true, false}, + {true, true, true}, + }; + boolean[][][] pieces_shapes = { + piece1_shape, + piece2_shape, + piece3_shape, + piece4_shape + }; + byte[] level_data = BinaryParser.ExtractLevelData(new ByteArrayInputStream(file_data)); + Piece[] pieces = BinaryParser.ExtractPiecesFromLevelData(level_data, false); + + for (int i = 0; i < pieces_shapes.length; i++) { + assertArrayEquals(pieces_shapes[i], pieces[i].getShape()); + } + } } \ No newline at end of file -- 2.46.0 From 035fe5cb9e8b074e1827564c4d45b0600d39dcb3 Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Thu, 30 Mar 2023 18:11:36 +0200 Subject: [PATCH 23/25] Finishing All Test The merge is comming soon I think --- app/build.gradle | 4 +- .../school_project/Parsers/BinaryParser.java | 19 ++-- app/src/main/java/school_project/Piece.java | 4 - app/src/main/java/school_project/Vec2.java | 12 +- .../Parsers/BinaryParserTest.java | 13 +++ .../Parsers/FileParserFactoryTest.java | 105 ++++++++++-------- 6 files changed, 94 insertions(+), 63 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 3f8d793..b253582 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -19,7 +19,9 @@ repositories { dependencies { // Use JUnit Jupiter for testing. - testImplementation 'org.junit.jupiter:junit-jupiter:5.9.1' + testImplementation 'org.junit.jupiter:junit-jupiter:5.9.2' + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.2' + testImplementation 'org.junit.jupiter:junit-jupiter-params:5.9.2' // This dependency is used by the application. implementation 'com.google.guava:guava:31.1-jre' diff --git a/app/src/main/java/school_project/Parsers/BinaryParser.java b/app/src/main/java/school_project/Parsers/BinaryParser.java index 7e672c5..98e32a1 100644 --- a/app/src/main/java/school_project/Parsers/BinaryParser.java +++ b/app/src/main/java/school_project/Parsers/BinaryParser.java @@ -102,7 +102,7 @@ public class BinaryParser implements FileParser { byte piece_count = levelData[2 + map_width * map_height / 8 + (map_height * map_width % 8 != 0 ? 1 : 0)]; Piece[] ret = new Piece[piece_count]; byte[] pieces_data = Arrays.copyOfRange(levelData, 3 + map_width * map_height / 8 + (map_height * map_width % 8 != 0 ? 1 : 0), levelData.length); - byte[] pieces_positions = saved_data ? Arrays.copyOfRange(levelData, levelData.length - 1 - piece_count,levelData.length - 1): null; + byte[] pieces_positions = saved_data ? Arrays.copyOfRange(levelData, levelData.length - piece_count*2,levelData.length ): null; int piece_offset = 0; for (int piece_index = 0; piece_index < piece_count; piece_index++) { Vec2 _piece_size = Bitwise.ByteToNible(pieces_data[piece_index + piece_offset]); @@ -140,21 +140,22 @@ public class BinaryParser implements FileParser { * @return byte array with each element compiled for file format */ static byte[] BuildByteFromMatrix(boolean[][] shape){ - // TODO: 3/27/23 Problem with this function to investigate int width = shape[0].length , height = shape.length; - boolean[] list = new boolean[width * height]; + boolean[] b_list = new boolean[width * height]; for (int x = 0; x < shape.length; x++) { for (int y = 0; y < shape[x].length; y++) { - list[x * shape[x].length + y] = shape[x][y]; + b_list[x * shape[x].length + y] = shape[x][y]; } } - byte[] ret = new byte[width * height / 8 + width * height % 8 == 0 ? 0 : 1 ]; + byte[] ret = new byte[width * height / 8 + (width * height % 8 == 0 ? 0 : 1)]; for (int i = 0; i < ret.length; i++) { - byte b = 0; - for (int b_count = i * 8; b_count < (i * 8 + 8) % (i * 8 - ret.length); b_count++) { - b = (byte) ((b << 1) | (list[b_count] ? 1 : 0)); + byte current_byte = 0; + boolean[] current_byte_data = Arrays.copyOfRange(b_list, i * 8, i * 8 + 8); + for (boolean curr_data: current_byte_data) { + current_byte = (byte) (current_byte << 1); + current_byte = (byte) (current_byte | (curr_data ? 1 : 0)); } - ret[i] = b; + ret[i] = current_byte; } return ret; } diff --git a/app/src/main/java/school_project/Piece.java b/app/src/main/java/school_project/Piece.java index 8d9c0e7..51df463 100644 --- a/app/src/main/java/school_project/Piece.java +++ b/app/src/main/java/school_project/Piece.java @@ -24,10 +24,6 @@ public class Piece extends Shape{ } public void setPosition(Vec2 position){ - if (linked_map == null) { - return; - } - this.Position = position; } diff --git a/app/src/main/java/school_project/Vec2.java b/app/src/main/java/school_project/Vec2.java index 79d4fd9..05867cc 100644 --- a/app/src/main/java/school_project/Vec2.java +++ b/app/src/main/java/school_project/Vec2.java @@ -1,10 +1,12 @@ package school_project; +import java.io.Serializable; + /** * This is used to represent a position/vector/... any ensemble of 2 elements that have to work together in * a plan. This way we can use some basic operations over them. */ -public class Vec2 { +public class Vec2 implements Serializable { public int x, y; public Vec2() { @@ -16,4 +18,12 @@ public class Vec2 { this.x = x; this.y = y; } + + @Override + public boolean equals(Object obj) { + if (obj instanceof Vec2 vec) { + return this.x == vec.x && this.y == vec.y; + } + return false; + } } diff --git a/app/src/test/java/school_project/Parsers/BinaryParserTest.java b/app/src/test/java/school_project/Parsers/BinaryParserTest.java index 4f52c12..ea28f6c 100644 --- a/app/src/test/java/school_project/Parsers/BinaryParserTest.java +++ b/app/src/test/java/school_project/Parsers/BinaryParserTest.java @@ -57,6 +57,19 @@ class BinaryParserTest { } + @Test + void BuildByteFromMatrix(){ + byte[] map_data = Arrays.copyOfRange(file_data, 5, 9); + boolean[][] map_shape = { + {false, false, true, true, false, false}, + {false, true, true, true, true, false}, + {true, true, false, false, true, true}, + {true, true, false, false, true, true}, + {true, true, true, true, true, true}, + }; + assertArrayEquals(map_data, BinaryParser.BuildByteFromMatrix(map_shape)); + } + @Test void BuildMatrixFromByte_map(){ byte[] map_data = Arrays.copyOfRange(file_data, 5, 9); diff --git a/app/src/test/java/school_project/Parsers/FileParserFactoryTest.java b/app/src/test/java/school_project/Parsers/FileParserFactoryTest.java index 7a08e67..e703db6 100644 --- a/app/src/test/java/school_project/Parsers/FileParserFactoryTest.java +++ b/app/src/test/java/school_project/Parsers/FileParserFactoryTest.java @@ -1,94 +1,103 @@ package school_project.Parsers; import org.junit.jupiter.api.*; +import org.junit.jupiter.api.io.TempDir; import school_project.Map; import school_project.Piece; +import school_project.Vec2; import java.io.File; import java.io.IOException; +import java.nio.file.Path; import static org.junit.jupiter.api.Assertions.*; -@TestMethodOrder(value = MethodOrderer.OrderAnnotation.class) class FileParserFactoryTest { static Map generateMapTest(){ boolean[][] map_shape = { - {true, true, true, true}, - {true, false, true, true}, - {true, true, false, true}, - {true, true, false, false}, + {false, false, true, true, false, false}, + {false, true, true, true, true, false}, + {true, true, false, false, true, true}, + {true, true, false, false, true, true}, + {true, true, true, true, true, true}, }; boolean[][] piece1_shape = { - {true, true}, - {true, false}, - {true, true}, + {false, true}, {true, true}, }; boolean[][] piece2_shape = { - {true, true}, + {true, false, false}, + {true, true, false}, + {false, true, true}, }; boolean[][] piece3_shape = { - {true, true}, - {false, true}, + {false, true, true}, + {true, true, true}, }; - Piece[] pieces = { new Piece(piece1_shape), new Piece(piece2_shape), new Piece(piece3_shape) }; + boolean[][] piece4_shape = { + {true, true, false}, + {true, true, false}, + {true, true, true}, + }; + Piece[] pieces = { new Piece(piece1_shape), new Piece(piece2_shape), new Piece(piece3_shape), new Piece(piece4_shape) }; Map map = new Map(map_shape); map.addPiece(pieces); + + pieces[0].setPosition(new Vec2(1, 0)); + pieces[1].setPosition(new Vec2(3, 0)); + pieces[2].setPosition(new Vec2(3, 3)); + pieces[3].setPosition(new Vec2(0, 2)); return map; } @Test - void saveFileFromMap_Binary() throws IOException { + void saveLoadFileFromMap_Binary(@TempDir Path tmpFolder) throws IOException { Map map = generateMapTest(); - FileParserFactory.saveFileFromMap(new File("TestBinaryLevel.level"), map); - } + FileParserFactory.saveFileFromMap(tmpFolder.resolve("TestBinaryLevel.level").toFile(), map); - @Test - void saveFileFromMap_save_Binary() throws IOException { - Map map = generateMapTest(); - FileParserFactory.saveFileFromMap(new File("TestBinarySave.slevel"), map); - } - @Test - void saveFileFromMap_Serialized() throws IOException { - Map map = generateMapTest(); - FileParserFactory.saveFileFromMap(new File("TestSerializedLevel.serialized"), map); - } - - @Test - void saveFileFromMap_save_Serialized() throws IOException{ - Map map = generateMapTest(); - FileParserFactory.saveFileFromMap(new File("TestSerializedSave.sserialized"), map); - } - - @Test - void loadMapFromFile_Binary() throws IOException { - Map map = generateMapTest(); - Map testMap = FileParserFactory.loadMapFromFile(new File("src/test/resources/saveFileExamples/TestBinaryLevel.level")); + Map testMap = FileParserFactory.loadMapFromFile(tmpFolder.resolve("TestBinaryLevel.level").toFile()); assertArrayEquals(map.getCleanedMap().getShape(), testMap.getShape()); - assertTrue(map.getCleanedMap().getPieces().equals(testMap.getPieces())); + for (int i = 0; i < map.getPieces().size(); i++) { + assertArrayEquals(map.getPieces().get(i).getShape(), testMap.getPieces().get(i).getShape()); + } } @Test - void loadMapFromFile_saved_Binary() throws IOException { + void saveLoadFileFromMap_save_Binary(@TempDir Path tmpFolder) throws IOException { Map map = generateMapTest(); - Map testMap = FileParserFactory.loadMapFromFile(new File("src/test/resources/saveFileExamples/TestBinarySave.slevel")); + FileParserFactory.saveFileFromMap(tmpFolder.resolve("TestBinarySave.slevel").toFile(), map); + + Map testMap = FileParserFactory.loadMapFromFile(tmpFolder.resolve("TestBinarySave.slevel").toFile()); assertArrayEquals(map.getShape(), testMap.getShape()); - assert(map.getPieces().equals(testMap.getPieces())); + for (int i = 0; i < map.getPieces().size(); i++) { + assertArrayEquals(map.getPieces().get(i).getShape(), testMap.getPieces().get(i).getShape()); + assertEquals(map.getPieces().get(i).getPosition(), testMap.getPieces().get(i).getPosition()); + } } @Test - void loadMapFromFile_Serialized() throws IOException { + void saveLoadFileFromMap_Serialized(@TempDir Path tmpFolder) throws IOException { Map map = generateMapTest(); - Map testMap = FileParserFactory.loadMapFromFile(new File("src/test/resources/saveFileExamples/TestSerializedLevel.serialized")); - assertArrayEquals(map.getCleanedMap().getShape(), testMap.getShape()); - assert(map.getCleanedMap().getPieces().equals(testMap.getPieces())); + FileParserFactory.saveFileFromMap( tmpFolder.resolve("TestSerializedLevel.serialized").toFile(), map); + + Map testMap = FileParserFactory.loadMapFromFile( tmpFolder.resolve("TestSerializedLevel.serialized").toFile()); + assertArrayEquals(map.getShape(), testMap.getShape()); + for (int i = 0; i < map.getPieces().size(); i++) { + assertArrayEquals(map.getPieces().get(i).getShape(), testMap.getPieces().get(i).getShape()); + } + } @Test - void loadMapFromFile_saved_Serialized() throws IOException { + void saveLoadFileFromMap_save_Serialized(@TempDir Path tmpFolder) throws IOException{ Map map = generateMapTest(); - Map testMap = FileParserFactory.loadMapFromFile(new File("src/test/resources/saveFileExamples/TestSerializedSave.sserialized")); + FileParserFactory.saveFileFromMap(tmpFolder.resolve("TestSerializedSave.sserialized").toFile(), map); + + Map testMap = FileParserFactory.loadMapFromFile(tmpFolder.resolve("TestSerializedSave.sserialized").toFile()); assertArrayEquals(map.getShape(), testMap.getShape()); - assertTrue(map.getPieces().equals(testMap.getPieces())); + for (int i = 0; i < map.getPieces().size(); i++) { + assertArrayEquals(map.getPieces().get(i).getShape(), testMap.getPieces().get(i).getShape()); + assertEquals(map.getPieces().get(i).getPosition(), testMap.getPieces().get(i).getPosition()); + } } -} \ No newline at end of file +} -- 2.46.0 From e2faf3e0f764efb0885ffa8a29c925d4fa9593fe Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Thu, 30 Mar 2023 18:23:40 +0200 Subject: [PATCH 24/25] Modyfing jdk version for CI Version jdk11 doesn't support instanceof assignation --- .drone.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.drone.yml b/.drone.yml index de0cf20..837d90d 100644 --- a/.drone.yml +++ b/.drone.yml @@ -5,7 +5,7 @@ name: Check_Requirement steps: - name: base_check - image: gradle:jdk11-alpine + image: gradle:jdk19-alpine commands: - ./gradlew clean - ./gradlew build @@ -44,6 +44,6 @@ depends_on: - Check_Requirement --- kind: signature -hmac: 9ca9095fdb69d7b89fda6b4db867877e76666c109607cc7b1e513814ad42bb7e +hmac: 8d927965f6bd0cebe619af7d5e2554f69928ad78d6912d10381fa44d06cad10f ... -- 2.46.0 From da70e6dcffba887630c85cb737d0dc4d65621b0a Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Thu, 30 Mar 2023 18:33:17 +0200 Subject: [PATCH 25/25] fixup! Modyfing jdk version for CI --- .drone.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.drone.yml b/.drone.yml index 837d90d..993edeb 100644 --- a/.drone.yml +++ b/.drone.yml @@ -12,7 +12,7 @@ steps: - ./gradlew test - name: syntax_check - image: gradle:jdk11-alpine + image: gradle:jdk19-alpine commands: - ./gradlew check @@ -44,6 +44,6 @@ depends_on: - Check_Requirement --- kind: signature -hmac: 8d927965f6bd0cebe619af7d5e2554f69928ad78d6912d10381fa44d06cad10f +hmac: f7588a8f835401820f6f596cad344ab01794dc0abcf9f81c989c625844ab4cc3 ... -- 2.46.0