From 0a0b750482f0d1d0433e5124aef00bd9da522f4e Mon Sep 17 00:00:00 2001 From: LimePotato Date: Mon, 30 Oct 2023 12:32:21 -0600 Subject: [PATCH] Tweak Config.kt --- build.gradle.kts | 4 +- .../ouroboros/potrogue/data/config/Config.kt | 41 ++++++++----------- .../ouroboros/potrogue/{Main.kt => main.kt} | 0 3 files changed, 20 insertions(+), 25 deletions(-) rename src/main/kotlin/group/ouroboros/potrogue/{Main.kt => main.kt} (100%) diff --git a/build.gradle.kts b/build.gradle.kts index 6b749fa..969bfdf 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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 { diff --git a/src/main/kotlin/group/ouroboros/potrogue/data/config/Config.kt b/src/main/kotlin/group/ouroboros/potrogue/data/config/Config.kt index ff9332a..22463dc 100644 --- a/src/main/kotlin/group/ouroboros/potrogue/data/config/Config.kt +++ b/src/main/kotlin/group/ouroboros/potrogue/data/config/Config.kt @@ -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() } \ No newline at end of file diff --git a/src/main/kotlin/group/ouroboros/potrogue/Main.kt b/src/main/kotlin/group/ouroboros/potrogue/main.kt similarity index 100% rename from src/main/kotlin/group/ouroboros/potrogue/Main.kt rename to src/main/kotlin/group/ouroboros/potrogue/main.kt