diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-11-09 19:38:33 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-11-09 19:38:33 +0100 |
commit | 861cbd33e56ecb32d464234ebb651f0b13cba17b (patch) | |
tree | 273709ae2be1785d2b55cbaed9ae45f4587176a0 /src/main/java/at/hannibal2/skyhanni | |
parent | 5a9af30efab8de12bb7b7431d47cbd4741274b82 (diff) | |
download | skyhanni-861cbd33e56ecb32d464234ebb651f0b13cba17b.tar.gz skyhanni-861cbd33e56ecb32d464234ebb651f0b13cba17b.tar.bz2 skyhanni-861cbd33e56ecb32d464234ebb651f0b13cba17b.zip |
code cleanup
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt | 41 |
1 files changed, 17 insertions, 24 deletions
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<Data : TrackerData>( } 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<Data : TrackerData>( } fun update() { - display = buildFinalDisplay() + display = getSharedTracker()?.let { + buildFinalDisplay(drawDisplay(it.get(displayMode))) + } ?: emptyList() } - private fun buildFinalDisplay(): List<List<Any>> { - 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<List<Any>>) = rawList.toMutableList().also { + if (inventoryOpen) { + it.add(1, buildDisplayModeView()) + } + if (inventoryOpen && displayMode == DisplayMode.SESSION) { + it.addAsSingletonList(buildSessionResetButton()) } } @@ -94,19 +94,13 @@ class SkyHanniTracker<Data : TrackerData>( } ) - private fun currentDisplay() = getSharedTracker()?.get(displayMode) - - private fun getSharedTracker(): SharedTracker<Data>? { - 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<Data : TrackerData>( SESSION("This Session"), ; } - } |