1
Fork 0

Prettify Document.getChunkFilename

This commit is contained in:
Joshua Goins 2022-02-14 12:31:08 -04:00
parent a71699c15d
commit d8c3229394

View file

@ -133,17 +133,14 @@ class Document: NSDocument {
} }
/* /*
Parses the chunk filename, ex. 1~1 to integer coordinates. Parses the chunk filename, ex. "1~1.chunk" to integer coordinates (1, 2).
*/ */
func parseChunkFilename(_ filename: String) -> (Int, Int)? { func parseChunkFilename(_ filename: String) -> (Int, Int)? {
let pathURL = URL(fileURLWithPath: filename) let pathURL = URL(fileURLWithPath: filename)
let pathComponents = pathURL.lastPathComponent.replacingOccurrences(of: ".chunk", with: "").components(separatedBy: "~") let pathComponents = pathURL.lastPathComponent.replacingOccurrences(of: ".chunk", with: "").components(separatedBy: "~")
let x = Int(pathComponents[0]) if let x = Int(pathComponents[0]), let y = Int(pathComponents[1]) {
let y = Int(pathComponents[1]) return (x, y + 1)
if x != nil && y != nil {
return (x!, y! + 1)
} else { } else {
return nil return nil
} }