import SwiftUI
struct AppState {
- var selectedMap: Map? = nil
+ var selectedEvolution: StageType = .general
var mapBeingDeleted: Map? = nil
}
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)
}
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: map.content ?? "", evolution: Stage.stages(state.selectedEvolution))
let view = NSHostingView(rootView: renderView)
window.contentView = view