aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorWalker Selby <git@walkerselby.com>2024-05-01 11:04:03 -0700
committerGitHub <noreply@github.com>2024-05-01 20:04:03 +0200
commit9af69225127767c83a8cdbfb6581c0ad9ef3125d (patch)
tree5d567d280ac26f7e56f7335159d9796ade088f92 /src/main
parentf118964bd54b3f58ce00e4cb865dcf95cb20fed8 (diff)
downloadskyhanni-9af69225127767c83a8cdbfb6581c0ad9ef3125d.tar.gz
skyhanni-9af69225127767c83a8cdbfb6581c0ad9ef3125d.tar.bz2
skyhanni-9af69225127767c83a8cdbfb6581c0ad9ef3125d.zip
Backend: Cleanup HoppityCollectionStats to improve readability (#1562)
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/event/hoppity/HoppityCollectionStats.kt132
1 files changed, 71 insertions, 61 deletions
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<Renderable>()
private val loggedRabbits = mutableMapOf<String, RabbitCollectionInfo>()
+ 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<Renderable> {
+ val totalAmount = logRabbits(event)
- if (itemName == "§dEinstein" && found) {
- ChocolateFactoryAPI.profileStorage?.timeTowerCooldown = 7
- }
+ val newList = mutableListOf<Renderable>()
+ 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<DisplayTableEntry> {
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<Renderable>()
- 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