From 1f13bc3be9fd5170875b2e2db43c3784eb958f40 Mon Sep 17 00:00:00 2001 From: masakih Date: Fri, 23 Jan 2015 23:03:15 +0900 Subject: [PATCH] =?utf8?q?HMRemodelSlotItemCommand=E3=82=AF=E3=83=A9?= =?utf8?q?=E3=82=B9=E3=82=92Swift=E3=81=A6=E3=82=99=E6=9B=B8=E3=81=8D?= =?utf8?q?=E6=8F=9B=E3=81=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- KCD.xcodeproj/project.pbxproj | 10 ++--- KCD/HMRemodelSlotItemCommand.h | 13 ------- KCD/HMRemodelSlotItemCommand.m | 80 -------------------------------------- KCD/HMRemodelSlotItemCommand.swift | 76 ++++++++++++++++++++++++++++++++++++ KCD/KCD-Bridging-Header.h | 1 - 5 files changed, 80 insertions(+), 100 deletions(-) delete mode 100644 KCD/HMRemodelSlotItemCommand.h delete mode 100644 KCD/HMRemodelSlotItemCommand.m create mode 100644 KCD/HMRemodelSlotItemCommand.swift diff --git a/KCD.xcodeproj/project.pbxproj b/KCD.xcodeproj/project.pbxproj index 216aa154..474de49c 100644 --- a/KCD.xcodeproj/project.pbxproj +++ b/KCD.xcodeproj/project.pbxproj @@ -85,6 +85,7 @@ F4896DF91A6BCEB600B09967 /* HMUpdateSlotItemCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4896DF81A6BCEB600B09967 /* HMUpdateSlotItemCommand.swift */; }; F4896DFB1A6D57C100B09967 /* HMNyukyoSpeedChangeCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4896DFA1A6D57C100B09967 /* HMNyukyoSpeedChangeCommand.swift */; }; F4896DFD1A6FD8DF00B09967 /* HMDestroyItem2Command.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4896DFC1A6FD8DE00B09967 /* HMDestroyItem2Command.swift */; }; + F4896DFF1A7119F100B09967 /* HMRemodelSlotItemCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4896DFE1A7119F100B09967 /* HMRemodelSlotItemCommand.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 */; }; @@ -99,7 +100,6 @@ F4B30CF81A45DACB008E3D79 /* HMSlotItemEquipTypeTransformer.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4B30CF71A45DACB008E3D79 /* HMSlotItemEquipTypeTransformer.swift */; }; F4B30CFA1A468216008E3D79 /* HMPlanToShowsBoldFontTransformer.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4B30CF91A468216008E3D79 /* HMPlanToShowsBoldFontTransformer.swift */; }; F4B30CFC1A4687E7008E3D79 /* HMIgnoreZeroTransformer.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4B30CFB1A4687E7008E3D79 /* HMIgnoreZeroTransformer.swift */; }; - F4B37EF619FBE801002F371A /* HMRemodelSlotItemCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4B37EF519FBE801002F371A /* HMRemodelSlotItemCommand.m */; }; F4B37EFF19FC8DCC002F371A /* HMUpgradableShipsWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F4B37F0119FC8DCC002F371A /* HMUpgradableShipsWindowController.xib */; }; F4B3DC2118DECF570011B4FC /* HMTSVSupport.m in Sources */ = {isa = PBXBuildFile; fileRef = F4B3DC2018DECF570011B4FC /* HMTSVSupport.m */; }; F4B3DC2A18DF31400011B4FC /* HMCreateShipCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4B3DC2918DF31400011B4FC /* HMCreateShipCommand.m */; }; @@ -249,6 +249,7 @@ F4896DF81A6BCEB600B09967 /* HMUpdateSlotItemCommand.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMUpdateSlotItemCommand.swift; sourceTree = ""; }; F4896DFA1A6D57C100B09967 /* HMNyukyoSpeedChangeCommand.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMNyukyoSpeedChangeCommand.swift; sourceTree = ""; }; F4896DFC1A6FD8DE00B09967 /* HMDestroyItem2Command.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMDestroyItem2Command.swift; sourceTree = ""; }; + F4896DFE1A7119F100B09967 /* HMRemodelSlotItemCommand.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMRemodelSlotItemCommand.swift; sourceTree = ""; }; F494DC5618C23E4300AE97E4 /* ja */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ja; path = ja.lproj/MainMenu.strings; sourceTree = ""; }; F494DC5718C23E4300AE97E4 /* ja */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ja; path = ja.lproj/InfoPlist.strings; sourceTree = ""; }; F494DC5918C23E4400AE97E4 /* ja */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ja; path = ja.lproj/InfoPlist.strings; sourceTree = ""; }; @@ -269,8 +270,6 @@ F4B30CF71A45DACB008E3D79 /* HMSlotItemEquipTypeTransformer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMSlotItemEquipTypeTransformer.swift; sourceTree = ""; }; F4B30CF91A468216008E3D79 /* HMPlanToShowsBoldFontTransformer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMPlanToShowsBoldFontTransformer.swift; sourceTree = ""; }; F4B30CFB1A4687E7008E3D79 /* HMIgnoreZeroTransformer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMIgnoreZeroTransformer.swift; sourceTree = ""; }; - F4B37EF419FBE801002F371A /* HMRemodelSlotItemCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMRemodelSlotItemCommand.h; sourceTree = ""; }; - F4B37EF519FBE801002F371A /* HMRemodelSlotItemCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMRemodelSlotItemCommand.m; sourceTree = ""; }; F4B37F0019FC8DCC002F371A /* ja */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = ja; path = ja.lproj/HMUpgradableShipsWindowController.xib; sourceTree = ""; }; F4B3DC1F18DECF570011B4FC /* HMTSVSupport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMTSVSupport.h; sourceTree = ""; }; F4B3DC2018DECF570011B4FC /* HMTSVSupport.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMTSVSupport.m; sourceTree = ""; }; @@ -627,8 +626,7 @@ F4896DEE1A680E1400B09967 /* HMApplySuppliesCommand.swift */, F4896DF01A692B0700B09967 /* HMKaisouLockCommand.swift */, F4896DE81A6681DF00B09967 /* HMRemodelSlotCommand.swift */, - F4B37EF419FBE801002F371A /* HMRemodelSlotItemCommand.h */, - F4B37EF519FBE801002F371A /* HMRemodelSlotItemCommand.m */, + F4896DFE1A7119F100B09967 /* HMRemodelSlotItemCommand.swift */, F4896DEC1A67E8E500B09967 /* HMResetSortieCommand.swift */, ); name = Command; @@ -805,6 +803,7 @@ F47C5C261A6404E200C276B5 /* HMMapStartCommand.swift in Sources */, F4C118FA18A67B1C005D5B25 /* CacheStoragePolicy.m in Sources */, F4B3DC2118DECF570011B4FC /* HMTSVSupport.m in Sources */, + F4896DFF1A7119F100B09967 /* HMRemodelSlotItemCommand.swift in Sources */, F47C5C0A1A6202C100C276B5 /* HMMasterFurnitureCommand.swift in Sources */, F4896DFD1A6FD8DF00B09967 /* HMDestroyItem2Command.swift in Sources */, F4551BF41A49843500BB0235 /* HMPreferencePanelController.swift in Sources */, @@ -877,7 +876,6 @@ F47C5C141A6282BD00C276B5 /* HMMasterMapAreaCommand.swift 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 */, F47C5BFE1A5A889500C276B5 /* HMKenzoDockStatus.swift in Sources */, diff --git a/KCD/HMRemodelSlotItemCommand.h b/KCD/HMRemodelSlotItemCommand.h deleted file mode 100644 index 4185db45..00000000 --- a/KCD/HMRemodelSlotItemCommand.h +++ /dev/null @@ -1,13 +0,0 @@ -// -// HMRemodelSlotItemCommand.h -// KCD -// -// Created by Hori,Masaki on 2014/10/25. -// Copyright (c) 2014å¹´ Hori,Masaki. All rights reserved. -// - -#import "HMJSONCommand.h" - -@interface HMRemodelSlotItemCommand : HMJSONCommand - -@end diff --git a/KCD/HMRemodelSlotItemCommand.m b/KCD/HMRemodelSlotItemCommand.m deleted file mode 100644 index d2d5000b..00000000 --- a/KCD/HMRemodelSlotItemCommand.m +++ /dev/null @@ -1,80 +0,0 @@ -// -// HMRemodelSlotItemCommand.m -// KCD -// -// Created by Hori,Masaki on 2014/10/25. -// Copyright (c) 2014å¹´ Hori,Masaki. All rights reserved. -// - -#import "HMRemodelSlotItemCommand.h" - -#import "KCD-Swift.h" - - -@implementation HMRemodelSlotItemCommand -- (void)execute -{ - NSDictionary *api_data = [self.json valueForKeyPath:self.dataKey]; - if(![api_data isKindOfClass:[NSDictionary class]]) { - [self log:@"api_data is NOT NSDictionary."]; - return; - } - - BOOL success = [api_data[@"api_remodel_flag"] boolValue]; - if(!success) { - [self log:@"Remodel is failed."]; - return; - } - - id slotitemId = self.arguments[@"api_slot_id"]; - - HMServerDataStore *serverDataStore = [HMServerDataStore oneTimeEditor]; - NSError *error = nil; - NSArray *result = [serverDataStore objectsWithEntityName:@"SlotItem" - sortDescriptors:nil - predicate:[NSPredicate predicateWithFormat:@"id = %ld", [slotitemId integerValue]] - error:&error]; - if(error) { - [self log:@"Fetch error: %@", error]; - return; - } - if(result.count == 0) { - [self log:@"Could not find SlotItem number %@", slotitemId]; - return; - } - - api_data = api_data[@"api_after_slot"]; - - BOOL locked = [api_data[@"api_locked"] boolValue]; - [result[0] setValue:@(locked) forKey:@"locked"]; - - NSNumber *masterSoltItemId = api_data[@"api_slotitem_id"]; - if([masterSoltItemId compare:[result[0] valueForKey:@"slotitem_id"]] != NSOrderedSame) { - [self setMasterSlotItemForItemID:masterSoltItemId object:result[0] store:serverDataStore]; - } - - NSNumber *level = api_data[@"api_level"]; - [result[0] setValue:level forKey:@"level"]; -} - -- (void)setMasterSlotItemForItemID:(NSNumber *)slotItemId object:(id)object store:(HMServerDataStore *)serverDataStore -{ - NSError *error = nil; - NSArray *result = [serverDataStore objectsWithEntityName:@"MasterSlotItem" - sortDescriptors:nil - predicate:[NSPredicate predicateWithFormat:@"id = %ld", [slotItemId integerValue]] - error:&error]; - if(error) { - [self log:@"Fetch error: %@", error]; - return; - } - if(result.count == 0) { - [self log:@"Could not find MasterSlotItem number %@", slotItemId]; - return; - } - id item = result[0]; - [self setValueIfNeeded:item toObject:object forKey:@"master_slotItem"]; - [self setValueIfNeeded:slotItemId toObject:object forKey:@"slotitem_id"]; -} - -@end diff --git a/KCD/HMRemodelSlotItemCommand.swift b/KCD/HMRemodelSlotItemCommand.swift new file mode 100644 index 00000000..8674b32d --- /dev/null +++ b/KCD/HMRemodelSlotItemCommand.swift @@ -0,0 +1,76 @@ +// +// HMRemodelSlotItemCommand.swift +// KCD +// +// Created by Hori,Masaki on 2015/01/22. +// Copyright (c) 2015å¹´ Hori,Masaki. All rights reserved. +// + +import Cocoa + +class HMRemodelSlotItemCommand: HMJSONCommand { + override func execute() { + let data = json[dataKey] as NSDictionary? + if data == nil { + NSLog("data is not dictionary") + return + } + + let success = data!["api_remodel_flag"] as NSNumber? + if success == nil || !success!.boolValue { + NSLog("Remodel is failed.") + return + } + + if let slotItemID = arguments["api_slot_id"] as? String { + let store = HMServerDataStore.oneTimeEditor() + let predicate = NSPredicate(format: "id = \(slotItemID)") + var error: NSError? = nil + let array = store.objectsWithEntityName("SlotItem", + sortDescriptors: nil, + predicate: predicate, + error: &error) + if array.count == 0 { + NSLog("Could not find SlotItem number \(slotItemID)") + if error != nil { + NSLog("Fetch error: \(error!)") + } + return + } + + if let item = array[0] as? HMKCSlotItemObject { + if let afterSlot = data!["api_after_slot"] as? NSDictionary { + if let locked = afterSlot["api_locked"] as? NSNumber { + item.locked = locked + } + if let level = afterSlot["api_level"] as? NSNumber { + item.level = level + } + } + if let masterSoltItemID = data!["api_slotitem_id"] as? NSNumber { + setMasterSlotItemForItemID(masterSoltItemID, item: item, store: store) + } + } + } + } + + func setMasterSlotItemForItemID(slotItemID: NSNumber, item: HMKCSlotItemObject, store: HMServerDataStore) { + let predicate = NSPredicate(format: "id = \(slotItemID)") + var error: NSError? = nil + let array = store.objectsWithEntityName("MasterSlotItem", + sortDescriptors: nil, + predicate: predicate, + error: &error) + if array.count == 0 { + NSLog("Could not find MasterSlotItem number \(slotItemID)") + if error != nil { + NSLog("Fetch error: \(error!)") + } + return + } + if let master = array[0] as? HMKCMasterSlotItemObject { + item.master_slotItem = master + item.slotitem_id = slotItemID + } + } +} diff --git a/KCD/KCD-Bridging-Header.h b/KCD/KCD-Bridging-Header.h index 642b1a4b..67619eaf 100644 --- a/KCD/KCD-Bridging-Header.h +++ b/KCD/KCD-Bridging-Header.h @@ -18,7 +18,6 @@ #import "HMMemberMaterialCommand.h" #import "HMMemberBasicCommand.h" #import "HMCalculateDamageCommand.h" -#import "HMRemodelSlotItemCommand.h" #import "HMStoreCreateSlotItemHistoryCommand.h" -- 2.11.0