import SwiftUI
struct AppState {
- var selectedMap: Map? = nil
- var mapBeingDeleted: Map? = nil
+ var selectedEvolution: StageType = .general
}
enum AppAction {
- case selectMap(map: Map?)
- case deleteMap(map: Map)
- case exportMapAsImage(map: Map, evolution: StageType)
+ case selectEvolution(evolution: StageType)
+ case exportMapAsImage(map: Map)
case exportMapAsText(map: Map)
+ case deleteMap(map: Map)
}
func appStateReducer(state: inout AppState, action: AppAction) {
switch action {
- case .selectMap(let map):
- state.selectedMap = map
+ case .selectEvolution(let evolution):
+ state.selectedEvolution = evolution
- case .deleteMap(let map):
- let context = PersistenceController.shared.container.viewContext
-
- context.delete(map)
- try? context.save()
-
- case .exportMapAsImage(let map, let evolution):
+ case .exportMapAsImage(let map):
let window = NSWindow(
contentRect: .init(
origin: .zero,
window.isMovableByWindowBackground = true
window.makeKeyAndOrderFront(nil)
- let renderView = MapRenderView(map: map, evolution: Stage.stages(evolution))
+ let renderView = MapRenderView(
+ content: Binding.constant(map.content ?? ""),
+ evolution: Binding.constant(Stage.stages(state.selectedEvolution)))
let view = NSHostingView(rootView: renderView)
window.contentView = view
print("Cancel")
}
}
+ case .deleteMap(let map):
+ let context = PersistenceController.shared.container.viewContext
+ context.delete(map)
+
+ try? context.save()
}
}