]> git.r.bdr.sh - rbdr/map/blob - Map/Presentation/Complex Components/MapRender/MapRenderView.swift
b256861f6ed8e36eb0a1c30ae8f89bbb5c81c90f
[rbdr/map] / Map / Presentation / Complex Components / MapRender / MapRenderView.swift
1 import Combine
2 import CoreData
3 import CoreGraphics
4 import SwiftUI
5
6 struct MapRenderView: View {
7
8 @Binding var document: MapDocument
9 @Binding var evolution: StageType
10
11 var stage: Stage {
12 Stage.stages(evolution)
13 }
14
15 var parsedMap: ParsedMap {
16 MapParser.parse(content: document.text)
17 }
18
19 let mapSize = Dimensions.mapSize
20 let padding = Dimensions.mapPadding
21
22 let lineWidth = CGFloat(0.5)
23 let vertexSize = CGSize(width: 25.0, height: 25.0)
24
25 var onDragVertex: (Vertex, CGFloat, CGFloat) -> Void = { _, _, _ in }
26
27 var body: some View {
28 ZStack(alignment: .topLeading) {
29
30 Path { path in
31 path.addRect(
32 CGRect(
33 x: -padding, y: -padding, width: mapSize.width + padding * 2,
34 height: mapSize.height + padding * 4))
35 }.fill(.white)
36
37 MapStages(mapSize: mapSize, lineWidth: lineWidth, stages: parsedMap.stages)
38 MapAxes(
39 mapSize: mapSize, lineWidth: lineWidth, evolution: stage, stages: parsedMap.stages)
40 MapEdges(
41 mapSize: mapSize, lineWidth: lineWidth, vertexSize: vertexSize, edges: parsedMap.edges)
42 MapBlockers(mapSize: mapSize, vertexSize: vertexSize, blockers: parsedMap.blockers)
43 MapVertices(
44 mapSize: mapSize, vertexSize: vertexSize, vertices: parsedMap.vertices,
45 onDragVertex: onDragVertex)
46 MapOpportunities(
47 mapSize: mapSize, lineWidth: lineWidth, vertexSize: vertexSize,
48 opportunities: parsedMap.opportunities)
49 MapGroups(mapSize: mapSize, vertexSize: vertexSize, groups: parsedMap.groups).drawingGroup(
50 opaque: true
51 ).opacity(0.1)
52 MapNotes(
53 mapSize: mapSize, lineWidth: lineWidth, notes: parsedMap.notes)
54 }.offset(x: padding, y: padding).frame(
55 width: mapSize.width + 2 * padding,
56 height: mapSize.height + 2 * padding, alignment: .topLeading
57 )
58 }
59 }
60
61 #Preview {
62 MapRenderView(
63 document: Binding.constant(MapDocument(text: "")),
64 evolution: Binding.constant(StageType.general)
65 )
66 }