Tweak Config.kt

This commit is contained in:
nelle 2023-10-30 12:32:21 -06:00
parent a9013b30b0
commit 0a0b750482
3 changed files with 20 additions and 25 deletions

View file

@ -13,7 +13,6 @@ plugins {
kotlin("jvm") version "1.9.10"
`kotlin-dsl`
id("com.github.johnrengelman.shadow") version "8.1.1"
id("io.gitlab.arturbosch.detekt") version("1.23.1")
}
repositories {
@ -40,6 +39,9 @@ dependencies {
implementation("org.freedesktop:xdg-java:0.0.1-SNAPSHOT@jar")
implementation("org.assertj:assertj-core:3.6.2")
implementation("com.akuleshov7:ktoml-core:0.5.0")
implementation("com.akuleshov7:ktoml-file:0.5.0")
}
tasks {

View file

@ -13,46 +13,39 @@ import java.util.*
val prop = Properties()
class Config {
val file = File("./run/potrogue.conf")
val prop = Properties()
var fileExists = file.exists()
private val file = File("./run/potrogue.conf")
private val prop = Properties()
private var fileExists = file.exists()
init {
//Check if config file exists, if it does, load it
if(fileExists){
FileInputStream(file).use { prop.load(it) }
}
//Otherwise create necessary directories
//TODO: Check for directories individually as well?
else{
Files.createDirectories(Paths.get("./run"))
Files.createDirectories(Paths.get("./run/tiles"))
Files.createDirectories(Paths.get("./run/data"))
Files.createFile(Path.of("./run/potrogue.conf"))
FileInputStream(file).use { prop.load(it) }
}
//Load config file, and set default properties
FileInputStream(file).use {
prop.load(it)
prop.setProperty("WINDOW_WIDTH", "80")
prop.setProperty("WINDOW_HEIGHT", "50")
prop.setProperty("DUNGEON_LEVELS", "2")
prop.setProperty("SIDEBAR_WIDTH", "18")
prop.setProperty("LOG_AREA_HEIGHT", "12")
//Adds comments
val out: OutputStream = FileOutputStream(file)
prop.store(out, "PotRogue Configuration File, restart game if changed value.")
FileInputStream(file).use {
prop.load(it)
prop.setProperty("windowWidth", "80")
prop.setProperty("windowHeight", "50")
prop.setProperty("dungeonLevels", "2")
prop.setProperty("sidebarWidth", "18")
prop.setProperty("logAreaHeight", "12")}
val out: OutputStream = FileOutputStream(file)
prop.store(out, "PotRogue Configuration File, restart game if changed value.")
}
}
//Convert values from the config file to in-code variables, so we can use them later, also make them public.
val windowWidth: Int = (prop.getProperty("WINDOW_WIDTH")).toInt()
val windowWidth: Int = (prop.getProperty("windowWidth")).toInt()
val windowHeight: Int = (prop.getProperty("WINDOW_HEIGHT")).toInt()
val windowHeight: Int = (prop.getProperty("windowHeight")).toInt()
val dungeonLevels: Int = (prop.getProperty("DUNGEON_LEVELS")).toInt()
val dungeonLevels: Int = (prop.getProperty("dungeonLevels")).toInt()
val sidebarWidth: Int = (prop.getProperty("SIDEBAR_WIDTH")).toInt()
val sidebarWidth: Int = (prop.getProperty("sidebarWidth")).toInt()
val logAreaHeight: Int = (prop.getProperty("LOG_AREA_HEIGHT")).toInt()
val logAreaHeight: Int = (prop.getProperty("logAreaHeight")).toInt()
}