5 // Created by Ruben Beltran del Rio on 2/1/21.
13 struct MapRenderView: View {
15 @Environment(\.colorScheme) var colorScheme
17 @Binding var content: String
18 @Binding var evolution: Stage
20 @State var parsedMap: ParsedMap = ParsedMap.empty
22 let mapSize = CGSize(width: 1300.0, height: 1000.0)
24 let lineWidth = CGFloat(1.0)
25 let vertexSize = CGSize(width: 25.0, height: 25.0)
26 let padding = CGFloat(30.0)
29 ZStack(alignment: .topLeading) {
34 x: -padding, y: -padding, width: mapSize.width + padding * 2,
35 height: mapSize.height + padding * 4))
36 }.fill(MapColor.colorForScheme(colorScheme).background)
38 MapStages(mapSize: mapSize, lineWidth: lineWidth, stages: parsedMap.stages)
40 mapSize: mapSize, lineWidth: lineWidth, evolution: evolution, stages: parsedMap.stages)
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)
47 mapSize: mapSize, lineWidth: lineWidth, vertexSize: vertexSize, edges: parsedMap.edges)
50 height: mapSize.height + 2 * padding, alignment: .topLeading
52 self.parsedMap = Map.parse(content: content)
53 }.padding(padding).onChange(of: content) { newState in
54 self.parsedMap = Map.parse(content: newState)
59 struct MapRenderView_Previews: PreviewProvider {
60 static var previews: some View {
62 content: Binding.constant(""), evolution: Binding.constant(Stage.stages(.general))
64 \.managedObjectContext, PersistenceController.preview.container.viewContext)