diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-11-07 19:56:09 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-11-07 19:56:09 +0100 |
commit | 98b3ba954a6da32bcc1bfe08a9bf67c17c2bca7f (patch) | |
tree | 7cb0e8e791aa64104a8a67ab2ec5a629dddb32e3 /src/main/java/at/hannibal2/skyhanni/utils/tracker | |
parent | bfd0e31ebb6d841b222369baf54f7955d13e85e9 (diff) | |
download | skyhanni-98b3ba954a6da32bcc1bfe08a9bf67c17c2bca7f.tar.gz skyhanni-98b3ba954a6da32bcc1bfe08a9bf67c17c2bca7f.tar.bz2 skyhanni-98b3ba954a6da32bcc1bfe08a9bf67c17c2bca7f.zip |
Added SkyHanniTracker and used it in DicerDropTracker
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils/tracker')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt | 47 |
1 files changed, 47 insertions, 0 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 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<Data : TrackerData>( + val name: String, + private val currentSessionData: Data, + val getStorage: (Storage.ProfileSpecific) -> Data, + val update: () -> Unit, +) { + + private fun getSharedTracker(): SharedTracker<Data>? { + val profileSpecific = ProfileStorageData.profileSpecific ?: return null + return SharedTracker(getStorage(profileSpecific), currentSessionData) + } + + fun addSessionResetButton(list: MutableList<List<Any>>, inventoryOpen: Boolean) { + if (inventoryOpen && TrackerUtils.currentDisplayMode == DisplayMode.CURRENT) { + list.addSessionResetButton(name, getSharedTracker()) { + update() + } + } + } + + fun addDisplayModeToggle(list: MutableList<List<Any>>, inventoryOpen: Boolean) { + if (inventoryOpen) { + list.addDisplayModeToggle { + update() + } + } + } + + fun currentDisplay() = getSharedTracker()?.getCurrent() + + fun resetCommand(args: Array<String>, command: String) { + TrackerUtils.resetCommand(name, command, args, getSharedTracker()) { + update() + } + } + + fun modify(modifyFunction: (Data) -> Unit) { + getSharedTracker()?.modify(modifyFunction) + } +} |