OSDN Git Service

predicate(for:)をshipTypePredicteに変更
[kcd/KCD.git] / KCD / StrengthenListItem.swift
1 //
2 //  StrengthenListItem.swift
3 //  KCD
4 //
5 //  Created by Hori,Masaki on 2017/03/24.
6 //  Copyright © 2017年 Hori,Masaki. All rights reserved.
7 //
8
9 import Cocoa
10
11 protocol StrengthenListItem {
12     var type: EquipmentType { get }
13     var cellType: StrengthenListCellType.Type { get }
14 }
15
16 protocol StrengthenListCellType {
17     static var cellIdentifier: String { get }
18     static func estimateCellHeightForItem(item: StrengthenListItem, tableView: NSTableView) -> CGFloat
19     static func makeCellWithItem(item: StrengthenListItem, tableView: NSTableView, owner: AnyObject?) -> NSTableCellView
20 }
21
22 extension StrengthenListCellType {
23     static func makeCellWithItem(item: StrengthenListItem,
24                                  tableView: NSTableView,
25                                  owner: AnyObject?) -> NSTableCellView {
26         let v = tableView.make(withIdentifier: cellIdentifier, owner: nil)
27         
28         // swiftlint:disable:next force_cast
29         return v as! NSTableCellView
30     }
31 }
32
33 struct StrengthenListGroupCellType: StrengthenListCellType {
34     static let cellIdentifier: String = "GroupCell"
35     static func estimateCellHeightForItem(item: StrengthenListItem, tableView: NSTableView) -> CGFloat {
36         return 23.0
37     }
38 }
39
40 class StrengthenListGroupItem: NSObject, StrengthenListItem {
41     let name: String
42     let type: EquipmentType
43     let cellType: StrengthenListCellType.Type = StrengthenListGroupCellType.self
44     
45     init(type: EquipmentType) {
46         self.name = SlotItemEquipTypeTransformer().transformedValue(type.rawValue) as? String ?? "Unkown"
47         self.type = type
48         super.init()
49     }
50 }
51
52 class StrengthenListEnhancementItem: NSObject, StrengthenListItem {
53     let item: EnhancementListItem
54     var type: EquipmentType { return item.equipmentType }
55     let cellType: StrengthenListCellType.Type = StrengthenListItemCellView.self
56     
57     init(item: EnhancementListItem) {
58         self.item = item
59         super.init()
60     }
61  }
62
63 extension StrengthenListEnhancementItem {
64     var identifier: String { return item.identifier }
65     var weekday: Int { return item.weekday }
66     var equipmentType: EquipmentType { return item.equipmentType }
67     var targetEquipment: String { return item.targetEquipment }
68     var remodelEquipment: String? { return item.remodelEquipment }
69     var requiredEquipments: RequiredEquipmentSet { return item.requiredEquipments }
70     var secondsShipNames: [String] { return item.secondsShipNames }
71 }