aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-11-07 19:56:09 +0100
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-11-07 19:56:09 +0100
commit98b3ba954a6da32bcc1bfe08a9bf67c17c2bca7f (patch)
tree7cb0e8e791aa64104a8a67ab2ec5a629dddb32e3 /src/main
parentbfd0e31ebb6d841b222369baf54f7955d13e85e9 (diff)
downloadskyhanni-98b3ba954a6da32bcc1bfe08a9bf67c17c2bca7f.tar.gz
skyhanni-98b3ba954a6da32bcc1bfe08a9bf67c17c2bca7f.tar.bz2
skyhanni-98b3ba954a6da32bcc1bfe08a9bf67c17c2bca7f.zip
Added SkyHanniTracker and used it in DicerDropTracker
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/Storage.java14
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/farming/DicerDropTracker.kt51
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt47
3 files changed, 68 insertions, 44 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/Storage.java b/src/main/java/at/hannibal2/skyhanni/config/Storage.java
index 5c4ef3c63..82aa9a4cb 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/Storage.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/Storage.java
@@ -8,6 +8,7 @@ import at.hannibal2.skyhanni.features.event.jerry.frozentreasure.FrozenTreasure;
import at.hannibal2.skyhanni.features.fishing.trophy.TrophyRarity;
import at.hannibal2.skyhanni.features.garden.CropAccessory;
import at.hannibal2.skyhanni.features.garden.CropType;
+import at.hannibal2.skyhanni.features.garden.farming.DicerDropTracker;
import at.hannibal2.skyhanni.features.garden.farming.FarmingArmorDrops;
import at.hannibal2.skyhanni.features.garden.fortuneguide.FarmingItems;
import at.hannibal2.skyhanni.features.garden.visitor.VisitorReward;
@@ -144,18 +145,7 @@ public class Storage {
public CropAccessory savedCropAccessory = null;
@Expose
- public DicerDropTracker dicerDropTracker = new DicerDropTracker();
-
- public static class DicerDropTracker extends TrackerData {
-
- public void reset() {
- drops.clear();
- }
-
- @Expose
- public Map<CropType, Map<at.hannibal2.skyhanni.features.garden.farming.DicerDropTracker.DropRarity, Integer>> drops = new HashMap<>();
-
- }
+ public DicerDropTracker.Data dicerDropTracker = new DicerDropTracker.Data();
@Expose
public long informedAboutLowMatter = 0;
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/DicerDropTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/DicerDropTracker.kt
index a3b4f73cb..bc4655bbe 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/DicerDropTracker.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/DicerDropTracker.kt
@@ -3,8 +3,6 @@ package at.hannibal2.skyhanni.features.garden.farming
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.ConfigManager
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
-import at.hannibal2.skyhanni.config.Storage.ProfileSpecific.GardenStorage.DicerDropTracker
-import at.hannibal2.skyhanni.data.ProfileStorageData
import at.hannibal2.skyhanni.events.GardenToolChangeEvent
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
@@ -17,11 +15,9 @@ import at.hannibal2.skyhanni.utils.LorenzUtils.addOrPut
import at.hannibal2.skyhanni.utils.LorenzUtils.sortedDesc
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems
-import at.hannibal2.skyhanni.utils.tracker.DisplayMode
-import at.hannibal2.skyhanni.utils.tracker.SharedTracker
-import at.hannibal2.skyhanni.utils.tracker.TrackerUtils
-import at.hannibal2.skyhanni.utils.tracker.TrackerUtils.addDisplayModeToggle
-import at.hannibal2.skyhanni.utils.tracker.TrackerUtils.addSessionResetButton
+import at.hannibal2.skyhanni.utils.tracker.SkyHanniTracker
+import at.hannibal2.skyhanni.utils.tracker.TrackerData
+import com.google.gson.annotations.Expose
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.inventory.GuiInventory
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
@@ -30,8 +26,17 @@ object DicerDropTracker {
private var display = emptyList<List<Any>>()
private val itemDrops = mutableListOf<ItemDrop>()
private val config get() = SkyHanniMod.feature.garden.dicerCounters
- private val currentSessionData = DicerDropTracker()
private var inventoryOpen = false
+ private val tracker = SkyHanniTracker("Dicer Drop Tracker", Data(), { it.garden.dicerDropTracker }) { update() }
+
+ class Data : TrackerData() {
+ override fun reset() {
+ drops.clear()
+ }
+
+ @Expose
+ var drops: MutableMap<CropType, MutableMap<DropRarity, Int>> = mutableMapOf()
+ }
init {
itemDrops.add(ItemDrop(CropType.MELON, DropRarity.UNCOMMON, "§a§lUNCOMMON DROP! §r§eDicer dropped §r§a(\\d+)x §r§aEnchanted Melon§r§e!".toRegex()))
@@ -75,30 +80,22 @@ object DicerDropTracker {
}
private fun update() {
- currentDisplay()?.let {
+ tracker.currentDisplay()?.let {
display = drawDisplay(it)
}
}
- private fun drawDisplay(storage: DicerDropTracker) = buildList<List<Any>> {
+ private fun drawDisplay(storage: Data) = buildList<List<Any>> {
val cropInHand = cropInHand ?: return@buildList
val items = storage.drops.getOrPut(cropInHand) { mutableMapOf() }
addAsSingletonList("§7Dicer Drop Tracker for $toolName§7:")
- if (inventoryOpen) {
- addDisplayModeToggle {
- update()
- }
- }
+ tracker.addDisplayModeToggle(this, inventoryOpen)
for ((rarity, amount) in items.sortedDesc()) {
val displayName = rarity.displayName
addAsSingletonList(" §7- §e${amount.addSeparators()}x $displayName")
}
- if (inventoryOpen && TrackerUtils.currentDisplayMode == DisplayMode.CURRENT) {
- addSessionResetButton("Dicer Drop Tracker", getSharedTracker()) {
- update()
- }
- }
+ tracker.addSessionResetButton(this, inventoryOpen)
}
private var cropInHand: CropType? = null
@@ -115,8 +112,7 @@ object DicerDropTracker {
}
private fun addDrop(crop: CropType, rarity: DropRarity) {
- val sharedTracker = getSharedTracker() ?: return
- sharedTracker.modify {
+ tracker.modify {
val map = it.drops.getOrPut(crop) { mutableMapOf() }
map.addOrPut(rarity, 1)
}
@@ -160,16 +156,7 @@ object DicerDropTracker {
}
}
- private fun currentDisplay() = getSharedTracker()?.getCurrent()
-
- private fun getSharedTracker(): SharedTracker<DicerDropTracker>? {
- val profileSpecific = ProfileStorageData.profileSpecific ?: return null
- return SharedTracker(profileSpecific.garden.dicerDropTracker, currentSessionData)
- }
-
fun resetCommand(args: Array<String>) {
- TrackerUtils.resetCommand("Dicer Drop Tracker", "shresetdicertracker", args, getSharedTracker()) {
- update()
- }
+ tracker.resetCommand(args, "shresetdicertracker")
}
}
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)
+ }
+}