From 9af69225127767c83a8cdbfb6581c0ad9ef3125d Mon Sep 17 00:00:00 2001 From: Walker Selby Date: Wed, 1 May 2024 11:04:03 -0700 Subject: Backend: Cleanup HoppityCollectionStats to improve readability (#1562) --- .../event/hoppity/HoppityCollectionStats.kt | 132 +++++++++++---------- 1 file changed, 71 insertions(+), 61 deletions(-) (limited to 'src/main') diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityCollectionStats.kt b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityCollectionStats.kt index 6f835b760..9be8907d8 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityCollectionStats.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityCollectionStats.kt @@ -46,6 +46,7 @@ class HoppityCollectionStats { private var display = emptyList() private val loggedRabbits = mutableMapOf() + private var totalRabbits = 0 private var inInventory = false private var currentPage = 0 @@ -55,43 +56,55 @@ class HoppityCollectionStats { if (!pagePattern.matches(event.inventoryName)) return inInventory = true + display = buildDisplay(event) + } - var totalAmount = 0 - - for ((_, item) in event.inventoryItems) { - val itemName = item.displayName ?: continue - val itemLore = item.getLore() + @SubscribeEvent + fun onInventoryClose(event: InventoryCloseEvent) { + inInventory = false + } - var duplicatesFound = 0 - var rabbitRarity: RabbitCollectionRarity? = null - var found = true + @SubscribeEvent + fun onProfileChange(event: ProfileJoinEvent) { + display = emptyList() + loggedRabbits.clear() + currentPage = 0 + inInventory = false + } - for (line in itemLore) { - rabbitRarityPattern.matchMatcher(line) { - rabbitRarity = RabbitCollectionRarity.fromDisplayName(group("rarity")) - } - duplicatesFoundPattern.matchMatcher(line) { - duplicatesFound = group("duplicates").formatInt() - } - if (rabbitNotFoundPattern.matches(line)) found = false + @SubscribeEvent + fun onBackgroundDraw(event: GuiRenderEvent.ChestGuiOverlayRenderEvent) { + if (!inInventory) return - rabbitsFoundPattern.matchMatcher(line) { - totalAmount = group("total").formatInt() - } - } + config.hoppityStatsPosition.renderRenderables( + display, + extraSpace = 5, + posLabel = "Hoppity's Collection Stats" + ) + } - val rarity = rabbitRarity ?: continue + private fun buildDisplay(event: InventoryFullyOpenedEvent): MutableList { + val totalAmount = logRabbits(event) - if (itemName == "§dEinstein" && found) { - ChocolateFactoryAPI.profileStorage?.timeTowerCooldown = 7 - } + val newList = mutableListOf() + newList.add(Renderable.string("§eHoppity Rabbit Collection§f:")) + newList.add(LorenzUtils.fillTable(getRabbitStats(), padding = 5)) - val duplicates = duplicatesFound.coerceAtLeast(0) - loggedRabbits[itemName] = RabbitCollectionInfo(rarity, found, duplicates) + if (totalAmount != totalRabbits) { + newList.add(Renderable.string("")) + newList.add( + Renderable.wrappedString( + "§cPlease Scroll through \n" + + "§call pages!", + width = 200, + ) + ) } + return newList + } + private fun getRabbitStats(): MutableList { var totalAmountFound = 0 - var totalRabbits = 0 var totalDuplicates = 0 var totalChocolatePerSecond = 0 var totalChocolateMultiplier = 0.0 @@ -143,47 +156,44 @@ class HoppityCollectionStats { ) ) } + return table + } - val newList = mutableListOf() - newList.add(Renderable.string("§eHoppity Rabbit Collection§f:")) - newList.add(LorenzUtils.fillTable(table, padding = 5)) + private fun logRabbits(event: InventoryFullyOpenedEvent): Int { + var totalAmount = 0 - if (totalAmount != totalRabbits) { - newList.add(Renderable.string("")) - newList.add( - Renderable.wrappedString( - "§cPlease Scroll through \n" + - "§call pages!", - width = 200, - ) - ) - } + for ((_, item) in event.inventoryItems) { + val itemName = item.displayName ?: continue + val itemLore = item.getLore() - display = newList - } + var duplicatesFound = 0 + var rabbitRarity: RabbitCollectionRarity? = null + var found = true - @SubscribeEvent - fun onInventoryClose(event: InventoryCloseEvent) { - inInventory = false - } + for (line in itemLore) { + rabbitRarityPattern.matchMatcher(line) { + rabbitRarity = RabbitCollectionRarity.fromDisplayName(group("rarity")) + } + duplicatesFoundPattern.matchMatcher(line) { + duplicatesFound = group("duplicates").formatInt() + } + if (rabbitNotFoundPattern.matches(line)) found = false - @SubscribeEvent - fun onProfileChange(event: ProfileJoinEvent) { - display = emptyList() - loggedRabbits.clear() - currentPage = 0 - inInventory = false - } + rabbitsFoundPattern.matchMatcher(line) { + totalAmount = group("total").formatInt() + } + } - @SubscribeEvent - fun onBackgroundDraw(event: GuiRenderEvent.ChestGuiOverlayRenderEvent) { - if (!inInventory) return + val rarity = rabbitRarity ?: continue - config.hoppityStatsPosition.renderRenderables( - display, - extraSpace = 5, - posLabel = "Hoppity's Collection Stats" - ) + if (itemName == "§dEinstein" && found) { + ChocolateFactoryAPI.profileStorage?.timeTowerCooldown = 7 + } + + val duplicates = duplicatesFound.coerceAtLeast(0) + loggedRabbits[itemName] = RabbitCollectionInfo(rarity, found, duplicates) + } + return totalAmount } private fun isEnabled() = LorenzUtils.inSkyBlock && config.hoppityCollectionStats -- cgit