aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal002@users.noreply.github.com>2023-11-07 01:46:18 +0100
committerGitHub <noreply@github.com>2023-11-07 01:46:18 +0100
commit4954f93cd878d269582ebe6ccc5486a3f8a5918b (patch)
tree41d1edeb2bbde736d965c5a14e278936d8153ce7 /src/main/java/at/hannibal2/skyhanni/utils
parent01a61929fffbad63c91f821244e9580b192129cf (diff)
downloadskyhanni-4954f93cd878d269582ebe6ccc5486a3f8a5918b.tar.gz
skyhanni-4954f93cd878d269582ebe6ccc5486a3f8a5918b.tar.bz2
skyhanni-4954f93cd878d269582ebe6ccc5486a3f8a5918b.zip
tracker core (#697)
Tracker API #697
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/tracker/DisplayMode.kt7
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/tracker/SharedTracker.kt18
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/tracker/TrackerData.kt5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/tracker/TrackerUtils.kt62
4 files changed, 92 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/tracker/DisplayMode.kt b/src/main/java/at/hannibal2/skyhanni/utils/tracker/DisplayMode.kt
new file mode 100644
index 000000000..6c0e14439
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/utils/tracker/DisplayMode.kt
@@ -0,0 +1,7 @@
+package at.hannibal2.skyhanni.utils.tracker
+
+enum class DisplayMode(val displayName: String) {
+ TOTAL("Total"),
+ CURRENT("This Session"),
+ ;
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SharedTracker.kt b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SharedTracker.kt
new file mode 100644
index 000000000..341600467
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SharedTracker.kt
@@ -0,0 +1,18 @@
+package at.hannibal2.skyhanni.utils.tracker
+
+class SharedTracker<T : TrackerData>(
+ private val total: T,
+ private val currentSession: T,
+) {
+ fun modify(modifyFunction: (T) -> Unit) {
+ modifyFunction(total)
+ modifyFunction(currentSession)
+ }
+
+ fun get(displayMode: DisplayMode) = when (displayMode) {
+ DisplayMode.TOTAL -> total
+ DisplayMode.CURRENT -> currentSession
+ }
+
+ fun getCurrent() = get(TrackerUtils.currentDisplayMode)
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/tracker/TrackerData.kt b/src/main/java/at/hannibal2/skyhanni/utils/tracker/TrackerData.kt
new file mode 100644
index 000000000..3c4a8bbd0
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/utils/tracker/TrackerData.kt
@@ -0,0 +1,5 @@
+package at.hannibal2.skyhanni.utils.tracker
+
+abstract class TrackerData {
+ abstract fun reset()
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/tracker/TrackerUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/tracker/TrackerUtils.kt
new file mode 100644
index 000000000..c223f17e7
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/utils/tracker/TrackerUtils.kt
@@ -0,0 +1,62 @@
+package at.hannibal2.skyhanni.utils.tracker
+
+import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList
+import at.hannibal2.skyhanni.utils.LorenzUtils.addSelector
+import at.hannibal2.skyhanni.utils.renderables.Renderable
+
+object TrackerUtils {
+ var currentDisplayMode = DisplayMode.TOTAL
+
+ fun MutableList<List<Any>>.addDisplayModeToggle(update: () -> Unit) {
+ addSelector<DisplayMode>(
+ "§7Display Mode: ",
+ getName = { type -> type.displayName },
+ isCurrent = { it == currentDisplayMode },
+ onChange = {
+ currentDisplayMode = it
+ update()
+ }
+ )
+ }
+
+ fun MutableList<List<Any>>.addSessionResetButton(name: String, data: SharedTracker<*>?, update: () -> Unit) {
+ addAsSingletonList(
+ Renderable.clickAndHover(
+ "§cReset session!",
+ listOf(
+ "§cThis will reset your",
+ "§ccurrent session for",
+ "§c$name"
+ ),
+ ) {
+ data?.get(DisplayMode.CURRENT)?.let {
+ reset(it) {
+ update()
+ }
+ }
+ })
+ }
+
+ fun resetCommand(name: String, command: String, args: Array<String>, data: SharedTracker<*>?, update: () -> Unit) {
+ if (args.size == 1 && args[0].lowercase() == "confirm") {
+ reset(data?.get(DisplayMode.TOTAL)) {
+ update()
+ LorenzUtils.chat("§e[SkyHanni] You reset your $name data!")
+ }
+ return
+ }
+
+ LorenzUtils.clickableChat(
+ "§e[SkyHanni] Are you sure you want to reset all your $name data? Click here to confirm.",
+ "$command confirm"
+ )
+ }
+
+ fun reset(data: TrackerData?, update: () -> Unit) {
+ data?.let {
+ it.reset()
+ update()
+ }
+ }
+}