.
This commit is contained in:
parent
194de024ff
commit
eb2c293d2a
@ -12,15 +12,15 @@ have the special objective of being really small.
|
|||||||
|
|
||||||
The file would use the .level file extension.
|
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.
|
The file can contain anything, the used data is enclosed between a header and a footer.
|
||||||
This could be used to add Music, images and other stuff in the level file for instance
|
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.
|
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
|
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.
|
level data at the top of the file.
|
||||||
|
|
||||||
- The HEADER will be defined by the characters 'S', 'M', 'S'
|
- The HEADER will be defined by the succesion of the characters 'S', 'M' then 'S'
|
||||||
- The FOOTER will be defined by the characters 'S', 'M', 'E'
|
- The FOOTER will be defined by the succesion of the characters 'S', 'M', then 'E'
|
||||||
- The bytes in between are the level data
|
- The bytes in between are the level data
|
||||||
- byte 1: Width of the map
|
- byte 1: Width of the map
|
||||||
- byte 2: Height 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
|
- 4 last bits: height
|
||||||
- next bytes -> Width * Height (+1 if Width * Height % 8 is not 0)
|
- next bytes -> Width * Height (+1 if Width * Height % 8 is not 0)
|
||||||
- Position ( only for saved file )
|
- 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
|
- x and y on 2 bytes for position if the piece is placed
|
||||||
|
|
||||||
## Known Limitation
|
## Known Limitation
|
||||||
|
@ -46,11 +46,8 @@ public class BinaryParser implements FileParser {
|
|||||||
|
|
||||||
ret = new Map(ExtractMapFromLevelData(level_data));
|
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();
|
fileStream.close();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -108,18 +105,22 @@ public class BinaryParser implements FileParser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Pieces out of the level data
|
* 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
|
* @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 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[3 + map_width * map_height / 8 + (map_height * map_width % 8 != 0 ? 1 : 0)];
|
||||||
Piece[] ret = new Piece[piece_count];
|
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++) {
|
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_size = Bitwise.ByteToNible(pieces_data[piece_index]);
|
||||||
byte _piece_width = _piece_size[0], _piece_height = _piece_size[1];
|
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_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);
|
boolean[][] _piece_matrix = BuildMatrixFromBytes(_piece_width, _piece_height, _piece_data);
|
||||||
ret[piece_index] = new Piece(_piece_matrix);
|
ret[piece_index] = new Piece(_piece_matrix);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user