Basic config class
This commit is contained in:
parent
a768347701
commit
a12acc388b
4 changed files with 50 additions and 1 deletions
|
@ -43,6 +43,9 @@ dependencies {
|
|||
implementation("com.fasterxml.jackson.core:jackson-databind:2.7.1-1")
|
||||
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.7.1-2")
|
||||
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.7.1")
|
||||
|
||||
implementation("org.freedesktop:xdg-java:0.0.1-SNAPSHOT@jar")
|
||||
implementation("org.assertj:assertj-core:3.6.2")
|
||||
}
|
||||
|
||||
tasks {
|
||||
|
|
3
run/conf.properties
Normal file
3
run/conf.properties
Normal file
|
@ -0,0 +1,3 @@
|
|||
#some comment
|
||||
#Sun Oct 29 12:37:06 MDT 2023
|
||||
myKey=myValue
|
41
src/main/kotlin/group/ouroboros/potrogue/config/Config.kt
Normal file
41
src/main/kotlin/group/ouroboros/potrogue/config/Config.kt
Normal file
|
@ -0,0 +1,41 @@
|
|||
package group.ouroboros.potrogue.config
|
||||
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.io.FileOutputStream
|
||||
import java.io.OutputStream
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
import java.util.*
|
||||
|
||||
class Config {
|
||||
init {
|
||||
//Config Stage
|
||||
val file = File("./run/conf.properties")
|
||||
val prop = Properties()
|
||||
var fileExists = file.exists()
|
||||
|
||||
if(fileExists){
|
||||
FileInputStream(file).use { prop.load(it) }
|
||||
}
|
||||
else{
|
||||
Files.createDirectories(Paths.get("./run"))
|
||||
Files.createFile(Path.of("./run/conf.properties"))
|
||||
FileInputStream(file).use { prop.load(it) }
|
||||
}
|
||||
|
||||
FileInputStream(file).use {
|
||||
prop.load(it)
|
||||
prop.setProperty("myKey", "myValue")
|
||||
|
||||
val out: OutputStream = FileOutputStream(file)
|
||||
prop.store(out, "some comment")
|
||||
}
|
||||
|
||||
// Print all properties
|
||||
prop.stringPropertyNames()
|
||||
.associateWith {prop.getProperty(it)}
|
||||
.forEach { println(it) }
|
||||
}
|
||||
}
|
|
@ -1,14 +1,16 @@
|
|||
package group.ouroboros.potrogue
|
||||
|
||||
import group.ouroboros.potrogue.config.Config
|
||||
import group.ouroboros.potrogue.view.StartView
|
||||
import org.hexworks.zircon.api.SwingApplications
|
||||
|
||||
|
||||
//Important Values
|
||||
const val GAME_ID = "PotRogue";
|
||||
const val GAME_VER = "0.1.0-DEV";
|
||||
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
Config()
|
||||
//Start Application
|
||||
val grid = SwingApplications.startTileGrid(GameConfig.buildAppConfig())
|
||||
StartView(grid).dock()
|
||||
|
|
Loading…
Reference in a new issue