Skip to content

Commit

Permalink
Improvement: SH Tracker Search (hannibal002#2477)
Browse files Browse the repository at this point in the history
Co-authored-by: hannibal2 <[email protected]>
  • Loading branch information
hannibal002 and hannibal002 authored Sep 9, 2024
1 parent e17e70b commit 18da4a7
Show file tree
Hide file tree
Showing 22 changed files with 513 additions and 261 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import at.hannibal2.skyhanni.events.OwnInventoryItemUpdateEvent
import at.hannibal2.skyhanni.events.SackChangeEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.CollectionUtils.addOrPut
import at.hannibal2.skyhanni.utils.CollectionUtils.addString
import at.hannibal2.skyhanni.utils.CollectionUtils.addSearchString
import at.hannibal2.skyhanni.utils.ConditionalUtils.afterChange
import at.hannibal2.skyhanni.utils.ConfigUtils
import at.hannibal2.skyhanni.utils.InventoryUtils
Expand All @@ -26,7 +26,7 @@ import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland
import at.hannibal2.skyhanni.utils.NEUItems.getPriceOrNull
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.NumberUtil.shortFormat
import at.hannibal2.skyhanni.utils.renderables.Renderable
import at.hannibal2.skyhanni.utils.renderables.Searchable
import at.hannibal2.skyhanni.utils.tracker.SkyHanniTracker
import at.hannibal2.skyhanni.utils.tracker.TrackerData
import com.google.gson.annotations.Expose
Expand Down Expand Up @@ -212,47 +212,46 @@ object EnderNodeTracker {
else -> null
}

private fun drawDisplay(data: Data) = buildList<Renderable> {
private fun drawDisplay(data: Data) = buildList<Searchable> {
val lootProfit = getLootProfit(data)

addString("§5§lEnder Node Tracker")
addString("§d${data.totalNodesMined.addSeparators()} Ender Nodes mined")
addString("§6${lootProfit.values.sum().shortFormat()} Coins made")
addString(" ")
addString("§b${data.totalEndermiteNests.addSeparators()} §cEndermite Nest")
addSearchString("§5§lEnder Node Tracker")
addSearchString("§d${data.totalNodesMined.addSeparators()} Ender Nodes mined")
addSearchString("§6${lootProfit.values.sum().shortFormat()} Coins made")
addSearchString(" ")
addSearchString("§b${data.totalEndermiteNests.addSeparators()} §cEndermite Nest", "Endermite Nest")

for (item in EnderNode.entries.subList(0, 11)) {
val count = (data.lootCount[item] ?: 0).addSeparators()
val profit = (lootProfit[item] ?: 0.0).shortFormat()
addString("§b$count ${item.displayName} §7(§6$profit§7)")
addSearchString("§b$count ${item.displayName} §7(§6$profit§7)", item.displayName)
}
addString(" ")
addSearchString(" ")

val totalEnderArmor = calculateEnderArmor(data)
addString(
"§b${totalEnderArmor.addSeparators()} §5Ender Armor " +
"§7(§6${(totalEnderArmor * 10_000).shortFormat()}§7)"
addSearchString(
"§b${totalEnderArmor.addSeparators()} §5Ender Armor " + "§7(§6${(totalEnderArmor * 10_000).shortFormat()}§7)"
)
for (item in EnderNode.entries.subList(11, 16)) {
val count = (data.lootCount[item] ?: 0).addSeparators()
val profit = (lootProfit[item] ?: 0.0).shortFormat()
addString("§b$count ${item.displayName} §7(§6$profit§7)")
addSearchString("§b$count ${item.displayName} §7(§6$profit§7)")
}
// enderman pet rarities
val (c, u, r, e, l) = EnderNode.entries.subList(16, 21).map { (data.lootCount[it] ?: 0).addSeparators() }
val profit = EnderNode.entries.subList(16, 21).sumOf { lootProfit[it] ?: 0.0 }.shortFormat()
addString("§f$c§7-§a$u§7-§9$r§7-§5$e§7-§6$l §fEnderman Pet §7(§6$profit§7)")
addSearchString("§f$c§7-§a$u§7-§9$r§7-§5$e§7-§6$l §fEnderman Pet §7(§6$profit§7)")
}

private fun calculateEnderArmor(storage: Data) =
storage.lootCount.filter { isEnderArmor(it.key) }
.map { it.value }
.sum()

private fun formatDisplay(map: List<Renderable>): List<Renderable> {
private fun formatDisplay(map: List<Searchable>): List<Searchable> {
if (!ProfileStorageData.loaded) return emptyList()

val newList = mutableListOf<Renderable>()
val newList = mutableListOf<Searchable>()
for (index in config.textFormat.get()) {
// TODO, change functionality to use enum rather than ordinals
newList.add(map[index.ordinal])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.RepositoryReloadEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.CollectionUtils.addString
import at.hannibal2.skyhanni.utils.CollectionUtils.addSearchString
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NEUInternalName
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
Expand All @@ -19,6 +19,8 @@ import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import at.hannibal2.skyhanni.utils.RegexUtils.matches
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.renderables.Renderable
import at.hannibal2.skyhanni.utils.renderables.Searchable
import at.hannibal2.skyhanni.utils.renderables.toSearchable
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import at.hannibal2.skyhanni.utils.tracker.ItemTrackerData
import at.hannibal2.skyhanni.utils.tracker.SkyHanniItemTracker
Expand Down Expand Up @@ -77,8 +79,8 @@ object DianaProfitTracker {
}
}

private fun drawDisplay(data: Data): List<Renderable> = buildList {
addString("§e§lDiana Profit Tracker")
private fun drawDisplay(data: Data): List<Searchable> = buildList {
addSearchString("§e§lDiana Profit Tracker")

val profit = tracker.drawItems(data, { true }, this)

Expand All @@ -87,7 +89,7 @@ object DianaProfitTracker {
Renderable.hoverTips(
"§7Burrows dug: §e${treasureCoins.addSeparators()}",
listOf("§7You dug out griffin burrows §e${treasureCoins.addSeparators()} §7times."),
),
).toSearchable(),
)

add(tracker.addTotalProfit(profit, data.burrowsDug, "burrow"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.CollectionUtils.addOrPut
import at.hannibal2.skyhanni.utils.CollectionUtils.addString
import at.hannibal2.skyhanni.utils.CollectionUtils.addSearchString
import at.hannibal2.skyhanni.utils.CollectionUtils.sumAllValues
import at.hannibal2.skyhanni.utils.ConditionalUtils
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.RegexUtils.matches
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.renderables.Renderable
import at.hannibal2.skyhanni.utils.renderables.Searchable
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import at.hannibal2.skyhanni.utils.tracker.SkyHanniTracker
import at.hannibal2.skyhanni.utils.tracker.TrackerData
Expand All @@ -30,32 +30,31 @@ object MythologicalCreatureTracker {
private val patternGroup = RepoPattern.group("event.diana.mythological.tracker")
private val minotaurPattern by patternGroup.pattern(
"minotaur",
".* §r§eYou dug out a §r§2Minotaur§r§e!"
".* §r§eYou dug out a §r§2Minotaur§r§e!",
)
private val gaiaConstructPattern by patternGroup.pattern(
"gaiaconstruct",
".* §r§eYou dug out a §r§2Gaia Construct§r§e!"
".* §r§eYou dug out a §r§2Gaia Construct§r§e!",
)
private val minosChampionPattern by patternGroup.pattern(
"minoschampion",
".* §r§eYou dug out a §r§2Minos Champion§r§e!"
".* §r§eYou dug out a §r§2Minos Champion§r§e!",
)
private val siameseLynxesPattern by patternGroup.pattern(
"siameselynxes",
".* §r§eYou dug out §r§2Siamese Lynxes§r§e!"
".* §r§eYou dug out §r§2Siamese Lynxes§r§e!",
)
private val minosHunterPattern by patternGroup.pattern(
"minoshunter",
".* §r§eYou dug out a §r§2Minos Hunter§r§e!"
".* §r§eYou dug out a §r§2Minos Hunter§r§e!",
)
private val minosInquisitorPattern by patternGroup.pattern(
"minosinquisitor",
".* §r§eYou dug out a §r§2Minos Inquisitor§r§e!"
".* §r§eYou dug out a §r§2Minos Inquisitor§r§e!",
)

private val tracker =
SkyHanniTracker("Mythological Creature Tracker", { Data() }, { it.diana.mythologicalMobTracker })
{ drawDisplay(it) }
SkyHanniTracker("Mythological Creature Tracker", { Data() }, { it.diana.mythologicalMobTracker }) { drawDisplay(it) }

class Data : TrackerData() {

Expand Down Expand Up @@ -90,8 +89,7 @@ object MythologicalCreatureTracker {

// TODO migrate to abstract feature in the future
if (creatureType == MythologicalCreatureType.MINOS_INQUISITOR) {
event.chatComponent =
ChatComponentText(event.message + " §e(${it.creaturesSinceLastInquisitor})")
event.chatComponent = ChatComponentText(event.message + " §e(${it.creaturesSinceLastInquisitor})")
it.creaturesSinceLastInquisitor = 0
} else it.creaturesSinceLastInquisitor++
}
Expand All @@ -100,19 +98,22 @@ object MythologicalCreatureTracker {
}
}

private fun drawDisplay(data: Data): List<Renderable> = buildList {
addString("§7Mythological Creature Tracker:")
private fun drawDisplay(data: Data): List<Searchable> = buildList {
addSearchString("§7Mythological Creature Tracker:")
val total = data.count.sumAllValues()
for ((creatureType, amount) in data.count.entries.sortedByDescending { it.value }) {
val percentageSuffix = if (config.showPercentage.get()) {
val percentage = LorenzUtils.formatPercentage(amount.toDouble() / total)
" §7$percentage"
} else ""

addString(" §7- §e${amount.addSeparators()} ${creatureType.displayName}$percentageSuffix")
addSearchString(
" §7- §e${amount.addSeparators()} ${creatureType.displayName}$percentageSuffix",
searchText = creatureType.displayName,
)
}
addString(" §7- §e${total.addSeparators()} §7Total Mythological Creatures")
addString(" §7- §e${data.creaturesSinceLastInquisitor.addSeparators()} §7Creatures since last Minos Inquisitor")
addSearchString(" §7- §e${total.addSeparators()} §7Total Mythological Creatures")
addSearchString(" §7- §e${data.creaturesSinceLastInquisitor.addSeparators()} §7Creatures since last Minos Inquisitor")
}

@SubscribeEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
import at.hannibal2.skyhanni.events.SecondPassedEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.CollectionUtils.addOrPut
import at.hannibal2.skyhanni.utils.CollectionUtils.addString
import at.hannibal2.skyhanni.utils.CollectionUtils.addSearchString
import at.hannibal2.skyhanni.utils.ConfigUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.NumberUtil.shortFormat
import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import at.hannibal2.skyhanni.utils.RegexUtils.matches
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.renderables.Renderable
import at.hannibal2.skyhanni.utils.renderables.Searchable
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import at.hannibal2.skyhanni.utils.tracker.SkyHanniTracker
import at.hannibal2.skyhanni.utils.tracker.TrackerData
Expand Down Expand Up @@ -105,8 +105,8 @@ object FrozenTreasureTracker {
icePerHour = (icePerSecond.average() * 3600).toInt()
}

private fun formatDisplay(map: List<Renderable>): List<Renderable> {
val newList = mutableListOf<Renderable>()
private fun formatDisplay(map: List<Searchable>): List<Searchable> {
val newList = mutableListOf<Searchable>()
for (index in config.textFormat) {
// TODO, change functionality to use enum rather than ordinals
newList.add(map[index.ordinal])
Expand Down Expand Up @@ -137,20 +137,20 @@ object FrozenTreasureTracker {
}
}

private fun drawDisplay(data: Data) = buildList {
private fun drawDisplay(data: Data) = buildList<Searchable> {
calculateIce(data)
addString("§e§lFrozen Treasure Tracker")
addString("§6${formatNumber(data.treasuresMined)} Treasures Mined")
addString("§3${formatNumber(estimatedIce)} Total Ice")
addString("§3${formatNumber(icePerHour)} Ice/hr")
addString("§8${formatNumber(data.compactProcs)} Compact Procs")
addString("")
addSearchString("§e§lFrozen Treasure Tracker")
addSearchString("§6${formatNumber(data.treasuresMined)} Treasures Mined")
addSearchString("§3${formatNumber(estimatedIce)} Total Ice")
addSearchString("§3${formatNumber(icePerHour)} Ice/hr")
addSearchString("§8${formatNumber(data.compactProcs)} Compact Procs")
addSearchString("")

for (treasure in FrozenTreasure.entries) {
val count = (data.treasureCount[treasure] ?: 0) * if (config.showAsDrops) treasure.defaultAmount else 1
addString("§b${formatNumber(count)} ${treasure.displayName}")
addSearchString("§b${formatNumber(count)} ${treasure.displayName}", treasure.displayName)
}
addString("")
addSearchString("")
}

fun formatNumber(amount: Number): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import at.hannibal2.skyhanni.features.fishing.FishingAPI
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.test.command.ErrorManager
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.CollectionUtils.addButton
import at.hannibal2.skyhanni.utils.CollectionUtils.addString
import at.hannibal2.skyhanni.utils.CollectionUtils.addSearchString
import at.hannibal2.skyhanni.utils.DelayedRun
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NEUInternalName
Expand All @@ -26,6 +25,9 @@ import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.StringUtils
import at.hannibal2.skyhanni.utils.renderables.Renderable
import at.hannibal2.skyhanni.utils.renderables.RenderableUtils.addButton
import at.hannibal2.skyhanni.utils.renderables.Searchable
import at.hannibal2.skyhanni.utils.renderables.toSearchable
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import at.hannibal2.skyhanni.utils.tracker.ItemTrackerData
import at.hannibal2.skyhanni.utils.tracker.SkyHanniItemTracker
Expand Down Expand Up @@ -119,8 +121,8 @@ object FishingProfitTracker {
return map
}

private fun drawDisplay(data: Data): List<Renderable> = buildList {
addString("§e§lFishing Profit Tracker")
private fun drawDisplay(data: Data): List<Searchable> = buildList {
addSearchString("§e§lFishing Profit Tracker")
val filter: (NEUInternalName) -> Boolean = addCategories(data)

val profit = tracker.drawItems(data, filter, this)
Expand All @@ -130,15 +132,15 @@ object FishingProfitTracker {
Renderable.hoverTips(
"§7Times fished: §e${fishedCount.addSeparators()}",
listOf("§7You've reeled in §e${fishedCount.addSeparators()} §7catches."),
),
).toSearchable(),
)

add(tracker.addTotalProfit(profit, data.totalCatchAmount, "catch"))

tracker.addPriceFromButton(this)
}

private fun MutableList<Renderable>.addCategories(data: Data): (NEUInternalName) -> Boolean {
private fun MutableList<Searchable>.addCategories(data: Data): (NEUInternalName) -> Boolean {
val amounts = getCurrentCategories(data)
checkMissingItems(data)
val list = amounts.keys.toList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import at.hannibal2.skyhanni.features.fishing.FishingAPI
import at.hannibal2.skyhanni.features.fishing.SeaCreatureManager
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.test.command.ErrorManager
import at.hannibal2.skyhanni.utils.CollectionUtils.addButton
import at.hannibal2.skyhanni.utils.CollectionUtils.addOrPut
import at.hannibal2.skyhanni.utils.CollectionUtils.addString
import at.hannibal2.skyhanni.utils.CollectionUtils.addSearchString
import at.hannibal2.skyhanni.utils.CollectionUtils.sumAllValues
import at.hannibal2.skyhanni.utils.ConditionalUtils
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.StringUtils.allLettersFirstUppercase
import at.hannibal2.skyhanni.utils.renderables.Renderable
import at.hannibal2.skyhanni.utils.renderables.RenderableUtils.addButton
import at.hannibal2.skyhanni.utils.renderables.Searchable
import at.hannibal2.skyhanni.utils.tracker.SkyHanniTracker
import at.hannibal2.skyhanni.utils.tracker.TrackerData
import com.google.gson.annotations.Expose
Expand Down Expand Up @@ -71,8 +71,8 @@ object SeaCreatureTracker {
return map
}

private fun drawDisplay(data: Data): List<Renderable> = buildList {
addString("§7Sea Creature Tracker:")
private fun drawDisplay(data: Data): List<Searchable> = buildList {
addSearchString("§7Sea Creature Tracker:")

val filter: (String) -> Boolean = addCategories(data)
val realAmount = data.amount.filter { filter(it.key) }
Expand All @@ -94,12 +94,12 @@ object SeaCreatureTracker {
" §7$percentage"
} else ""

addString(" §7- §e${amount.addSeparators()} $displayName$percentageSuffix")
addSearchString(" §7- §e${amount.addSeparators()} $displayName$percentageSuffix", displayName)
}
addString(" §7- §e${total.addSeparators()} §7Total Sea Creatures")
addSearchString(" §7- §e${total.addSeparators()} §7Total Sea Creatures")
}

private fun MutableList<Renderable>.addCategories(data: Data): (String) -> Boolean {
private fun MutableList<Searchable>.addCategories(data: Data): (String) -> Boolean {
val amounts = getCurrentCategories(data)
val list = amounts.keys.toList()
if (currentCategory !in list) {
Expand Down
Loading

0 comments on commit 18da4a7

Please sign in to comment.