File Parser for levels #18

Merged
tonitch merged 29 commits from MapParser into master 2023-04-21 20:00:16 +02:00
3 changed files with 5 additions and 16 deletions
Showing only changes of commit 194de024ff - Show all commits

View File

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

View File

@ -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 {

View File

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