aboutsummaryrefslogtreecommitdiff
path: root/Map/Presentation/Complex Components/MapRender/MapRenderView.swift
blob: b256861f6ed8e36eb0a1c30ae8f89bbb5c81c90f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import Combine
import CoreData
import CoreGraphics
import SwiftUI

struct MapRenderView: View {

  @Binding var document: MapDocument
  @Binding var evolution: StageType

  var stage: Stage {
    Stage.stages(evolution)
  }

  var parsedMap: ParsedMap {
    MapParser.parse(content: document.text)
  }

  let mapSize = Dimensions.mapSize
  let padding = Dimensions.mapPadding

  let lineWidth = CGFloat(0.5)
  let vertexSize = CGSize(width: 25.0, height: 25.0)

  var onDragVertex: (Vertex, CGFloat, CGFloat) -> Void = { _, _, _ in }

  var body: some View {
    ZStack(alignment: .topLeading) {

      Path { path in
        path.addRect(
          CGRect(
            x: -padding, y: -padding, width: mapSize.width + padding * 2,
            height: mapSize.height + padding * 4))
      }.fill(.white)

      MapStages(mapSize: mapSize, lineWidth: lineWidth, stages: parsedMap.stages)
      MapAxes(
        mapSize: mapSize, lineWidth: lineWidth, evolution: stage, stages: parsedMap.stages)
      MapEdges(
        mapSize: mapSize, lineWidth: lineWidth, vertexSize: vertexSize, edges: parsedMap.edges)
      MapBlockers(mapSize: mapSize, vertexSize: vertexSize, blockers: parsedMap.blockers)
      MapVertices(
        mapSize: mapSize, vertexSize: vertexSize, vertices: parsedMap.vertices,
        onDragVertex: onDragVertex)
      MapOpportunities(
        mapSize: mapSize, lineWidth: lineWidth, vertexSize: vertexSize,
        opportunities: parsedMap.opportunities)
      MapGroups(mapSize: mapSize, vertexSize: vertexSize, groups: parsedMap.groups).drawingGroup(
        opaque: true
      ).opacity(0.1)
      MapNotes(
        mapSize: mapSize, lineWidth: lineWidth, notes: parsedMap.notes)
    }.offset(x: padding, y: padding).frame(
      width: mapSize.width + 2 * padding,
      height: mapSize.height + 2 * padding, alignment: .topLeading
    )
  }
}

#Preview {
  MapRenderView(
    document: Binding.constant(MapDocument(text: "")),
    evolution: Binding.constant(StageType.general)
  )
}