From c63b34c5109c401cebc030f52cb0c2e649da779f Mon Sep 17 00:00:00 2001 From: masakih Date: Sat, 14 Jan 2017 20:22:40 +0900 Subject: [PATCH] =?utf8?q?HMSetActionCommand=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/HMSetActionCommand.h | 13 ----------- KCD/HMSetActionCommand.m | 54 ------------------------------------------- KCD/HMSetActionCommand.swift | 42 +++++++++++++++++++++++++++++++++ KCD/KCD-Bridging-Header.h | 1 - 5 files changed, 46 insertions(+), 74 deletions(-) delete mode 100644 KCD/HMSetActionCommand.h delete mode 100644 KCD/HMSetActionCommand.m create mode 100644 KCD/HMSetActionCommand.swift diff --git a/KCD.xcodeproj/project.pbxproj b/KCD.xcodeproj/project.pbxproj index 7c7032bb..ff191abd 100644 --- a/KCD.xcodeproj/project.pbxproj +++ b/KCD.xcodeproj/project.pbxproj @@ -19,7 +19,6 @@ F42185111DF461A600256590 /* HMScreenshotTouchBar.xib in Resources */ = {isa = PBXBuildFile; fileRef = F42185101DF461A600256590 /* HMScreenshotTouchBar.xib */; }; F4268009193AF4E000B2C27F /* HMUserDefaults.m in Sources */ = {isa = PBXBuildFile; fileRef = F4268008193AF4E000B2C27F /* HMUserDefaults.m */; }; F42680121943E92D00B2C27F /* HMKCShipObject+Extensions.m in Sources */ = {isa = PBXBuildFile; fileRef = F42680111943E92D00B2C27F /* HMKCShipObject+Extensions.m */; }; - F431E9761DF3AC1C00FB56AE /* HMSetActionCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F431E9751DF3AC1C00FB56AE /* HMSetActionCommand.m */; }; F43769DE1AE1248800DE6204 /* HMAirBattleCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F43769DD1AE1248800DE6204 /* HMAirBattleCommand.m */; }; F43769E71AE7D22700DE6204 /* HMKCQuest.m in Sources */ = {isa = PBXBuildFile; fileRef = F43769E61AE7D22700DE6204 /* HMKCQuest.m */; }; F43E67B718BE02A10087E5B6 /* STypeShortName.plist in Resources */ = {isa = PBXBuildFile; fileRef = F43E67B618BE02A10087E5B6 /* STypeShortName.plist */; }; @@ -90,6 +89,7 @@ F44BC72F1E2A0B75004644E3 /* HMMaserShipCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = F44BC72E1E2A0B75004644E3 /* HMMaserShipCommand.swift */; }; F44BC7311E2A247F004644E3 /* HMMasterSTypeCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = F44BC7301E2A247F004644E3 /* HMMasterSTypeCommand.swift */; }; F44BC7331E2A25E4004644E3 /* HMStart2Command.swift in Sources */ = {isa = PBXBuildFile; fileRef = F44BC7321E2A25E4004644E3 /* HMStart2Command.swift */; }; + F44BC7351E2A295E004644E3 /* HMSetActionCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = F44BC7341E2A295E004644E3 /* HMSetActionCommand.swift */; }; F4513EDD18B619B600073552 /* HMCoreDataManager.m in Sources */ = {isa = PBXBuildFile; fileRef = F4513EDC18B619B600073552 /* HMCoreDataManager.m */; }; F45771231E1BCC7C008A9215 /* HMPeriodicNotifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = F45771221E1BCC7C008A9215 /* HMPeriodicNotifier.swift */; }; F45F3BE11E067A870009434E /* HMHistoryItemCleaner.swift in Sources */ = {isa = PBXBuildFile; fileRef = F45F3BE01E067A870009434E /* HMHistoryItemCleaner.swift */; }; @@ -338,8 +338,6 @@ F42680101943E92D00B2C27F /* HMKCShipObject+Extensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "HMKCShipObject+Extensions.h"; sourceTree = ""; }; F42680111943E92D00B2C27F /* HMKCShipObject+Extensions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "HMKCShipObject+Extensions.m"; sourceTree = ""; }; F42CBB201D1ED41D004C2AE2 /* LocalData 3.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "LocalData 3.xcdatamodel"; sourceTree = ""; }; - F431E9741DF3AC1C00FB56AE /* HMSetActionCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMSetActionCommand.h; sourceTree = ""; }; - F431E9751DF3AC1C00FB56AE /* HMSetActionCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMSetActionCommand.m; sourceTree = ""; }; F43769DC1AE1248800DE6204 /* HMAirBattleCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMAirBattleCommand.h; sourceTree = ""; }; F43769DD1AE1248800DE6204 /* HMAirBattleCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMAirBattleCommand.m; sourceTree = ""; }; F43769E51AE7D22700DE6204 /* HMKCQuest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMKCQuest.h; sourceTree = ""; }; @@ -423,6 +421,7 @@ F44BC72E1E2A0B75004644E3 /* HMMaserShipCommand.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMMaserShipCommand.swift; sourceTree = ""; }; F44BC7301E2A247F004644E3 /* HMMasterSTypeCommand.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMMasterSTypeCommand.swift; sourceTree = ""; }; F44BC7321E2A25E4004644E3 /* HMStart2Command.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMStart2Command.swift; sourceTree = ""; }; + F44BC7341E2A295E004644E3 /* HMSetActionCommand.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMSetActionCommand.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 = ""; }; F45771221E1BCC7C008A9215 /* HMPeriodicNotifier.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMPeriodicNotifier.swift; sourceTree = ""; }; @@ -869,8 +868,7 @@ F48A704C1DE326F0005DFC0B /* HMAirBaseCommand.m */, F4E90B5C1DE713FF00643B5F /* HMSetPlaneCommand.h */, F4E90B5D1DE713FF00643B5F /* HMSetPlaneCommand.m */, - F431E9741DF3AC1C00FB56AE /* HMSetActionCommand.h */, - F431E9751DF3AC1C00FB56AE /* HMSetActionCommand.m */, + F44BC7341E2A295E004644E3 /* HMSetActionCommand.swift */, ); name = BattleCommand; sourceTree = ""; @@ -1666,6 +1664,7 @@ F4D05BE11E0FAB8E00688D66 /* HMShipViewController.swift in Sources */, F44BC6EB1E234531004644E3 /* HMChangeHenseiCommand.swift in Sources */, F4E5FF041E1518200026868C /* HMScreenshotDetailViewController.swift in Sources */, + F44BC7351E2A295E004644E3 /* HMSetActionCommand.swift in Sources */, F472159E1E1E6EE70083D3BC /* HMShipMasterDetailWindowController.swift in Sources */, F44BC6D71E226CB1004644E3 /* HMHokyuChargeCommand.swift in Sources */, F44BC6F91E23DAC5004644E3 /* HMRealDestroyShipCommand.swift in Sources */, @@ -1716,7 +1715,6 @@ F4D05BC61E0ABD6800688D66 /* HMSlotItemWindowController.swift in Sources */, F4AA593A1E1E02D9001667AF /* HMUpgradeShipExcludeColorTransformer.swift in Sources */, F42680121943E92D00B2C27F /* HMKCShipObject+Extensions.m in Sources */, - F431E9761DF3AC1C00FB56AE /* HMSetActionCommand.m in Sources */, F44BC6C71E222675004644E3 /* HMFailedCommand.swift in Sources */, F47215A01E1E90C10083D3BC /* HMJSONNode.swift in Sources */, F44BC6DB1E2281A7004644E3 /* HMClearItemGetComand.swift in Sources */, diff --git a/KCD/HMSetActionCommand.h b/KCD/HMSetActionCommand.h deleted file mode 100644 index d6d223c8..00000000 --- a/KCD/HMSetActionCommand.h +++ /dev/null @@ -1,13 +0,0 @@ -// -// HMSetActionCommand.h -// KCD -// -// Created by Hori,Masaki on 2016/12/04. -// Copyright © 2016年 Hori,Masaki. All rights reserved. -// - -#import "HMJSONCommand.h" - -@interface HMSetActionCommand : HMJSONCommand - -@end diff --git a/KCD/HMSetActionCommand.m b/KCD/HMSetActionCommand.m deleted file mode 100644 index b455240a..00000000 --- a/KCD/HMSetActionCommand.m +++ /dev/null @@ -1,54 +0,0 @@ -// -// HMSetActionCommand.m -// KCD -// -// Created by Hori,Masaki on 2016/12/04. -// Copyright © 2016年 Hori,Masaki. All rights reserved. -// - -#import "HMSetActionCommand.h" - -#import "KCD-Swift.h" - -#import "HMKCAirBase.h" -#import "HMKCAirBasePlaneInfo.h" -#import "HMKCMaterial.h" - - -@implementation HMSetActionCommand -//+ (void)load -//{ -// static dispatch_once_t onceToken; -// dispatch_once(&onceToken, ^{ -// [HMJSONCommand registerClass:self]; -// }); -//} - -+ (BOOL)canExcuteAPI:(NSString *)api -{ - if([api isEqualToString:@"/kcsapi/api_req_air_corps/set_action"]) return YES; - return NO; -} - -- (void)execute -{ - HMServerDataStore *store = [HMServerDataStore oneTimeEditor]; - - NSString *areaId = self.arguments[@"api_area_id"]; - NSString *rIdsString = self.arguments[@"api_base_id"]; - NSString *actionKindsString = self.arguments[@"api_action_kind"]; - - NSArray *rIds = [rIdsString componentsSeparatedByString:@","]; - NSArray *actionKinds = [actionKindsString componentsSeparatedByString:@","]; - - [rIds enumerateObjectsUsingBlock:^(NSString * _Nonnull rId, NSUInteger idx, BOOL * _Nonnull stop) { - NSError *error = nil; - NSArray *airBases = [store objectsWithEntityName:@"AirBase" - sortDescriptors:nil - error:&error - predicateFormat:@"area_id == %@ AND rid == %@", @(areaId.integerValue), @(rId.integerValue)]; - if(airBases.count == 0) { return; } - airBases[0].action_kind = @(actionKinds[idx].integerValue); - }]; -} -@end diff --git a/KCD/HMSetActionCommand.swift b/KCD/HMSetActionCommand.swift new file mode 100644 index 00000000..777fcf8d --- /dev/null +++ b/KCD/HMSetActionCommand.swift @@ -0,0 +1,42 @@ +// +// HMSetActionCommand.swift +// KCD +// +// Created by Hori,Masaki on 2017/01/14. +// Copyright © 2017年 Hori,Masaki. All rights reserved. +// + +import Cocoa + +class HMSetActionCommand: HMJSONCommand { + override class func canExcuteAPI(_ api: String) -> Bool { + if api == "/kcsapi/api_req_air_corps/set_action" { return true } + return false + } + + override func execute() { + guard let args = arguments as? [String:Any], + let areaId = args["api_area_id"] as? String, + let rIdsString = args["api_base_id"] as? String, + let actionKindsString = args["api_action_kind"] as? String + else { return print("Argument is rwong") } + let dIds = rIdsString.components(separatedBy: ",") + let actionKinds = actionKindsString.components(separatedBy: ",") + if dIds.count != actionKinds.count { print("missmatch count") } + + let actions: [Int] = actionKinds.map { + guard let type = Int($0) else { return -1 } + return type + } + + let store = HMServerDataStore.oneTimeEditor() + zip(dIds, actions).forEach { (z :(rId: String, action: Int)) in + let p = NSPredicate(format: "area_id == %@ AND rid == %@", areaId, z.rId) + guard let ab = try? store?.objects(withEntityName: "AirBase", predicate: p), + let airBases = ab as? [HMKCAirBase], + let airBase = airBases.first + else { return print("AirBase is not found") } + airBase.action_kind = z.action as NSNumber + } + } +} diff --git a/KCD/KCD-Bridging-Header.h b/KCD/KCD-Bridging-Header.h index ec8be94b..68cdc65f 100644 --- a/KCD/KCD-Bridging-Header.h +++ b/KCD/KCD-Bridging-Header.h @@ -36,7 +36,6 @@ #import "HMGuardShelterCommand.h" #import "HMMapInfoCommand.h" #import "HMSetPlaneCommand.h" -#import "HMSetActionCommand.h" #import "HMResetSortieCommand.h" #import "HMDropShipHistoryCommand.h" #import "HMDummyShipCommand.h" -- 2.11.0