Work on saves
This commit is contained in:
parent
57c94eccf8
commit
dd51345a5a
1
saves/terrain.json
Normal file
1
saves/terrain.json
Normal file
File diff suppressed because one or more lines are too long
@ -285,7 +285,7 @@ public class LoadingThread extends Thread {
|
||||
Globals.serverTerrainManager.load();
|
||||
} else {
|
||||
Globals.serverTerrainManager.generate();
|
||||
// Globals.serverTerrainManager.save();
|
||||
Globals.serverTerrainManager.save();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -85,7 +85,7 @@ public class ServerTerrainManager {
|
||||
Gson gson = new Gson();
|
||||
String terrainOutRaw = gson.toJson(model);
|
||||
try {
|
||||
Files.write(new File("./Config/terrain.json").toPath(), terrainOutRaw.getBytes());
|
||||
Files.write(new File("./terrain.json").toPath(), terrainOutRaw.getBytes());
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
@ -93,7 +93,7 @@ public class ServerTerrainManager {
|
||||
|
||||
public void load(){
|
||||
Gson gson = new Gson();
|
||||
model = FileLoadingUtils.loadObjectFromAssetPath("./Config/terrain.json", TerrainModel.class);
|
||||
model = FileLoadingUtils.loadObjectFromSavePath("./terrain.json", TerrainModel.class);
|
||||
}
|
||||
|
||||
public float[][] getTerrainAtChunk(int x, int y){
|
||||
|
||||
@ -183,7 +183,7 @@ public class Globals {
|
||||
public static EntityManager entityManager;
|
||||
|
||||
//terrain manager
|
||||
public static boolean LOAD_TERRAIN = false;
|
||||
public static boolean LOAD_TERRAIN = true;
|
||||
public static ServerTerrainManager serverTerrainManager;
|
||||
public static Vector3f spawnPoint = new Vector3f(1000,0,1000);
|
||||
|
||||
|
||||
@ -106,7 +106,7 @@ public class FileLoadingUtils {
|
||||
// return rVal;
|
||||
// }
|
||||
|
||||
public static String sanitizeAssetFilePath(String filePath){
|
||||
public static String sanitizeFilePath(String filePath){
|
||||
String rVal = new String(filePath);
|
||||
rVal = rVal.trim();
|
||||
if(!rVal.startsWith("/")){
|
||||
@ -135,34 +135,50 @@ public class FileLoadingUtils {
|
||||
}
|
||||
|
||||
public static File getAssetFile(String pathName){
|
||||
String sanitizedFilePath = sanitizeAssetFilePath(pathName);
|
||||
String sanitizedFilePath = sanitizeFilePath(pathName);
|
||||
File targetFile = new File("./assets" + sanitizedFilePath);
|
||||
return targetFile;
|
||||
}
|
||||
|
||||
public static File getSaveFile(String pathName){
|
||||
String sanitizedFilePath = sanitizeFilePath(pathName);
|
||||
File targetFile = new File("./saves" + sanitizedFilePath);
|
||||
return targetFile;
|
||||
}
|
||||
|
||||
public static InputStream getAssetFileAsStream(String pathName) throws IOException{
|
||||
String sanitizedFilePath = sanitizeAssetFilePath(pathName);
|
||||
String sanitizedFilePath = sanitizeFilePath(pathName);
|
||||
File targetFile = new File("./assets" + sanitizedFilePath);
|
||||
return Files.newInputStream(targetFile.toPath());
|
||||
}
|
||||
|
||||
public static String getAssetFileAsString(String pathName) throws IOException{
|
||||
String sanitizedFilePath = sanitizeAssetFilePath(pathName);
|
||||
String sanitizedFilePath = sanitizeFilePath(pathName);
|
||||
File targetFile = new File("./assets" + sanitizedFilePath);
|
||||
return Files.readString(targetFile.toPath());
|
||||
}
|
||||
|
||||
public static <T>T loadObjectFromAssetPath(String pathName, Class<T> className){
|
||||
T rVal = null;
|
||||
String sanitizedFilePath = sanitizeAssetFilePath(pathName);
|
||||
String rawJSON = "";
|
||||
String sanitizedFilePath = sanitizeFilePath(pathName);
|
||||
Gson gson = new Gson();
|
||||
try {
|
||||
rawJSON = readStreamToString(Files.newInputStream(getAssetFile(sanitizedFilePath).toPath()));
|
||||
rVal = gson.fromJson(Files.newBufferedReader(getAssetFile(sanitizedFilePath).toPath()), className);
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public static <T>T loadObjectFromSavePath(String pathName, Class<T> className){
|
||||
T rVal = null;
|
||||
String sanitizedFilePath = sanitizeFilePath(pathName);
|
||||
Gson gson = new Gson();
|
||||
rVal = gson.fromJson(rawJSON, className);
|
||||
try {
|
||||
rVal = gson.fromJson(Files.newBufferedReader(getSaveFile(sanitizedFilePath).toPath()), className);
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return rVal;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user