diff options
| author | Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com> | 2024-09-05 10:34:44 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-05 10:34:44 +0200 |
| commit | 81aebf952893555a48441c4ac5516ac869741bb0 (patch) | |
| tree | b0fd7bd1ee9116f6472ea48b6e7695e82b1f4b72 /src/main/java/at/hannibal2/skyhanni/data | |
| parent | 6dae2df502995679bbd7742ac919d9ee467db9d8 (diff) | |
| download | skyhanni-81aebf952893555a48441c4ac5516ac869741bb0.tar.gz skyhanni-81aebf952893555a48441c4ac5516ac869741bb0.tar.bz2 skyhanni-81aebf952893555a48441c4ac5516ac869741bb0.zip | |
Backend: Graph Editor Split & Dissolve (#2466)
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/data')
| -rw-r--r-- | src/main/java/at/hannibal2/skyhanni/data/model/Graph.kt | 17 |
1 files changed, 9 insertions, 8 deletions
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<GraphNode>, + @Expose val graph: List<GraphNode>, ) : List<GraphNode> { override val size get() = graph.size @@ -82,6 +82,10 @@ value class Graph( var tags: List<String>? = null var neighbors = mutableListOf<Pair<Int, Double>>() 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<Graph, Double> { val distances = mutableMapOf<GraphNode, Double>() @@ -199,11 +202,9 @@ fun Graph.findShortestPathAsGraphWithDistance(start: GraphNode, end: GraphNode): ) to distances[end]!! } -fun Graph.findShortestPath(start: GraphNode, end: GraphNode): List<LorenzVec> = - this.findShortestPathAsGraph(start, end).toPositionsList() +fun Graph.findShortestPath(start: GraphNode, end: GraphNode): List<LorenzVec> = 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 } |
