Config Version

This commit is contained in:
nelle 2023-11-06 04:27:15 -07:00
parent 5d397e10cf
commit 5ef0f2c9e3
2 changed files with 20 additions and 11 deletions

View file

@ -12,23 +12,26 @@ import java.util.*
val prop = Properties()
class Config {
private val file = File("./run/potrogue.conf")
val runDir = File("./run")
val confFile = File("./run/potrogue.conf")
private val prop = Properties()
private var fileExists = file.exists()
private var runDirExists = runDir.exists()
init {
//Check if config file exists, if it does, load it
if(fileExists){
FileInputStream(file).use { prop.load(it) }
//Check if the directories and files exist, if not, create them. Also check if config version is incorrect.
//TODO: DataPacks and Advanced configuration system (see values.conf in jar)
//Files.createDirectories(Paths.get("./run/data"))
if(!runDirExists){
Files.createDirectories(Paths.get("./run"))
}
if(confFile.exists()) {
FileInputStream(confFile).use { prop.load(it) }
}
//Otherwise create the necessary directories
else{
Files.createDirectories(Paths.get("./run"))
Files.createDirectories(Paths.get("./run/tiles"))
//TODO: DataPacks and Advanced configuration system (see values.conf in jar)
//Files.createDirectories(Paths.get("./run/data"))
Files.createFile(Path.of("./run/potrogue.conf"))
FileInputStream(file).use {
FileInputStream(confFile).use {
prop.load(it)
prop.setProperty("configVersion", "1")
prop.setProperty("windowWidth", "80")
prop.setProperty("windowHeight", "54")
prop.setProperty("dungeonLevels", "2")
@ -38,7 +41,7 @@ class Config {
prop.setProperty("creaturesPerLevel", "15")
prop.setProperty("creatureMaxSpread", "20")
}
val out: OutputStream = FileOutputStream(file)
val out: OutputStream = FileOutputStream(confFile)
prop.store(out, "PotRogue Configuration File, restart game if changed value. HERE BE DRAGONS.")
}
}
@ -59,4 +62,6 @@ class Config {
val creaturesPerLevel: Int = (prop.getProperty("creaturesPerLevel")).toInt()
val creatureMaxSpread: Int = (prop.getProperty("creatureMaxSpread")).toInt()
val configVersion: Int = (prop.getProperty("configVersion")).toInt()
}

View file

@ -8,9 +8,13 @@ import org.hexworks.zircon.api.SwingApplications
// Important Values
const val GAME_ID = "PotRogue"
const val GAME_VER = "0.1.0-DEV"
const val confVers = 1
fun main() {
Config()
if (Config().configVersion != confVers){
Config().confFile.delete()
}
// Start Application
val grid = SwingApplications.startTileGrid(GameConfig.buildAppConfig())
StartView(grid).dock()