]>
Commit | Line | Data |
---|---|---|
5e8ff485 RBR |
1 | // |
2 | // ContentView.swift | |
3 | // Map | |
4 | // | |
5 | // Created by Ruben Beltran del Rio on 2/1/21. | |
6 | // | |
7 | ||
77d0155b | 8 | import Combine |
5e8ff485 RBR |
9 | import CoreData |
10 | import CoreGraphics | |
11 | import SwiftUI | |
12 | ||
13 | struct MapRenderView: View { | |
14 | ||
15 | @Environment(\.colorScheme) var colorScheme | |
16 | ||
75a0e450 RBR |
17 | @Binding var content: String |
18 | @Binding var evolution: Stage | |
19 | ||
20 | @State var parsedMap: ParsedMap = ParsedMap.empty | |
5e8ff485 RBR |
21 | |
22 | let mapSize = CGSize(width: 1300.0, height: 1000.0) | |
23 | ||
24 | let lineWidth = CGFloat(1.0) | |
25 | let vertexSize = CGSize(width: 25.0, height: 25.0) | |
26 | let padding = CGFloat(30.0) | |
27 | ||
5e8ff485 RBR |
28 | var body: some View { |
29 | ZStack(alignment: .topLeading) { | |
30 | ||
31 | Path { path in | |
32 | path.addRect( | |
33 | CGRect( | |
34 | x: -padding, y: -padding, width: mapSize.width + padding * 2, | |
77d0155b | 35 | height: mapSize.height + padding * 4)) |
5e8ff485 RBR |
36 | }.fill(MapColor.colorForScheme(colorScheme).background) |
37 | ||
38 | MapStages(mapSize: mapSize, lineWidth: lineWidth, stages: parsedMap.stages) | |
39 | MapAxes( | |
40 | mapSize: mapSize, lineWidth: lineWidth, evolution: evolution, stages: parsedMap.stages) | |
41 | MapOpportunities( | |
42 | mapSize: mapSize, lineWidth: lineWidth, vertexSize: vertexSize, | |
43 | opportunities: parsedMap.opportunities) | |
44 | MapBlockers(mapSize: mapSize, vertexSize: vertexSize, blockers: parsedMap.blockers) | |
45 | MapVertices(mapSize: mapSize, vertexSize: vertexSize, vertices: parsedMap.vertices) | |
46 | MapEdges( | |
47 | mapSize: mapSize, lineWidth: lineWidth, vertexSize: vertexSize, edges: parsedMap.edges) | |
48 | }.frame( | |
49 | width: mapSize.width, | |
77d0155b | 50 | height: mapSize.height + 2 * padding, alignment: .topLeading |
75a0e450 RBR |
51 | ).onAppear { |
52 | self.parsedMap = Map.parse(content: content) | |
53 | }.padding(padding).onChange(of: content) { newState in | |
54 | self.parsedMap = Map.parse(content: newState) | |
55 | } | |
5e8ff485 RBR |
56 | } |
57 | } | |
58 | ||
59 | struct MapRenderView_Previews: PreviewProvider { | |
60 | static var previews: some View { | |
75a0e450 RBR |
61 | MapRenderView( |
62 | content: Binding.constant(""), evolution: Binding.constant(Stage.stages(.general)) | |
63 | ).environment( | |
5e8ff485 RBR |
64 | \.managedObjectContext, PersistenceController.preview.container.viewContext) |
65 | } | |
66 | } |