From a8138b0aa20d2b2fd266b1352eaf075999365bb6 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Fri, 22 Mar 2024 18:16:49 +0100 Subject: Backend: ChatClickActionManager (#1128) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Co-authored-by: Cal Co-authored-by: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> --- .../features/fishing/trophy/TrophyFishManager.kt | 28 ++++++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/features') diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishManager.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishManager.kt index 78fbf6731..9bff45019 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishManager.kt @@ -37,27 +37,45 @@ object TrophyFishManager { loadedNeu = true - val savedFish = fish ?: return + val savedFishes = fish ?: return var changed = false + val neuData = mutableListOf>() for ((fishName, apiAmount) in caughtTrophyFish) { val rarity = TrophyRarity.getByName(fishName) ?: continue val name = fishName.split("_").dropLast(1).joinToString("") - val savedFishData = savedFish.getOrPut(name) { mutableMapOf() } + val savedFishData = savedFishes.getOrPut(name) { mutableMapOf() } val currentSavedAmount = savedFishData[rarity] ?: 0 + neuData.add(Triple(name, rarity, apiAmount)) if (apiAmount > currentSavedAmount) { - savedFishData[rarity] = apiAmount - ChatUtils.debug("Updated trophy fishing data from NEU PV: $name $rarity: $currentSavedAmount -> $apiAmount") changed = true } } if (changed) { - ChatUtils.chat("Updated Trophy Fishing data via NEU PV!") + ChatUtils.clickableChat("Click here to load data from NEU PV!", onClick = { + updateFromNeuPv(savedFishes, neuData) + }) } } + private fun updateFromNeuPv( + savedFishes: MutableMap>, + neuData: MutableList>, + ) { + for ((name, rarity, newValue) in neuData) { + val saved = savedFishes[name] ?: continue + + val current = saved[rarity] ?: 0 + if (newValue > current) { + saved[rarity] = newValue + ChatUtils.debug("Updated trophy fishing data from NEU PV: $name $rarity: $current -> $newValue") + } + } + ChatUtils.chat("Updated Trophy Fishing data via NEU PV!") + } + private var trophyFishInfo = mapOf() fun getInfo(internalName: String) = trophyFishInfo[internalName] -- cgit