OSDN Git Service

swiftlint 'line_length'の警告を修正
[kcd/KCD.git] / KCD / DamageValueTransformer.swift
1 //
2 //  DamageValueTransformer.swift
3 //  KCD
4 //
5 //  Created by Hori,Masaki on 2017/01/05.
6 //  Copyright © 2017年 Hori,Masaki. All rights reserved.
7 //
8
9 import Cocoa
10
11 class DamageValueTransformer: ValueTransformer {
12     override class func transformedValueClass() -> Swift.AnyClass {
13         return NSAttributedString.self
14     }
15     override func transformedValue(_ value: Any?) -> Any? {
16         guard let v = value as? Int, let type = DamageType(rawValue: v) else { return nil }
17         let attributes: (string: String, attr: [String: Any])
18         switch type {
19         case .none:
20             return nil
21         case .slightly:
22             attributes = ("●",
23                           [
24                             NSForegroundColorAttributeName:
25                                 NSColor(calibratedRed: 1.0, green: 0.925, blue: 0.0, alpha: 1.0),
26                             NSParagraphStyleAttributeName: paragraphStyle
27                 ]
28             )
29         case .modest:
30             attributes = ("●",
31                           [
32                             NSForegroundColorAttributeName:
33                                 NSColor(calibratedRed: 1.0, green: 0.392, blue: 0.0, alpha: 1.0),
34                             NSParagraphStyleAttributeName: paragraphStyle
35                 ]
36             )
37         case .badly:
38             attributes = ("◼︎",
39                           [
40                             NSForegroundColorAttributeName:
41                                 NSColor(calibratedRed: 0.87, green: 0.0, blue: 0.036, alpha: 1.0),
42                             NSParagraphStyleAttributeName: paragraphStyle
43                 ]
44             )
45         }
46         
47         return NSAttributedString(string: attributes.string, attributes: attributes.attr)
48     }
49     
50     var paragraphStyle: NSParagraphStyle = {
51         let style = NSMutableParagraphStyle()
52         style.alignment = .center
53         return style
54     }()
55 }