Prettify Document.getChunkFilename
This commit is contained in:
parent
a71699c15d
commit
d8c3229394
1 changed files with 3 additions and 6 deletions
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue