From 98b3ba954a6da32bcc1bfe08a9bf67c17c2bca7f Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Tue, 7 Nov 2023 19:56:09 +0100 Subject: Added SkyHanniTracker and used it in DicerDropTracker --- .../skyhanni/utils/tracker/SkyHanniTracker.kt | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt (limited to 'src/main/java/at/hannibal2/skyhanni/utils/tracker') diff --git a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt new file mode 100644 index 000000000..5e9181447 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt @@ -0,0 +1,47 @@ +package at.hannibal2.skyhanni.utils.tracker + +import at.hannibal2.skyhanni.config.Storage +import at.hannibal2.skyhanni.data.ProfileStorageData +import at.hannibal2.skyhanni.utils.tracker.TrackerUtils.addDisplayModeToggle +import at.hannibal2.skyhanni.utils.tracker.TrackerUtils.addSessionResetButton + +class SkyHanniTracker( + val name: String, + private val currentSessionData: Data, + val getStorage: (Storage.ProfileSpecific) -> Data, + val update: () -> Unit, +) { + + private fun getSharedTracker(): SharedTracker? { + val profileSpecific = ProfileStorageData.profileSpecific ?: return null + return SharedTracker(getStorage(profileSpecific), currentSessionData) + } + + fun addSessionResetButton(list: MutableList>, inventoryOpen: Boolean) { + if (inventoryOpen && TrackerUtils.currentDisplayMode == DisplayMode.CURRENT) { + list.addSessionResetButton(name, getSharedTracker()) { + update() + } + } + } + + fun addDisplayModeToggle(list: MutableList>, inventoryOpen: Boolean) { + if (inventoryOpen) { + list.addDisplayModeToggle { + update() + } + } + } + + fun currentDisplay() = getSharedTracker()?.getCurrent() + + fun resetCommand(args: Array, command: String) { + TrackerUtils.resetCommand(name, command, args, getSharedTracker()) { + update() + } + } + + fun modify(modifyFunction: (Data) -> Unit) { + getSharedTracker()?.modify(modifyFunction) + } +} -- cgit