From f4419b8c77926fd160a04e5b888864e91ee17b0d Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Sat, 28 Sep 2024 21:38:11 +0200 Subject: abstracted navigation rerouting (#2597) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../at/hannibal2/skyhanni/features/misc/IslandAreas.kt | 18 +++++++++--------- .../features/misc/pathfind/NavigationHelper.kt | 8 +++++--- 2 files changed, 14 insertions(+), 12 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/features/misc') diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/IslandAreas.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/IslandAreas.kt index 5ece5897c..cddbd201d 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/IslandAreas.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/IslandAreas.kt @@ -2,6 +2,7 @@ package at.hannibal2.skyhanni.features.misc import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.data.IslandGraphs +import at.hannibal2.skyhanni.data.IslandGraphs.pathFind import at.hannibal2.skyhanni.data.model.Graph import at.hannibal2.skyhanni.data.model.GraphNode import at.hannibal2.skyhanni.data.model.GraphNodeTag @@ -13,7 +14,6 @@ import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule -import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.CollectionUtils.addSearchString import at.hannibal2.skyhanni.utils.CollectionUtils.sorted import at.hannibal2.skyhanni.utils.ColorUtils.toChromaColor @@ -81,7 +81,7 @@ object IslandAreas { nodes = finalNodes } - var hasMoved = false + private var hasMoved = false @SubscribeEvent fun onTick(event: LorenzTickEvent) { @@ -144,11 +144,6 @@ object IslandAreas { val isTarget = node.name == targetNode?.name val color = if (isTarget) LorenzColor.GOLD else tag.color - // trying to find a faster path to the existing target - if (isTarget && node != targetNode) { - ChatUtils.debug("Found a faster node, rerouting...") - setTarget(node) - } val coloredName = "${color.getChatColor()}${name}" var suffix = "" @@ -159,6 +154,7 @@ object IslandAreas { passedAreas.remove("null") passedAreas.remove(currentAreaName) // so show areas needed to pass thorough + // TODO show this pass through in the /shnavigate command if (passedAreas.isNotEmpty()) { // suffix = " §7${passedAreas.joinToString(", ")}" } @@ -268,9 +264,13 @@ object IslandAreas { private fun setTarget(node: GraphNode) { targetNode = node + val tag = node.getAreaTag() ?: return + val displayName = tag.color.getChatColor() + node.name val color = config.pathfinder.color.get().toChromaColor() - IslandGraphs.pathFind( - node.position, color, + node.pathFind( + displayName, + color, + allowRerouting = true, onFound = { targetNode = null updatePosition() diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/pathfind/NavigationHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/pathfind/NavigationHelper.kt index e753948bc..48719e63e 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/pathfind/NavigationHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/pathfind/NavigationHelper.kt @@ -2,11 +2,12 @@ package at.hannibal2.skyhanni.features.misc.pathfind import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.data.IslandGraphs +import at.hannibal2.skyhanni.data.IslandGraphs.pathFind import at.hannibal2.skyhanni.data.model.GraphNode import at.hannibal2.skyhanni.data.model.GraphNodeTag -import at.hannibal2.skyhanni.data.model.findShortestDistance import at.hannibal2.skyhanni.features.misc.IslandAreas import at.hannibal2.skyhanni.utils.CollectionUtils.sorted +import at.hannibal2.skyhanni.utils.GraphUtils import at.hannibal2.skyhanni.utils.NumberUtil.roundTo import at.hannibal2.skyhanni.utils.chat.Text import at.hannibal2.skyhanni.utils.chat.Text.asComponent @@ -57,7 +58,8 @@ object NavigationHelper { val distance = distances[node]!!.roundTo(1) val component = "$name §e$distance".asComponent() component.onClick { - IslandGraphs.pathFind(node.position) +// node.pathFind(label = node.name!!, allowRerouting = true) + node.pathFind(label = name, allowRerouting = true) sendNavigateMessage(name, goBack) } val tag = node.tags.first { it in allowedTags } @@ -102,7 +104,7 @@ object NavigationHelper { val remainingTags = node.tags.filter { it in allowedTags } if (remainingTags.isEmpty()) continue if (name.lowercase().contains(searchTerm)) { - distances[node] = graph.findShortestDistance(closedNote, node) + distances[node] = GraphUtils.findShortestDistance(closedNote, node) } if (remainingTags.size != 1) { println("found node with invalid amount of tags: ${node.name} (${remainingTags.map { it.cleanName }}") -- cgit