Tweak Config.kt
This commit is contained in:
parent
a9013b30b0
commit
0a0b750482
3 changed files with 20 additions and 25 deletions
|
@ -13,7 +13,6 @@ plugins {
|
||||||
kotlin("jvm") version "1.9.10"
|
kotlin("jvm") version "1.9.10"
|
||||||
`kotlin-dsl`
|
`kotlin-dsl`
|
||||||
id("com.github.johnrengelman.shadow") version "8.1.1"
|
id("com.github.johnrengelman.shadow") version "8.1.1"
|
||||||
id("io.gitlab.arturbosch.detekt") version("1.23.1")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
|
@ -40,6 +39,9 @@ dependencies {
|
||||||
|
|
||||||
implementation("org.freedesktop:xdg-java:0.0.1-SNAPSHOT@jar")
|
implementation("org.freedesktop:xdg-java:0.0.1-SNAPSHOT@jar")
|
||||||
implementation("org.assertj:assertj-core:3.6.2")
|
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 {
|
tasks {
|
||||||
|
|
|
@ -13,46 +13,39 @@ import java.util.*
|
||||||
val prop = Properties()
|
val prop = Properties()
|
||||||
|
|
||||||
class Config {
|
class Config {
|
||||||
val file = File("./run/potrogue.conf")
|
private val file = File("./run/potrogue.conf")
|
||||||
val prop = Properties()
|
private val prop = Properties()
|
||||||
var fileExists = file.exists()
|
private var fileExists = file.exists()
|
||||||
init {
|
init {
|
||||||
//Check if config file exists, if it does, load it
|
//Check if config file exists, if it does, load it
|
||||||
if(fileExists){
|
if(fileExists){
|
||||||
FileInputStream(file).use { prop.load(it) }
|
FileInputStream(file).use { prop.load(it) }
|
||||||
}
|
}
|
||||||
//Otherwise create necessary directories
|
//Otherwise create necessary directories
|
||||||
//TODO: Check for directories individually as well?
|
|
||||||
else{
|
else{
|
||||||
Files.createDirectories(Paths.get("./run"))
|
Files.createDirectories(Paths.get("./run"))
|
||||||
Files.createDirectories(Paths.get("./run/tiles"))
|
Files.createDirectories(Paths.get("./run/tiles"))
|
||||||
Files.createDirectories(Paths.get("./run/data"))
|
Files.createDirectories(Paths.get("./run/data"))
|
||||||
Files.createFile(Path.of("./run/potrogue.conf"))
|
Files.createFile(Path.of("./run/potrogue.conf"))
|
||||||
FileInputStream(file).use { prop.load(it) }
|
|
||||||
}
|
|
||||||
|
|
||||||
//Load config file, and set default properties
|
|
||||||
FileInputStream(file).use {
|
FileInputStream(file).use {
|
||||||
prop.load(it)
|
prop.load(it)
|
||||||
prop.setProperty("WINDOW_WIDTH", "80")
|
prop.setProperty("windowWidth", "80")
|
||||||
prop.setProperty("WINDOW_HEIGHT", "50")
|
prop.setProperty("windowHeight", "50")
|
||||||
prop.setProperty("DUNGEON_LEVELS", "2")
|
prop.setProperty("dungeonLevels", "2")
|
||||||
prop.setProperty("SIDEBAR_WIDTH", "18")
|
prop.setProperty("sidebarWidth", "18")
|
||||||
prop.setProperty("LOG_AREA_HEIGHT", "12")
|
prop.setProperty("logAreaHeight", "12")}
|
||||||
|
|
||||||
//Adds comments
|
|
||||||
val out: OutputStream = FileOutputStream(file)
|
val out: OutputStream = FileOutputStream(file)
|
||||||
prop.store(out, "PotRogue Configuration File, restart game if changed value.")
|
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.
|
//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()
|
||||||
}
|
}
|
Loading…
Reference in a new issue