F44BC7391E2A5013004644E3 /* HMAirBaseCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = F44BC7381E2A5013004644E3 /* HMAirBaseCommand.swift */; };
F44BC73B1E2A5C34004644E3 /* HMMapInfoCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = F44BC73A1E2A5C34004644E3 /* HMMapInfoCommand.swift */; };
F44BC73D1E2A5D39004644E3 /* HMDropShipHistoryCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = F44BC73C1E2A5D39004644E3 /* HMDropShipHistoryCommand.swift */; };
+ F44BC73F1E2B1AD4004644E3 /* HMDummyShipCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = F44BC73E1E2B1AD4004644E3 /* HMDummyShipCommand.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 */; };
F4BDEB71187252F30069D0CE /* KCDTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F4BDEB70187252F30069D0CE /* KCDTests.m */; };
F4BDEB7B187253130069D0CE /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F4BDEB7A187253130069D0CE /* WebKit.framework */; };
F4BEEE9F18D211280006F70C /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = F4BEEE9D18D211280006F70C /* Localizable.strings */; };
- F4BEEFE11B0B6326004702B8 /* HMDummyShipCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4BEEFE01B0B6326004702B8 /* HMDummyShipCommand.m */; };
F4BEEFE91B0CE312004702B8 /* HMAPIResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = F4BEEFE81B0CE312004702B8 /* HMAPIResponse.m */; };
F4BEEFFC1B11A5A7004702B8 /* HMExternalBrowserWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F4BEEFFE1B11A5A7004702B8 /* HMExternalBrowserWindowController.xib */; };
F4BEEFFF1B11A5C2004702B8 /* HMMediumShipViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F4BEF0011B11A5C2004702B8 /* HMMediumShipViewController.xib */; };
F44BC7381E2A5013004644E3 /* HMAirBaseCommand.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMAirBaseCommand.swift; sourceTree = "<group>"; };
F44BC73A1E2A5C34004644E3 /* HMMapInfoCommand.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMMapInfoCommand.swift; sourceTree = "<group>"; };
F44BC73C1E2A5D39004644E3 /* HMDropShipHistoryCommand.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMDropShipHistoryCommand.swift; sourceTree = "<group>"; };
+ F44BC73E1E2B1AD4004644E3 /* HMDummyShipCommand.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMDummyShipCommand.swift; sourceTree = "<group>"; };
F4513EDB18B619B600073552 /* HMCoreDataManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMCoreDataManager.h; sourceTree = "<group>"; };
F4513EDC18B619B600073552 /* HMCoreDataManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMCoreDataManager.m; sourceTree = "<group>"; };
F45771221E1BCC7C008A9215 /* HMPeriodicNotifier.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMPeriodicNotifier.swift; sourceTree = "<group>"; };
F4BEEEA118D211360006F70C /* ja */ = {isa = PBXFileReference; lastKnownFileType = text; name = ja; path = ja.lproj/Localizable.strings.sed; sourceTree = "<group>"; };
F4BEEEA418D211500006F70C /* ja */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.make; name = ja; path = ja.lproj/Makefile; sourceTree = "<group>"; };
F4BEEEA718D323520006F70C /* Makefile */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.make; path = Makefile; sourceTree = SOURCE_ROOT; };
- F4BEEFDF1B0B6326004702B8 /* HMDummyShipCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMDummyShipCommand.h; sourceTree = "<group>"; };
- F4BEEFE01B0B6326004702B8 /* HMDummyShipCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMDummyShipCommand.m; sourceTree = "<group>"; };
F4BEEFE71B0CE312004702B8 /* HMAPIResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMAPIResponse.h; sourceTree = "<group>"; };
F4BEEFE81B0CE312004702B8 /* HMAPIResponse.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMAPIResponse.m; sourceTree = "<group>"; };
F4C041B91875CAF5009273EB /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
F43F3D451A33F7D400D6DAF7 /* HMResetSortieCommand.m */,
F4ED5D2B1B7C677E00D1BDEF /* HMGuardShelterCommand.h */,
F4ED5D2C1B7C677E00D1BDEF /* HMGuardShelterCommand.m */,
- F4BEEFDF1B0B6326004702B8 /* HMDummyShipCommand.h */,
- F4BEEFE01B0B6326004702B8 /* HMDummyShipCommand.m */,
+ F44BC73E1E2B1AD4004644E3 /* HMDummyShipCommand.swift */,
F44BC73C1E2A5D39004644E3 /* HMDropShipHistoryCommand.swift */,
F44BC73A1E2A5C34004644E3 /* HMMapInfoCommand.swift */,
F44BC7381E2A5013004644E3 /* HMAirBaseCommand.swift */,
F4AA594A1E1E4863001667AF /* HMMapWindowController.swift in Sources */,
F4E5FF101E17A83D0026868C /* HMScreenshotListWindowController.swift in Sources */,
F44BC7031E252C4F004644E3 /* HMUpdateSlotItemCommand.swift in Sources */,
+ F44BC73F1E2B1AD4004644E3 /* HMDummyShipCommand.swift in Sources */,
F44AB23E19E824D700F217AF /* HMKCSlotItemObject.m in Sources */,
F44BC73D1E2A5D39004644E3 /* HMDropShipHistoryCommand.swift in Sources */,
F45771231E1BCC7C008A9215 /* HMPeriodicNotifier.swift in Sources */,
F4AA59421E1E2854001667AF /* HMOrderedSetToArrayTransformer.swift in Sources */,
F494DC5F18C30AE100AE97E4 /* HMMissionStatus.m in Sources */,
F43F3D4C1A34AC8000D6DAF7 /* HMKCMasterShipObject.m in Sources */,
- F4BEEFE11B0B6326004702B8 /* HMDummyShipCommand.m in Sources */,
F4AA59441E1E300B001667AF /* HMActinKindTransformer.swift in Sources */,
F4D05BCC1E0D274100688D66 /* HMBookmarkEditorViewController.swift in Sources */,
F494DC6D18CC054800AE97E4 /* HMNyukyoDockStatus.m in Sources */,
+++ /dev/null
-//
-// HMDummyShipCommand.m
-// KCD
-//
-// Created by Hori,Masaki on 2015/05/19.
-// Copyright (c) 2015年 Hori,Masaki. All rights reserved.
-//
-
-#import "HMDummyShipCommand.h"
-
-#import "KCD-Swift.h"
-
-#import "HMKCShipObject+Extensions.h"
-
-
-@implementation HMDummyShipCommand
-
-static BOOL getShipFlag = 0;
-
-- (void)checkGetShip
-{
- id data = [self.json valueForKey:@"api_data"];
- id getShip = [data valueForKey:@"api_get_ship"];
- if(!getShip || [getShip isKindOfClass:[NSNull class]]) return;
-
- getShipFlag = YES;
-}
-- (void)enterDummy
-{
- if(!getShipFlag) return;
-
- HMServerDataStore *serverDataStore = [HMServerDataStore oneTimeEditor];
-
- HMKCShipObject *object = [serverDataStore insertNewObjectForEntityForName:@"Ship"];
- object.id = @(-2);
- getShipFlag = NO;
-}
-
-- (void)removeDummy
-{
- getShipFlag = NO;
-
- NSError *error = nil;
- HMServerDataStore *serverDataStore = [HMServerDataStore oneTimeEditor];
- NSArray<HMKCShipObject *> *dummys = [serverDataStore objectsWithEntityName:@"Ship"
- error:&error
- predicateFormat:@"id = %@", @(-2)];
- for(HMKCShipObject *dummy in dummys) {
- [serverDataStore deleteObject:dummy];
- }
-}
-
-- (void)execute
-{
- if([self.api isEqualToString:@"/kcsapi/api_req_sortie/battleresult"]) {
- [self checkGetShip];
- }
- if([self.api isEqualToString:@"/kcsapi/api_get_member/ship_deck"]) {
- [self enterDummy];
- }
- if([self.api isEqualToString:@"/kcsapi/api_port/port"]) {
- [self removeDummy];
- }
-}
-
-@end
--- /dev/null
+//
+// HMDummyShipCommand.swift
+// KCD
+//
+// Created by Hori,Masaki on 2017/01/15.
+// Copyright © 2017年 Hori,Masaki. All rights reserved.
+//
+
+import Cocoa
+
+/**
+ * 出撃中にドロップした艦をマスクした上で入居数に反映させるためのダミーデータの生成と削除を行う
+ **/
+class HMDummyShipCommand: HMJSONCommand {
+ override func execute() {
+ if api == "/kcsapi/api_req_sortie/battleresult" { checkGetShip() }
+ if api == "/kcsapi/api_get_member/ship_deck" { enterDummy() }
+ if api == "/kcsapi/api_port/port" { removeDummy() }
+ }
+
+ private static var needsEnterDummy: Bool = false
+
+ private func checkGetShip() {
+ guard let j = json as? [String:Any],
+ let data = j[dataKey] as? [String:Any],
+ let _ = data["api_get_ship"]
+ else { return }
+ HMDummyShipCommand.needsEnterDummy = true
+ }
+ private func enterDummy() {
+ if !HMDummyShipCommand.needsEnterDummy { return }
+
+ let store = HMServerDataStore.oneTimeEditor()
+ guard let dummy = store?.insertNewObjectForEntity(forName: "Ship") as? HMKCShipObject
+ else { return print("Can not create Ship for dummy") }
+ dummy.id = -2 as NSNumber
+ HMDummyShipCommand.needsEnterDummy = false
+ }
+ private func removeDummy() {
+ HMDummyShipCommand.needsEnterDummy = false
+
+ let store = HMServerDataStore.oneTimeEditor()
+ let p = NSPredicate(format: "id = -2")
+ guard let d = try? store?.objects(withEntityName: "Ship", predicate: p),
+ let dummys = d as? [HMKCShipObject]
+ else { return }
+ dummys.forEach { store?.delete($0) }
+ }
+}