diff options
Diffstat (limited to 'Map/Data/MapDocument.swift')
| -rw-r--r-- | Map/Data/MapDocument.swift | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/Map/Data/MapDocument.swift b/Map/Data/MapDocument.swift index 3c6d352..2377d5a 100644 --- a/Map/Data/MapDocument.swift +++ b/Map/Data/MapDocument.swift @@ -25,19 +25,31 @@ struct MapDocument: FileDocument { var text: String init( - text: String = """ - Anchor (60, 5) [x] - Node A (78, 23) - Node B (40, 30) [square] - Node C (65, 70) - - Anchor -> Node A - Anchor -> Node B - Node A -> Node C - Node B -> Node C - """ + text: String? = nil ) { - self.text = text + if let text = text { + self.text = text + } else { + // Try to get default template, fallback to built-in content + if let templatesData = UserDefaults.standard.data(forKey: "mapTemplates"), + let templates = try? JSONDecoder().decode([Template].self, from: templatesData), + let defaultTemplate = templates.first(where: { $0.isDefault }) + { + self.text = defaultTemplate.content + } else { + self.text = """ + Anchor (60, 5) [x] + Node A (78, 23) + Node B (40, 30) [square] + Node C (65, 70) + + Anchor -> Node A + Anchor -> Node B + Node A -> Node C + Node B -> Node C + """ + } + } } static var readableContentTypes: [UTType] { [.wmap] } |