Skip to content

Commit

Permalink
cleaned up some config stuff and fixed a bug
Browse files Browse the repository at this point in the history
  • Loading branch information
CalMWolfs committed Nov 3, 2023
1 parent 4b2a3c1 commit 3f2ec97
Showing 1 changed file with 2 additions and 28 deletions.
30 changes: 2 additions & 28 deletions src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package at.hannibal2.skyhanni.config

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.features.fishing.trophy.TrophyRarity
import at.hannibal2.skyhanni.features.garden.CropType
import at.hannibal2.skyhanni.features.misc.update.UpdateManager
import at.hannibal2.skyhanni.utils.LorenzLogger
import at.hannibal2.skyhanni.utils.LorenzRarity
Expand Down Expand Up @@ -126,16 +125,9 @@ class ConfigManager {
try {
val inputStreamReader = InputStreamReader(FileInputStream(configFile!!), StandardCharsets.UTF_8)
val bufferedReader = BufferedReader(inputStreamReader)
val builder = StringBuilder()
for (line in bufferedReader.lines()) {
val result = fixConfig(line)
builder.append(result)
builder.append("\n")
}


logger.log("load-config-now")
val jsonObject = gson.fromJson(builder.toString(), JsonObject::class.java)
val jsonObject = gson.fromJson(bufferedReader.readText(), JsonObject::class.java)
val newJsonObject = ConfigUpdaterMigrator.fixConfig(jsonObject)
features = gson.fromJson(
newJsonObject,
Expand All @@ -160,16 +152,10 @@ class ConfigManager {
try {
val inputStreamReader = InputStreamReader(FileInputStream(sackFile!!), StandardCharsets.UTF_8)
val bufferedReader = BufferedReader(inputStreamReader)
val builder = StringBuilder()
for (line in bufferedReader.lines()) {
builder.append(line)
builder.append("\n")
}


logger.log("load-sacks-now")
sackData = gson.fromJson(
builder.toString(),
bufferedReader.readText(),
SackData::class.java
)
logger.log("Loaded sacks from file")
Expand Down Expand Up @@ -205,18 +191,6 @@ class ConfigManager {
)
}

private fun fixConfig(line: String): String {
var result = line
for (type in CropType.entries) {
val normal = "\"${type.cropName}\""
val enumName = "\"${type.name}\""
while (result.contains(normal)) {
result = result.replace(normal, enumName)
}
}
return result
}

fun saveConfig(reason: String) {
if (disableSaving) return
logger.log("saveConfig: $reason")
Expand Down

0 comments on commit 3f2ec97

Please sign in to comment.