From d5b4a817e2b9e7e5c88eb0c8212b9a6e678bd92f Mon Sep 17 00:00:00 2001 From: Walker Selby Date: Mon, 11 Dec 2023 13:59:52 -0800 Subject: Internal: Migrate Deprecated Config Values to Enums (#790) Migrate Deprecated Config Values to Enums. #790 --- .../rift/everywhere/motes/ShowMotesNpcSellPrice.kt | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/features/rift') diff --git a/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/motes/ShowMotesNpcSellPrice.kt b/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/motes/ShowMotesNpcSellPrice.kt index 256349220..867e88dcd 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/motes/ShowMotesNpcSellPrice.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/motes/ShowMotesNpcSellPrice.kt @@ -1,5 +1,7 @@ package at.hannibal2.skyhanni.features.rift.everywhere.motes +import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator +import at.hannibal2.skyhanni.config.features.rift.motes.InventoryValueConfig.NumberFormatEntry import at.hannibal2.skyhanni.events.GuiContainerEvent import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.InventoryCloseEvent @@ -9,6 +11,7 @@ import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.events.LorenzToolTipEvent import at.hannibal2.skyhanni.features.rift.RiftAPI import at.hannibal2.skyhanni.features.rift.RiftAPI.motesNpcPrice +import at.hannibal2.skyhanni.utils.ConfigUtils import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.LorenzColor @@ -163,14 +166,14 @@ class ShowMotesNpcSellPrice { } val total = itemMap.values.fold(0.0) { acc, pair -> acc + pair.second }.formatPrice() newDisplay.addAsSingletonList("§7Total price: §b$total") - val name = FormatType.entries[config.inventoryValue.formatType].type + val name = FormatType.entries[config.inventoryValue.formatType.ordinal].type // todo avoid ordinal newDisplay.addAsSingletonList("§7Price format: §c$name") newDisplay.addSelector( " ", getName = { type -> type.type }, - isCurrent = { it.ordinal == config.inventoryValue.formatType }, + isCurrent = { it.ordinal == config.inventoryValue.formatType.ordinal }, // todo avoid ordinal onChange = { - config.inventoryValue.formatType = it.ordinal + config.inventoryValue.formatType = NumberFormatEntry.entries[it.ordinal] // todo avoid ordinal update() } ) @@ -183,12 +186,19 @@ class ShowMotesNpcSellPrice { } private fun Double.formatPrice(): String = when (config.inventoryValue.formatType) { - 0 -> NumberUtil.format(this) - 1 -> this.addSeparators() + NumberFormatEntry.SHORT -> NumberUtil.format(this) + NumberFormatEntry.LONG -> this.addSeparators() else -> "0" } private fun isShowPriceEnabled() = RiftAPI.inRift() && config.showPrice private fun isInventoryValueEnabled() = RiftAPI.inRift() && config.inventoryValue.enabled + + @SubscribeEvent + fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { + event.transform(14, "rift.motes.inventoryValue.formatType") { element -> + ConfigUtils.migrateIntToEnum(element, NumberFormatEntry::class.java) + } + } } -- cgit