diff --git a/src/main/java/at/hannibal2/skyhanni/data/model/Graph.kt b/src/main/java/at/hannibal2/skyhanni/data/model/Graph.kt index 56d491912844..b9ad1251ca8c 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/model/Graph.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/model/Graph.kt @@ -50,7 +50,7 @@ value class Graph( out.name("Name").value(it) } - it.tagNames?.takeIf { it.isNotEmpty() }?.let { + it.tagNames.takeIf { list -> list.isNotEmpty() }?.let { out.name("Tags") out.beginArray() for (tagName in it) { @@ -80,8 +80,8 @@ value class Graph( reader.beginObject() var position: LorenzVec? = null var name: String? = null - var tags: List? = null - var neighbors = mutableListOf>() + var tags = emptyList() + val neighbors = mutableListOf>() while (reader.hasNext()) { if (reader.peek() != JsonToken.NAME) { reader.skipValue() @@ -141,10 +141,10 @@ value class Graph( } // The node object that gets parsed from/to json -class GraphNode(val id: Int, val position: LorenzVec, val name: String? = null, val tagNames: List? = null) { +class GraphNode(val id: Int, val position: LorenzVec, val name: String? = null, val tagNames: List = emptyList()) { val tags: List by lazy { - tagNames?.mapNotNull { GraphNodeTag.byId(it) } ?: emptyList() + tagNames.mapNotNull { GraphNodeTag.byId(it) } } /** Keys are the neighbours and value the edge weight (e.g. Distance) */ diff --git a/src/main/java/at/hannibal2/skyhanni/test/GraphEditor.kt b/src/main/java/at/hannibal2/skyhanni/test/GraphEditor.kt index db1f082410ff..16c350b14f31 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/GraphEditor.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/GraphEditor.kt @@ -524,7 +524,7 @@ object GraphEditor { it.id, it.position, it.name, - it.tagNames?.mapNotNull { GraphNodeTag.byId(it) }?.toMutableList() ?: mutableListOf(), + it.tagNames.mapNotNull { tag -> GraphNodeTag.byId(tag) }.toMutableList(), ) }, ) diff --git a/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt b/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt index a6bb07d82636..7aea494acb14 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt @@ -72,6 +72,7 @@ import net.minecraft.item.ItemStack import net.minecraft.nbt.NBTTagCompound import net.minecraftforge.common.MinecraftForge import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.awt.Color import java.io.File import kotlin.time.Duration.Companion.seconds @@ -176,29 +177,54 @@ object SkyHanniDebugsAndTests { private fun asyncTest() { val graph = IslandGraphs.currentIslandGraph ?: return - val displayMap = mutableMapOf() - val names = mutableMapOf() + val nodesWithErrors = mutableMapOf() val nodes = graph.nodes + + for (node in nodes) { + node.name?.let { + if (node.tagNames.isEmpty()) { + nodesWithErrors[node.position] = "§cHas name and no tag!" + println("has name and no tag: $it") + } + } + if (node.tagNames.isNotEmpty()) { + if (node.name == null) { + nodesWithErrors[node.position] = "§cHas a tag and no name!" + println("Has a tag and no name: ${node.tagNames}") + } + } + } + + val nameOfClosestArea = mutableMapOf() for ((index, node) in nodes.withIndex()) { val map = GraphUtils.findFastestPath(graph, node) { it.getAreaTag() != null } val first = map?.first?.lastOrNull() val name = first?.name ?: "§cnone" - names[node] = name + nameOfClosestArea[node] = name } - - var bugs = 0 - for ((node, name) in names) { + for ((node, name) in nameOfClosestArea) { for ((other, distance) in node.neighbours) { if (other.getAreaTag() != null) continue - if (names[other] != name) { - displayMap[node.position] = "§cArea error!" - bugs++ + if (nameOfClosestArea[other] != name) { + val otherName = other.name + val thisName = node.name + if (node.position !in nodesWithErrors) { + nodesWithErrors[node.position] = "§cArea error! ('$thisName' != '$otherName')" + } } } } - println("found $bugs bugs!") - displayOnWorld = displayMap + + var hasUsedPathfind = false + for ((location, text) in nodesWithErrors) { + if (!hasUsedPathfind) { + hasUsedPathfind = true + IslandGraphs.pathFind(location, Color.RED) + } + } + println("found ${nodesWithErrors.size} bugs!") + displayOnWorld = nodesWithErrors } fun findNullConfig(args: Array) {