OSDN Git Service

HMApplySuppliesCommandクラスをSwiftで書き換え
authormasakih <masakih@users.sourceforge.jp>
Thu, 15 Jan 2015 16:31:51 +0000 (01:31 +0900)
committermasakih <masakih@users.sourceforge.jp>
Thu, 15 Jan 2015 16:31:51 +0000 (01:31 +0900)
KCD.xcodeproj/project.pbxproj
KCD/HMApplySuppliesCommand.h [deleted file]
KCD/HMApplySuppliesCommand.m [deleted file]
KCD/HMApplySuppliesCommand.swift [new file with mode: 0644]
KCD/KCD-Bridging-Header.h

index 5406547..7e2b065 100644 (file)
@@ -83,6 +83,7 @@
                F4896DE91A6681DF00B09967 /* HMRemodelSlotCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4896DE81A6681DF00B09967 /* HMRemodelSlotCommand.swift */; };
                F4896DEB1A67D11000B09967 /* HMCreateSlotItemCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4896DEA1A67D11000B09967 /* HMCreateSlotItemCommand.swift */; };
                F4896DED1A67E8E500B09967 /* HMResetSortieCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4896DEC1A67E8E500B09967 /* HMResetSortieCommand.swift */; };
+               F4896DEF1A680E1400B09967 /* HMApplySuppliesCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4896DEE1A680E1400B09967 /* HMApplySuppliesCommand.swift */; };
                F494DC6A18C8BAB900AE97E4 /* HMPowerUpSupportViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F494DC6818C8BAB900AE97E4 /* HMPowerUpSupportViewController.xib */; };
                F4A2AF541A074DE40024BD9E /* HMScreenshotListWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F4A2AF561A074DE40024BD9E /* HMScreenshotListWindowController.xib */; };
                F4A2AF581A0930160024BD9E /* Quartz.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F4A2AF571A0930160024BD9E /* Quartz.framework */; };
@@ -90,7 +91,6 @@
                F4A3AD9419BDDE5500FDBF80 /* HMPreferencePanelController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F4A3AD9619BDDE5500FDBF80 /* HMPreferencePanelController.xib */; };
                F4AA05FB192B92C800844688 /* Temporary.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = F4AA05F9192B92C700844688 /* Temporary.xcdatamodeld */; };
                F4AA0604192E20F500844688 /* HMCalculateDamageCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4AA0603192E20F500844688 /* HMCalculateDamageCommand.m */; };
-               F4B1E30F19D1C9C400805879 /* HMApplySuppliesCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4B1E30E19D1C9C400805879 /* HMApplySuppliesCommand.m */; };
                F4B2A0901A1F9C2100D2EF12 /* HMExternalBrowserWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F4B2A08E1A1F9C2100D2EF12 /* HMExternalBrowserWindowController.xib */; };
                F4B2D02B18F83A2F00542742 /* HMScreenshotWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F4B2D02D18F83A2F00542742 /* HMScreenshotWindowController.xib */; };
                F4B2D03318F83CC800542742 /* HMDeckViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F4B2D03518F83CC800542742 /* HMDeckViewController.xib */; };
                F4896DE81A6681DF00B09967 /* HMRemodelSlotCommand.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMRemodelSlotCommand.swift; sourceTree = "<group>"; };
                F4896DEA1A67D11000B09967 /* HMCreateSlotItemCommand.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMCreateSlotItemCommand.swift; sourceTree = "<group>"; };
                F4896DEC1A67E8E500B09967 /* HMResetSortieCommand.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMResetSortieCommand.swift; sourceTree = "<group>"; };
+               F4896DEE1A680E1400B09967 /* HMApplySuppliesCommand.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMApplySuppliesCommand.swift; sourceTree = "<group>"; };
                F494DC5618C23E4300AE97E4 /* ja */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ja; path = ja.lproj/MainMenu.strings; sourceTree = "<group>"; };
                F494DC5718C23E4300AE97E4 /* ja */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ja; path = ja.lproj/InfoPlist.strings; sourceTree = "<group>"; };
                F494DC5918C23E4400AE97E4 /* ja */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ja; path = ja.lproj/InfoPlist.strings; sourceTree = "<group>"; };
                F4AA05FA192B92C800844688 /* Temporary.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Temporary.xcdatamodel; sourceTree = "<group>"; };
                F4AA0602192E20F500844688 /* HMCalculateDamageCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMCalculateDamageCommand.h; sourceTree = "<group>"; };
                F4AA0603192E20F500844688 /* HMCalculateDamageCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMCalculateDamageCommand.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>"; };
                F4B2A08E1A1F9C2100D2EF12 /* HMExternalBrowserWindowController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = HMExternalBrowserWindowController.xib; sourceTree = "<group>"; };
                F4B2D02C18F83A2F00542742 /* ja */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = ja; path = ja.lproj/HMScreenshotWindowController.xib; sourceTree = "<group>"; };
                F4B2D03418F83CC800542742 /* ja */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = ja; path = ja.lproj/HMDeckViewController.xib; sourceTree = "<group>"; };
                                F4A3AD8619B6149D00FDBF80 /* HMNyukyoStartCommand.h */,
                                F4A3AD8719B6149D00FDBF80 /* HMNyukyoStartCommand.m */,
                                F4896DE61A6567AA00B09967 /* HMHokyuChargeCommand.swift */,
-                               F4B1E30D19D1C9C400805879 /* HMApplySuppliesCommand.h */,
-                               F4B1E30E19D1C9C400805879 /* HMApplySuppliesCommand.m */,
+                               F4896DEE1A680E1400B09967 /* HMApplySuppliesCommand.swift */,
                                F44AB23319E805D100F217AF /* HMKaisouLockCommand.h */,
                                F44AB23419E805D100F217AF /* HMKaisouLockCommand.m */,
                                F4896DE81A6681DF00B09967 /* HMRemodelSlotCommand.swift */,
                                F44AB23519E805D100F217AF /* HMKaisouLockCommand.m in Sources */,
                                F4BDEB53187252F30069D0CE /* main.m in Sources */,
                                F47C5C0E1A620E4200C276B5 /* HMMasterUseItemCommand.swift in Sources */,
-                               F4B1E30F19D1C9C400805879 /* HMApplySuppliesCommand.m in Sources */,
                                F477E2471A5426B600493198 /* HMKCShipObject+Extension.swift in Sources */,
                                F47C5C041A60082000C276B5 /* HMMemberNDockCommand.swift in Sources */,
                                F4B30CFC1A4687E7008E3D79 /* HMIgnoreZeroTransformer.swift in Sources */,
                                F47C5C141A6282BD00C276B5 /* HMMasterMapAreaCommand.swift in Sources */,
                                F43BA4A4197BE6C200CFF788 /* HMRealDestroyShipCommand.m in Sources */,
                                F47150351A654B8400B714F2 /* HMBattleResultCommand.swift in Sources */,
+                               F4896DEF1A680E1400B09967 /* HMApplySuppliesCommand.swift in Sources */,
                                F4B37EF619FBE801002F371A /* HMRemodelSlotItemCommand.m in Sources */,
                                F4513EF318B991F800073552 /* HMMemberBasicCommand.m in Sources */,
                                F47150371A6562C800B714F2 /* HMCombinedBattleCommand.swift 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 4e9244e..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"
-
-
-@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 *array = [store objectsWithEntityName:@"Ship"
-                                                                         sortDescriptors:nil
-                                                                                       predicate:[NSPredicate predicateWithFormat:@"id = %@", @([updataInfo[@"api_id"] integerValue])]
-                                                                                               error:&error];
-               if(array.count == 0) {
-                       if(error) {
-                               NSLog(@"Error: at %@ : %@", NSStringFromClass([self class]), error);
-                       }
-                       continue;
-               }
-               
-               HMKCShipObject *ship = array[0];
-               ship.bull = updataInfo[@"api_bull"];
-               ship.fuel = updataInfo[@"api_fuel"];
-               NSArray *onslots = updataInfo[@"api_onslot"];
-               ship.onslot_0 = onslots[0];
-               ship.onslot_1 = onslots[1];
-               ship.onslot_2 = onslots[2];
-               ship.onslot_3 = onslots[3];
-               ship.onslot_4 = onslots[4];
-       }
-}
-@end
diff --git a/KCD/HMApplySuppliesCommand.swift b/KCD/HMApplySuppliesCommand.swift
new file mode 100644 (file)
index 0000000..c1cf8e4
--- /dev/null
@@ -0,0 +1,52 @@
+//
+//  HMApplySuppliesCommand.swift
+//  KCD
+//
+//  Created by Hori,Masaki on 2015/01/16.
+//  Copyright (c) 2015年 Hori,Masaki. All rights reserved.
+//
+
+import Cocoa
+
+class HMApplySuppliesCommand: HMJSONCommand {
+       override func execute() {
+               if let data = json["api_data"] as? [NSObject : AnyObject] {
+                       if let shipInfos = data["api_ship"] as? [AnyObject] {
+                               let store = HMServerDataStore.oneTimeEditor()
+                               
+                               for shipInfo in shipInfos {
+                                       if let shipID = shipInfo["api_id"] as? NSNumber {
+                                               var error: NSError? = nil
+                                               let array = store.objectsWithEntityName(
+                                                       "Ship",
+                                                       sortDescriptors: nil,
+                                                       predicate: NSPredicate(format: "id = \(shipID)"),
+                                                       error: &error)
+                                               if array.count == 0 {
+                                                       if error != nil {
+                                                               NSLog("\(__FUNCTION__) error: \(error!)")
+                                                       }
+                                                       continue
+                                               }
+                                               
+                                               if let ship = array[0] as? HMKCShipObject {
+                                                       if let bull = shipInfo["api_bull"] as? NSNumber {
+                                                               ship.bull = bull
+                                                       }
+                                                       if let fuel = shipInfo["api_fuel"] as? NSNumber {
+                                                               ship.fuel = fuel
+                                                       }
+                                                       if let onslot = shipInfo["api_onslot"] as? [NSNumber] {
+                                                               ship.onslot_0 = onslot[0]
+                                                               ship.onslot_1 = onslot[1]
+                                                               ship.onslot_2 = onslot[2]
+                                                               ship.onslot_3 = onslot[3]
+                                                               ship.onslot_4 = onslot[4]
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+}
index 0dcd7d7..72e72a3 100644 (file)
@@ -19,7 +19,6 @@
 #import "HMMemberMaterialCommand.h"
 #import "HMMemberBasicCommand.h"
 #import "HMCalculateDamageCommand.h"
-#import "HMApplySuppliesCommand.h"
 #import "HMRemodelSlotItemCommand.h"
 #import "HMStoreCreateSlotItemHistoryCommand.h"
 #import "HMUpdateSlotItemCommand.h"