Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend: Migrate Plhlegblast #2684

Merged
merged 1 commit into from
Oct 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.ConfigLoadEvent
import at.hannibal2.skyhanni.events.FishingBobberCastEvent
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.ProfileJoinEvent
import at.hannibal2.skyhanni.events.SeaCreatureFishEvent
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.ChatUtils
import at.hannibal2.skyhanni.utils.CollectionUtils.addOrPut
import at.hannibal2.skyhanni.utils.CollectionUtils.addSearchString
import at.hannibal2.skyhanni.utils.CollectionUtils.sumAllValues
Expand All @@ -25,6 +27,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

@SkyHanniModule
object SeaCreatureTracker {
private var needMigration = true

private val config get() = SkyHanniMod.feature.fishing.seaCreatureTracker

Expand Down Expand Up @@ -72,7 +75,15 @@ object SeaCreatureTracker {
return map
}

@SubscribeEvent
fun onProfileJoin(event: ProfileJoinEvent) {
needMigration = true
}

private fun drawDisplay(data: Data): List<Searchable> = buildList {
// manually migrating from "Phlhlegblast" to "Plhlegblast" when the new name is in the repo
tryToMigrate(data.amount)

addSearchString("§7Sea Creature Tracker:")

val filter: (String) -> Boolean = addCategories(data)
Expand All @@ -85,7 +96,7 @@ object SeaCreatureTracker {
"Sea Creature Tracker can not display a name correctly",
"Could not find sea creature by name",
"SeaCreatureManager.allFishingMobs.keys" to SeaCreatureManager.allFishingMobs.keys,
"name" to name
"name" to name,
)
name
}
Expand All @@ -100,6 +111,25 @@ object SeaCreatureTracker {
addSearchString(" §7- §e${total.addSeparators()} §7Total Sea Creatures")
}

private fun tryToMigrate(
data: MutableMap<String, Int>,
) {
if (!needMigration) return
needMigration = false

val oldName = "Phlhlegblast"
val newName = "Plhlegblast"

// only migrate once the repo contains the new name
if (SeaCreatureManager.allFishingMobs.containsKey(newName)) {
data[oldName]?.let {
ChatUtils.debug("Sea Creature Tracker migrated $it $oldName to $newName")
data[newName] = it
data.remove(oldName)
}
}
}

private fun MutableList<Searchable>.addCategories(data: Data): (String) -> Boolean {
val amounts = getCurrentCategories(data)
val list = amounts.keys.toList()
Expand All @@ -115,7 +145,7 @@ object SeaCreatureTracker {
val id = list.indexOf(currentCategory)
currentCategory = list[(id + 1) % list.size]
tracker.update()
}
},
)
}

Expand Down Expand Up @@ -161,6 +191,5 @@ object SeaCreatureTracker {
tracker.resetCommand()
}

private fun isEnabled() =
LorenzUtils.inSkyBlock && config.enabled && !FishingAPI.wearingTrophyArmor && !LorenzUtils.inKuudraFight
private fun isEnabled() = LorenzUtils.inSkyBlock && config.enabled && !FishingAPI.wearingTrophyArmor && !LorenzUtils.inKuudraFight
}
Loading