From e44edc3789f6610efa8eab07bc91b3aecc0bf7a6 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sat, 16 Dec 2023 13:10:40 +0100 Subject: Only modifying the total session when opening Vermin Bin. --- .../features/rift/area/westvillage/VerminTracker.kt | 7 ++++--- .../hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni') diff --git a/src/main/java/at/hannibal2/skyhanni/features/rift/area/westvillage/VerminTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/rift/area/westvillage/VerminTracker.kt index 02644a370..1f2b38122 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/rift/area/westvillage/VerminTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/rift/area/westvillage/VerminTracker.kt @@ -53,7 +53,8 @@ object VerminTracker { fun onChat(event: LorenzChatEvent) { VerminType.entries.forEach { verminType -> if (verminType.pattern.matches(event.message)) { - addVermin(verminType) + tracker.modify { it.count.addOrPut(verminType, 1) } + if (config.hideChat) { event.blockedReason = "vermin_vacuumed" } @@ -106,11 +107,11 @@ object VerminTracker { } private fun addVermin(vermin: VerminType, count: Int = 1) { - tracker.modify { it.count.addOrPut(vermin, count) } + tracker.modify(SkyHanniTracker.DisplayMode.TOTAL) { it.count.addOrPut(vermin, count) } } private fun setVermin(vermin: VerminType, count: Int) { - tracker.modify { it.count[vermin] = count } + tracker.modify(SkyHanniTracker.DisplayMode.TOTAL) { it.count[vermin] = count } } private fun drawDisplay(data: Data): List> = buildList { diff --git a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt index 02ce5129a..ad3418ace 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt @@ -68,6 +68,16 @@ open class SkyHanniTracker( } } + fun modify(mode: DisplayMode, modifyFunction: (Data) -> Unit) { + val storage = ProfileStorageData.profileSpecific ?: return + val data: Data = when (mode) { + DisplayMode.TOTAL -> storage.getTotal() + DisplayMode.SESSION -> storage.getCurrentSession() + } + modifyFunction(data) + update() + } + fun renderDisplay(position: Position) { if (config.hideInEstimatedItemValue && EstimatedItemValue.isCurrentlyShowing()) return @@ -127,9 +137,13 @@ open class SkyHanniTracker( ) protected fun getSharedTracker() = ProfileStorageData.profileSpecific?.let { - SharedTracker(getStorage(it), currentSessions.getOrPut(it) { createNewSession() }) + SharedTracker(it.getTotal(), it.getCurrentSession()) } + private fun Storage.ProfileSpecific.getCurrentSession() = currentSessions.getOrPut(this) { createNewSession() } + + private fun Storage.ProfileSpecific.getTotal(): Data = getStorage(this) + private fun reset(displayMode: DisplayMode, message: String) { getSharedTracker()?.let { it.get(displayMode).reset() -- cgit