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 a787423..09782ed 100644 --- a/src/main/kotlin/group/ouroboros/potrogue/data/config/Config.kt +++ b/src/main/kotlin/group/ouroboros/potrogue/data/config/Config.kt @@ -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() } \ 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 index c799c06..cc09de8 100644 --- a/src/main/kotlin/group/ouroboros/potrogue/main.kt +++ b/src/main/kotlin/group/ouroboros/potrogue/main.kt @@ -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()