// Created by Ruben Beltran del Rio on 2/1/21.
//
+import Combine
import CoreData
import CoreGraphics
import SwiftUI
@Environment(\.colorScheme) var colorScheme
- @ObservedObject var map: Map
- let evolution: Stage
+ @Binding var content: String
+ @Binding var evolution: Stage
+
+ @State var parsedMap: ParsedMap = ParsedMap.empty
let mapSize = CGSize(width: 1300.0, height: 1000.0)
let vertexSize = CGSize(width: 25.0, height: 25.0)
let padding = CGFloat(30.0)
- var parsedMap: ParsedMap {
- return map.parse()
- }
-
var body: some View {
ZStack(alignment: .topLeading) {
path.addRect(
CGRect(
x: -padding, y: -padding, width: mapSize.width + padding * 2,
- height: mapSize.height + padding * 2))
+ height: mapSize.height + padding * 4))
}.fill(MapColor.colorForScheme(colorScheme).background)
MapStages(mapSize: mapSize, lineWidth: lineWidth, stages: parsedMap.stages)
mapSize: mapSize, lineWidth: lineWidth, vertexSize: vertexSize, edges: parsedMap.edges)
}.frame(
width: mapSize.width,
- height: mapSize.height, alignment: .topLeading
- ).padding(padding)
+ height: mapSize.height + 2 * padding, alignment: .topLeading
+ ).onAppear {
+ self.parsedMap = Map.parse(content: content)
+ }.padding(padding).onChange(of: content) { newState in
+ self.parsedMap = Map.parse(content: newState)
+ }
}
}
struct MapRenderView_Previews: PreviewProvider {
static var previews: some View {
- MapDetailView(map: Map()).environment(
+ MapRenderView(
+ content: Binding.constant(""), evolution: Binding.constant(Stage.stages(.general))
+ ).environment(
\.managedObjectContext, PersistenceController.preview.container.viewContext)
}
}