wip map parser

This commit is contained in:
Debucquoy Anthony 2023-02-28 07:13:50 +01:00
parent e983c5aa13
commit a1e36ccbc7
Signed by: tonitch
GPG Key ID: A78D6421F083D42E
2 changed files with 44 additions and 2 deletions

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;