aboutsummaryrefslogtreecommitdiff
path: root/Map/Presentation/Complex Components/MapRender/MapRenderView.swift
diff options
context:
space:
mode:
Diffstat (limited to 'Map/Presentation/Complex Components/MapRender/MapRenderView.swift')
-rw-r--r--Map/Presentation/Complex Components/MapRender/MapRenderView.swift45
1 files changed, 18 insertions, 27 deletions
diff --git a/Map/Presentation/Complex Components/MapRender/MapRenderView.swift b/Map/Presentation/Complex Components/MapRender/MapRenderView.swift
index ce95813..ba525ad 100644
--- a/Map/Presentation/Complex Components/MapRender/MapRenderView.swift
+++ b/Map/Presentation/Complex Components/MapRender/MapRenderView.swift
@@ -16,13 +16,13 @@ import Combine
import CoreData
import CoreGraphics
import SwiftUI
+import WmapParser
struct MapRenderView: View {
- var entities: [Wmap.Entity]
+ var parsedMap: WmapParser.Map
@Binding var evolution: StageType
- @State private var lastEntityHash: Int = 0
@AppStorage("showMapBackground") var showMapBackground: Bool = UserPreferences.Defaults
.showMapBackground
@AppStorage("useCustomFont") var useCustomFont: Bool = UserPreferences.Defaults.useCustomFont
@@ -34,7 +34,7 @@ struct MapRenderView: View {
Stage.stages(evolution)
}
- @State private var parsedMap: RenderableMap = RenderableMap.empty
+ @State private var renderableMap: RenderableMap = .empty
@State private var smartLabelPositions: [Int: CGPoint] = [:]
@State private var parseTask: Task<Void, Never>?
@@ -49,11 +49,10 @@ struct MapRenderView: View {
private func convertEntitiesInBackground() {
parseTask?.cancel()
- let currentEntities = entities
parseTask = Task {
let parsed = await Task.detached(priority: .userInitiated) {
- RenderableMap.from(currentEntities)
+ RenderableMap.from(parsedMap)
}.value
let positions = await Task.detached(priority: .userInitiated) {
@@ -87,7 +86,7 @@ struct MapRenderView: View {
if !Task.isCancelled {
await MainActor.run {
- parsedMap = parsed
+ renderableMap = parsed
smartLabelPositions = positions
}
}
@@ -107,37 +106,37 @@ struct MapRenderView: View {
// The order Matters. Think of this as layers.
if showMapBackground {
- MapBackground(mapSize: mapSize, lineWidth: lineWidth, stages: parsedMap.stages)
+ MapBackground(mapSize: mapSize, stages: renderableMap.stages)
}
MapAxes(
- mapSize: mapSize, lineWidth: lineWidth, evolution: stage, stages: parsedMap.stages)
+ mapSize: mapSize, lineWidth: lineWidth, evolution: stage, stages: renderableMap.stages)
Group {
- MapStages(mapSize: mapSize, lineWidth: lineWidth, stages: parsedMap.stages)
+ MapStages(mapSize: mapSize, lineWidth: lineWidth, stages: renderableMap.stages)
MapEdges(
- mapSize: mapSize, lineWidth: lineWidth, vertexSize: vertexSize, edges: parsedMap.edges)
+ mapSize: mapSize, lineWidth: lineWidth, vertexSize: vertexSize, edges: renderableMap.edges)
MapOpportunities(
mapSize: mapSize, lineWidth: lineWidth, vertexSize: vertexSize,
- opportunities: parsedMap.opportunities)
- MapIntertias(mapSize: mapSize, vertexSize: vertexSize, inertias: parsedMap.inertias)
+ opportunities: renderableMap.opportunities)
+ MapIntertias(mapSize: mapSize, vertexSize: vertexSize, inertias: renderableMap.inertias)
}.mask {
MapMask(
- mapSize: mapSize, vertexSize: vertexSize, vertices: parsedMap.vertices,
+ mapSize: mapSize, vertexSize: vertexSize, vertices: renderableMap.vertices,
labelPositions: smartLabelPositions)
}
MapVertices(
- mapSize: mapSize, vertexSize: vertexSize, vertices: parsedMap.vertices,
+ mapSize: mapSize, vertexSize: vertexSize, vertices: renderableMap.vertices,
labelPositions: smartLabelPositions, onDragVertex: onDragVertex)
if #available(macOS 26.0, *) {
- MapGroups(mapSize: mapSize, vertexSize: vertexSize, groups: parsedMap.groups)
+ MapGroups(mapSize: mapSize, vertexSize: vertexSize, groups: renderableMap.groups)
.drawingGroup()
.opacity(0.1)
} else {
- MapGroups(mapSize: mapSize, vertexSize: vertexSize, groups: parsedMap.groups).drawingGroup(
+ MapGroups(mapSize: mapSize, vertexSize: vertexSize, groups: renderableMap.groups).drawingGroup(
opaque: true
).opacity(0.1)
}
MapNotes(
- mapSize: mapSize, lineWidth: lineWidth, notes: parsedMap.notes)
+ mapSize: mapSize, lineWidth: lineWidth, notes: renderableMap.notes)
}
.id("\(useCustomFont)-\(customFontName)")
.offset(x: padding, y: padding).frame(
@@ -147,7 +146,7 @@ struct MapRenderView: View {
.onAppear {
convertEntitiesInBackground()
}
- .onChange(of: entities) { _, _ in
+ .onChange(of: parsedMap) { _, _ in
convertEntitiesInBackground()
}
.onChange(of: useSmartLabelPositioning) {
@@ -157,19 +156,11 @@ struct MapRenderView: View {
parseTask?.cancel()
}
}
-
- func h(_ dimension: CGFloat) -> CGFloat {
- max(0.0, min(mapSize.height, dimension * mapSize.height / 100.0))
- }
-
- func w(_ dimension: CGFloat) -> CGFloat {
- max(0.0, min(mapSize.width, dimension * mapSize.width / 100.0))
- }
}
#Preview {
MapRenderView(
- entities: [],
+ parsedMap: WmapParser.parse(""),
evolution: Binding.constant(StageType.general)
)
}