diff options
| author | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-07-09 08:43:04 +0200 |
|---|---|---|
| committer | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-07-09 08:43:04 +0200 |
| commit | 1e89ea22d551cebfd6c0c0451000c3283ddb2d2e (patch) | |
| tree | 77afac88484877fbea5fecd1ddda85741584c6c5 /Map/Presentation | |
| parent | 1ec7f2c6deb64f5b13b32fae2bf74ae2d8aaaabb (diff) | |
Get rid of old map parser
Diffstat (limited to 'Map/Presentation')
| -rw-r--r-- | Map/Presentation/Complex Components/MapRender/MapRenderView.swift | 136 |
1 files changed, 2 insertions, 134 deletions
diff --git a/Map/Presentation/Complex Components/MapRender/MapRenderView.swift b/Map/Presentation/Complex Components/MapRender/MapRenderView.swift index 08d1d61..fe98ace 100644 --- a/Map/Presentation/Complex Components/MapRender/MapRenderView.swift +++ b/Map/Presentation/Complex Components/MapRender/MapRenderView.swift @@ -34,7 +34,7 @@ struct MapRenderView: View { Stage.stages(evolution) } - @State private var parsedMap: ParsedMap = ParsedMap.empty + @State private var parsedMap: RenderableMap = RenderableMap.empty @State private var smartLabelPositions: [Int: CGPoint] = [:] @State private var parseTask: Task<Void, Never>? @@ -53,7 +53,7 @@ struct MapRenderView: View { parseTask = Task { let parsed = await Task.detached(priority: .userInitiated) { - convertEntitiesToParsedMap(currentEntities) + RenderableMap.from(currentEntities) }.value let positions = await Task.detached(priority: .userInitiated) { @@ -94,138 +94,6 @@ struct MapRenderView: View { } } - private nonisolated func convertEntitiesToParsedMap(_ entities: [Wmap.Entity]) -> ParsedMap { - var vertices: [Vertex] = [] - var edges: [MapEdge] = [] - var inertias: [Inertia] = [] - var opportunities: [Opportunity] = [] - var notes: [Note] = [] - var stages: [CGFloat] = [25.0, 50.0, 75.0] // default dimensions - var groups: [[Vertex]] = [] - - // Build a vertex lookup for edges, groups, etc. - var vertexMap: [String: Vertex] = [:] - var vertexIdCounter = 0 - - for entity in entities { - switch entity { - case .vertex(let vertex): - let newVertex = Vertex( - id: vertexIdCounter, - label: vertex.label, - position: CGPoint(x: vertex.coordinates.0, y: vertex.coordinates.1), - shape: convertShape(vertex.shape) - ) - vertices.append(newVertex) - vertexMap[vertex.label] = newVertex - vertexIdCounter += 1 - - case .note(let note): - notes.append( - Note( - id: notes.count, - position: CGPoint(x: note.coordinates.0, y: note.coordinates.1), - text: note.text - )) - - case .stage(let stage): - let stageIndex = convertStageNumber(stage.number) - 1 - if stageIndex >= 0 && stageIndex < 3 { - stages[stageIndex] = stage.value - } - - default: - continue - } - } - - // Second pass for entities that depend on vertices - for entity in entities { - switch entity { - case .edge(let edge): - if let fromVertex = vertexMap[edge.from], - let toVertex = vertexMap[edge.to] - { - edges.append( - MapEdge( - id: edges.count, - origin: fromVertex.position, - destination: toVertex.position, - arrowhead: edge.isDirected - )) - } - - case .inertia(let inertia): - if let vertex = vertexMap[inertia.vertex] { - inertias.append( - Inertia( - id: inertias.count, - position: vertex.position - )) - } - - case .evolution(let evolution): - if let vertex = vertexMap[evolution.vertex] { - let direction: CGFloat = evolution.isPositive ? 1.0 : -1.0 - let destination = CGPoint( - x: vertex.position.x + (direction * evolution.value), - y: vertex.position.y - ) - opportunities.append( - Opportunity( - id: opportunities.count, - origin: vertex.position, - destination: destination - )) - } - - case .group(let group): - var groupVertices: [Vertex] = [] - for vertexName in group.vertices { - if let vertex = vertexMap[vertexName] { - groupVertices.append(vertex) - } - } - if !groupVertices.isEmpty { - groups.append(groupVertices) - } - - default: - continue - } - } - - return ParsedMap( - vertices: vertices, - edges: edges, - inertias: inertias, - opportunities: opportunities, - notes: notes, - stages: stages, - groups: groups - ) - } - - private nonisolated func convertShape(_ shape: String?) -> VertexShape { - guard let shape = shape?.lowercased() else { return .circle } - switch shape { - case "square": return .square - case "triangle": return .triangle - case "x": return .x - default: return .circle - } - } - - private nonisolated func convertStageNumber(_ stageNumber: String) -> Int { - switch stageNumber.lowercased() { - case "i": return 1 - case "ii": return 2 - case "iii": return 3 - case "iv": return 4 - default: return 1 - } - } - var body: some View { ZStack(alignment: .topLeading) { |