Finishing Parser save
TODO: - Tests - Clasical Parser - Recognise file by file extension instead of guessing type
This commit is contained in:
parent
acf1faba49
commit
4b71339758
@ -54,8 +54,8 @@ public class BinaryParser implements FileParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveLevel(File file, Map level_data, boolean save_data) throws FileNotFoundException {
|
public void saveLevel(File file, Map level_data, boolean save_data) throws IOException {
|
||||||
int byteSize = getByteSizeForMap(level_data, false);
|
int byteSize = getByteSizeForMap(level_data, save_data);
|
||||||
byte[] data = new byte[byteSize];
|
byte[] data = new byte[byteSize];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
data[i++] = 'S'; data[i++] = 'M'; data[i++] = 'S';
|
data[i++] = 'S'; data[i++] = 'M'; data[i++] = 'S';
|
||||||
@ -71,9 +71,17 @@ public class BinaryParser implements FileParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (save_data){
|
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
|
* 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
|
* @param saved_data Should extract saved data and included it in the pieces
|
||||||
* @return array of Piece from level data
|
* @return array of Piece from level data
|
||||||
*/
|
*/
|
||||||
private static Piece[] ExtractPiecesFromLevelData(byte[] levelData, boolean saved_data) {
|
private static Piece[] ExtractPiecesFromLevelData(byte[] levelData, boolean saved_data) {
|
||||||
|
@ -38,6 +38,6 @@ class BinaryParserTest {
|
|||||||
|
|
||||||
|
|
||||||
assertEquals(15, BinaryParser.getByteSizeForMap(map, false));
|
assertEquals(15, BinaryParser.getByteSizeForMap(map, false));
|
||||||
assertEquals(18, BinaryParser.getByteSizeForMap(map, true));
|
assertEquals(19, BinaryParser.getByteSizeForMap(map, true));
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user