From 861cbd33e56ecb32d464234ebb651f0b13cba17b Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 9 Nov 2023 19:38:33 +0100 Subject: code cleanup --- .../skyhanni/utils/tracker/SkyHanniTracker.kt | 41 +++++++++------------- 1 file changed, 17 insertions(+), 24 deletions(-) (limited to 'src/main/java') 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 e80f93edf..73bba2b51 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt @@ -39,8 +39,10 @@ class SkyHanniTracker( } fun modify(modifyFunction: (Data) -> Unit) { - getSharedTracker()?.modify(modifyFunction) - update() + getSharedTracker()?.let { + it.modify(modifyFunction) + update() + } } fun renderDisplay(position: Position) { @@ -54,19 +56,17 @@ class SkyHanniTracker( } fun update() { - display = buildFinalDisplay() + display = getSharedTracker()?.let { + buildFinalDisplay(drawDisplay(it.get(displayMode))) + } ?: emptyList() } - private fun buildFinalDisplay(): List> { - val data = currentDisplay() ?: return emptyList() - - return drawDisplay(data).toMutableList().also { - if (inventoryOpen) { - it.add(1, buildDisplayModeView()) - } - if (inventoryOpen && displayMode == DisplayMode.SESSION) { - it.addAsSingletonList(buildSessionResetButton()) - } + private fun buildFinalDisplay(rawList: List>) = rawList.toMutableList().also { + if (inventoryOpen) { + it.add(1, buildDisplayModeView()) + } + if (inventoryOpen && displayMode == DisplayMode.SESSION) { + it.addAsSingletonList(buildSessionResetButton()) } } @@ -94,19 +94,13 @@ class SkyHanniTracker( } ) - private fun currentDisplay() = getSharedTracker()?.get(displayMode) - - private fun getSharedTracker(): SharedTracker? { - val profileSpecific = ProfileStorageData.profileSpecific ?: return null - return SharedTracker(getStorage(profileSpecific), getCurrentSession(profileSpecific)) + private fun getSharedTracker() = ProfileStorageData.profileSpecific?.let { + SharedTracker(getStorage(it), currentSessions.getOrPut(it) { createNewSession() }) } - private fun getCurrentSession(profileSpecific: Storage.ProfileSpecific) = - currentSessions.getOrPut(profileSpecific) { createNewSession() } - private fun reset(displayMode: DisplayMode, message: String) { - getSharedTracker()?.get(displayMode)?.let { - it.reset() + getSharedTracker()?.let { + it.get(displayMode).reset() LorenzUtils.chat(message) update() } @@ -129,5 +123,4 @@ class SkyHanniTracker( SESSION("This Session"), ; } - } -- cgit