Skip to content

Commit

Permalink
added more node bug detections
Browse files Browse the repository at this point in the history
  • Loading branch information
hannibal002 committed Sep 18, 2024
1 parent 92ff621 commit 7ae9220
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 17 deletions.
10 changes: 5 additions & 5 deletions src/main/java/at/hannibal2/skyhanni/data/model/Graph.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -80,8 +80,8 @@ value class Graph(
reader.beginObject()
var position: LorenzVec? = null
var name: String? = null
var tags: List<String>? = null
var neighbors = mutableListOf<Pair<Int, Double>>()
var tags = emptyList<String>()
val neighbors = mutableListOf<Pair<Int, Double>>()
while (reader.hasNext()) {
if (reader.peek() != JsonToken.NAME) {
reader.skipValue()
Expand Down Expand Up @@ -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<String>? = null) {
class GraphNode(val id: Int, val position: LorenzVec, val name: String? = null, val tagNames: List<String> = emptyList()) {

val tags: List<GraphNodeTag> 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) */
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/at/hannibal2/skyhanni/test/GraphEditor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
)
},
)
Expand Down
48 changes: 37 additions & 11 deletions src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -176,29 +177,54 @@ object SkyHanniDebugsAndTests {

private fun asyncTest() {
val graph = IslandGraphs.currentIslandGraph ?: return
val displayMap = mutableMapOf<LorenzVec, String>()
val names = mutableMapOf<GraphNode, String>()
val nodesWithErrors = mutableMapOf<LorenzVec, String>()
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<GraphNode, String>()
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<String>) {
Expand Down

0 comments on commit 7ae9220

Please sign in to comment.