]> git.r.bdr.sh - rbdr/map/blob - Map/Presentation/Complex Components/MapRender/MapRenderView.swift
b12dabce12393e4de8752055b4939b0adbaac0f4
[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 content: String
9 @Binding var evolution: StageType
10
11 var stage: Stage {
12 Stage.stages(evolution)
13 }
14
15 @State var parsedMap: ParsedMap = ParsedMap.empty
16
17 let mapSize = CGSize(width: 1300.0, height: 1000.0)
18
19 let lineWidth = CGFloat(0.5)
20 let vertexSize = CGSize(width: 25.0, height: 25.0)
21 let padding = CGFloat(30.0)
22
23 var body: some View {
24 ZStack(alignment: .topLeading) {
25
26 Path { path in
27 path.addRect(
28 CGRect(
29 x: -padding, y: -padding, width: mapSize.width + padding * 2,
30 height: mapSize.height + padding * 4))
31 }.fill(.white)
32
33 MapStages(mapSize: mapSize, lineWidth: lineWidth, stages: parsedMap.stages)
34 MapAxes(
35 mapSize: mapSize, lineWidth: lineWidth, evolution: stage, stages: parsedMap.stages)
36 MapEdges(
37 mapSize: mapSize, lineWidth: lineWidth, vertexSize: vertexSize, edges: parsedMap.edges)
38 MapBlockers(mapSize: mapSize, vertexSize: vertexSize, blockers: parsedMap.blockers)
39 MapVertices(mapSize: mapSize, vertexSize: vertexSize, vertices: parsedMap.vertices)
40 MapOpportunities(
41 mapSize: mapSize, lineWidth: lineWidth, vertexSize: vertexSize,
42 opportunities: parsedMap.opportunities)
43 MapNotes(
44 mapSize: mapSize, lineWidth: lineWidth, notes: parsedMap.notes)
45 }.frame(
46 width: mapSize.width,
47 height: mapSize.height + 2 * padding, alignment: .topLeading
48 ).onAppear {
49 self.parsedMap = Map.parse(content: content)
50 }.padding(padding).onChange(of: content) { newState in
51 self.parsedMap = Map.parse(content: newState)
52 }
53 }
54 }
55
56 struct MapRenderView_Previews: PreviewProvider {
57 static var previews: some View {
58 MapRenderView(
59 content: Binding.constant(""), evolution: Binding.constant(StageType.general)
60 ).environment(
61 \.managedObjectContext, PersistenceController.preview.container.viewContext)
62 }
63 }