Skip to content

Commit

Permalink
fixed tunnelMaps values not clearing on lobby swap
Browse files Browse the repository at this point in the history
  • Loading branch information
Thunderblade73 committed Jul 30, 2024
1 parent 47c0590 commit f20e1fd
Showing 1 changed file with 80 additions and 45 deletions.
125 changes: 80 additions & 45 deletions src/main/java/at/hannibal2/skyhanni/features/mining/TunnelsMaps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import at.hannibal2.skyhanni.events.ConfigLoadEvent
import at.hannibal2.skyhanni.events.GuiContainerEvent
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
import at.hannibal2.skyhanni.events.IslandChangeEvent
import at.hannibal2.skyhanni.events.ItemClickEvent
import at.hannibal2.skyhanni.events.LorenzKeyPressEvent
import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent
Expand Down Expand Up @@ -110,13 +111,13 @@ object TunnelsMaps {
}

private val oldGemstonePattern by RepoPattern.pattern(
"mining.tunnels.maps.gem.old", ".*(?:Ruby|Amethyst|Jade|Sapphire|Amber|Topaz).*"
"mining.tunnels.maps.gem.old", ".*(?:Ruby|Amethyst|Jade|Sapphire|Amber|Topaz).*",
)
private val newGemstonePattern by RepoPattern.pattern(
"mining.tunnels.maps.gem.new", ".*(?:Aquamarine|Onyx|Citrine|Peridot).*"
"mining.tunnels.maps.gem.new", ".*(?:Aquamarine|Onyx|Citrine|Peridot).*",
)
private val commissionInvPattern by RepoPattern.pattern(
"mining.commission.inventory", "Commissions"
"mining.commission.inventory", "Commissions",
)

/**
Expand All @@ -125,19 +126,19 @@ object TunnelsMaps {
*/
private val glacitePattern by RepoPattern.pattern(
"mining.commisson.reward.glacite",
"§7- §b[\\d,]+ Glacite Powder"
"§7- §b[\\d,]+ Glacite Powder",
)
private val collectorCommissionPattern by RepoPattern.pattern(
"mining.commisson.collector",
"§9(?<what>\\w+(?: \\w+)?) Collector"
"§9(?<what>\\w+(?: \\w+)?) Collector",
)
private val invalidGoalPattern by RepoPattern.pattern(
"mining.commisson.collector.invalid",
"Glacite|Scrap"
"Glacite|Scrap",
)
private val completedPattern by RepoPattern.pattern(
"mining.commisson.completed",
"§a§lCOMPLETED"
"§a§lCOMPLETED",
)

private val translateTable = mutableMapOf<String, String>()
Expand Down Expand Up @@ -170,7 +171,7 @@ object TunnelsMaps {
"Unknown Collection Commission: $type", "$type can't be found in the graph.",
"type" to type,
"graphNames" to possibleLocations.keys,
"lore" to lore
"lore" to lore,
)
null
} else {
Expand Down Expand Up @@ -234,7 +235,7 @@ object TunnelsMaps {
fun onConfigLoad(event: ConfigLoadEvent) {
onToggle(
config.compactGemstone,
config.excludeFairy
config.excludeFairy,
) {
locationDisplay = generateLocationsDisplay()
}
Expand All @@ -247,21 +248,31 @@ object TunnelsMaps {
if (active.isNotEmpty()) {
if (goal == campfire && active != campfire.name) {
add(Renderable.string("§6Override for ${campfire.name}"))
add(Renderable.clickable(Renderable.string("§eMake §f$active §eactive"), onClick = {
goal = getNext()
}))
add(
Renderable.clickable(
Renderable.string("§eMake §f$active §eactive"),
onClick = {
goal = getNext()
},
),
)
} else {
add(
Renderable.clickAndHover(
Renderable.string("§6Active: §f$active"),
listOf("§eClick to disable current Waypoint"),
onClick = ::clearPath
)
onClick = ::clearPath,
),
)
if (hasNext()) {
add(Renderable.clickable(Renderable.string("§eNext Spot"), onClick = {
goal = getNext()
}))
add(
Renderable.clickable(
Renderable.string("§eNext Spot"),
onClick = {
goal = getNext()
},
),
)
} else {
add(Renderable.string(""))
}
Expand All @@ -279,45 +290,61 @@ object TunnelsMaps {
add(Renderable.string("§6Locations:"))
add(
Renderable.multiClickAndHover(
campfire.name!!, listOf(
"§eLeft Click to set active", "§eRight Click for override"
), click = mapOf(
0 to guiSetActive(campfire.name!!), 1 to ::campfireOverride
)
)
campfire.name!!,
listOf(
"§eLeft Click to set active", "§eRight Click for override",
),
click = mapOf(
0 to guiSetActive(campfire.name!!), 1 to ::campfireOverride,
),
),
)
if (!config.excludeFairy.get()) {
add(Renderable.hoverable(Renderable.horizontalContainer(listOf(Renderable.string("§dFairy Souls")) + fairySouls.map {
val name = it.key.removePrefix("§dFairy Soul ")
Renderable.clickable(Renderable.string("§d[${name}]"), onClick = guiSetActive(it.key))
}), Renderable.string("§dFairy Souls")))
add(
Renderable.hoverable(
Renderable.horizontalContainer(
listOf(Renderable.string("§dFairy Souls")) + fairySouls.map {
val name = it.key.removePrefix("§dFairy Soul ")
Renderable.clickable(Renderable.string("§d[${name}]"), onClick = guiSetActive(it.key))
},
),
Renderable.string("§dFairy Souls"),
),
)
}
if (config.compactGemstone.get()) {
add(
Renderable.table(
listOf(
newGemstones.map(::toCompactGemstoneName), oldGemstones.map(::toCompactGemstoneName)
)
)
newGemstones.map(::toCompactGemstoneName), oldGemstones.map(::toCompactGemstoneName),
),
),
)
} else {
addAll(newGemstones.map {
Renderable.clickable(Renderable.string(it.key), onClick = guiSetActive(it.key))
})
addAll(oldGemstones.map {
Renderable.clickable(Renderable.string(it.key), onClick = guiSetActive(it.key))
})
addAll(
newGemstones.map {
Renderable.clickable(Renderable.string(it.key), onClick = guiSetActive(it.key))
},
)
addAll(
oldGemstones.map {
Renderable.clickable(Renderable.string(it.key), onClick = guiSetActive(it.key))
},
)
}
addAll(normalLocations.map {
Renderable.clickable(Renderable.string(it.key), onClick = guiSetActive(it.key))
})
addAll(
normalLocations.map {
Renderable.clickable(Renderable.string(it.key), onClick = guiSetActive(it.key))
},
)
}

private fun toCompactGemstoneName(it: Map.Entry<String, List<GraphNode>>): Renderable = Renderable.clickAndHover(
Renderable.string((it.key.getFirstColorCode()?.let { "§$it" } ?: "") + ("ROUGH_".plus(
it.key.removeColor().removeSuffix("stone")
).asInternalName().itemName.takeWhile { it != ' ' }.removeColor()),
horizontalAlign = RenderUtils.HorizontalAlignment.CENTER
Renderable.string(
(it.key.getFirstColorCode()?.let { "§$it" } ?: "") + ("ROUGH_".plus(
it.key.removeColor().removeSuffix("stone"),
).asInternalName().itemName.takeWhile { it != ' ' }.removeColor()),
horizontalAlign = RenderUtils.HorizontalAlignment.CENTER,
),
tips = listOf(it.key),
onClick = guiSetActive(it.key),
Expand Down Expand Up @@ -400,7 +427,7 @@ object TunnelsMaps {
config.pathWidth.toInt(),
true,
bezierPoint = 2.0,
textSize = config.textSize.toDouble()
textSize = config.textSize.toDouble(),
)
event.drawDynamicText(
if (config.distanceFirst) {
Expand All @@ -410,7 +437,7 @@ object TunnelsMaps {
}.position,
"§e${path.second.roundToInt()}m",
config.textSize.toDouble(),
yOff = 10f
yOff = 10f,
)
}

Expand Down Expand Up @@ -455,6 +482,14 @@ object TunnelsMaps {
}
}

@SubscribeEvent
fun onIslandChange(event: IslandChangeEvent) {
if (closedNote == null) return // Value that must be none null if it was active
closedNote = null
clearPath()
cooldowns.clear()
}

private var nextSpotDelay = SimpleTimeMark.farPast()

private fun nextSpotKey(event: LorenzKeyPressEvent) {
Expand Down

0 comments on commit f20e1fd

Please sign in to comment.