OSDN Git Service

HMSlotItemShortNameTransformerをSwiftに変換した
authormasakih <masakih@users.sourceforge.jp>
Wed, 4 Jan 2017 13:56:05 +0000 (22:56 +0900)
committermasakih <masakih@users.sourceforge.jp>
Wed, 4 Jan 2017 13:56:05 +0000 (22:56 +0900)
KCD.xcodeproj/project.pbxproj
KCD/HMSlotItemShortNameTransformer.h [deleted file]
KCD/HMSlotItemShortNameTransformer.m [deleted file]
KCD/HMSlotItemShortNameTransformer.swift [new file with mode: 0644]
KCD/KCD-Bridging-Header.h

index 444d9c9..c02b0cb 100644 (file)
@@ -85,7 +85,6 @@
                F46F104918ABAC910063E503 /* KCD.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = F46F104718ABAC910063E503 /* KCD.xcdatamodeld */; };
                F46F45BF1CFF0BEE00EB7F4D /* HMSlotDepriveCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F46F45BE1CFF0BEE00EB7F4D /* HMSlotDepriveCommand.m */; };
                F46F45C21CFF0CFF00EB7F4D /* HMSlotDepriveUnsetCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F46F45C11CFF0CFF00EB7F4D /* HMSlotDepriveUnsetCommand.m */; };
-               F46FCB291BD933C600304DE7 /* HMSlotItemShortNameTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = F46FCB281BD933C600304DE7 /* HMSlotItemShortNameTransformer.m */; };
                F47178471B6DE9F400F5E59D /* HMMapAreaTransformaer.m in Sources */ = {isa = PBXBuildFile; fileRef = F47178461B6DE9F400F5E59D /* HMMapAreaTransformaer.m */; };
                F471784A1B6F9B5600F5E59D /* ResourceHistory.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = F47178481B6F9B5600F5E59D /* ResourceHistory.xcdatamodeld */; };
                F471784D1B6FA18800F5E59D /* HMKCResource.m in Sources */ = {isa = PBXBuildFile; fileRef = F471784C1B6FA18800F5E59D /* HMKCResource.m */; };
                F4AA592E1E1D1D4D001667AF /* HMSokuTransformer.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4AA592D1E1D1D4D001667AF /* HMSokuTransformer.swift */; };
                F4AA59301E1D1FAB001667AF /* HMLengTransformer.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4AA592F1E1D1FAB001667AF /* HMLengTransformer.swift */; };
                F4AA59321E1D211C001667AF /* HMSlotitemNameTransformer.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4AA59311E1D211C001667AF /* HMSlotitemNameTransformer.swift */; };
+               F4AA59341E1D2512001667AF /* HMSlotItemShortNameTransformer.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4AA59331E1D2512001667AF /* HMSlotItemShortNameTransformer.swift */; };
                F4AC136D1E0802C000851147 /* HMPreferencePanelController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4AC136C1E0802C000851147 /* HMPreferencePanelController.swift */; };
                F4AC136F1E0963DB00851147 /* HMProgressPanel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4AC136E1E0963DB00851147 /* HMProgressPanel.swift */; };
                F4AC13711E096A7B00851147 /* HMHistoryWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4AC13701E096A7B00851147 /* HMHistoryWindowController.swift */; };
                F46F45BE1CFF0BEE00EB7F4D /* HMSlotDepriveCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMSlotDepriveCommand.m; sourceTree = "<group>"; };
                F46F45C01CFF0CFF00EB7F4D /* HMSlotDepriveUnsetCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMSlotDepriveUnsetCommand.h; sourceTree = "<group>"; };
                F46F45C11CFF0CFF00EB7F4D /* HMSlotDepriveUnsetCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMSlotDepriveUnsetCommand.m; sourceTree = "<group>"; };
-               F46FCB271BD933C600304DE7 /* HMSlotItemShortNameTransformer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMSlotItemShortNameTransformer.h; sourceTree = "<group>"; };
-               F46FCB281BD933C600304DE7 /* HMSlotItemShortNameTransformer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMSlotItemShortNameTransformer.m; sourceTree = "<group>"; };
                F47178451B6DE9F400F5E59D /* HMMapAreaTransformaer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMMapAreaTransformaer.h; sourceTree = "<group>"; };
                F47178461B6DE9F400F5E59D /* HMMapAreaTransformaer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMMapAreaTransformaer.m; sourceTree = "<group>"; };
                F47178491B6F9B5600F5E59D /* ResourceHistory.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = ResourceHistory.xcdatamodel; sourceTree = "<group>"; };
                F4AA592D1E1D1D4D001667AF /* HMSokuTransformer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMSokuTransformer.swift; sourceTree = "<group>"; };
                F4AA592F1E1D1FAB001667AF /* HMLengTransformer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMLengTransformer.swift; sourceTree = "<group>"; };
                F4AA59311E1D211C001667AF /* HMSlotitemNameTransformer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMSlotitemNameTransformer.swift; sourceTree = "<group>"; };
+               F4AA59331E1D2512001667AF /* HMSlotItemShortNameTransformer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMSlotItemShortNameTransformer.swift; sourceTree = "<group>"; };
                F4AC136C1E0802C000851147 /* HMPreferencePanelController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMPreferencePanelController.swift; sourceTree = "<group>"; };
                F4AC136E1E0963DB00851147 /* HMProgressPanel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMProgressPanel.swift; sourceTree = "<group>"; };
                F4AC13701E096A7B00851147 /* HMHistoryWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMHistoryWindowController.swift; sourceTree = "<group>"; };
                                F4AA592D1E1D1D4D001667AF /* HMSokuTransformer.swift */,
                                F4AA592F1E1D1FAB001667AF /* HMLengTransformer.swift */,
                                F4AA59311E1D211C001667AF /* HMSlotitemNameTransformer.swift */,
-                               F46FCB271BD933C600304DE7 /* HMSlotItemShortNameTransformer.h */,
-                               F46FCB281BD933C600304DE7 /* HMSlotItemShortNameTransformer.m */,
+                               F4AA59331E1D2512001667AF /* HMSlotItemShortNameTransformer.swift */,
                                F4666C5C1B242124001840DB /* HMQuestProgressTransformer.h */,
                                F4666C5D1B242124001840DB /* HMQuestProgressTransformer.m */,
                                F47178451B6DE9F400F5E59D /* HMMapAreaTransformaer.h */,
                                F4D05BD91E0F748900688D66 /* HMQuestListViewController.swift in Sources */,
                                F4513EE818B77A5300073552 /* HMMemberKDockCommand.m in Sources */,
                                F4F9F87E1C6B5E4A00D0EE76 /* HMKCMasterSType.m in Sources */,
+                               F4AA59251E1CE7E5001667AF /* HMKCMasterSlotItemEquipTypeObject+CoreDataClass.m in Sources */,
                                F431E9791DF3CD1B00FB56AE /* HMActinKindTransformer.m in Sources */,
                                F4048A9F1E19308A008ACFD6 /* HMStrokeTextFieldCell.swift in Sources */,
                                F45F3BE11E067A870009434E /* HMHistoryItemCleaner.swift in Sources */,
                                F4B3DC1E18DEB8C70011B4FC /* HMKenzoHistory.m in Sources */,
                                F490977B1E19C3910085A45D /* HMSuppliesView.swift in Sources */,
                                F4F9F86D1C6A306A00D0EE76 /* HMKCDamage+CoreDataProperties.m in Sources */,
+                               F4AA59341E1D2512001667AF /* HMSlotItemShortNameTransformer.swift in Sources */,
                                F4F9F8771C6B5BA900D0EE76 /* HMKCKenzoDock+CoreDataProperties.m in Sources */,
                                F4A2AF5B1A0F9B490024BD9E /* HMScreenshotInformation.m in Sources */,
                                F43769DE1AE1248800DE6204 /* HMAirBattleCommand.m in Sources */,
                                F4D05BE11E0FAB8E00688D66 /* HMShipViewController.swift in Sources */,
                                F4C86B921C1C445D00F260FE /* HMUpgradeShipExcludeColorTransformer.m in Sources */,
                                F4E5FF041E1518200026868C /* HMScreenshotDetailViewController.swift in Sources */,
-                               F46FCB291BD933C600304DE7 /* HMSlotItemShortNameTransformer.m in Sources */,
                                F4D05BDB1E0F76A800688D66 /* HMResourceViewController.swift in Sources */,
                                F4A3AD82199F529700FDBF80 /* HMCombinedBattleCommand.m in Sources */,
                                F4AA591A1E1CE2EA001667AF /* HMSlotItemEquipTypeTransformer.swift in Sources */,
                                F471784D1B6FA18800F5E59D /* HMKCResource.m in Sources */,
                                F4F9F87D1C6B5E4A00D0EE76 /* HMKCMasterSType+CoreDataProperties.m in Sources */,
                                F4E5FF0A1E15CE3D0026868C /* HMBridgeViewController.swift in Sources */,
-                               F4AA59251E1CE7E5001667AF /* HMKCMasterSlotItemEquipTypeObject+CoreDataClass.m in Sources */,
                                F4C6687D1C545E3800601AFB /* HMMapWindowController.m in Sources */,
                                F4AA060D1930E69200844688 /* HMMidnightBattleCommand.m in Sources */,
                                F4D6BC551A93903E00742FEB /* HMDropShipHistory.m in Sources */,
diff --git a/KCD/HMSlotItemShortNameTransformer.h b/KCD/HMSlotItemShortNameTransformer.h
deleted file mode 100644 (file)
index f5de522..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-//
-//  HMSlotItemShortNameTransformer.h
-//  KCD
-//
-//  Created by Hori,Masaki on 2015/10/23.
-//  Copyright (c) 2015年 Hori,Masaki. All rights reserved.
-//
-
-#import <Foundation/Foundation.h>
-
-@interface HMSlotItemShortNameTransformer : NSValueTransformer
-
-@end
diff --git a/KCD/HMSlotItemShortNameTransformer.m b/KCD/HMSlotItemShortNameTransformer.m
deleted file mode 100644 (file)
index 62acece..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-//
-//  HMSlotItemShortNameTransformer.m
-//  KCD
-//
-//  Created by Hori,Masaki on 2015/10/23.
-//  Copyright (c) 2015年 Hori,Masaki. All rights reserved.
-//
-
-#import "HMSlotItemShortNameTransformer.h"
-
-#import "HMServerDataStore.h"
-
-#import "HMKCSlotItemObject+Extensions.h"
-#import "HMKCMasterSlotItemObject.h"
-
-static NSDictionary *slotItemShortName = nil;
-
-@implementation HMSlotItemShortNameTransformer
-+ (void)load
-{
-       static dispatch_once_t onceToken;
-       dispatch_once(&onceToken, ^{
-//             [NSValueTransformer setValueTransformer:[self new] forName:@"HMSlotItemShortNameTransformer"];
-               
-               NSBundle *mainBundle = [NSBundle mainBundle];
-               NSString *path = [mainBundle pathForResource:@"SlotItemShortName" ofType:@"plist"];
-               if(!path) {
-                       NSLog(@"Could not find SlotItemShortName.plist");
-                       NSBeep();
-                       return;
-               }
-               id dict = [NSDictionary dictionaryWithContentsOfFile:path];
-               if(!dict) {
-                       NSLog(@"SlotItemShortName.plist is not dictionay.");
-                       NSBeep();
-                       return;
-               }
-               slotItemShortName = dict;
-       });
-}
-
-+ (Class)transformedValueClass
-{
-       return [NSString class];
-}
-+ (BOOL)allowsReverseTransformation
-{
-       return NO;
-}
-
-- (id)transformedValue:(id)value
-{
-       if(![value isKindOfClass:[NSNumber class]]) return nil;
-       NSInteger slotItemID = [value integerValue];
-       if(slotItemID == -1) return nil;
-       if(slotItemID == 0) return nil;
-       
-       HMServerDataStore *store = [HMServerDataStore defaultManager];
-       
-       NSError *error = nil;
-       NSArray *array = [store objectsWithEntityName:@"SlotItem"
-                                                                                       error:&error
-                                                                 predicateFormat:@"id = %@", value];
-       if([array count] == 0) {
-               NSLog(@"SlotItem is invalid.");
-               return nil;
-       }
-       
-       HMKCSlotItemObject *slotItem = array[0];
-       NSString *mstIDString = [slotItem.master_slotItem.id stringValue];
-       NSString *shortName = slotItemShortName[mstIDString];
-       if(shortName) return shortName;
-       
-       return [slotItem.name copy];
-}
-@end
diff --git a/KCD/HMSlotItemShortNameTransformer.swift b/KCD/HMSlotItemShortNameTransformer.swift
new file mode 100644 (file)
index 0000000..b5714c9
--- /dev/null
@@ -0,0 +1,40 @@
+//
+//  HMSlotItemShortNameTransformer.swift
+//  KCD
+//
+//  Created by Hori,Masaki on 2017/01/04.
+//  Copyright © 2017年 Hori,Masaki. All rights reserved.
+//
+
+import Cocoa
+
+class HMSlotItemShortNameTransformer: ValueTransformer {
+    
+    private static var slotItemShortName: [Int : String] = {
+        guard let url = Bundle.main.url(forResource: "SlotItemShortName", withExtension: "plist"),
+            let dict = NSDictionary(contentsOf: url) as? [String:String]
+            else { fatalError("Can not load SlotItemShortName.plist") }
+        var names: [Int : String] = [:]
+        dict.keys.forEach {
+            guard let k = Int($0) else { return }
+            names[k] = dict[$0]
+        }
+        return names
+    }()
+    
+    override class func transformedValueClass() -> Swift.AnyClass {
+        return String.self as! AnyClass
+    }
+    override func transformedValue(_ value: Any?) -> Any? {
+        guard let v = value as? Int, v != 0, v != -1 else { return nil }
+        guard let store = HMServerDataStore.default() else { return nil }
+        let predicate = NSPredicate(format: "id = %d", v)
+        guard let a = try? store.objects(withEntityName: "SlotItem", predicate: predicate),
+            let array = a as? [HMKCSlotItemObject],
+            array.count != 0
+            else { return nil }
+        let itemId = array[0].master_slotItem.id as Int
+        if let shortName = HMSlotItemShortNameTransformer.slotItemShortName[itemId] { return shortName }
+        return array[0].name
+    }
+}
index 83c0d88..adc1ff8 100644 (file)
@@ -6,7 +6,6 @@
 #import "HMUserDefaults.h"
 
 // ValueTransformer
-#import "HMSlotItemShortNameTransformer.h"
 #import "HMQuestProgressTransformer.h"
 #import "HMMapAreaTransformaer.h"
 #import "HMUpgradeShipExcludeColorTransformer.h"
 
 #import "HMKCMasterShipObject.h"
 #import "HMKCMasterSType.h"
-#import "HMKCShipObject+Extensions.h"
 #import "HMKCMasterMapInfo.h"
-#import "HMKCSlotItemObject+Extensions.h"
+#import "HMKCMasterSlotItemObject.h"
 #import "HMKCMasterSlotItemEquipTypeObject.h"
 
+#import "HMKCShipObject+Extensions.h"
+#import "HMKCSlotItemObject+Extensions.h"
 
 #import "HMKCDeck+Extension.h"