File Parser for levels #18
@ -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;
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user