]> git.r.bdr.sh - rbdr/map/blob - Map/Views/MapRender.swift
b35b7241b8ee7cb0a3d750f8065902d119e2804f
[rbdr/map] / Map / Views / MapRender.swift
1 //
2 // ContentView.swift
3 // Map
4 //
5 // Created by Ruben Beltran del Rio on 2/1/21.
6 //
7
8 import CoreData
9 import CoreGraphics
10 import SwiftUI
11
12 struct MapRenderView: View {
13
14 @Environment(\.colorScheme) var colorScheme
15
16 @ObservedObject var map: Map
17 let evolution: Stage
18
19 let mapSize = CGSize(width: 1300.0, height: 1000.0)
20
21 let lineWidth = CGFloat(1.0)
22 let vertexSize = CGSize(width: 25.0, height: 25.0)
23 let padding = CGFloat(30.0)
24
25 var parsedMap: ParsedMap {
26 return map.parse()
27 }
28
29 var body: some View {
30 ZStack(alignment: .topLeading) {
31
32 Path { path in
33 path.addRect(
34 CGRect(
35 x: -padding, y: -padding, width: mapSize.width + padding * 2,
36 height: mapSize.height + padding * 2))
37 }.fill(MapColor.colorForScheme(colorScheme).background)
38
39 MapStages(mapSize: mapSize, lineWidth: lineWidth, stages: parsedMap.stages)
40 MapAxes(
41 mapSize: mapSize, lineWidth: lineWidth, evolution: evolution, stages: parsedMap.stages)
42 MapOpportunities(
43 mapSize: mapSize, lineWidth: lineWidth, vertexSize: vertexSize,
44 opportunities: parsedMap.opportunities)
45 MapBlockers(mapSize: mapSize, vertexSize: vertexSize, blockers: parsedMap.blockers)
46 MapVertices(mapSize: mapSize, vertexSize: vertexSize, vertices: parsedMap.vertices)
47 MapEdges(
48 mapSize: mapSize, lineWidth: lineWidth, vertexSize: vertexSize, edges: parsedMap.edges)
49 }.frame(
50 width: mapSize.width,
51 height: mapSize.height, alignment: .topLeading
52 ).padding(padding)
53 }
54 }
55
56 struct MapRenderView_Previews: PreviewProvider {
57 static var previews: some View {
58 MapDetailView(map: Map()).environment(
59 \.managedObjectContext, PersistenceController.preview.container.viewContext)
60 }
61 }