79 lines
2.0 KiB
Plaintext
79 lines
2.0 KiB
Plaintext
class Files {
|
|
|
|
boolean checkSaveFile(String filepath) {
|
|
return new File(dataPath(filepath)).exists();
|
|
}
|
|
|
|
int[] loadJson(String jsonfile) {
|
|
if (!checkSaveFile(jsonfile)) {
|
|
JSONArray values = loadJSONArray(jsonfile);
|
|
|
|
int[] arrayfromjson = new int[values.size()];
|
|
return arrayfromjson;
|
|
} else {
|
|
int[] arrayfromjson = new int[100];
|
|
return arrayfromjson;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
//// This Handles loading and saving the level
|
|
JSONArray json;
|
|
|
|
// This saves the Current save to file
|
|
int savetofile(String filename) {
|
|
json = new JSONArray();
|
|
|
|
for (int i = 0; i < level.length; i++) {
|
|
|
|
JSONArray mapsave = new JSONArray();
|
|
mapsave.setInt(0, level[i][0]);
|
|
mapsave.setInt(1, level[i][1]);
|
|
mapsave.setInt(2, level[i][2]);
|
|
mapsave.setInt(3, level[i][3]);
|
|
mapsave.setInt(4, level[i][4]);
|
|
|
|
json.setJSONArray(i, mapsave);
|
|
}
|
|
saveJSONArray(json,"./saves/" + filename + ".json");
|
|
return 1;
|
|
}
|
|
|
|
boolean checkSaveFile(String filepath) {
|
|
return new File(dataPath(filepath)).exists();
|
|
}
|
|
|
|
// Check if there already is a safefile and load it if it is possible. If not load empty array
|
|
int[][] loadJson(String jsonfile) {
|
|
if (!checkSaveFile("./saves/save.json")) {
|
|
JSONArray values = loadJSONArray(jsonfile);
|
|
// println(values.size());
|
|
|
|
int[][] arrayfromjson = new int[values.size()][values.size()];
|
|
|
|
for (int i = 0; i < values.size(); i++) {
|
|
|
|
JSONArray jsontoarray = values.getJSONArray(i);
|
|
|
|
int x = jsontoarray.getInt(0);
|
|
int y = jsontoarray.getInt(1);
|
|
int rectwidth = jsontoarray.getInt(2);
|
|
int rectheight = jsontoarray.getInt(3);
|
|
int isspike = jsontoarray.getInt(4);
|
|
|
|
arrayfromjson[i][0] = x;
|
|
arrayfromjson[i][1] = y;
|
|
arrayfromjson[i][2] = rectwidth;
|
|
arrayfromjson[i][3] = rectheight;
|
|
arrayfromjson[i][4] = isspike;
|
|
}
|
|
return arrayfromjson;
|
|
} else {
|
|
int[][] arrayfromjson = new int[100][5];
|
|
return arrayfromjson;
|
|
}
|
|
}
|
|
*/
|