// // Star.swift // lottie-swift // // Created by Brandon Withrow on 1/8/19. // import Foundation enum StarType: Int, Codable { case none case star case polygon } /// An item that define an ellipse shape final class Star: ShapeItem { /// The direction of the star. let direction: PathDirection /// The position of the star let position: KeyframeGroup /// The outer radius of the star let outerRadius: KeyframeGroup /// The outer roundness of the star let outerRoundness: KeyframeGroup /// The outer radius of the star let innerRadius: KeyframeGroup? /// The outer roundness of the star let innerRoundness: KeyframeGroup? /// The rotation of the star let rotation: KeyframeGroup /// The number of points on the star let points: KeyframeGroup /// The type of star let starType: StarType private enum CodingKeys : String, CodingKey { case direction = "d" case position = "p" case outerRadius = "or" case outerRoundness = "os" case innerRadius = "ir" case innerRoundness = "is" case rotation = "r" case points = "pt" case starType = "sy" } required init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: Star.CodingKeys.self) self.direction = try container.decodeIfPresent(PathDirection.self, forKey: .direction) ?? .clockwise self.position = try container.decode(KeyframeGroup.self, forKey: .position) self.outerRadius = try container.decode(KeyframeGroup.self, forKey: .outerRadius) self.outerRoundness = try container.decode(KeyframeGroup.self, forKey: .outerRoundness) self.innerRadius = try container.decodeIfPresent(KeyframeGroup.self, forKey: .innerRadius) self.innerRoundness = try container.decodeIfPresent(KeyframeGroup.self, forKey: .innerRoundness) self.rotation = try container.decode(KeyframeGroup.self, forKey: .rotation) self.points = try container.decode(KeyframeGroup.self, forKey: .points) self.starType = try container.decode(StarType.self, forKey: .starType) try super.init(from: decoder) } override func encode(to encoder: Encoder) throws { try super.encode(to: encoder) var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(direction, forKey: .direction) try container.encode(position, forKey: .position) try container.encode(outerRadius, forKey: .outerRadius) try container.encode(outerRoundness, forKey: .outerRoundness) try container.encode(innerRadius, forKey: .innerRadius) try container.encode(innerRoundness, forKey: .innerRoundness) try container.encode(rotation, forKey: .rotation) try container.encode(points, forKey: .points) try container.encode(starType, forKey: .starType) } }