From 442b65c99e9095551a1a6fde059d519c1b2ef0de Mon Sep 17 00:00:00 2001 From: masakih Date: Wed, 11 Jan 2017 00:13:56 +0900 Subject: [PATCH] =?utf8?q?HMUpdateSlotItemCommand=E3=82=92Swift=E3=81=AB?= =?utf8?q?=E5=A4=89=E6=8F=9B=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- KCD.xcodeproj/project.pbxproj | 10 ++++------ KCD/HMUpdateSlotItemCommand.h | 13 ------------- KCD/HMUpdateSlotItemCommand.m | 41 --------------------------------------- KCD/HMUpdateSlotItemCommand.swift | 31 +++++++++++++++++++++++++++++ KCD/KCD-Bridging-Header.h | 1 - 5 files changed, 35 insertions(+), 61 deletions(-) delete mode 100644 KCD/HMUpdateSlotItemCommand.h delete mode 100644 KCD/HMUpdateSlotItemCommand.m create mode 100644 KCD/HMUpdateSlotItemCommand.swift diff --git a/KCD.xcodeproj/project.pbxproj b/KCD.xcodeproj/project.pbxproj index ef2f73ab..ca472950 100644 --- a/KCD.xcodeproj/project.pbxproj +++ b/KCD.xcodeproj/project.pbxproj @@ -13,7 +13,6 @@ F4048AA11E1951BB008ACFD6 /* HMSuppliesCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4048AA01E1951BB008ACFD6 /* HMSuppliesCell.swift */; }; F40ADA021CE6317500AE29B0 /* HMIgnoreCommand.plist in Resources */ = {isa = PBXBuildFile; fileRef = F40ADA011CE6317500AE29B0 /* HMIgnoreCommand.plist */; }; F4131ECF190F5C08004F7F9A /* HMStoreCreateSlotItemHistoryCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4131ECE190F5C08004F7F9A /* HMStoreCreateSlotItemHistoryCommand.m */; }; - F4131ED5190F63D8004F7F9A /* HMUpdateSlotItemCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4131ED4190F63D8004F7F9A /* HMUpdateSlotItemCommand.m */; }; F4131EDE190FEBDB004F7F9A /* HMSlotItemWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F4131EE0190FEBDB004F7F9A /* HMSlotItemWindowController.xib */; }; F4131EE61910318F004F7F9A /* HMMasterSlotItemEquipTypeCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4131EE51910318F004F7F9A /* HMMasterSlotItemEquipTypeCommand.m */; }; F41465681DAB852E00D68C97 /* HMScreenshotCollectionViewItem.xib in Resources */ = {isa = PBXBuildFile; fileRef = F41465671DAB852E00D68C97 /* HMScreenshotCollectionViewItem.xib */; }; @@ -71,6 +70,7 @@ F44BC6FD1E250B2A004644E3 /* HMGetShipCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = F44BC6FC1E250B2A004644E3 /* HMGetShipCommand.swift */; }; F44BC6FF1E250CED004644E3 /* HMCreateSlotItemCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = F44BC6FE1E250CED004644E3 /* HMCreateSlotItemCommand.swift */; }; F44BC7011E251408004644E3 /* HMDestroyItem2Command.swift in Sources */ = {isa = PBXBuildFile; fileRef = F44BC7001E251408004644E3 /* HMDestroyItem2Command.swift */; }; + F44BC7031E252C4F004644E3 /* HMUpdateSlotItemCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = F44BC7021E252C4F004644E3 /* HMUpdateSlotItemCommand.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 */; }; @@ -333,8 +333,6 @@ F40ADA011CE6317500AE29B0 /* HMIgnoreCommand.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = HMIgnoreCommand.plist; sourceTree = ""; }; F4131ECD190F5C08004F7F9A /* HMStoreCreateSlotItemHistoryCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMStoreCreateSlotItemHistoryCommand.h; sourceTree = ""; }; F4131ECE190F5C08004F7F9A /* HMStoreCreateSlotItemHistoryCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMStoreCreateSlotItemHistoryCommand.m; sourceTree = ""; }; - F4131ED3190F63D8004F7F9A /* HMUpdateSlotItemCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMUpdateSlotItemCommand.h; sourceTree = ""; }; - F4131ED4190F63D8004F7F9A /* HMUpdateSlotItemCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMUpdateSlotItemCommand.m; sourceTree = ""; }; F4131EE41910318F004F7F9A /* HMMasterSlotItemEquipTypeCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMMasterSlotItemEquipTypeCommand.h; sourceTree = ""; }; F4131EE51910318F004F7F9A /* HMMasterSlotItemEquipTypeCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMMasterSlotItemEquipTypeCommand.m; sourceTree = ""; }; F41465671DAB852E00D68C97 /* HMScreenshotCollectionViewItem.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = HMScreenshotCollectionViewItem.xib; sourceTree = ""; }; @@ -410,6 +408,7 @@ F44BC6FC1E250B2A004644E3 /* HMGetShipCommand.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMGetShipCommand.swift; sourceTree = ""; }; F44BC6FE1E250CED004644E3 /* HMCreateSlotItemCommand.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMCreateSlotItemCommand.swift; sourceTree = ""; }; F44BC7001E251408004644E3 /* HMDestroyItem2Command.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMDestroyItem2Command.swift; sourceTree = ""; }; + F44BC7021E252C4F004644E3 /* HMUpdateSlotItemCommand.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMUpdateSlotItemCommand.swift; sourceTree = ""; }; F4513EDB18B619B600073552 /* HMCoreDataManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMCoreDataManager.h; sourceTree = ""; }; F4513EDC18B619B600073552 /* HMCoreDataManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMCoreDataManager.m; sourceTree = ""; }; F4513EE618B77A5300073552 /* HMMemberKDockCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMMemberKDockCommand.h; sourceTree = ""; }; @@ -877,8 +876,7 @@ F4B3DC2918DF31400011B4FC /* HMCreateShipCommand.m */, F4131ECD190F5C08004F7F9A /* HMStoreCreateSlotItemHistoryCommand.h */, F4131ECE190F5C08004F7F9A /* HMStoreCreateSlotItemHistoryCommand.m */, - F4131ED3190F63D8004F7F9A /* HMUpdateSlotItemCommand.h */, - F4131ED4190F63D8004F7F9A /* HMUpdateSlotItemCommand.m */, + F44BC7021E252C4F004644E3 /* HMUpdateSlotItemCommand.swift */, F44BC7001E251408004644E3 /* HMDestroyItem2Command.swift */, F44BC6F81E23DAC5004644E3 /* HMRealDestroyShipCommand.swift */, F44BC6F61E23DA4A004644E3 /* HMDestroyShipCommand.swift */, @@ -1704,7 +1702,6 @@ F4A9E7FB1D045BC100F91746 /* HMScreenshotModel.m in Sources */, F47215AC1E1FA2460083D3BC /* HMTemporaryDataStore.swift in Sources */, F448F9981B75A128004901AD /* HMKCBasic.m in Sources */, - F4131ED5190F63D8004F7F9A /* HMUpdateSlotItemCommand.m in Sources */, F4D05BC81E0C0DA100688D66 /* HMAirBaseWindowController.swift in Sources */, F4C1190518A71AEA005D5B25 /* HMJSONReciever.m in Sources */, F4F9F8901C6B6ACA00D0EE76 /* HMKCNyukyoDock.m in Sources */, @@ -1731,6 +1728,7 @@ F4AA592E1E1D1D4D001667AF /* HMSokuTransformer.swift in Sources */, F4AA594A1E1E4863001667AF /* HMMapWindowController.swift in Sources */, F4E5FF101E17A83D0026868C /* HMScreenshotListWindowController.swift in Sources */, + F44BC7031E252C4F004644E3 /* HMUpdateSlotItemCommand.swift in Sources */, F44AB23E19E824D700F217AF /* HMKCSlotItemObject.m in Sources */, F45771231E1BCC7C008A9215 /* HMPeriodicNotifier.swift in Sources */, F4B414F518B1888800468DAF /* HMMasterFurnitureCommand.m in Sources */, diff --git a/KCD/HMUpdateSlotItemCommand.h b/KCD/HMUpdateSlotItemCommand.h deleted file mode 100644 index 4dea2025..00000000 --- a/KCD/HMUpdateSlotItemCommand.h +++ /dev/null @@ -1,13 +0,0 @@ -// -// HMUpdateSlotItemCommand.h -// KCD -// -// Created by Hori,Masaki on 2014/04/29. -// Copyright (c) 2014年 Hori,Masaki. All rights reserved. -// - -#import "HMJSONCommand.h" - -@interface HMUpdateSlotItemCommand : HMJSONCommand - -@end diff --git a/KCD/HMUpdateSlotItemCommand.m b/KCD/HMUpdateSlotItemCommand.m deleted file mode 100644 index 533757ba..00000000 --- a/KCD/HMUpdateSlotItemCommand.m +++ /dev/null @@ -1,41 +0,0 @@ -// -// HMUpdateSlotItemCommand.m -// KCD -// -// Created by Hori,Masaki on 2014/04/29. -// Copyright (c) 2014年 Hori,Masaki. All rights reserved. -// - -#import "HMUpdateSlotItemCommand.h" - -#import "KCD-Swift.h" - -#import "HMKCMasterSlotItemObject.h" -#import "HMKCSlotItemObject+Extensions.h" - -@implementation HMUpdateSlotItemCommand -- (NSString *)dataKey -{ - return @"api_data.api_slot_item"; -} -- (void)execute -{ - NSDictionary *data = [self.json valueForKeyPath:self.dataKey]; - if(!data || [data isKindOfClass:[NSNull class]]) return; - - HMServerDataStore *store = [HMServerDataStore oneTimeEditor]; - NSError *error = nil; - NSArray *masterSlotItems = [store objectsWithEntityName:@"MasterSlotItem" - error:&error - predicateFormat:@"id = %@", data[@"api_slotitem_id"]]; - if(masterSlotItems.count == 0) { - NSLog(@"MasterSlotItem is invalid"); - return; - } - - HMKCSlotItemObject *newSlotItem = [store insertNewObjectForEntityForName:@"SlotItem"]; - newSlotItem.id = data[@"api_id"]; - newSlotItem.master_slotItem = masterSlotItems[0]; -} - -@end diff --git a/KCD/HMUpdateSlotItemCommand.swift b/KCD/HMUpdateSlotItemCommand.swift new file mode 100644 index 00000000..0304f0d1 --- /dev/null +++ b/KCD/HMUpdateSlotItemCommand.swift @@ -0,0 +1,31 @@ +// +// HMUpdateSlotItemCommand.swift +// KCD +// +// Created by Hori,Masaki on 2017/01/10. +// Copyright © 2017年 Hori,Masaki. All rights reserved. +// + +import Cocoa + +class HMUpdateSlotItemCommand: HMJSONCommand { + override func execute() { + guard let j = json as? [String:Any], + let d = j["api_data"] as? [String:Any], + let data = d["api_slot_item"] as? [String:Any], + let slotItemId = data["api_slotitem_id"] as? Int + else { return print("api_slotitem_id is wrong") } + guard let newSlotItemId = data["api_id"] as? Int + else { return print("api_id is wrong") } + let store = HMServerDataStore.oneTimeEditor() + let p = NSPredicate(format: "id = %ld", slotItemId) + guard let ms = try? store?.objects(withEntityName: "MasterSlotItem", predicate: p), + let masterSlotItems = ms as? [HMKCMasterSlotItemObject], + let masterSlotItem = masterSlotItems.first + else { return print("MasterSlotItem is not found") } + guard let new = store?.insertNewObjectForEntity(forName: "SlotItem") as? HMKCSlotItemObject + else { return print("Can not create new SlotItem") } + new.id = newSlotItemId as NSNumber + new.master_slotItem = masterSlotItem + } +} diff --git a/KCD/KCD-Bridging-Header.h b/KCD/KCD-Bridging-Header.h index 9d9d0ed1..fbd0b060 100644 --- a/KCD/KCD-Bridging-Header.h +++ b/KCD/KCD-Bridging-Header.h @@ -53,7 +53,6 @@ #import "HMDropShipHistoryCommand.h" #import "HMDummyShipCommand.h" #import "HMKenzoMarkCommand.h" -#import "HMUpdateSlotItemCommand.h" #import "HMStoreCreateSlotItemHistoryCommand.h" // Core Data -- 2.11.0