OSDN Git Service

関数名を変更
[kcd/KCD.git] / KCD / DocksViewController.swift
index 612419e..551fe76 100644 (file)
@@ -15,25 +15,20 @@ final class DocksViewController: MainTabVIewItemViewController {
         [NSBindingName(#keyPath(deck2Time)), NSBindingName(#keyPath(mission2Name)),
          NSBindingName(#keyPath(deck3Time)), NSBindingName(#keyPath(mission3Name)),
          NSBindingName(#keyPath(deck4Time)), NSBindingName(#keyPath(mission4Name))]
-            .forEach { unbind($0) }
+            .forEach(unbind)
         [NSBindingName(#keyPath(nDock1Time)), NSBindingName(#keyPath(nDock1ShipName)),
          NSBindingName(#keyPath(nDock2Time)), NSBindingName(#keyPath(nDock2ShipName)),
          NSBindingName(#keyPath(nDock3Time)), NSBindingName(#keyPath(nDock3ShipName)),
          NSBindingName(#keyPath(nDock4Time)), NSBindingName(#keyPath(nDock4ShipName))]
-            .forEach { unbind($0) }
+            .forEach(unbind)
         [NSBindingName(#keyPath(kDock1Time)), NSBindingName(#keyPath(kDock2Time)),
          NSBindingName(#keyPath(kDock3Time)), NSBindingName(#keyPath(kDock4Time))]
-            .forEach { unbind($0) }
-        
-        ["selection", "selection.no", "content.battleCell"]
-            .forEach {
-            battleContoller.removeObserver(self, forKeyPath: $0)
-        }
+            .forEach(unbind)
     }
     
     @objc let managedObjectContext = ServerDataStore.default.context
-    @objc let battleManagedObjectController = TemporaryDataStore.default.context
     let questListViewController = QuestListViewController()
+    let battleInfoViewController = BattleInformationViewController()
     
     let missionStates = (2...4).flatMap { MissionStatus(number: $0) }
     let ndockStatus = (1...4).flatMap { NyukyoDockStatus(number: $0) }
@@ -62,92 +57,14 @@ final class DocksViewController: MainTabVIewItemViewController {
     @objc var mission3Name: String?
     @objc var mission4Name: String?
     
-    @IBOutlet var battleContoller: NSObjectController!
+    @IBOutlet weak var battleInformationViewPlaceholder: NSView!
     @IBOutlet weak var questListViewPlaceholder: NSView!
-    @IBOutlet weak var cellNumberField: NSTextField!
     
     override var nibName: NSNib.Name {
         
         return .nibName(instanceOf: self)
     }
     
-    var battle: Battle? {
-        
-        return TemporaryDataStore.default.battle()
-    }
-    
-    @objc var cellNumber: Int {
-        
-        return battleContoller.value(forKeyPath: "content.no") as? Int ?? 0
-    }
-    
-    var battleCellNumber: Int {
-        
-        return battleContoller.value(forKeyPath: "content.battleCell") as? Int ?? 0
-    }
-    
-    var isBossCell: Bool {
-        
-        return battleContoller.value(forKeyPath: "content.isBossCell") as? Bool ?? false
-    }
-    
-    var fleetName: String? {
-        
-        guard let deckId = battleContoller.value(forKeyPath: "content.deckId") as? Int else { return nil }
-        
-        return ServerDataStore.default.deck(by: deckId)?.name
-    }
-    
-    var areaNumber: String? {
-        
-        let mapArea: String = {
-            
-            guard let mapArea = battleContoller.value(forKeyPath: "content.mapArea") as? Int else { return "" }
-            
-            if mapArea > 10 { return "E" }
-            
-            return "\(mapArea)"
-        }()
-        
-        guard mapArea != "" else { return nil }
-        
-        guard let mapInfo = battleContoller.value(forKeyPath: "content.mapInfo") as? Int else { return "" }
-        
-        return "\(mapArea)-\(mapInfo)"
-    }
-    
-    var areaName: String? {
-        
-        guard let mapArea = battleContoller.value(forKeyPath: "content.mapArea") as? Int else { return nil }
-        guard let mapInfo = battleContoller.value(forKeyPath: "content.mapInfo") as? Int else { return nil }
-        
-        return ServerDataStore.default.mapInfo(area: mapArea, no: mapInfo)?.name
-    }
-    
-    @objc var sortieString: String? {
-        
-        guard let fleetName = self.fleetName,
-            let areaName = self.areaName,
-            let areaNumber = self.areaNumber else { return nil }
-        
-        if battleCellNumber == 0 {
-            
-            let format = LocalizedStrings.sortieInfomation.string
-            
-            return String(format: format, arguments: [fleetName, areaName, areaNumber])
-        }
-        if isBossCell {
-            
-            let format = LocalizedStrings.battleWithBOSS.string
-            
-            return String(format: format, arguments: [fleetName, battleCellNumber as NSNumber, areaName, areaNumber])
-        }
-        
-        let format = LocalizedStrings.battleInformation.string
-        
-        return String(format: format, arguments: [fleetName, battleCellNumber as NSNumber, areaName, areaNumber])
-    }
-    
     override func viewDidLoad() {
         
         super.viewDidLoad()
@@ -161,37 +78,13 @@ final class DocksViewController: MainTabVIewItemViewController {
             self.ndockStatus.forEach { $0.update() }
         }
         
+        battleInfoViewController.view.frame = battleInformationViewPlaceholder.frame
+        battleInfoViewController.view.autoresizingMask = battleInformationViewPlaceholder.autoresizingMask
+        battleInformationViewPlaceholder.superview?.replaceSubview(battleInformationViewPlaceholder, with: battleInfoViewController.view)
+        
         questListViewController.view.frame = questListViewPlaceholder.frame
         questListViewController.view.autoresizingMask = questListViewPlaceholder.autoresizingMask
         questListViewPlaceholder.superview?.replaceSubview(questListViewPlaceholder, with: questListViewController.view)
-        
-        ["selection", "selection.no", "content.battleCell"]
-            .forEach {
-                battleContoller.addObserver(self, forKeyPath: $0, context: nil)
-        }
-        
-        #if DEBUG
-            cellNumberField.isHidden = false
-        #endif
-    }
-    
-    override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey: Any]?, context: UnsafeMutableRawPointer?) {
-        
-        if keyPath == "selection" || keyPath == "content.battleCell" {
-            
-            notifyChangeValue(forKey: #keyPath(sortieString))
-            
-            return
-        }
-        
-        if keyPath == "selection.no" {
-            
-            notifyChangeValue(forKey: #keyPath(cellNumber))
-            
-            return
-        }
-        
-        super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context)
     }
     
     private func setupStatus() {
@@ -215,14 +108,14 @@ final class DocksViewController: MainTabVIewItemViewController {
         ]
         zip(ndockStatus, ndockKeys).forEach {
             
-            bind(NSBindingName(rawValue: $0.1.0), to: $0.0, withKeyPath: #keyPath(MissionStatus.time), options: nil)
-            bind(NSBindingName(rawValue: $0.1.1), to: $0.0, withKeyPath: #keyPath(MissionStatus.name), options: nil)
+            bind(NSBindingName(rawValue: $0.1.0), to: $0.0, withKeyPath: #keyPath(NyukyoDockStatus.time), options: nil)
+            bind(NSBindingName(rawValue: $0.1.1), to: $0.0, withKeyPath: #keyPath(NyukyoDockStatus.name), options: nil)
         }
         
         let kdockKeys = [#keyPath(kDock1Time), #keyPath(kDock2Time), #keyPath(kDock3Time), #keyPath(kDock4Time)]
         zip(kdockStatus, kdockKeys).forEach {
             
-            bind(NSBindingName(rawValue: $0.1), to: $0.0, withKeyPath: #keyPath(MissionStatus.time), options: nil)
+            bind(NSBindingName(rawValue: $0.1), to: $0.0, withKeyPath: #keyPath(KenzoDockStatus.time), options: nil)
         }
     }