Redo file loading / builds proper jar now

This commit is contained in:
austin 2021-06-20 14:29:54 -04:00
parent aba735dac0
commit 64928852ba
16 changed files with 237 additions and 175 deletions

5
.gitignore vendored
View File

@ -4,5 +4,10 @@
/src/main/resources/Config/localconfig.json /src/main/resources/Config/localconfig.json
/src/main/resources/Config/keybinds.json /src/main/resources/Config/keybinds.json
/dependency-reduced-pom.xml
/Models
/Models/**.*
/Telephone-*.jar /Telephone-*.jar
/hs_err_pid* /hs_err_pid*

20
pom.xml
View File

@ -171,6 +171,26 @@
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>electrosphere.main.Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins> </plugins>
</build> </build>
</project> </project>

View File

@ -6,6 +6,7 @@ import electrosphere.game.server.creature.type.CreatureType;
import electrosphere.game.server.creature.type.model.CreatureTypeMap; import electrosphere.game.server.creature.type.model.CreatureTypeMap;
import electrosphere.game.server.culture.Culture; import electrosphere.game.server.culture.Culture;
import electrosphere.game.server.culture.religion.Religion; import electrosphere.game.server.culture.religion.Religion;
import electrosphere.util.FileLoadingUtils;
import electrosphere.util.Utilities; import electrosphere.util.Utilities;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -23,8 +24,8 @@ public class Simulation {
} }
void init(){ void init(){
CreatureTypeMap creatureTypeMap = Utilities.loadObjectFromBakedJsonFile("Data/creatures.json", CreatureTypeMap.class); CreatureTypeMap creatureTypeMap = FileLoadingUtils.loadModelObjectFromBakedJsonFile("Data/creatures.json", CreatureTypeMap.class);
CivilizationMap civilizationMap = Utilities.loadObjectFromBakedJsonFile("Data/civilization.json", CivilizationMap.class); CivilizationMap civilizationMap = FileLoadingUtils.loadModelObjectFromBakedJsonFile("Data/civilization.json", CivilizationMap.class);
} }
public void simulate(){ public void simulate(){

View File

@ -5,6 +5,7 @@ import electrosphere.game.terrain.processing.TerrainInterpolator;
import electrosphere.main.Globals; import electrosphere.main.Globals;
import electrosphere.game.server.terrain.generation.TerrainGen; import electrosphere.game.server.terrain.generation.TerrainGen;
import electrosphere.game.server.terrain.models.TerrainModel; import electrosphere.game.server.terrain.models.TerrainModel;
import electrosphere.util.FileLoadingUtils;
import electrosphere.util.Utilities; import electrosphere.util.Utilities;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -90,7 +91,7 @@ public class ServerTerrainManager {
public void load(){ public void load(){
Gson gson = new Gson(); Gson gson = new Gson();
model = gson.fromJson(Utilities.readFileToString(new File(Globals.mainConfig.loadTerrainLocation)), TerrainModel.class); model = FileLoadingUtils.loadModelObjectFromBakedJsonFile(Globals.mainConfig.loadTerrainLocation, TerrainModel.class);
} }
public float[][] getTerrainAtChunk(int x, int y){ public float[][] getTerrainAtChunk(int x, int y){

View File

@ -40,6 +40,7 @@ import electrosphere.renderer.ui.WidgetUtils;
import electrosphere.renderer.ui.font.FontUtils; import electrosphere.renderer.ui.font.FontUtils;
import electrosphere.renderer.ui.font.RawFontMap; import electrosphere.renderer.ui.font.RawFontMap;
import electrosphere.renderer.ui.font.TextBox; import electrosphere.renderer.ui.font.TextBox;
import electrosphere.util.FileLoadingUtils;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
@ -236,7 +237,7 @@ public class Globals {
// try { // try {
//deserializes the texture map from its default path using gson //deserializes the texture map from its default path using gson
//also done in one line //also done in one line
textureMapDefault = Utilities.loadObjectFromBakedJsonFile("/Textures/default_texture_map.json", TextureMap.class); textureMapDefault = FileLoadingUtils.loadModelObjectFromBakedJsonFile("Textures/default_texture_map.json", TextureMap.class);
// textureMapDefault = gson.fromJson(Files.newBufferedReader(new File(Thread.currentThread().getContextClassLoader().getResource("Textures/default_texture_map.json").getFile()).toPath()), TextureMap.class); //only the best of coding practices :) // textureMapDefault = gson.fromJson(Files.newBufferedReader(new File(Thread.currentThread().getContextClassLoader().getResource("Textures/default_texture_map.json").getFile()).toPath()), TextureMap.class); //only the best of coding practices :)
// } catch (IOException ex) { ex.printStackTrace(); } //TODO: handle better :tm: // } catch (IOException ex) { ex.printStackTrace(); } //TODO: handle better :tm:
//entity type map //entity type map
@ -266,7 +267,7 @@ public class Globals {
//create default lights //create default lights
lightDirectionalDefault = new DirectionalLight(new Vector3f(0,-1f,0)); lightDirectionalDefault = new DirectionalLight(new Vector3f(0,-1f,0));
assetManager.registerModelToSpecificString(ModelUtils.createBitmapDisplay(), AssetDataStrings.ASSET_STRING_BITMAP_FONT); assetManager.registerModelToSpecificString(ModelUtils.createBitmapDisplay(), AssetDataStrings.ASSET_STRING_BITMAP_FONT);
RawFontMap fontMap = Utilities.loadObjectFromBakedJsonFile("/Textures/Fonts/myFontMap.json", RawFontMap.class); RawFontMap fontMap = FileLoadingUtils.loadModelObjectFromBakedJsonFile("Textures/Fonts/myFontMap.json", RawFontMap.class);
FontUtils.setFontDataMap(fontMap); FontUtils.setFontDataMap(fontMap);
//black texture for backgrouns //black texture for backgrouns
blackTexture = new Texture("Textures/b1.png"); blackTexture = new Texture("Textures/b1.png");
@ -285,7 +286,7 @@ public class Globals {
} }
static void initEntityTypeMap(){ static void initEntityTypeMap(){
CreatureTypeList typeList = Utilities.loadObjectFromBakedJsonFile("/Data/entity_map.json", CreatureTypeList.class); CreatureTypeList typeList = FileLoadingUtils.loadModelObjectFromBakedJsonFile("Data/entity_map.json", CreatureTypeList.class);
for(CreatureType type : typeList.getTypes()){ for(CreatureType type : typeList.getTypes()){
entityTypeMap.put(type.getId(), type); entityTypeMap.put(type.getId(), type);
} }

View File

@ -18,6 +18,7 @@ import electrosphere.game.state.LoadingThread;
import electrosphere.game.state.SimulationState; import electrosphere.game.state.SimulationState;
import electrosphere.game.state.SimulationState.SimulationStateMachine; import electrosphere.game.state.SimulationState.SimulationStateMachine;
import electrosphere.renderer.RenderingEngine; import electrosphere.renderer.RenderingEngine;
import electrosphere.util.FileLoadingUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.Random; import java.util.Random;
@ -286,7 +287,7 @@ public class Main {
public static void initControlHandler(){ public static void initControlHandler(){
// ControlHandler.generateExampleControlsMap(); // ControlHandler.generateExampleControlsMap();
Globals.controlHandler = Utilities.loadObjectFromBakedJsonFile("/Config/keybinds.json",ControlHandler.class); Globals.controlHandler = FileLoadingUtils.loadModelObjectFromBakedJsonFile("/Config/keybinds.json",ControlHandler.class);
} }

View File

@ -56,7 +56,7 @@ public class Model {
AnimNode root_anim_node; AnimNode root_anim_node;
public static Model create_model_from_aiscene(AIScene s){ public static Model createModelFromAiscene(AIScene s){
Model rVal = new Model(); Model rVal = new Model();
// //
//set the scene //set the scene

View File

@ -154,7 +154,7 @@ public class ModelUtils {
m.parent = rVal; m.parent = rVal;
Material groundMat = new Material(); Material groundMat = new Material();
Texture groundTex = new Texture("Textures/Ground/Dirt1.png"); Texture groundTex = new Texture("/Textures/Ground/Dirt1.png");
groundMat.set_diffuse(groundTex); groundMat.set_diffuse(groundTex);
groundMat.set_specular(groundTex); groundMat.set_specular(groundTex);
m.set_material(groundMat); m.set_material(groundMat);
@ -318,7 +318,7 @@ public class ModelUtils {
m.parent = rVal; m.parent = rVal;
Material groundMat = new Material(); Material groundMat = new Material();
Texture groundTex = new Texture("Textures/Ground/Dirt1.png"); Texture groundTex = new Texture("/Textures/Ground/Dirt1.png");
groundMat.set_diffuse(groundTex); groundMat.set_diffuse(groundTex);
groundMat.set_specular(groundTex); groundMat.set_specular(groundTex);
m.set_material(groundMat); m.set_material(groundMat);
@ -486,7 +486,7 @@ public class ModelUtils {
m.parent = rVal; m.parent = rVal;
Material groundMat = new Material(); Material groundMat = new Material();
Texture groundTex = new Texture("Textures/Ground/Dirt1.png"); Texture groundTex = new Texture("/Textures/Ground/Dirt1.png");
groundMat.set_diffuse(groundTex); groundMat.set_diffuse(groundTex);
groundMat.set_specular(groundTex); groundMat.set_specular(groundTex);
m.set_material(groundMat); m.set_material(groundMat);
@ -606,7 +606,7 @@ public class ModelUtils {
m.nodeID = AssetDataStrings.ASSET_STRING_BITMAP_FONT_MESH_NAME; m.nodeID = AssetDataStrings.ASSET_STRING_BITMAP_FONT_MESH_NAME;
Material uiMat = new Material(); Material uiMat = new Material();
Texture uiTex = new Texture("Textures/Fonts/myfont1-harsher.png"); Texture uiTex = new Texture("/Textures/Fonts/myfont1-harsher.png");
uiMat.set_diffuse(uiTex); uiMat.set_diffuse(uiTex);
uiMat.set_specular(uiTex); uiMat.set_specular(uiTex);
m.set_material(uiMat); m.set_material(uiMat);

View File

@ -1,9 +1,11 @@
package electrosphere.renderer; package electrosphere.renderer;
import electrosphere.main.Main; import electrosphere.main.Main;
import electrosphere.util.FileLoadingUtils;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import org.lwjgl.opengl.GL20; import org.lwjgl.opengl.GL20;
@ -63,7 +65,7 @@ public class ShaderProgram {
// //
String tempForReadingShaders = ""; String tempForReadingShaders = "";
try { try {
BufferedReader br = new BufferedReader(new FileReader(Main.class.getResource(vertex_shader_path).getFile())); BufferedReader br = new BufferedReader(new InputStreamReader(Main.class.getResourceAsStream(vertex_shader_path)));
try { try {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
String line = br.readLine(); String line = br.readLine();
@ -82,7 +84,7 @@ public class ShaderProgram {
String vertexShaderSource = tempForReadingShaders; String vertexShaderSource = tempForReadingShaders;
//This try-catch block reads the FragmentShader source into memory //This try-catch block reads the FragmentShader source into memory
try { try {
BufferedReader br = new BufferedReader(new FileReader(Main.class.getResource(fragment_shader_path).getFile())); BufferedReader br = new BufferedReader(new InputStreamReader(Main.class.getResourceAsStream(fragment_shader_path)));
try { try {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
String line = br.readLine(); String line = br.readLine();
@ -280,43 +282,8 @@ public class ShaderProgram {
// //
//Read in shader programs //Read in shader programs
// //
String tempForReadingShaders = ""; String vertexShaderSource = FileLoadingUtils.readStringFromBakedFile(vertex_shader_path);
try { String fragmentShaderSource = FileLoadingUtils.readStringFromBakedFile(fragment_shader_path);
BufferedReader br = new BufferedReader(new FileReader(Main.class.getResource(vertex_shader_path).getFile()));
try {
StringBuilder sb = new StringBuilder();
String line = br.readLine();
while (line != null) {
sb.append(line);
sb.append(System.lineSeparator());
line = br.readLine();
}
tempForReadingShaders = sb.toString();
} finally {
br.close();
}
} catch (IOException e) {
}
String vertexShaderSource = tempForReadingShaders;
//This try-catch block reads the FragmentShader source into memory
try {
BufferedReader br = new BufferedReader(new FileReader(Main.class.getResource(fragment_shader_path).getFile()));
try {
StringBuilder sb = new StringBuilder();
String line = br.readLine();
while (line != null) {
sb.append(line);
sb.append(System.lineSeparator());
line = br.readLine();
}
tempForReadingShaders = sb.toString();
} finally {
br.close();
}
} catch (IOException e) {
}
String fragmentShaderSource = tempForReadingShaders;
//Creates a new shader object and assigns its 'pointer' to the integer "vertexShader" //Creates a new shader object and assigns its 'pointer' to the integer "vertexShader"
rVal.vertexShader = glCreateShader(GL_VERTEX_SHADER); rVal.vertexShader = glCreateShader(GL_VERTEX_SHADER);
//This alerts openGL to the presence of a vertex shader and points the shader at its source //This alerts openGL to the presence of a vertex shader and points the shader at its source

View File

@ -5,6 +5,8 @@
*/ */
package electrosphere.renderer.texture; package electrosphere.renderer.texture;
import electrosphere.main.Main;
import electrosphere.util.FileLoadingUtils;
import java.awt.Color; import java.awt.Color;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
@ -49,7 +51,7 @@ public class Texture {
width = 1; width = 1;
height = 1; height = 1;
try { try {
BufferedImage image_data = ImageIO.read(new File(Thread.currentThread().getContextClassLoader().getResource(path).getFile())); BufferedImage image_data = ImageIO.read(Main.class.getResourceAsStream(FileLoadingUtils.sanitizeBakedFilePath(path)));
if ( if (
image_data.getType() == BufferedImage.TYPE_3BYTE_BGR || image_data.getType() == BufferedImage.TYPE_3BYTE_BGR ||
image_data.getType() == BufferedImage.TYPE_INT_RGB image_data.getType() == BufferedImage.TYPE_INT_RGB

View File

@ -0,0 +1,154 @@
package electrosphere.util;
import com.google.gson.Gson;
import electrosphere.main.Main;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.concurrent.TimeUnit;
public class FileLoadingUtils {
static final int maxReadFails = 3;
static final int READ_TIMEOUT_DURATION = 5;
public static String readFileToString(File f){
String rVal = "";
BufferedReader reader;
try {
reader = Files.newBufferedReader(f.toPath());
int failCounter = 0;
boolean reading = true;
StringBuilder builder = new StringBuilder("");
while(reading){
if(reader.ready()){
failCounter = 0;
int nextValue = reader.read();
if(nextValue == -1){
reading = false;
} else {
builder.append((char)nextValue);
}
} else {
failCounter++;
if(failCounter > maxReadFails){
reading = false;
} else {
try {
TimeUnit.MILLISECONDS.sleep(READ_TIMEOUT_DURATION);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
}
rVal = builder.toString();
} catch (IOException ex) {
ex.printStackTrace();
}
return rVal;
}
public static String readStreamToString(InputStream resourceInputStream){
String rVal = "";
BufferedReader reader;
try {
reader = new BufferedReader(new InputStreamReader(resourceInputStream));
int failCounter = 0;
boolean reading = true;
StringBuilder builder = new StringBuilder("");
while(reading){
if(reader.ready()){
failCounter = 0;
int nextValue = reader.read();
if(nextValue == -1){
reading = false;
} else {
builder.append((char)nextValue);
}
} else {
failCounter++;
if(failCounter > maxReadFails){
reading = false;
} else {
try {
TimeUnit.MILLISECONDS.sleep(READ_TIMEOUT_DURATION);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
}
rVal = builder.toString();
} catch (IOException ex) {
ex.printStackTrace();
}
return rVal;
}
public static String sanitizeBakedFilePath(String filePath){
String rVal = new String(filePath);
rVal = rVal.trim();
if(!rVal.startsWith("/")){
rVal = "/" + rVal;
}
return rVal;
}
public static String readStringFromBakedFile(String bakedFilePath){
String rVal = "";
String sanitizedFilePath = sanitizeBakedFilePath(bakedFilePath);
rVal = readStreamToString(Main.class.getResourceAsStream(sanitizedFilePath));
return rVal;
}
public static void serializeObjectToFilePath(String filePath, Object object){
Path path = new File(filePath).toPath();
Gson gson = new Gson();
try {
Files.write(path, gson.toJson(object).getBytes());
} catch (IOException ex) {
ex.printStackTrace();
System.exit(1);
}
}
public static <T>T loadModelObjectFromBakedJsonFile(String fileName, Class<T> className){
T rVal = null;
String sanitizedFilePath = sanitizeBakedFilePath(fileName);
String rawJSON = readStreamToString(Main.class.getResourceAsStream(sanitizedFilePath));
Gson gson = new Gson();
rVal = gson.fromJson(rawJSON, className);
return rVal;
}
public static File unpackBakedFileToFilePath(String bakedFilePath){
String sanitizedFilePath = sanitizeBakedFilePath(bakedFilePath);
System.out.println(bakedFilePath);
if(!Files.exists(new File("./Models").toPath())){
try {
Files.createDirectory(new File("./Models").toPath());
} catch (IOException ex) {
ex.printStackTrace();
}
}
File targetFile = new File("." + sanitizedFilePath);
try {
Files.write(targetFile.toPath(), Main.class.getResourceAsStream(sanitizedFilePath).readAllBytes(),StandardOpenOption.CREATE,StandardOpenOption.WRITE);
} catch (IOException ex) {
ex.printStackTrace();
}
return targetFile;
}
}

View File

@ -1,6 +1,7 @@
package electrosphere.util; package electrosphere.util;
import electrosphere.main.Globals; import electrosphere.main.Globals;
import electrosphere.main.Main;
import electrosphere.renderer.Material; import electrosphere.renderer.Material;
import electrosphere.renderer.Mesh; import electrosphere.renderer.Mesh;
import electrosphere.renderer.Model; import electrosphere.renderer.Model;
@ -11,6 +12,8 @@ import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
@ -24,8 +27,10 @@ public class ModelLoader {
public static Model load_Model_From_File(String fileName){ public static Model load_Model_From_File(String fileName){
Model rVal; Model rVal;
AIScene scene; AIScene scene;
File file = new File(Thread.currentThread().getContextClassLoader().getResource(fileName).getFile()); // File file = new File(Thread.currentThread().getContextClassLoader().getResource(fileName).getFile());
scene = aiImportFile(file.getAbsolutePath(), // Main.class.getResourceAsStream(fileName).readAllBytes();
File toRead = FileLoadingUtils.unpackBakedFileToFilePath(fileName);
scene = aiImportFile(toRead.getAbsolutePath(),
aiProcess_GenSmoothNormals | aiProcess_GenSmoothNormals |
aiProcess_JoinIdenticalVertices | aiProcess_JoinIdenticalVertices |
aiProcess_Triangulate | aiProcess_Triangulate |
@ -34,14 +39,14 @@ public class ModelLoader {
if(scene == null){ if(scene == null){
throw new IllegalStateException(aiGetErrorString()); throw new IllegalStateException(aiGetErrorString());
} }
rVal = Model.create_model_from_aiscene(scene); rVal = Model.createModelFromAiscene(scene);
attempt_add_textures_from_pathname(fileName, rVal); attemptAddTexturesFromPathname(fileName, rVal);
return rVal; return rVal;
} }
//TODO: this logic should exclusively use functions provided in the TextureMap class //TODO: this logic should exclusively use functions provided in the TextureMap class
//this way if we change the underlying structure of the TextureMap it doesn't fuck over this logic //this way if we change the underlying structure of the TextureMap it doesn't fuck over this logic
static void attempt_add_textures_from_pathname(String path, Model m){ static void attemptAddTexturesFromPathname(String path, Model m){
//first we get the default texture map that's global //first we get the default texture map that's global
TextureMap global_map = Globals.textureMapDefault; TextureMap global_map = Globals.textureMapDefault;
//then we try to get the path of our model from the map //then we try to get the path of our model from the map

View File

@ -82,7 +82,7 @@ public class Utilities {
public static void save_test_texture_map_to_location(String s){ public static void saveTestTextureMapToLocation(String s){
TextureMap t = new TextureMap(); TextureMap t = new TextureMap();
t.add_model("model1"); t.add_model("model1");
t.add_mesh_to_model("model1", "mesh1"); t.add_mesh_to_model("model1", "mesh1");
@ -104,87 +104,11 @@ public class Utilities {
} }
} }
static final int maxReadFails = 3;
static final int READ_TIMEOUT_DURATION = 5;
public static String readFileToString(File f){
String rVal = "";
BufferedReader reader;
try {
reader = Files.newBufferedReader(f.toPath());
int failCounter = 0;
boolean reading = true;
StringBuilder builder = new StringBuilder("");
while(reading){
if(reader.ready()){
failCounter = 0;
int nextValue = reader.read();
if(nextValue == -1){
reading = false;
} else {
builder.append((char)nextValue);
}
} else {
failCounter++;
if(failCounter > maxReadFails){
reading = false;
} else {
try {
TimeUnit.MILLISECONDS.sleep(READ_TIMEOUT_DURATION);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
}
rVal = builder.toString();
} catch (IOException ex) {
ex.printStackTrace();
}
return rVal;
}
public static String readBakedResourceToString(InputStream resourceInputStream){
String rVal = "";
BufferedReader reader;
try {
reader = new BufferedReader(new InputStreamReader(resourceInputStream));
int failCounter = 0;
boolean reading = true;
StringBuilder builder = new StringBuilder("");
while(reading){
if(reader.ready()){
failCounter = 0;
int nextValue = reader.read();
if(nextValue == -1){
reading = false;
} else {
builder.append((char)nextValue);
}
} else {
failCounter++;
if(failCounter > maxReadFails){
reading = false;
} else {
try {
TimeUnit.MILLISECONDS.sleep(READ_TIMEOUT_DURATION);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
}
rVal = builder.toString();
} catch (IOException ex) {
ex.printStackTrace();
}
return rVal;
}
public static void loadMainConfig(){ public static void loadMainConfig(){
if(Main.class.getResource("/Config/localconfig.json") != null){ if(Main.class.getResource("/Config/localconfig.json") != null){
Globals.mainConfig = loadObjectFromBakedJsonFile("/Config/localconfig.json", MainConfig.class); Globals.mainConfig = FileLoadingUtils.loadModelObjectFromBakedJsonFile("/Config/localconfig.json", MainConfig.class);
if(Globals.mainConfig.version != MainConfig.CONFIG_FILE_VERSION){ if(Globals.mainConfig.version != MainConfig.CONFIG_FILE_VERSION){
//dynamically generate config and save it //dynamically generate config and save it
MainConfig.generateMainConfig(); MainConfig.generateMainConfig();
@ -194,15 +118,6 @@ public class Utilities {
} }
} }
public static <T>T loadObjectFromBakedJsonFile(String fileName, Class<T> className){
T rVal = null;
String rawJSON = Utilities.readBakedResourceToString(Main.class.getResourceAsStream(fileName));
Gson gson = new Gson();
rVal = gson.fromJson(rawJSON, className);
return rVal;
}
public static void saveObjectToBakedJsonFile(String fileName, Object object){ public static void saveObjectToBakedJsonFile(String fileName, Object object){
URL resourceUrl = Main.class.getResource(fileName); URL resourceUrl = Main.class.getResource(fileName);
File file = new File(""); File file = new File("");
@ -219,15 +134,4 @@ public class Utilities {
System.exit(1); System.exit(1);
} }
} }
public static void saveObjectToJsonFile(String fileName, Object object){
Path path = new File(Main.class.getResource(fileName).getPath()).toPath();
Gson gson = new Gson();
try {
Files.write(path, gson.toJson(object).getBytes());
} catch (IOException ex) {
ex.printStackTrace();
System.exit(1);
}
}
} }

View File

@ -6,6 +6,7 @@ import electrosphere.game.server.terrain.manager.ServerTerrainManager;
import electrosphere.game.server.terrain.models.TerrainModel; import electrosphere.game.server.terrain.models.TerrainModel;
import electrosphere.main.Globals; import electrosphere.main.Globals;
import electrosphere.main.Main; import electrosphere.main.Main;
import electrosphere.util.FileLoadingUtils;
import electrosphere.util.Utilities; import electrosphere.util.Utilities;
import java.awt.Color; import java.awt.Color;
import java.awt.Graphics; import java.awt.Graphics;
@ -38,7 +39,7 @@ public class TerrainViewer {
// terrainModel = terrainManager.getModel(); // terrainModel = terrainManager.getModel();
// Utilities.saveObjectToBakedJsonFile("/Config/testingTerrain.json", terrainModel); // Utilities.saveObjectToBakedJsonFile("/Config/testingTerrain.json", terrainModel);
terrainModel = Utilities.loadObjectFromBakedJsonFile("/Config/testingTerrain.json", TerrainModel.class); terrainModel = FileLoadingUtils.loadModelObjectFromBakedJsonFile("/Config/testingTerrain.json", TerrainModel.class);
Simulation simulation = new Simulation(); Simulation simulation = new Simulation();

View File

@ -2,7 +2,7 @@
"types": [ "types": [
{ {
"id" : 0, "id" : 0,
"modelPath" : "Models/person1walkanim.fbx", "modelPath" : "/Models/person1walkanim.fbx",
"hitboxes" : [ "hitboxes" : [
{ {
"type": "hurt", "type": "hurt",
@ -58,7 +58,7 @@
}, },
{ {
"id" : 2, "id" : 2,
"modelPath" : "Models/katana1alt.fbx", "modelPath" : "/Models/katana1alt.fbx",
"hitboxes" : [ "hitboxes" : [
{ {
"type": "hit", "type": "hit",

View File

@ -2,48 +2,48 @@
"texture_map": { "texture_map": {
"Models/plane.fbx": { "Models/plane.fbx": {
"Cube": [ "Cube": [
"Textures/Ground/Dirt1.png", "/Textures/Ground/Dirt1.png",
"Textures/Ground/Dirt1.png" "/Textures/Ground/Dirt1.png"
] ]
}, },
"Models/arcdock5deg1notex.fbx": { "Models/arcdock5deg1notex.fbx": {
"Cube": [ "Cube": [
"Textures/w1.png", "/Textures/w1.png",
"Textures/w1.png" "/Textures/w1.png"
] ]
}, },
"Models/Wheat1.fbx": { "Models/Wheat1.fbx": {
"Stalk": [ "Stalk": [
"Textures/Wheat1stretch.png", "/Textures/Wheat1stretch.png",
"Textures/Wheat1stretch.png" "/Textures/Wheat1stretch.png"
] ]
}, },
"Models/unitsphere.fbx": { "Models/unitsphere.fbx": {
"Sphere": [ "Sphere": [
"Textures/transparent_blue.png", "/Textures/transparent_blue.png",
"Textures/transparent_blue.png" "/Textures/transparent_blue.png"
] ]
}, },
"Models/unitsphere_1.fbx": { "Models/unitsphere_1.fbx": {
"Sphere": [ "Sphere": [
"Textures/transparent_red.png", "/Textures/transparent_red.png",
"Textures/transparent_red.png" "/Textures/transparent_red.png"
] ]
}, },
"Models/katana1alt.fbx": { "Models/katana1alt.fbx": {
"SwordMesh": [ "SwordMesh": [
"Textures/katana1.png", "/Textures/katana1.png",
"Textures/katana1.png" "/Textures/katana1.png"
] ]
}, },
"Models/tree1.fbx": { "Models/tree1.fbx": {
"Cube.002": [ "Cube.002": [
"Textures/Branch.png", "/Textures/Branch.png",
"Textures/Branch.png" "/Textures/Branch.png"
], ],
"Cylinder": [ "Cylinder": [
"Textures/Branch.png", "/Textures/Branch.png",
"Textures/Branch.png" "/Textures/Branch.png"
] ]
} }
} }