Localconfig generation and updates
This commit is contained in:
parent
a87fcbed3a
commit
c265b71e8b
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
/target/
|
/target/
|
||||||
|
|
||||||
/src/main/resources/Config/terrain.json
|
/src/main/resources/Config/terrain.json
|
||||||
|
/src/main/resources/Config/localconfig.json
|
||||||
|
|||||||
@ -1,5 +1,15 @@
|
|||||||
package electrosphere.cfg;
|
package electrosphere.cfg;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import electrosphere.main.Globals;
|
||||||
|
import electrosphere.main.Main;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.util.Scanner;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author satellite
|
* @author satellite
|
||||||
@ -7,11 +17,21 @@ package electrosphere.cfg;
|
|||||||
|
|
||||||
//Main configuration file for application
|
//Main configuration file for application
|
||||||
public class MainConfig {
|
public class MainConfig {
|
||||||
|
|
||||||
|
//localconfig.json version
|
||||||
|
public static final int CONFIG_FILE_VERSION = 2;
|
||||||
|
//physical file version
|
||||||
|
public int version;
|
||||||
|
|
||||||
//Main directory of project resources
|
//Main directory of project resources
|
||||||
public String projectMainDirectory;
|
public String projectMainDirectory;
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
//Networking related
|
||||||
|
//
|
||||||
|
public boolean runServer;
|
||||||
|
public boolean runRenderer;
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -22,4 +42,55 @@ public class MainConfig {
|
|||||||
public boolean loadTerrain;
|
public boolean loadTerrain;
|
||||||
//If load terrain, where from?
|
//If load terrain, where from?
|
||||||
public String loadTerrainLocation;
|
public String loadTerrainLocation;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static void generateMainConfig(){
|
||||||
|
System.out.println("localconfig.json either doesn't exist or is out of date");
|
||||||
|
System.out.println("Would you like to generate a new one?(1-y/0-n)");
|
||||||
|
Scanner scan = new Scanner(System.in);
|
||||||
|
if(scan.nextInt() == 0){
|
||||||
|
System.err.println("Bad localconfig.json");
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
Globals.mainConfig = new MainConfig();
|
||||||
|
System.out.println("What is the main resources directory?");
|
||||||
|
System.out.println("(Suggested: \"" + Main.class.getResource("/").getPath() + "\"");
|
||||||
|
Globals.mainConfig.projectMainDirectory = scan.next();
|
||||||
|
System.out.println("Where would you like to save quickload terrain to?");
|
||||||
|
System.out.println("(Suggested: \"" + Globals.mainConfig.projectMainDirectory + "/src/main/resources/Config/terrain.json" + "\"");
|
||||||
|
Globals.mainConfig.loadTerrainLocation = scan.next();
|
||||||
|
System.out.println("Would you like to load terrain from file?(1-y/0-n)");
|
||||||
|
if(scan.nextInt() == 1){
|
||||||
|
Globals.mainConfig.loadTerrain = true;
|
||||||
|
} else {
|
||||||
|
Globals.mainConfig.loadTerrain = false;
|
||||||
|
}
|
||||||
|
System.out.println("Would you like to run the server?(1-y/0-n)");
|
||||||
|
if(scan.nextInt() == 1){
|
||||||
|
Globals.mainConfig.runServer = true;
|
||||||
|
} else {
|
||||||
|
Globals.mainConfig.runServer = false;
|
||||||
|
}
|
||||||
|
System.out.println("Would you like to run the renderer?(1-y/0-n)");
|
||||||
|
if(scan.nextInt() == 1){
|
||||||
|
Globals.mainConfig.runRenderer = true;
|
||||||
|
} else {
|
||||||
|
Globals.mainConfig.runRenderer = false;
|
||||||
|
}
|
||||||
|
Globals.mainConfig.version = MainConfig.CONFIG_FILE_VERSION;
|
||||||
|
System.out.println("Saving config to " + Globals.mainConfig.projectMainDirectory + "/src/main/resources/Config/localconfig.json");
|
||||||
|
Gson gson = new Gson();
|
||||||
|
try {
|
||||||
|
Files.write(
|
||||||
|
new File(Globals.mainConfig.projectMainDirectory + "/src/main/resources/Config/localconfig.json").toPath(),
|
||||||
|
gson.toJson(Globals.mainConfig).getBytes()
|
||||||
|
);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
System.err.println("Failed to save!!");
|
||||||
|
ex.printStackTrace();
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
System.out.println("Saved");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -401,4 +401,14 @@ public class Main {
|
|||||||
|
|
||||||
Globals.cellManager.invalidateAllCells();
|
Globals.cellManager.invalidateAllCells();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void initServer(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void initClient(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -141,8 +141,16 @@ public class Utilities {
|
|||||||
|
|
||||||
|
|
||||||
public static void loadMainConfig(){
|
public static void loadMainConfig(){
|
||||||
Gson gson = new Gson();
|
if(Files.exists(new File(Main.class.getResource("/Config/localconfig.json").getPath()).toPath())){
|
||||||
String configRaw = Utilities.readFileToString(new File(Main.class.getResource("/Config/localconfig.json").getPath()));
|
Gson gson = new Gson();
|
||||||
Globals.mainConfig = gson.fromJson(configRaw, MainConfig.class);
|
String configRaw = Utilities.readFileToString(new File(Main.class.getResource("/Config/localconfig.json").getPath()));
|
||||||
|
Globals.mainConfig = gson.fromJson(configRaw, MainConfig.class);
|
||||||
|
if(Globals.mainConfig.version != MainConfig.CONFIG_FILE_VERSION){
|
||||||
|
//dynamically generate config and save it
|
||||||
|
MainConfig.generateMainConfig();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
MainConfig.generateMainConfig();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1 @@
|
|||||||
{
|
{"version":2,"projectMainDirectory":"/Users/satellite/p/Renderer","runServer":true,"runRenderer":true,"loadTerrain":true,"loadTerrainLocation":"/Users/satellite/p/Renderer/src/main/resources/Config/terrain.json"}
|
||||||
"projectMainDirectory" : "/Users/satellite/p/Renderer/src/main/resources/Config",
|
|
||||||
"loadTerrain" : true,
|
|
||||||
"loadTerrainLocation" : "/Users/satellite/p/Renderer/src/main/resources/Config/terrain.json"
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user