]>
Commit | Line | Data |
---|---|---|
e2c37ac1 RBR |
1 | import SwiftUI |
2 | import UniformTypeIdentifiers | |
3 | ||
4 | extension UTType { | |
5 | static var exampleText: UTType { | |
6 | UTType(importedAs: "systems.tranquil.map.wmap") | |
7 | } | |
8 | } | |
9 | ||
10 | struct MapDocument: FileDocument { | |
11 | var text: String | |
12 | ||
13 | init(text: String = "Hello, world!") { | |
14 | self.text = text | |
15 | } | |
16 | ||
17 | static var readableContentTypes: [UTType] { [.exampleText] } | |
18 | ||
19 | init(configuration: ReadConfiguration) throws { | |
20 | guard let data = configuration.file.regularFileContents, | |
21 | let string = String(data: data, encoding: .utf8) | |
22 | else { | |
23 | throw CocoaError(.fileReadCorruptFile) | |
24 | } | |
25 | text = string | |
26 | } | |
27 | ||
28 | func fileWrapper(configuration: WriteConfiguration) throws -> FileWrapper { | |
29 | let data = text.data(using: .utf8)! | |
30 | return .init(regularFileWithContents: data) | |
31 | } | |
32 | ||
33 | @MainActor | |
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) | |
39 | ||
40 | return renderer.nsImage | |
41 | } | |
42 | } |