OSDN Git Service

HMApplySuppliesCommandをSwiftに変換した
authormasakih <masakih@users.sourceforge.jp>
Sun, 8 Jan 2017 11:56:53 +0000 (20:56 +0900)
committermasakih <masakih@users.sourceforge.jp>
Sun, 8 Jan 2017 11:56:53 +0000 (20:56 +0900)
KCD.xcodeproj/project.pbxproj
KCD/HMApplySuppliesCommand.h [deleted file]
KCD/HMApplySuppliesCommand.m [deleted file]
KCD/HMApplySuppliesCommand.swift [new file with mode: 0644]
KCD/HMHokyuChargeCommand.m

index 1e7af0f..cefa981 100644 (file)
@@ -59,6 +59,7 @@
                F44BC6C91E22314B004644E3 /* HMUnknownComand.swift in Sources */ = {isa = PBXBuildFile; fileRef = F44BC6C81E22314B004644E3 /* HMUnknownComand.swift */; };
                F44BC6CB1E223208004644E3 /* HMIgnoreCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = F44BC6CA1E223208004644E3 /* HMIgnoreCommand.swift */; };
                F44BC6D11E224299004644E3 /* HMPortCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = F44BC6D01E224299004644E3 /* HMPortCommand.swift */; };
+               F44BC6D31E22581D004644E3 /* HMApplySuppliesCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = F44BC6D21E22581D004644E3 /* HMApplySuppliesCommand.swift */; };
                F4513EDD18B619B600073552 /* HMCoreDataManager.m in Sources */ = {isa = PBXBuildFile; fileRef = F4513EDC18B619B600073552 /* HMCoreDataManager.m */; };
                F4513EE818B77A5300073552 /* HMMemberKDockCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4513EE718B77A5300073552 /* HMMemberKDockCommand.m */; };
                F4513EEB18B7900A00073552 /* HMMemberDeckCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4513EEA18B7900A00073552 /* HMMemberDeckCommand.m */; };
                F4AC13711E096A7B00851147 /* HMHistoryWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4AC13701E096A7B00851147 /* HMHistoryWindowController.swift */; };
                F4B15CBD1E21BA870078CFFC /* CommandRegister.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4B15CBC1E21BA870078CFFC /* CommandRegister.swift */; };
                F4B1E30C19D1C06900805879 /* HMHokyuChargeCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4B1E30B19D1C06900805879 /* HMHokyuChargeCommand.m */; };
-               F4B1E30F19D1C9C400805879 /* HMApplySuppliesCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4B1E30E19D1C9C400805879 /* HMApplySuppliesCommand.m */; };
                F4B37EF319FBBBED002F371A /* HMRemodelSlotCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4B37EF219FBBBED002F371A /* HMRemodelSlotCommand.m */; };
                F4B37EF619FBE801002F371A /* HMRemodelSlotItemCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4B37EF519FBE801002F371A /* HMRemodelSlotItemCommand.m */; };
                F4B37EFF19FC8DCC002F371A /* HMUpgradableShipsWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F4B37F0119FC8DCC002F371A /* HMUpgradableShipsWindowController.xib */; };
                F44BC6C81E22314B004644E3 /* HMUnknownComand.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMUnknownComand.swift; sourceTree = "<group>"; };
                F44BC6CA1E223208004644E3 /* HMIgnoreCommand.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMIgnoreCommand.swift; sourceTree = "<group>"; };
                F44BC6D01E224299004644E3 /* HMPortCommand.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMPortCommand.swift; sourceTree = "<group>"; };
+               F44BC6D21E22581D004644E3 /* HMApplySuppliesCommand.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMApplySuppliesCommand.swift; sourceTree = "<group>"; };
                F4513EDB18B619B600073552 /* HMCoreDataManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMCoreDataManager.h; sourceTree = "<group>"; };
                F4513EDC18B619B600073552 /* HMCoreDataManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMCoreDataManager.m; sourceTree = "<group>"; };
                F4513EE618B77A5300073552 /* HMMemberKDockCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMMemberKDockCommand.h; sourceTree = "<group>"; };
                F4B15CBC1E21BA870078CFFC /* CommandRegister.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CommandRegister.swift; sourceTree = "<group>"; };
                F4B1E30A19D1C06900805879 /* HMHokyuChargeCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMHokyuChargeCommand.h; sourceTree = "<group>"; };
                F4B1E30B19D1C06900805879 /* HMHokyuChargeCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMHokyuChargeCommand.m; sourceTree = "<group>"; };
-               F4B1E30D19D1C9C400805879 /* HMApplySuppliesCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMApplySuppliesCommand.h; sourceTree = "<group>"; };
-               F4B1E30E19D1C9C400805879 /* HMApplySuppliesCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMApplySuppliesCommand.m; sourceTree = "<group>"; };
                F4B37EF119FBBBED002F371A /* HMRemodelSlotCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMRemodelSlotCommand.h; sourceTree = "<group>"; };
                F4B37EF219FBBBED002F371A /* HMRemodelSlotCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMRemodelSlotCommand.m; sourceTree = "<group>"; };
                F4B37EF419FBE801002F371A /* HMRemodelSlotItemCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMRemodelSlotItemCommand.h; sourceTree = "<group>"; };
                                F4B1E30B19D1C06900805879 /* HMHokyuChargeCommand.m */,
                                F43BA4A5197CD59400CFF788 /* HMNyukyoSpeedChangeCommand.h */,
                                F43BA4A6197CD59400CFF788 /* HMNyukyoSpeedChangeCommand.m */,
-                               F4B1E30D19D1C9C400805879 /* HMApplySuppliesCommand.h */,
-                               F4B1E30E19D1C9C400805879 /* HMApplySuppliesCommand.m */,
+                               F44BC6D21E22581D004644E3 /* HMApplySuppliesCommand.swift */,
                        );
                        name = "Supply&DockCommand";
                        sourceTree = "<group>";
                                F4D05BE11E0FAB8E00688D66 /* HMShipViewController.swift in Sources */,
                                F4E5FF041E1518200026868C /* HMScreenshotDetailViewController.swift in Sources */,
                                F472159E1E1E6EE70083D3BC /* HMShipMasterDetailWindowController.swift in Sources */,
+                               F44BC6D31E22581D004644E3 /* HMApplySuppliesCommand.swift in Sources */,
                                F4D05BDB1E0F76A800688D66 /* HMResourceViewController.swift in Sources */,
                                F4A3AD82199F529700FDBF80 /* HMCombinedBattleCommand.m in Sources */,
                                F4AA591A1E1CE2EA001667AF /* HMSlotItemEquipTypeTransformer.swift in Sources */,
                                F4BDEB53187252F30069D0CE /* main.m in Sources */,
                                F47215B01E1FEACC0083D3BC /* HMServerDataStore.swift in Sources */,
                                F47215A81E1F947A0083D3BC /* HMBookmarkDataStore.swift in Sources */,
-                               F4B1E30F19D1C9C400805879 /* HMApplySuppliesCommand.m in Sources */,
                                F4AA59421E1E2854001667AF /* HMOrderedSetToArrayTransformer.swift in Sources */,
                                F494DC5F18C30AE100AE97E4 /* HMMissionStatus.m in Sources */,
                                F43F3D4C1A34AC8000D6DAF7 /* HMKCMasterShipObject.m in Sources */,
diff --git a/KCD/HMApplySuppliesCommand.h b/KCD/HMApplySuppliesCommand.h
deleted file mode 100644 (file)
index 06f3331..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-//
-//  HMApplySuppliesCommand.h
-//  KCD
-//
-//  Created by Hori,Masaki on 2014/09/24.
-//  Copyright (c) 2014年 Hori,Masaki. All rights reserved.
-//
-
-#import "HMJSONCommand.h"
-
-@interface HMApplySuppliesCommand : HMJSONCommand
-
-@end
diff --git a/KCD/HMApplySuppliesCommand.m b/KCD/HMApplySuppliesCommand.m
deleted file mode 100644 (file)
index 0c76de1..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-//
-//  HMApplySuppliesCommand.m
-//  KCD
-//
-//  Created by Hori,Masaki on 2014/09/24.
-//  Copyright (c) 2014年 Hori,Masaki. All rights reserved.
-//
-
-#import "HMApplySuppliesCommand.h"
-
-#import "KCD-Swift.h"
-
-#import "HMKCShipObject+Extensions.h"
-
-
-@implementation HMApplySuppliesCommand
-- (void)execute
-{
-       HMServerDataStore *store = [HMServerDataStore oneTimeEditor];
-       
-       NSDictionary *data = self.json[@"api_data"];
-       NSArray *shipInfos = data[@"api_ship"];
-       
-       for(NSDictionary *updataInfo in shipInfos) {
-               NSError *error = nil;
-               NSArray<HMKCShipObject *> *ships = [store objectsWithEntityName:@"Ship"
-                                                                                                                                 error:&error
-                                                                                                               predicateFormat:@"id = %@", @([updataInfo[@"api_id"] integerValue])];
-               if(ships.count == 0) {
-                       if(error) {
-                               NSLog(@"Error: at %@ : %@", NSStringFromClass([self class]), error);
-                       }
-                       continue;
-               }
-               
-               ships[0].bull = updataInfo[@"api_bull"];
-               ships[0].fuel = updataInfo[@"api_fuel"];
-               NSArray *onslots = updataInfo[@"api_onslot"];
-               ships[0].onslot_0 = onslots[0];
-               ships[0].onslot_1 = onslots[1];
-               ships[0].onslot_2 = onslots[2];
-               ships[0].onslot_3 = onslots[3];
-               ships[0].onslot_4 = onslots[4];
-       }
-}
-@end
diff --git a/KCD/HMApplySuppliesCommand.swift b/KCD/HMApplySuppliesCommand.swift
new file mode 100644 (file)
index 0000000..3cf5646
--- /dev/null
@@ -0,0 +1,37 @@
+//
+//  HMApplySuppliesCommand.swift
+//  KCD
+//
+//  Created by Hori,Masaki on 2017/01/08.
+//  Copyright © 2017年 Hori,Masaki. All rights reserved.
+//
+
+import Cocoa
+
+class HMApplySuppliesCommand: HMJSONCommand {
+    override func execute() {
+        let store = HMServerDataStore.oneTimeEditor()
+        guard let j = json as? [String:AnyObject],
+            let data = j["api_data"] as? [String:AnyObject],
+            let infos = data["api_ship"] as? [[String:AnyObject]]
+            else { return }
+        infos.forEach {
+            guard let i = $0["api_id"] as? NSNumber else { return }
+            let p = NSPredicate(format: "id == %@", argumentArray: [i])
+            guard let s = try? store?.objects(withEntityName: "Ship", predicate: p),
+                let ships = s as? [HMKCShipObject],
+                let ship = ships.first,
+                let bull = $0["api_bull"] as? NSNumber,
+                let fuel = $0["api_fuel"] as? NSNumber,
+                let slots = $0["api_onslot"] as? [NSNumber]
+                else { return }
+            ship.bull = bull
+            ship.fuel = fuel
+            ship.onslot_0 = slots[0]
+            ship.onslot_1 = slots[1]
+            ship.onslot_2 = slots[2]
+            ship.onslot_3 = slots[3]
+            ship.onslot_4 = slots[4]
+        }
+    }
+}
index 01856e9..f9e6a22 100644 (file)
@@ -8,8 +8,9 @@
 
 #import "HMHokyuChargeCommand.h"
 
+#import "KCD-Swift.h"
+
 #import "HMMemberMaterialCommand.h"
-#import "HMApplySuppliesCommand.h"
 
 
 @implementation HMHokyuChargeCommand