diff --git a/src/main/java/net/halbear/Terrain4J/EngineCore/Logic/EngineConfig.java b/src/main/java/net/halbear/Terrain4J/EngineCore/Logic/EngineConfig.java index 2e69d98..88adcdc 100644 --- a/src/main/java/net/halbear/Terrain4J/EngineCore/Logic/EngineConfig.java +++ b/src/main/java/net/halbear/Terrain4J/EngineCore/Logic/EngineConfig.java @@ -2,9 +2,7 @@ package net.halbear.Terrain4J.EngineCore.Logic; import org.tinylog.Logger; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStream; +import java.io.*; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Properties; @@ -15,6 +13,7 @@ public class EngineConfig { private static final int DEFAULT_WIDTH = 640; private static final int DEFAULT_HEIGHT = 480; private static final String FILENAME = "terrain4j.properties"; + private static String SOFTWARE_TITLE; private static EngineConfig instance; private long accuracy; private int TickRate; @@ -31,51 +30,67 @@ public class EngineConfig { private EngineConfig() { - var EngineConfig = new Properties(); + var EngineConfigVar = new Properties(); Path path = Paths.get(""); - InputStream stream = EngineConfig.class.getResourceAsStream("/" + FILENAME); + File ConfigFile = new File(path.toAbsolutePath().toString() + "/" + FILENAME); boolean SuccessfulLoad = false; - if (stream != null) { + try(InputStream stream = new FileInputStream(path.toAbsolutePath().toString() + "/" + FILENAME)){ try { - EngineConfig.load(stream); + + EngineConfigVar.load(stream); SuccessfulLoad = true; Logger.debug("File [{}] read", FILENAME); } catch (IOException excp) { Logger.error("File [{}] not read", FILENAME, excp); } - } else{ - Logger.debug("FileStream for file [{}] is null, Filepath [{}] not found", FILENAME,path.toAbsolutePath().toString() + "/" + FILENAME); - - } - if (SuccessfulLoad){ - PhysicalDeviceName = EngineConfig.getOrDefault("PhysicalDeviceName", DEFAULT_ACCURACY).toString(); - accuracy = Long.parseLong(EngineConfig.getOrDefault("frame_accuracy", DEFAULT_ACCURACY).toString()); - TickRate = Integer.parseInt(EngineConfig.getOrDefault("main_tick_rate", DEFAULT_TICKRATE).toString()); - Width = Integer.parseInt(EngineConfig.getOrDefault("display_width", DEFAULT_TICKRATE).toString()); - Height = Integer.parseInt(EngineConfig.getOrDefault("display_height", DEFAULT_TICKRATE).toString()); - VSYNC = Boolean.parseBoolean(EngineConfig.getOrDefault("vsync", false).toString()); try { assert stream != null; stream.close(); } catch(IOException excp) { Logger.error("stream unable to be closed", excp); } - } else{ + } catch(IOException | NullPointerException error){ + Logger.error("FileStream for file [{}] is null, Error: [{}]", ConfigFile.getAbsolutePath(),error); + } + if (!SuccessfulLoad){ + InputStream NewStream = (EngineConfig.class.getResourceAsStream("terrain4j.properties")); try { - EngineConfig.setProperty("vkValidated", "true"); - EngineConfig.setProperty("frame_accuracy", "0"); - EngineConfig.setProperty("main_tick_rate", "120"); - EngineConfig.setProperty("display_width", "640"); - EngineConfig.setProperty("display_height", "480"); - EngineConfig.setProperty("vsync", "false"); - EngineConfig.store(new FileWriter(path.toAbsolutePath().toString() + "/" + FILENAME), "created new properties file"); + EngineConfigVar.load(NewStream); + SuccessfulLoad = true; + } catch (IOException error){ + Logger.error("FileStream for file [{}] is null, Error: [{}]", "terrain4j.properties",error); + } + } + if(SuccessfulLoad) { + SOFTWARE_TITLE = EngineConfigVar.getOrDefault("Software_Title", "Terrain4J").toString(); + PhysicalDeviceName = EngineConfigVar.getOrDefault("PhysicalDeviceName", "").toString(); + accuracy = Long.parseLong(EngineConfigVar.getOrDefault("frame_accuracy", DEFAULT_ACCURACY).toString()); + TickRate = Integer.parseInt(EngineConfigVar.getOrDefault("main_tick_rate", DEFAULT_TICKRATE).toString()); + Width = Integer.parseInt(EngineConfigVar.getOrDefault("display_width", "1280").toString()); + Height = Integer.parseInt(EngineConfigVar.getOrDefault("display_height", "720").toString()); + VSYNC = Boolean.parseBoolean(EngineConfigVar.getOrDefault("vsync", false).toString()); + vkValidated = Boolean.parseBoolean(EngineConfigVar.getOrDefault("vkValidated", false).toString()); + Logger.debug("\n\nsuccessfully loaded configuration: \n{}\n\n",EngineConfigVar.toString()); + } + else if(!ConfigFile.exists()){ + try { + EngineConfigVar.setProperty("Software_Title","Terrain4J Software"); + EngineConfigVar.setProperty("PhysicalDeviceName",null); + EngineConfigVar.setProperty("frame_accuracy", String.valueOf(DEFAULT_ACCURACY)); + EngineConfigVar.setProperty("main_tick_rate", String.valueOf(DEFAULT_TICKRATE)); + EngineConfigVar.setProperty("display_width","1280"); + EngineConfigVar.setProperty("display_height","720"); + EngineConfigVar.setProperty("vsync","true"); + EngineConfigVar.setProperty("vkValidated","false"); + EngineConfigVar.store(new FileWriter(path.toAbsolutePath().toString() + "/" + FILENAME), "created new properties file"); + Logger.debug("Wrote New Config File [{}]", ConfigFile.getAbsolutePath()); } catch (IOException excp2) { Logger.error("File [{}] not written", FILENAME, excp2); } - accuracy = DEFAULT_ACCURACY; - TickRate = DEFAULT_TICKRATE; + } else{ + Logger.debug("Config File [{}] exists but was unable to be loaded",ConfigFile.getAbsolutePath()); } - vkValidated = Boolean.parseBoolean(EngineConfig.getOrDefault("vkValidated", false).toString()); + } public boolean VkValidated(){ diff --git a/src/main/resources/terrain4j.properties b/src/main/resources/terrain4j.properties new file mode 100644 index 0000000..2aada15 --- /dev/null +++ b/src/main/resources/terrain4j.properties @@ -0,0 +1,18 @@ +#created new properties file +#Tue Jan 20 08:16:32 GMT 2026 +#Default Window dimensions +display_height=480 +display_width=640 +#the precision of frames, set this to 16000 and it will limit the whole engine to 64FPS +frame_accuracy=0 +#event tick rate for game process +main_tick_rate=120 +#Vulkan Debugging toggle +vkValidated=true + +vsync=false +#This is the name of the GPU you want the engine to use +PhysicalDeviceName= +#Title that shows up on app window +Software_Title=Terrain4J Game Engine + diff --git a/terrain4j.properties b/terrain4j.properties index ad2aa2d..2aada15 100644 --- a/terrain4j.properties +++ b/terrain4j.properties @@ -1,8 +1,18 @@ #created new properties file #Tue Jan 20 08:16:32 GMT 2026 +#Default Window dimensions display_height=480 display_width=640 +#the precision of frames, set this to 16000 and it will limit the whole engine to 64FPS frame_accuracy=0 +#event tick rate for game process main_tick_rate=120 +#Vulkan Debugging toggle vkValidated=true + vsync=false +#This is the name of the GPU you want the engine to use +PhysicalDeviceName= +#Title that shows up on app window +Software_Title=Terrain4J Game Engine +