File Parser for levels #18

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

View File

@ -0,0 +1,44 @@
package school_project;
import java.io.*;
import java.lang.reflect.Array;
import java.util.Arrays;
public class MapParser {
public static Map ParseMapFile(File file) throws IllegalArgumentException, IllegalAccessException, IOException {
System.out.println(file.getAbsolutePath());
FileInputStream fileStream = new FileInputStream(file);
if(!file.isFile()) throw new IllegalArgumentException("The argument should be a file");
if(!file.canRead()) throw new IllegalAccessException("This file can't be read");
byte[] bytes = fileStream.readAllBytes();
int start_position = 0, end_position = 0;
for (int i = 0; i < bytes.length; i++) {
if(bytes[i] == 83 && bytes[i+1] == 77 && bytes[i+2] == 83){ // SMS
start_position = i+3;
break;
}
}
for (int i = start_position; i < bytes.length; i++) {
if(bytes[i] == 83 && bytes[i+1] == 77 && bytes[i+2] == 69){ // SME
end_position = i;
break;
}
}
byte[] map_data = Arrays.copyOfRange(bytes, start_position, end_position); //TODO tonitch cursor
fileStream.close();
return new Map(); //TODO: Send the parsed map
}
// public static void SaveMapFile(File file){
// }
public static void main(String[] args) throws IOException, IllegalAccessException {
ParseMapFile(new File("test.smap"));
}
}

View File

@ -1,2 +0,0 @@
package school_project;