2 import UniformTypeIdentifiers
5 static var exampleText: UTType {
6 UTType(importedAs: "systems.tranquil.map.wmap")
10 struct MapDocument: FileDocument {
13 init(text: String = "Hello, world!") {
17 static var readableContentTypes: [UTType] { [.exampleText] }
19 init(configuration: ReadConfiguration) throws {
20 guard let data = configuration.file.regularFileContents,
21 let string = String(data: data, encoding: .utf8)
23 throw CocoaError(.fileReadCorruptFile)
28 func fileWrapper(configuration: WriteConfiguration) throws -> FileWrapper {
29 let data = text.data(using: .utf8)!
30 return .init(regularFileWithContents: data)
34 func exportAsImage(withEvolution selectedEvolution: StageType) -> NSImage? {
35 let renderView = MapRenderView(
36 document: .constant(self),
37 evolution: .constant(selectedEvolution))
38 let renderer = ImageRenderer(content: renderView)
40 return renderer.nsImage