Loads the imported monster from file and sets the new monster's name from the loaded data.

This commit is contained in:
2021-04-04 01:46:58 -07:00
parent c09c332758
commit 2e6b8bb377

View File

@@ -48,9 +48,24 @@ struct ContentView: View {
}
func beginImportingMonster(url: URL) {
self.importInfo.monster.name = url.absoluteString
// TOOD: only do this if the file name ends in .json or .monster
let decoder = JSONDecoder()
do {
let data = try Data(contentsOf: url)
let monsterDTO = try decoder.decode(MonsterDTO.self, from: data)
print(String(format: "Loaded monster: %@", monsterDTO.name))
// TODO: check for some minimal set of properties to ensure this is the expected json schema
self.importInfo.monster = MonsterImportHelper.import5ESBMonster(monsterDTO)
// TODO: throw or set an err here and don't set isShowingImportDialog to true if the file didn't match any of our supported monster schemas.
self.isShowingImportDialog = true
} catch let error as NSError {
// TODO: handle this better
print(error)
}
}
}
struct ContentView_Previews: PreviewProvider {