This commit is contained in:
nelle 2023-10-30 01:51:30 -06:00
parent 32698d48ee
commit e801c88584

View file

@ -17,10 +17,12 @@ class Config {
val prop = Properties()
var fileExists = file.exists()
init {
//Config Stage
//Check if config file exists, if it does, load it
if(fileExists){
FileInputStream(file).use { prop.load(it) }
}
//Otherwise create necesssary directories
//TODO: Check for directories individually as well?
else{
Files.createDirectories(Paths.get("./run"))
Files.createDirectories(Paths.get("./run/tiles"))
@ -29,6 +31,7 @@ class Config {
FileInputStream(file).use { prop.load(it) }
}
//Load config file, and set default properties
FileInputStream(file).use {
prop.load(it)
prop.setProperty("WINDOW_WIDTH", "80")
@ -37,12 +40,12 @@ class Config {
prop.setProperty("SIDEBAR_WIDTH", "18")
prop.setProperty("LOG_AREA_HEIGHT", "12")
//Adds comments
val out: OutputStream = FileOutputStream(file)
prop.store(out, "some comment")
prop.store(out, "PotRogue Configuartion File, restart game if changed value.")
}
}
//SET ALL PROPERTIES
//Convert values from the config file to in-code variables, so we can use them later, also make them public.
val WINDOW_WIDTH: Int = (prop.getProperty("WINDOW_WIDTH")).toInt()
val WINDOW_HEIGHT: Int = (prop.getProperty("WINDOW_HEIGHT")).toInt()
@ -52,5 +55,4 @@ class Config {
val SIDEBAR_WIDTH: Int = (prop.getProperty("SIDEBAR_WIDTH")).toInt()
val LOG_AREA_HEIGHT: Int = (prop.getProperty("LOG_AREA_HEIGHT")).toInt()
}