diff options
author | Walker Selby <git@walkerselby.com> | 2023-12-11 13:34:53 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-11 22:34:53 +0100 |
commit | b8ec689ce9bd6fe89e4b825a988edb63fb51b5ab (patch) | |
tree | 08cc781633a232ba5b4b3c403028ad6b40f17e8e /src | |
parent | 8f3f2318352a2b24625566751daefd1c5e71e51a (diff) | |
download | skyhanni-b8ec689ce9bd6fe89e4b825a988edb63fb51b5ab.tar.gz skyhanni-b8ec689ce9bd6fe89e4b825a988edb63fb51b5ab.tar.bz2 skyhanni-b8ec689ce9bd6fe89e4b825a988edb63fb51b5ab.zip |
Internal Changes: Add Config Transform function (#769)
Added Config Transform function. #769
Diffstat (limited to 'src')
13 files changed, 28 insertions, 27 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt index a113286fe..da558b77f 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt @@ -13,7 +13,7 @@ object ConfigUpdaterMigrator { fun JsonElement.at(chain: List<String>, init: Boolean): JsonElement? { if (chain.isEmpty()) return this if (this !is JsonObject) return null - var obj = this.get(chain.first()) + var obj = this[chain.first()] if (obj == null && init) { obj = JsonObject() this.add(chain.first(), obj) @@ -34,7 +34,11 @@ object ConfigUpdaterMigrator { } } - fun move(since: Int, oldPath: String, newPath: String = oldPath, transform: (JsonElement) -> JsonElement = { it }) { + fun transform(since: Int, path: String, transform: (JsonElement) -> JsonElement = { it }) { + move(since, path, path, transform) + } + + fun move(since: Int, oldPath: String, newPath: String, transform: (JsonElement) -> JsonElement = { it }) { if (since <= oldVersion) { logger.log("Skipping move from $oldPath to $newPath ($since <= $oldVersion)") return @@ -83,7 +87,7 @@ object ConfigUpdaterMigrator { private fun merge(originalObject: JsonObject, overrideObject: JsonObject): Int { var count = 0 overrideObject.entrySet().forEach { - val element = originalObject.get(it.key) + val element = originalObject[it.key] val newElement = it.value if (element is JsonObject && newElement is JsonObject) { count += merge(element, newElement) @@ -99,19 +103,19 @@ object ConfigUpdaterMigrator { } fun fixConfig(config: JsonObject): JsonObject { - val lastVersion = (config.get("lastVersion") as? JsonPrimitive)?.asIntOrNull ?: -1 + val lastVersion = (config["lastVersion"] as? JsonPrimitive)?.asIntOrNull ?: -1 if (lastVersion > CONFIG_VERSION) { error("Cannot downgrade config") } if (lastVersion == CONFIG_VERSION) return config return (lastVersion until CONFIG_VERSION).fold(config) { accumulator, i -> logger.log("Starting config transformation from $i to ${i + 1}") - val storage = accumulator.get("storage")?.asJsonObject + val storage = accumulator["storage"]?.asJsonObject val dynamicPrefix: Map<String, List<String>> = mapOf( "#profile" to (storage?.get("players")?.asJsonObject?.entrySet() ?.flatMap { player -> - player.value.asJsonObject.get("profiles")?.asJsonObject?.entrySet()?.map { + player.value.asJsonObject["profiles"]?.asJsonObject?.entrySet()?.map { "storage.players.${player.key}.profiles.${it.key}" } ?: listOf() } diff --git a/src/main/java/at/hannibal2/skyhanni/features/combat/damageindicator/DamageIndicatorManager.kt b/src/main/java/at/hannibal2/skyhanni/features/combat/damageindicator/DamageIndicatorManager.kt index b12f48cba..42fee548c 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/combat/damageindicator/DamageIndicatorManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/combat/damageindicator/DamageIndicatorManager.kt @@ -872,7 +872,7 @@ class DamageIndicatorManager { event.move(2, "damageIndicator", "combat.damageIndicator") event.move(3, "slayer.endermanPhaseDisplay", "slayer.endermen.phaseDisplay") event.move(3, "slayer.blazePhaseDisplay", "slayer.blazes.phaseDisplay") - event.move(11, "combat.damageIndicator.bossesToShow", "combat.damageIndicator.bossesToShow") { element -> + event.transform(11, "combat.damageIndicator.bossesToShow") { element -> ConfigUtils.migrateIntArrayListToEnumArrayList(element, DamageIndicatorBossEntry::class.java) } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/combat/endernodetracker/EnderNodeTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/combat/endernodetracker/EnderNodeTracker.kt index 51f9a7e8b..87f83208a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/combat/endernodetracker/EnderNodeTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/combat/endernodetracker/EnderNodeTracker.kt @@ -160,7 +160,7 @@ object EnderNodeTracker { @SubscribeEvent fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { event.move(2, "misc.enderNodeTracker", "combat.enderNodeTracker") - event.move(11, "combat.enderNodeTracker.textFormat", "combat.enderNodeTracker.textFormat") { element -> + event.transform(11, "combat.enderNodeTracker.textFormat") { element -> ConfigUtils.migrateIntArrayListToEnumArrayList(element, EnderNodeDisplayEntry::class.java) } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/combat/ghostcounter/GhostCounter.kt b/src/main/java/at/hannibal2/skyhanni/features/combat/ghostcounter/GhostCounter.kt index eb9b68643..be138463f 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/combat/ghostcounter/GhostCounter.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/combat/ghostcounter/GhostCounter.kt @@ -491,7 +491,7 @@ object GhostCounter { @SubscribeEvent fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { event.move(2, "ghostCounter", "combat.ghostCounter") - event.move(11, "combat.ghostCounter.ghostDisplayText", "combat.ghostCounter.ghostDisplayText") { element -> + event.transform(11, "combat.ghostCounter.ghostDisplayText") { element -> ConfigUtils.migrateIntArrayListToEnumArrayList(element, GhostDisplayEntry::class.java) } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt index 937a94a45..e46b9e56e 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt @@ -441,7 +441,7 @@ object CropMoneyDisplay { event.move(3, "garden.moneyPerHourDicer", "garden.moneyPerHours.dicer") event.move(3, "garden.moneyPerHourHideTitle", "garden.moneyPerHours.hideTitle") event.move(3, "garden.moneyPerHourPos", "garden.moneyPerHours.pos") - event.move(11, "garden.moneyPerHours.customFormat") { element -> + event.transform(11, "garden.moneyPerHours.customFormat") { element -> ConfigUtils.migrateIntArrayListToEnumArrayList(element, CustomFormatEntry::class.java) } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingWeightDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingWeightDisplay.kt index 3ba3ad59f..adb30a5cd 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingWeightDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingWeightDisplay.kt @@ -74,7 +74,7 @@ class FarmingWeightDisplay { @SubscribeEvent fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { - event.move(1, "garden.eliteFarmingWeightoffScreenDropMessage", "garden.eliteFarmingWeightOffScreenDropMessage") + event.transform(1, "garden.eliteFarmingWeightoffScreenDropMessage") event.move(3, "garden.eliteFarmingWeightDisplay", "garden.eliteFarmingWeights.display") event.move(3, "garden.eliteFarmingWeightPos", "garden.eliteFarmingWeights.pos") event.move(3, "garden.eliteFarmingWeightLeaderboard", "garden.eliteFarmingWeights.leaderboard") diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorDropStatistics.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorDropStatistics.kt index 59db979be..35f53038d 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorDropStatistics.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorDropStatistics.kt @@ -247,7 +247,7 @@ object GardenVisitorDropStatistics { event.move(3, "${originalPrefix}onlyOnBarn", "${newPrefix}onlyOnBarn") event.move(3, "${originalPrefix}visitorDropPos", "${newPrefix}pos") - event.move(11, "${newPrefix}textFormat", "${newPrefix}textFormat") { element -> + event.transform(11, "${newPrefix}textFormat") { element -> ConfigUtils.migrateIntArrayListToEnumArrayList(element, DropsStatisticsTextEntry::class.java) } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt index 22a53c388..6e24bee4b 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt @@ -607,10 +607,10 @@ class GardenVisitorFeatures { event.move(3, "garden.visitorColoredName", "garden.visitors.coloredName") event.move(3, "garden.visitorHypixelArrivedMessage", "garden.visitors.hypixelArrivedMessage") event.move(3, "garden.visitorHideChat", "garden.visitors.hideChat") - event.move(11, "garden.visitors.rewardWarning.drops", "garden.visitors.rewardWarning.drops") { element -> + event.transform(11, "garden.visitors.rewardWarning.drops") { element -> ConfigUtils.migrateIntArrayListToEnumArrayList(element, VisitorReward::class.java) } - event.move(12, "garden.visitors.rewardWarning.drops", "garden.visitors.rewardWarning.drops") { element -> + event.transform(12, "garden.visitors.rewardWarning.drops") { element -> val drops = JsonArray() for (jsonElement in element.asJsonArray) { val old = jsonElement.asString diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemDisplayOverlayFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemDisplayOverlayFeatures.kt index db4443677..6df462af1 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemDisplayOverlayFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemDisplayOverlayFeatures.kt @@ -252,7 +252,7 @@ object ItemDisplayOverlayFeatures { @SubscribeEvent fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { - event.move(11, "inventory.itemNumberAsStackSize", "inventory.itemNumberAsStackSize") { element -> + event.transform(11, "inventory.itemNumberAsStackSize") { element -> ConfigUtils.migrateIntArrayListToEnumArrayList(element, ItemNumberEntry::class.java) } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/powdertracker/PowderTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/powdertracker/PowderTracker.kt index 63ae5763e..ce5a8dd48 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/mining/powdertracker/PowderTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/mining/powdertracker/PowderTracker.kt @@ -174,11 +174,8 @@ object PowderTracker { @SubscribeEvent fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { event.move(2, "misc.powderTrackerConfig", "mining.powderTracker") - - event.move(8, "#profile.powderTracker", "#profile.powderTracker") { old -> - old.asJsonObject.get("0") - } - event.move(11, "mining.powderTracker.textFormat", "mining.powderTracker.textFormat") { element -> + event.transform(8, "#profile.powderTracker") { old -> old.asJsonObject.get("0") } + event.transform(11, "mining.powderTracker.textFormat") { element -> ConfigUtils.migrateIntArrayListToEnumArrayList(element, PowderDisplayEntry::class.java) } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordRPCManager.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordRPCManager.kt index 96123826e..deba594e7 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordRPCManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordRPCManager.kt @@ -217,16 +217,16 @@ object DiscordRPCManager : IPCListener { @SubscribeEvent fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { - event.move(11, "misc.discordRPC.firstLine", "misc.discordRPC.firstLine") { element -> + event.transform(11, "misc.discordRPC.firstLine") { element -> ConfigUtils.migrateIntToEnum(element, LineEntry::class.java) } - event.move(11, "misc.discordRPC.secondLine", "misc.discordRPC.secondLine") { element -> + event.transform(11, "misc.discordRPC.secondLine") { element -> ConfigUtils.migrateIntToEnum(element, LineEntry::class.java) } - event.move(11, "misc.discordRPC.auto", "misc.discordRPC.auto") { element -> + event.transform(11, "misc.discordRPC.auto") { element -> ConfigUtils.migrateIntToEnum(element, LineEntry::class.java) } - event.move(11, "misc.discordRPC.autoPriority", "misc.discordRPC.autoPriority") { element -> + event.transform(11, "misc.discordRPC.autoPriority") { element -> ConfigUtils.migrateIntArrayListToEnumArrayList(element, PriorityEntry::class.java) } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorFeatures.kt index b07c4dab6..6ac802ab6 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorFeatures.kt @@ -307,7 +307,7 @@ object TrevorFeatures { @SubscribeEvent fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { - event.move(11, "misc.trevorTheTrapper.textFormat", "misc.trevorTheTrapper.textFormat") { element -> + event.transform(11, "misc.trevorTheTrapper.textFormat") { element -> ConfigUtils.migrateIntArrayListToEnumArrayList(element, TrackerEntry::class.java) } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerProfitTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerProfitTracker.kt index 52e27d305..1a4d54ab9 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerProfitTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerProfitTracker.kt @@ -4,6 +4,7 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator import at.hannibal2.skyhanni.config.Storage import at.hannibal2.skyhanni.data.SlayerAPI +import at.hannibal2.skyhanni.data.jsonobjects.repo.SlayerProfitTrackerItemsJson import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.ItemAddEvent import at.hannibal2.skyhanni.events.PurseChangeCause @@ -18,7 +19,6 @@ import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.NumberUtil import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.StringUtils.removeColor -import at.hannibal2.skyhanni.data.jsonobjects.repo.SlayerProfitTrackerItemsJson import at.hannibal2.skyhanni.utils.renderables.Renderable import at.hannibal2.skyhanni.utils.tracker.ItemTrackerData import at.hannibal2.skyhanni.utils.tracker.SkyHanniItemTracker @@ -222,7 +222,7 @@ object SlayerProfitTracker { @SubscribeEvent fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { - event.move(10, "#profile.slayerProfitData", "#profile.slayerProfitData") { old -> + event.transform(10, "#profile.slayerProfitData") { old -> for (data in old.asJsonObject.entrySet().map { it.value.asJsonObject }) { val items = data.get("items").asJsonObject for (item in items.entrySet().map { it.value.asJsonObject }) { |