From 81aebf952893555a48441c4ac5516ac869741bb0 Mon Sep 17 00:00:00 2001 From: Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com> Date: Thu, 5 Sep 2024 10:34:44 +0200 Subject: Backend: Graph Editor Split & Dissolve (#2466) --- src/main/java/at/hannibal2/skyhanni/data/model/Graph.kt | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/data/model') 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 89fd413f5..21440197d 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/model/Graph.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/model/Graph.kt @@ -7,12 +7,12 @@ import at.hannibal2.skyhanni.utils.json.fromJson import com.google.gson.GsonBuilder import com.google.gson.JsonElement import com.google.gson.annotations.Expose +import com.google.gson.stream.JsonToken import java.util.PriorityQueue @JvmInline value class Graph( - @Expose - val graph: List, + @Expose val graph: List, ) : List { override val size get() = graph.size @@ -82,6 +82,10 @@ value class Graph( var tags: List? = null var neighbors = mutableListOf>() while (reader.hasNext()) { + if (reader.peek() != JsonToken.NAME) { + reader.skipValue() + continue + } when (reader.nextName()) { "Position" -> { position = reader.nextString().split(":").let { parts -> @@ -157,8 +161,7 @@ class GraphNode(val id: Int, val position: LorenzVec, val name: String? = null, } } -fun Graph.findShortestPathAsGraph(start: GraphNode, end: GraphNode): Graph = - this.findShortestPathAsGraphWithDistance(start, end).first +fun Graph.findShortestPathAsGraph(start: GraphNode, end: GraphNode): Graph = this.findShortestPathAsGraphWithDistance(start, end).first fun Graph.findShortestPathAsGraphWithDistance(start: GraphNode, end: GraphNode): Pair { val distances = mutableMapOf() @@ -199,11 +202,9 @@ fun Graph.findShortestPathAsGraphWithDistance(start: GraphNode, end: GraphNode): ) to distances[end]!! } -fun Graph.findShortestPath(start: GraphNode, end: GraphNode): List = - this.findShortestPathAsGraph(start, end).toPositionsList() +fun Graph.findShortestPath(start: GraphNode, end: GraphNode): List = this.findShortestPathAsGraph(start, end).toPositionsList() -fun Graph.findShortestDistance(start: GraphNode, end: GraphNode): Double = - this.findShortestPathAsGraphWithDistance(start, end).second +fun Graph.findShortestDistance(start: GraphNode, end: GraphNode): Double = this.findShortestPathAsGraphWithDistance(start, end).second fun Graph.toPositionsList() = this.map { it.position } -- cgit