public struct PlayerM: HasCodableProxy { public var trackingID: String public var id: Player.ID public var x: Float public var y: Float public var distance: Float public var speed: Float public var position: GLKVector2 { GLKVector2(x, y) } public struct CodableProxy: Codable { public var id: String public var no: Player.ID @FormatCoding<FloatStaticFormatter> public var x: Float @FormatCoding<FloatStaticFormatter> public var y: Float @FormatCoding<FloatStaticFormatter> public var distance: Float @FormatCoding<FloatStaticFormatter> public var speed: Float } public init(trackingID: String, id: Player.ID, x: Float, y: Float, distance: Float, speed: Float) { self.trackingID = trackingID self.id = id self.x = x self.y = y self.distance = distance self.speed = speed } public init(fromCodableProxy p: CodableProxy) { self.init(trackingID: p.id, id: p.no, x: p.x, y: p.y, distance: p.distance, speed: p.speed) } public func encodeToCodableProxy() -> CodableProxy { CodableProxy(id: trackingID, no: id, x: x, y: y, distance: distance, speed: speed) } }
@FormatCoding<FormatStaticFormatter>
は Floatを %.2f
書式の 文字列としてエンコードする型public struct CameraCalibration: Codable { public typealias JSON = [CameraCalibration] public var fov: Float @ColumnMajorFloatArray9Coding public var rotation: GLKMatrix3 @FloatArray3Coding public var translation: GLKVector3 public init(fov: Float, rotation: GLKMatrix3, translation: GLKVector3) { self.fov = fov self.rotation = rotation self.translation = translation } }
@FloatArray3Coding
などが、3次元ベクトルを 3要素Float Array にエンコードする型public struct PlayerSpecifier : HasCodableProxy, Hashable { public struct CodableProxy : Codable { public var teamID: Team.ID public var teamColor: ColorProxyRGB public var playerID: Player.ID public var name: String } public var teamID: Team.ID public var teamColor: Color public var playerID: Player.ID public var name: String public init(teamID: Team.ID, teamColor: Color, playerID: Player.ID, name: String) { self.teamID = teamID self.teamColor = teamColor self.playerID = playerID self.name = name } public init(fromCodableProxy p: CodableProxy) { self.init(teamID: p.teamID, teamColor: p.teamColor.value, playerID: p.playerID, name: p.name) } public func encodeToCodableProxy() -> PlayerSpecifier.CodableProxy { return CodableProxy(teamID: teamID, teamColor: ColorProxyRGB(teamColor), playerID: playerID, name: name) } }
ColorProxyRGB
が Color型を Float3要素Array にコーディングするための型