blob: 42535fccbb8446b150d980e2e09d4264d6a2ad6e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
import Foundation
struct StageParserStrategy: MapParserStrategy {
private let regex = MapParsingPatterns.stage
func canHandle(line: String) -> Bool {
let range = NSRange(location: 0, length: line.utf16.count)
let matches = regex.matches(in: String(line), options: [], range: range)
return matches.count > 0 && matches[0].numberOfRanges == 3
}
func handle(index: Int, line: String, vertices: [String: Vertex]) -> (Any.Type, Any) {
let range = NSRange(location: 0, length: line.utf16.count)
let matches = regex.matches(in: String(line), options: [], range: range)
let match = matches[0]
let stage = String(line[Range(match.range(at: 1), in: line)!])
let dimensionsString = String(line[Range(match.range(at: 2), in: line)!])
let dimensions = CGFloat(truncating: NumberFormatter().number(from: dimensionsString) ?? 0.0)
let stageDimensions = StageDimensions(index: stage.count - 1, dimensions: dimensions)
return (StageDimensions.self, stageDimensions)
}
}
|