From a084c2c1871170e9bde6c3d35330048ffb6369c0 Mon Sep 17 00:00:00 2001 From: masakih Date: Sat, 14 Jan 2017 22:15:48 +0900 Subject: [PATCH] =?utf8?q?HMAirBaseCommand=E3=82=92Swift=E3=81=AB=E5=A4=89?= =?utf8?q?=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/HMAirBaseCommand.h | 13 ------- KCD/HMAirBaseCommand.m | 79 ------------------------------------------- KCD/HMAirBaseCommand.swift | 74 ++++++++++++++++++++++++++++++++++++++++ KCD/HMMapInfoCommand.m | 2 +- 5 files changed, 79 insertions(+), 99 deletions(-) delete mode 100644 KCD/HMAirBaseCommand.h delete mode 100644 KCD/HMAirBaseCommand.m create mode 100644 KCD/HMAirBaseCommand.swift diff --git a/KCD.xcodeproj/project.pbxproj b/KCD.xcodeproj/project.pbxproj index 4b9d8a2d..dce4dec0 100644 --- a/KCD.xcodeproj/project.pbxproj +++ b/KCD.xcodeproj/project.pbxproj @@ -91,6 +91,7 @@ F44BC7331E2A25E4004644E3 /* HMStart2Command.swift in Sources */ = {isa = PBXBuildFile; fileRef = F44BC7321E2A25E4004644E3 /* HMStart2Command.swift */; }; F44BC7351E2A295E004644E3 /* HMSetActionCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = F44BC7341E2A295E004644E3 /* HMSetActionCommand.swift */; }; F44BC7371E2A4258004644E3 /* HMSetPlaneCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = F44BC7361E2A4258004644E3 /* HMSetPlaneCommand.swift */; }; + F44BC7391E2A5013004644E3 /* HMAirBaseCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = F44BC7381E2A5013004644E3 /* HMAirBaseCommand.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 */; }; @@ -116,7 +117,6 @@ F47215AA1E1F96B60083D3BC /* HMResourceHistoryDataStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = F47215A91E1F96B60083D3BC /* HMResourceHistoryDataStore.swift */; }; F47215AC1E1FA2460083D3BC /* HMTemporaryDataStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = F47215AB1E1FA2460083D3BC /* HMTemporaryDataStore.swift */; }; F47215B01E1FEACC0083D3BC /* HMServerDataStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = F47215AF1E1FEACC0083D3BC /* HMServerDataStore.swift */; }; - F48A704D1DE326F0005DFC0B /* HMAirBaseCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F48A704C1DE326F0005DFC0B /* HMAirBaseCommand.m */; }; F48A70501DE32847005DFC0B /* HMMapInfoCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F48A704F1DE32847005DFC0B /* HMMapInfoCommand.m */; }; F48A705C1DE58A38005DFC0B /* HMKCAirBase+CoreDataClass.m in Sources */ = {isa = PBXBuildFile; fileRef = F48A70551DE58A38005DFC0B /* HMKCAirBase+CoreDataClass.m */; }; F48A705D1DE58A38005DFC0B /* HMKCAirBase+CoreDataProperties.m in Sources */ = {isa = PBXBuildFile; fileRef = F48A70571DE58A38005DFC0B /* HMKCAirBase+CoreDataProperties.m */; }; @@ -423,6 +423,7 @@ 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 = ""; }; F44BC7361E2A4258004644E3 /* HMSetPlaneCommand.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMSetPlaneCommand.swift; sourceTree = ""; }; + F44BC7381E2A5013004644E3 /* HMAirBaseCommand.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMAirBaseCommand.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 = ""; }; @@ -458,8 +459,6 @@ F47215A91E1F96B60083D3BC /* HMResourceHistoryDataStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMResourceHistoryDataStore.swift; sourceTree = ""; }; F47215AB1E1FA2460083D3BC /* HMTemporaryDataStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMTemporaryDataStore.swift; sourceTree = ""; }; F47215AF1E1FEACC0083D3BC /* HMServerDataStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMServerDataStore.swift; sourceTree = ""; }; - F48A704B1DE326F0005DFC0B /* HMAirBaseCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMAirBaseCommand.h; sourceTree = ""; }; - F48A704C1DE326F0005DFC0B /* HMAirBaseCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMAirBaseCommand.m; sourceTree = ""; }; F48A704E1DE32847005DFC0B /* HMMapInfoCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMMapInfoCommand.h; sourceTree = ""; }; F48A704F1DE32847005DFC0B /* HMMapInfoCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMMapInfoCommand.m; sourceTree = ""; }; F48A70541DE58A38005DFC0B /* HMKCAirBase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMKCAirBase.h; sourceTree = ""; }; @@ -863,8 +862,7 @@ F4D6BC4E1A938EFC00742FEB /* HMDropShipHistoryCommand.m */, F48A704E1DE32847005DFC0B /* HMMapInfoCommand.h */, F48A704F1DE32847005DFC0B /* HMMapInfoCommand.m */, - F48A704B1DE326F0005DFC0B /* HMAirBaseCommand.h */, - F48A704C1DE326F0005DFC0B /* HMAirBaseCommand.m */, + F44BC7381E2A5013004644E3 /* HMAirBaseCommand.swift */, F44BC7361E2A4258004644E3 /* HMSetPlaneCommand.swift */, F44BC7341E2A295E004644E3 /* HMSetActionCommand.swift */, ); @@ -1609,6 +1607,7 @@ F4AA59161E1C9C5D001667AF /* ValueTransformerRegister.swift in Sources */, F4F9F88A1C6B642B00D0EE76 /* HMKCMasterMapArea.m in Sources */, F4E5FF141E17F93B0026868C /* HMBroserWindowController.swift in Sources */, + F44BC7391E2A5013004644E3 /* HMAirBaseCommand.swift in Sources */, F44BC7051E2660E4004644E3 /* HMStoreCreateSlotItemHistoryCommand.swift in Sources */, F4F9F8841C6B63AE00D0EE76 /* HMKCMasterMapInfo.m in Sources */, F4F9F8831C6B63AE00D0EE76 /* HMKCMasterMapInfo+CoreDataProperties.m in Sources */, @@ -1768,7 +1767,6 @@ F44BC71F1E29E740004644E3 /* HMMasterSlotItemEquipTypeCommand.swift in Sources */, F4C2ACA51D7167C2007BFE90 /* HMTimeSignalNotifier.m in Sources */, F4F9F8781C6B5BA900D0EE76 /* HMKCKenzoDock.m in Sources */, - F48A704D1DE326F0005DFC0B /* HMAirBaseCommand.m in Sources */, F44AB20619E053CB00F217AF /* HMKCDeck+Extension.m in Sources */, F4D05BDF1E0F8B6900688D66 /* HMPowerUpSupportViewController.swift in Sources */, F4F6E82A1B3045970008B66E /* CanonicalRequest.m in Sources */, diff --git a/KCD/HMAirBaseCommand.h b/KCD/HMAirBaseCommand.h deleted file mode 100644 index 5788acd7..00000000 --- a/KCD/HMAirBaseCommand.h +++ /dev/null @@ -1,13 +0,0 @@ -// -// HMAirBaseCommand.h -// KCD -// -// Created by Hori,Masaki on 2016/11/21. -// Copyright © 2016年 Hori,Masaki. All rights reserved. -// - -#import "HMJSONCommand.h" - -@interface HMAirBaseCommand : HMJSONCommand - -@end diff --git a/KCD/HMAirBaseCommand.m b/KCD/HMAirBaseCommand.m deleted file mode 100644 index 7575f6f5..00000000 --- a/KCD/HMAirBaseCommand.m +++ /dev/null @@ -1,79 +0,0 @@ -// -// HMAirBaseCommand.m -// KCD -// -// Created by Hori,Masaki on 2016/11/21. -// Copyright © 2016年 Hori,Masaki. All rights reserved. -// - -#import "HMAirBaseCommand.h" - -#import "KCD-Swift.h" - -#import "HMKCAirBase.h" -#import "HMKCAirBasePlaneInfo.h" - - -@implementation HMAirBaseCommand - -- (NSString *)dataKey -{ - return @"api_data.api_air_base"; -} - -- (NSArray *)cmpositPrimaryKeys -{ - return @[@"area_id", @"rid"]; -} - -- (void)execute -{ - HMServerDataStore *serverDataStore = [HMServerDataStore oneTimeEditor]; - - NSError *error = nil; - NSArray *objects = [serverDataStore objectsWithEntityName:@"AirBase" - predicate:nil - error:&error]; - for(NSManagedObject *obj in objects) { - [serverDataStore deleteObject:obj]; - } - serverDataStore = nil; - - [self commitJSONToEntityNamed:@"AirBase"]; -} - -- (BOOL)handleExtraValue:(id)value forKey:(NSString *)key toObject:(NSManagedObject *)object -{ - if(![key isEqualToString:@"api_plane_info"]) return NO; - - HMKCAirBase *airbase = (HMKCAirBase *)object; - if(airbase.planeInfo.count == 0) { - NSManagedObjectContext *moc = object.managedObjectContext; - NSMutableOrderedSet *newinfo = [NSMutableOrderedSet orderedSet]; - for(NSInteger i = 0; i < 4; i++) { - HMKCAirBasePlaneInfo *info = [NSEntityDescription insertNewObjectForEntityForName:@"AirBasePlaneInfo" - inManagedObjectContext:moc]; - [newinfo addObject:info]; - } - airbase.planeInfo = newinfo; - } - - NSArray *planeInfos = value; - NSOrderedSet *infos = airbase.planeInfo; - - for(NSInteger i = 0; i < 4; i++) { - NSDictionary *planeInfo = planeInfos[i]; - HMKCAirBasePlaneInfo *info = infos[i]; - info.cond = planeInfo[@"api_cond"]; - info.count = planeInfo[@"api_count"]; - info.max_count = planeInfo[@"api_max_count"]; - info.slotid = planeInfo[@"api_slotid"]; - info.squadron_id = planeInfo[@"api_squadron_id"]; - info.state = planeInfo[@"api_state"]; - info.airBase = airbase; - } - - return YES; -} - -@end diff --git a/KCD/HMAirBaseCommand.swift b/KCD/HMAirBaseCommand.swift new file mode 100644 index 00000000..1f1a4d6a --- /dev/null +++ b/KCD/HMAirBaseCommand.swift @@ -0,0 +1,74 @@ +// +// HMAirBaseCommand.swift +// KCD +// +// Created by Hori,Masaki on 2017/01/14. +// Copyright © 2017年 Hori,Masaki. All rights reserved. +// + +import Cocoa + +class HMAirBaseCommand: HMJSONCommand { + override var dataKey: String { + return "api_data.api_air_base" + } + override var cmpositPrimaryKeys: [String] { + return ["area_id", "rid"] + } + + override func execute() { + let store = HMServerDataStore.oneTimeEditor() + guard let ab = try? store?.objects(withEntityName: "AirBase", predicate: nil), + let airbases = ab as? [HMKCAirBase] + else { return print("AirBase is not found") } + airbases.forEach { store?.delete($0) } + store?.saveAction(nil) + + commitJSON(toEntityNamed: "AirBase") + } + override func handleExtraValue(_ value: Any!, forKey key: String!, to object: NSManagedObject!) -> Bool { + if key != "api_plane_info" { return false } + + guard let airbase = object as? HMKCAirBase else { + print("object is not AirBase") + return false + } + if airbase.planeInfo == nil || airbase.planeInfo?.count == 0 { + let moc = airbase.managedObjectContext + let new: [HMKCAirBasePlaneInfo] = (0..<4).flatMap {_ in + NSEntityDescription.insertNewObject(forEntityName: "AirBasePlaneInfo", into: moc!) as? HMKCAirBasePlaneInfo + } + airbase.planeInfo = NSOrderedSet(array: new) + } + + guard let planeInfos = value as? [[String:Any]] + else { + print("value is wrong") + return false + } + guard let infosSet = airbase.planeInfo, + let infos = infosSet.array as? [HMKCAirBasePlaneInfo] + else { print("airbase is wrong") + return false + } + zip(infos, planeInfos).forEach { + let info = $0.0 + let dict = $0.1 + guard let cond = dict["api_cond"] as? NSNumber, + let count = dict["api_count"] as? NSNumber, + let maxCount = dict["api_max_count"] as? NSNumber, + let slotid = dict["api_slotid"] as? NSNumber, + let squadronid = dict["api_squadron_id"] as? NSNumber, + let state = dict["api_state"] as? NSNumber + else { return print("planeInfos is wrong") } + info.cond = cond + info.count = count + info.max_count = maxCount + info.slotid = slotid + info.squadron_id = squadronid + info.state = state + info.airBase = airbase + } + return true + } +} diff --git a/KCD/HMMapInfoCommand.m b/KCD/HMMapInfoCommand.m index 3ae0c1c4..cd55841f 100644 --- a/KCD/HMMapInfoCommand.m +++ b/KCD/HMMapInfoCommand.m @@ -8,7 +8,7 @@ #import "HMMapInfoCommand.h" -#import "HMAirBaseCommand.h" +#import "KCD-Swift.h" @implementation HMMapInfoCommand -- 2.11.0