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); }