OSDN Git Service

ソースコードを整形
authormasakih <masakih@users.sourceforge.jp>
Sat, 5 Aug 2017 13:57:28 +0000 (22:57 +0900)
committermasakih <masakih@users.sourceforge.jp>
Sat, 5 Aug 2017 13:57:28 +0000 (22:57 +0900)
12 files changed:
KCD/BorderTextField.swift
KCD/DamageView.swift
KCD/GuardEscapedView.swift
KCD/PowerUpSupportViewController.swift
KCD/ScreenshotEditorViewController.swift
KCD/ScreenshotInformation.swift
KCD/ScreenshotListViewController.swift
KCD/ShipViewController.swift
KCD/SlotItemFrameView.swift
KCD/SlotItemLevelView.swift
KCD/StrengthenListItemView.swift
KCD/TiledImageView.swift

index dc1f379..891b7db 100644 (file)
@@ -24,8 +24,7 @@ final class BorderTextField: NSTextField {
             [
                 (NSPoint(x: 3, y: height), NSPoint(x: bounds.maxX, y: height)),
                 (NSPoint(x: width, y: 0), NSPoint(x: width, y: height))
-            ]
-            )
+            ])
             .stroke()
     }
 }
index fc7fb7f..dc95005 100644 (file)
@@ -88,37 +88,37 @@ final class DamageView: NSView {
             return nil
             
         case .slightly:
-            return polygon {
-                [NSPoint]()
-                    .appended { NSPoint(x: 35.0, y: height - 2.0) }
-                    .appended { NSPoint(x: 0.0, y: height - 2.0) }
-                    .appended { NSPoint(x: 0.0, y: height - 35.0) }
-            }
+            return polygon(points:
+                [
+                    NSPoint(x: 35.0, y: height - 2.0),
+                    NSPoint(x: 0.0, y: height - 2.0),
+                    NSPoint(x: 0.0, y: height - 35.0)
+                ])
             
         case .modest:
-            return polygon {
-                [NSPoint]()
-                    .appended { NSPoint(x: 50.0, y: height - 2.0) }
-                    .appended { NSPoint(x: 25.0, y: height - 2.0) }
-                    .appended { NSPoint(x: 0.0, y: height - 25.0) }
-                    .appended { NSPoint(x: 0.0, y: height - 50.0) }
-            }
+            return polygon(points:
+                [
+                    NSPoint(x: 50.0, y: height - 2.0),
+                    NSPoint(x: 25.0, y: height - 2.0),
+                    NSPoint(x: 0.0, y: height - 25.0),
+                    NSPoint(x: 0.0, y: height - 50.0)
+                ])
             
         case .badly:
-            let p = polygon {
-                [NSPoint]()
-                    .appended { NSPoint(x: 60.0, y: height - 2.0) }
-                    .appended { NSPoint(x: 53.0, y: height - 2.0) }
-                    .appended { NSPoint(x: 0.0, y: height - 53.0) }
-                    .appended { NSPoint(x: 0.0, y: height - 60.0) }
-            }
-            polygon {
-                [NSPoint]()
-                    .appended { NSPoint(x: 47.0, y: height - 2.0) }
-                    .appended { NSPoint(x: 23.0, y: height - 2.0) }
-                    .appended { NSPoint(x: 0.0, y: height - 23.0) }
-                    .appended { NSPoint(x: 0.0, y: height - 47.0) }
-            }
+            let p = polygon(points:
+                [
+                    NSPoint(x: 60.0, y: height - 2.0),
+                    NSPoint(x: 53.0, y: height - 2.0),
+                    NSPoint(x: 0.0, y: height - 53.0),
+                    NSPoint(x: 0.0, y: height - 60.0)
+                ])
+            polygon(points:
+                [
+                    NSPoint(x: 47.0, y: height - 2.0),
+                    NSPoint(x: 23.0, y: height - 2.0),
+                    NSPoint(x: 0.0, y: height - 23.0),
+                    NSPoint(x: 0.0, y: height - 47.0)
+                ])
                 .map { p?.append($0) }
             return p
         }
@@ -133,37 +133,37 @@ final class DamageView: NSView {
             return nil
             
         case .slightly:
-            return polygon {
-                [NSPoint]()
-                    .appended { NSPoint(x: 35.0, y: height - 2.0) }
-                    .appended { NSPoint(x: 0.0, y: height - 2.0) }
-                    .appended { NSPoint(x: 0.0, y: height - 35.0) }
-            }
+            return polygon(points:
+                [
+                    NSPoint(x: 35.0, y: height - 2.0),
+                    NSPoint(x: 0.0, y: height - 2.0),
+                    NSPoint(x: 0.0, y: height - 35.0)
+                ])
             
         case .modest:
-            return polygon {
-                [NSPoint]()
-                    .appended { NSPoint(x: 50.0, y: height - 2.0) }
-                    .appended { NSPoint(x: 25.0, y: height - 2.0) }
-                    .appended { NSPoint(x: 0.0, y: height - 25.0) }
-                    .appended { NSPoint(x: 0.0, y: height - 50.0) }
-            }
+            return polygon(points:
+                [
+                    NSPoint(x: 50.0, y: height - 2.0),
+                    NSPoint(x: 25.0, y: height - 2.0),
+                    NSPoint(x: 0.0, y: height - 25.0),
+                    NSPoint(x: 0.0, y: height - 50.0)
+                ])
             
         case .badly:
-            let p = polygon {
-                [NSPoint]()
-                    .appended { NSPoint(x: 55.0, y: height - 2.0) }
-                    .appended { NSPoint(x: 48.0, y: height - 2.0) }
-                    .appended { NSPoint(x: 0.0, y: height - 48.0) }
-                    .appended { NSPoint(x: 0.0, y: height - 55.0) }
-            }
-            polygon {
-                [NSPoint]()
-                    .appended { NSPoint(x: 42.0, y: height - 2.0) }
-                    .appended { NSPoint(x: 20.0, y: height - 2.0) }
-                    .appended { NSPoint(x: 0.0, y: height - 20.0) }
-                    .appended { NSPoint(x: 0.0, y: height - 42.0) }
-                }
+            let p = polygon(points:
+                [
+                    NSPoint(x: 55.0, y: height - 2.0),
+                    NSPoint(x: 48.0, y: height - 2.0),
+                    NSPoint(x: 0.0, y: height - 48.0),
+                    NSPoint(x: 0.0, y: height - 55.0)
+                ])
+            polygon(points:
+                [
+                    NSPoint(x: 42.0, y: height - 2.0),
+                    NSPoint(x: 20.0, y: height - 2.0),
+                    NSPoint(x: 0.0, y: height - 20.0),
+                    NSPoint(x: 0.0, y: height - 42.0)
+                ])
                 .map { p?.append($0) }
             return p
         }
index 01e74ec..7387a78 100644 (file)
@@ -16,7 +16,8 @@ final class GuardEscapedView: NSView {
             let taihiString = try? String(contentsOf: url, encoding: .utf8)
             else { fatalError("Can not load Taihi.txt") }
         
-        guard (taihiString as NSString).length == 2 else { fatalError("Taihi string is not 2 charactor") }
+        guard (taihiString as NSString).length == 2
+            else { fatalError("Taihi string is not 2 charactor") }
         
          return taihiString
     }()
index ccf8cd6..d43f16c 100644 (file)
@@ -85,6 +85,7 @@ final class PowerUpSupportViewController: MainTabVIewItemViewController {
     fileprivate func customPredicate() -> NSPredicate? {
         
         switch (shipTypePredicte, omitPredicate) {
+            
         case let (s?, o?): return NSCompoundPredicate(type: .and, subpredicates: [o, s])
         case let (s?, nil): return s
         case let (nil, o?): return o
index e91e593..59fbf14 100644 (file)
@@ -190,29 +190,29 @@ final class ScreenshotEditorViewController: BridgeViewController {
             return
         }
         
-        DispatchQueue(label: "makeTrimedImage queue")
-            .async {
+        DispatchQueue(label: "makeTrimedImage queue").async {
+            
+            let images: [NSImage] = self.editedImages.flatMap {
                 
-                let images: [NSImage] = self.editedImages.flatMap {
-                    
-                    guard let originalImage = NSImage(contentsOf: $0.url) else { return nil }
-                    
-                    let trimedImage = NSImage(size: self.currentTrimInfo.rect.size)
-                    
-                    trimedImage.lockFocus()
-                    originalImage.draw(at: .zero,
-                                       from: self.currentTrimInfo.rect,
-                                       operation: NSCompositeCopy,
-                                       fraction: 1.0)
-                    trimedImage.unlockFocus()
-                    
-                    return trimedImage
-                }
+                guard let originalImage = NSImage(contentsOf: $0.url)
+                    else { return nil }
                 
-                DispatchQueue.main.async {
-                    
-                    self.tiledImageView.images = images
-                }
+                let trimedImage = NSImage(size: self.currentTrimInfo.rect.size)
+                
+                trimedImage.lockFocus()
+                originalImage.draw(at: .zero,
+                                   from: self.currentTrimInfo.rect,
+                                   operation: NSCompositeCopy,
+                                   fraction: 1.0)
+                trimedImage.unlockFocus()
+                
+                return trimedImage
+            }
+            
+            DispatchQueue.main.async {
+                
+                self.tiledImageView.images = images
+            }
         }
     }
     
index 03e49f9..ab63478 100644 (file)
@@ -69,7 +69,6 @@ final class ScreenshotInformation: NSObject, NSCoding {
     struct CodingKey {
         
         static let url = "Url"
-        static let version = "Version"
     }
     
     required convenience init?(coder aDecoder: NSCoder) {
index ecf866d..d2b8087 100644 (file)
@@ -175,43 +175,42 @@ final class ScreenshotListViewController: NSViewController {
     
     func registerScreenshot(_ image: NSBitmapImageRep, fromOnScreen: NSRect) {
         
-        DispatchQueue(label: "Screenshot queue")
-            .async {
+        DispatchQueue(label: "Screenshot queue").async {
+            
+            guard let data = image.representation(using: .JPEG, properties: [:])
+                else { return }
+            
+            let url = self.screenshotSaveDirectoryURL
+                .appendingPathComponent(self.dirName)
+                .appendingPathExtension("jpg")
+            let pathURL = FileManager.default.uniqueFileURL(url)
+            
+            do {
                 
-                guard let data = image.representation(using: .JPEG, properties: [:])
-                    else { return }
+                try data.write(to: pathURL)
                 
-                let url = self.screenshotSaveDirectoryURL
-                    .appendingPathComponent(self.dirName)
-                    .appendingPathExtension("jpg")
-                let pathURL = FileManager.default.uniqueFileURL(url)
+            } catch {
                 
-                do {
-                    
-                    try data.write(to: pathURL)
-                    
-                } catch {
-                    
-                    print("Can not write image")
-                    return
-                }
+                print("Can not write image")
+                return
+            }
+            
+            DispatchQueue.main.async {
                 
-                DispatchQueue.main.async {
-                    
-                    let info = ScreenshotInformation(url: pathURL, version: self.cacheVersion(forUrl: pathURL))
-                    
-                    self.screenshotsController.insert(info, atArrangedObjectIndex: 0)
-                    let set: Set<IndexPath> = [NSIndexPath(forItem: 0, inSection: 0) as IndexPath]
-                    self.collectionView.selectionIndexPaths = set
-                    
-                    self.collectionView.scrollToItems(at: set, scrollPosition: .nearestHorizontalEdge)
-                    if UserDefaults.standard[.showsListWindowAtScreenshot] {
-                        
-                        self.view.window?.makeKeyAndOrderFront(nil)
-                    }
+                let info = ScreenshotInformation(url: pathURL, version: self.cacheVersion(forUrl: pathURL))
+                
+                self.screenshotsController.insert(info, atArrangedObjectIndex: 0)
+                let set: Set<IndexPath> = [NSIndexPath(forItem: 0, inSection: 0) as IndexPath]
+                self.collectionView.selectionIndexPaths = set
+                
+                self.collectionView.scrollToItems(at: set, scrollPosition: .nearestHorizontalEdge)
+                if UserDefaults.standard[.showsListWindowAtScreenshot] {
                     
-                    self.saveCache()
+                    self.view.window?.makeKeyAndOrderFront(nil)
                 }
+                
+                self.saveCache()
+            }
         }
     }
     
@@ -240,11 +239,10 @@ final class ScreenshotListViewController: NSViewController {
     
     fileprivate func reloadData() {
         
-        guard let f = try? FileManager
-            .default
-            .contentsOfDirectory(at: screenshotSaveDirectoryURL, includingPropertiesForKeys: nil) else {
-            print("can not read list of screenshot directory")
-            return
+        guard let f = try? FileManager.default.contentsOfDirectory(at: screenshotSaveDirectoryURL, includingPropertiesForKeys: nil)
+            else {
+                print("can not read list of screenshot directory")
+                return
         }
         
         let imageTypes = NSImage.imageTypes()
index 166c487..59d0c10 100644 (file)
@@ -151,26 +151,24 @@ final class ShipViewController: MainTabVIewItemViewController {
     
     private func tag(_ sender: AnyObject?) -> Int {
         
-        guard let sender = sender
-            else { return -1 }
-        
-        if let control = sender as? NSSegmentedControl,
-            let cell = sender.cell as? NSSegmentedCell {
+        switch sender {
             
-            return cell.tag(forSegment: control.selectedSegment)
-        }
-        
-        if let control = sender as? NSControl {
+        case let segmented as NSSegmentedControl:
+            let cell = segmented.cell as? NSSegmentedCell
             
+            return cell?.tag(forSegment: segmented.selectedSegment) ?? -1
+            
+        case let control as NSControl:
             return control.tag
+            
+        default:
+            return -1
         }
-        
-        return -1
     }
     
     @IBAction func changeView(_ sender: AnyObject?) {
         
-        ViewType(rawValue: tag(sender)).map { showView(with: $0) }
+        ViewType(rawValue: tag(sender)).map(showView)
     }
 }
 
index cd61fb6..a9ab8a3 100644 (file)
@@ -20,13 +20,25 @@ final class SlotItemFrameView: NSBox {
         NSColor.gridColor.set()
         NSBezierPath.setDefaultLineWidth(1.0)
         
-        multiline {
-            [(NSPoint, NSPoint)]()
-                .appended { (NSPoint(x: 40.5, y: 0), NSPoint(x: 40.5, y: height)) }
-                .appended { (NSPoint(x: 0, y: 17.5), NSPoint(x: width, y: 17.5)) }
-                .appended { (NSPoint(x: 0, y: 34.5), NSPoint(x: width, y: 34.5)) }
-                .appended { (NSPoint(x: 0, y: 51.5), NSPoint(x: width, y: 51.5)) }
-            }
+        multiline(lines:
+            [
+                (
+                    NSPoint(x: 40.5, y: 0),
+                    NSPoint(x: 40.5, y: height)
+                ),
+                (
+                    NSPoint(x: 0, y: 17.5),
+                    NSPoint(x: width, y: 17.5)
+                ),
+                (
+                    NSPoint(x: 0, y: 34.5),
+                    NSPoint(x: width, y: 34.5)
+                ),
+                (
+                    NSPoint(x: 0, y: 51.5),
+                    NSPoint(x: width, y: 51.5)
+                )
+            ])
             .stroke()
     }
 }
index 2be3af0..7e9061f 100644 (file)
@@ -93,7 +93,12 @@ final class SlotItemLevelView: NSTextField {
         
         let width = bounds.width
         let height = bounds.height
-        let path = multiline { [(NSPoint(x: width - offset, y: 0), NSPoint(x: width - offset, y: height))] }
+        let path = multiline(lines: [
+            (
+                NSPoint(x: width - offset, y: 0),
+                NSPoint(x: width - offset, y: height)
+            )
+            ])
         path.lineWidth = 1.0
         
         return path
@@ -103,13 +108,17 @@ final class SlotItemLevelView: NSTextField {
         
         let width = bounds.width
         let height = bounds.height
-        let path = multiline {
-            [(NSPoint, NSPoint)]()
-                .appended { (NSPoint(x: width - offset, y: 0), NSPoint(x: width - offset, y: height)) }
-                .appended {
-                    (NSPoint(x: width - offset - padding, y: 0), NSPoint(x: width - offset - padding, y: height))
-            }
-        }
+        let path = multiline(lines:
+            [
+                (
+                    NSPoint(x: width - offset, y: 0),
+                    NSPoint(x: width - offset, y: height)
+                ),
+                (
+                    NSPoint(x: width - offset - padding, y: 0),
+                    NSPoint(x: width - offset - padding, y: height)
+                )
+            ])
         path.lineWidth = 1.0
         
         return path
@@ -119,17 +128,21 @@ final class SlotItemLevelView: NSTextField {
         
         let width = bounds.width
         let height = bounds.height
-        let path = multiline {
-            [(NSPoint, NSPoint)]()
-                .appended { (NSPoint(x: width - offset, y: 0), NSPoint(x: width - offset, y: height)) }
-                .appended {
-                    (NSPoint(x: width - offset - padding, y: 0), NSPoint(x: width - offset - padding, y: height))
-                }
-                .appended {
-                    (NSPoint(x: width - offset - padding * 2, y: 0),
-                     NSPoint(x: width - offset - padding * 2, y: height))
-            }
-        }
+        let path = multiline(lines:
+            [
+                (
+                    NSPoint(x: width - offset, y: 0),
+                    NSPoint(x: width - offset, y: height)
+                ),
+                (
+                    NSPoint(x: width - offset - padding, y: 0),
+                    NSPoint(x: width - offset - padding, y: height)
+                ),
+                (
+                    NSPoint(x: width - offset - padding * 2, y: 0),
+                    NSPoint(x: width - offset - padding * 2, y: height)
+                )
+            ])
         path.lineWidth = 1.0
         
         return path
@@ -139,10 +152,13 @@ final class SlotItemLevelView: NSTextField {
         
         let width = bounds.width
         let height = bounds.height
-        let path = multiline {
-            [(NSPoint, NSPoint)]()
-                .appended { (NSPoint(x: width - offset - slideOffset, y: 0), NSPoint(x: width - offset, y: height)) }
-        }
+        let path = multiline(lines:
+            [
+                (
+                    NSPoint(x: width - offset - slideOffset, y: 0),
+                    NSPoint(x: width - offset, y: height)
+                )
+            ])
         path.lineWidth = 2.0
         
         return path
@@ -152,14 +168,17 @@ final class SlotItemLevelView: NSTextField {
         
         let width = bounds.width
         let height = bounds.height
-        let path = multiline {
-            [(NSPoint, NSPoint)]()
-                .appended { (NSPoint(x: width - offset - slideOffset, y: 0), NSPoint(x: width - offset, y: height)) }
-                .appended {
-                    (NSPoint(x: width - offset - padding - slideOffset, y: 0),
-                     NSPoint(x: width - offset - padding, y: height))
-            }
-        }
+        let path = multiline(lines:
+            [
+                (
+                    NSPoint(x: width - offset - slideOffset, y: 0),
+                    NSPoint(x: width - offset, y: height)
+                ),
+                (
+                    NSPoint(x: width - offset - padding - slideOffset, y: 0),
+                    NSPoint(x: width - offset - padding, y: height)
+                )
+            ])
         path.lineWidth = 2.0
         
         return path
@@ -169,18 +188,21 @@ final class SlotItemLevelView: NSTextField {
         
         let width = bounds.width
         let height = bounds.height
-        let path = multiline {
-            [(NSPoint, NSPoint)]()
-                .appended { (NSPoint(x: width - offset - slideOffset, y: 0), NSPoint(x: width - offset, y: height)) }
-                .appended {
-                    (NSPoint(x: width - offset - padding - slideOffset, y: 0),
-                     NSPoint(x: width - offset - padding, y: height))
-                }
-                .appended {
-                    (NSPoint(x: width - offset - padding * 2 - slideOffset, y: 0),
-                     NSPoint(x: width - offset - padding * 2, y: height))
-            }
-        }
+        let path = multiline(lines:
+            [
+                (
+                    NSPoint(x: width - offset - slideOffset, y: 0),
+                    NSPoint(x: width - offset, y: height)
+                ),
+                (
+                    NSPoint(x: width - offset - padding - slideOffset, y: 0),
+                    NSPoint(x: width - offset - padding, y: height)
+                ),
+                (
+                    NSPoint(x: width - offset - padding * 2 - slideOffset, y: 0),
+                    NSPoint(x: width - offset - padding * 2, y: height)
+                )
+            ])
         path.lineWidth = 2.0
         
         return path
@@ -190,18 +212,18 @@ final class SlotItemLevelView: NSTextField {
         
         let width = bounds.width
         let height = bounds.height
-        let path = polyline {
-            [NSPoint]()
-                .appended { NSPoint(x: width - offset - slideOffset, y: 0) }
-                .appended { NSPoint(x: width - offset, y: height * 0.5) }
-                .appended { NSPoint(x: width - offset - anglePoint, y: height) }
-        }
-        polyline {
-            [NSPoint]()
-                .appended { NSPoint(x: width - offset - padding - slideOffset, y: 0) }
-                .appended { NSPoint(x: width - offset - padding, y: height * 0.5) }
-                .appended { NSPoint(x: width - offset - padding - anglePoint, y: height) }
-            }
+        let path = polyline(points:
+            [
+                NSPoint(x: width - offset - slideOffset, y: 0),
+                NSPoint(x: width - offset, y: height * 0.5),
+                NSPoint(x: width - offset - anglePoint, y: height)
+            ])
+        polyline(points:
+            [
+                NSPoint(x: width - offset - padding - slideOffset, y: 0),
+                NSPoint(x: width - offset - padding, y: height * 0.5),
+                NSPoint(x: width - offset - padding - anglePoint, y: height)
+            ])
             .map { path?.append($0) }
         path?.lineWidth = 2.0
         
index 0d5b039..c581910 100644 (file)
@@ -29,8 +29,7 @@ final class StrengthenListItemView: NSBox {
                 (NSPoint(x: 209.5, y: 0), NSPoint(x: 209.5, y: height)),
                 (NSPoint(x: 0, y: 17.5), NSPoint(x: width, y: 17.5)),
                 (NSPoint(x: 0, y: 34.5), NSPoint(x: width, y: 34.5))
-            ]
-            )
+            ])
             .stroke()
     }
 }
index 69a2359..48866f6 100644 (file)
@@ -210,7 +210,7 @@ final class TiledImageView: NSView {
     
     fileprivate func removeAllTrackingAreas() {
         
-        trackingAreas.forEach { removeTrackingArea($0) }
+        trackingAreas.forEach(removeTrackingArea)
     }
     
     fileprivate func setTrackingArea() {
@@ -279,8 +279,7 @@ extension TiledImageView {
 
 extension TiledImageView: NSDraggingSource {
     
-    func draggingSession(_ session: NSDraggingSession,
-                         sourceOperationMaskFor context: NSDraggingContext) -> NSDragOperation {
+    func draggingSession(_ session: NSDraggingSession, sourceOperationMaskFor context: NSDraggingContext) -> NSDragOperation {
         
         return context == .withinApplication ? .move : []
     }