From cfdc1e4a3177c1fdae2bfcfb623872d0977e15d2 Mon Sep 17 00:00:00 2001 From: masakih Date: Sat, 22 Mar 2014 23:37:42 +0900 Subject: [PATCH] =?utf8?q?=E9=96=8B=E7=99=BA=E5=B1=A5=E6=AD=B4=E3=82=92?= =?utf8?q?=E6=AE=8B=E3=81=99=E3=82=88=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- KCD.xcodeproj/project.pbxproj | 12 ++++ KCD/HMCreateSlotItemCommand.h | 13 ++++ KCD/HMCreateSlotItemCommand.m | 71 ++++++++++++++++++++++ KCD/HMKaihatuHistory.h | 23 +++++++ KCD/HMKaihatuHistory.m | 22 +++++++ .../LocalData.xcdatamodel/contents | 14 ++++- 6 files changed, 153 insertions(+), 2 deletions(-) create mode 100644 KCD/HMCreateSlotItemCommand.h create mode 100644 KCD/HMCreateSlotItemCommand.m create mode 100644 KCD/HMKaihatuHistory.h create mode 100644 KCD/HMKaihatuHistory.m diff --git a/KCD.xcodeproj/project.pbxproj b/KCD.xcodeproj/project.pbxproj index 9c96f3a2..95d8c3e9 100644 --- a/KCD.xcodeproj/project.pbxproj +++ b/KCD.xcodeproj/project.pbxproj @@ -34,6 +34,8 @@ F494DC6718C8BA6400AE97E4 /* HMPowerUpSupportViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F494DC6618C8BA6400AE97E4 /* HMPowerUpSupportViewController.m */; }; F494DC6A18C8BAB900AE97E4 /* HMPowerUpSupportViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F494DC6818C8BAB900AE97E4 /* HMPowerUpSupportViewController.xib */; }; F494DC6D18CC054800AE97E4 /* HMNyukyoDockStatus.m in Sources */ = {isa = PBXBuildFile; fileRef = F494DC6C18CC054800AE97E4 /* HMNyukyoDockStatus.m */; }; + F4B3DBCA18DDB9170011B4FC /* HMCreateSlotItemCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4B3DBC918DDB9170011B4FC /* HMCreateSlotItemCommand.m */; }; + F4B3DBCD18DDBA200011B4FC /* HMKaihatuHistory.m in Sources */ = {isa = PBXBuildFile; fileRef = F4B3DBCC18DDBA200011B4FC /* HMKaihatuHistory.m */; }; F4B414E918B09A4B00468DAF /* HMMasterMapAreaCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4B414E818B09A4B00468DAF /* HMMasterMapAreaCommand.m */; }; F4B414EC18B0A7D600468DAF /* HMMasterUseItemCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4B414EB18B0A7D600468DAF /* HMMasterUseItemCommand.m */; }; F4B414EF18B0BF1A00468DAF /* HMMasterMapInfoCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4B414EE18B0BF1A00468DAF /* HMMasterMapInfoCommand.m */; }; @@ -132,6 +134,10 @@ F494DC6918C8BAB900AE97E4 /* ja */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = ja; path = ja.lproj/HMPowerUpSupportViewController.xib; sourceTree = ""; }; F494DC6B18CC054800AE97E4 /* HMNyukyoDockStatus.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMNyukyoDockStatus.h; sourceTree = ""; }; F494DC6C18CC054800AE97E4 /* HMNyukyoDockStatus.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMNyukyoDockStatus.m; sourceTree = ""; }; + F4B3DBC818DDB9170011B4FC /* HMCreateSlotItemCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMCreateSlotItemCommand.h; sourceTree = ""; }; + F4B3DBC918DDB9170011B4FC /* HMCreateSlotItemCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMCreateSlotItemCommand.m; sourceTree = ""; }; + F4B3DBCB18DDBA200011B4FC /* HMKaihatuHistory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMKaihatuHistory.h; sourceTree = ""; }; + F4B3DBCC18DDBA200011B4FC /* HMKaihatuHistory.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMKaihatuHistory.m; sourceTree = ""; }; F4B414E718B09A4B00468DAF /* HMMasterMapAreaCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMMasterMapAreaCommand.h; sourceTree = ""; }; F4B414E818B09A4B00468DAF /* HMMasterMapAreaCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMMasterMapAreaCommand.m; sourceTree = ""; }; F4B414EA18B0A7D600468DAF /* HMMasterUseItemCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMMasterUseItemCommand.h; sourceTree = ""; }; @@ -348,6 +354,8 @@ F46F104718ABAC910063E503 /* KCD.xcdatamodeld */, F4E7802F18DC42680011BC4C /* HMKenzoHistory.h */, F4E7803018DC42680011BC4C /* HMKenzoHistory.m */, + F4B3DBCB18DDBA200011B4FC /* HMKaihatuHistory.h */, + F4B3DBCC18DDBA200011B4FC /* HMKaihatuHistory.m */, F4E7802C18DC3AF00011BC4C /* LocalData.xcdatamodeld */, ); name = CoreData; @@ -435,6 +443,8 @@ F4E33B5718BF5F67005B8C07 /* HMMemberSlotItemCommand.m */, F4E7802618DBD2A00011BC4C /* HMGetShipCommand.h */, F4E7802718DBD2A00011BC4C /* HMGetShipCommand.m */, + F4B3DBC818DDB9170011B4FC /* HMCreateSlotItemCommand.h */, + F4B3DBC918DDB9170011B4FC /* HMCreateSlotItemCommand.m */, ); name = Command; sourceTree = ""; @@ -569,6 +579,7 @@ F47B78B218A7B42B0011386E /* HMJSONViewWindowController.m in Sources */, F4B414EF18B0BF1A00468DAF /* HMMasterMapInfoCommand.m in Sources */, F4C118FC18A67B1C005D5B25 /* CustomHTTPProtocol.m in Sources */, + F4B3DBCD18DDBA200011B4FC /* HMKaihatuHistory.m in Sources */, F4D2CBCB18B05E58000EBC59 /* HMMaserShipCommand.m in Sources */, F4513EFA18BB699700073552 /* HMShipWindowController.m in Sources */, F46F104118A9B85E0063E503 /* HMJSONNode.m in Sources */, @@ -577,6 +588,7 @@ F4513EF618B9F29800073552 /* HMMemberShipCommand.m in Sources */, F4C1190818A746EB005D5B25 /* HMJSONTracker.m in Sources */, F4513EDD18B619B600073552 /* HMCoreDataManager.m in Sources */, + F4B3DBCA18DDB9170011B4FC /* HMCreateSlotItemCommand.m in Sources */, F4B414E918B09A4B00468DAF /* HMMasterMapAreaCommand.m in Sources */, F4C3957418CDDFE500A1E918 /* HMKenzoDockStatus.m in Sources */, F4C118FB18A67B1C005D5B25 /* CanonicalRequest.m in Sources */, diff --git a/KCD/HMCreateSlotItemCommand.h b/KCD/HMCreateSlotItemCommand.h new file mode 100644 index 00000000..6c0ff295 --- /dev/null +++ b/KCD/HMCreateSlotItemCommand.h @@ -0,0 +1,13 @@ +// +// HMCreateSlotItemCommand.h +// KCD +// +// Created by Hori,Masaki on 2014/03/22. +// Copyright (c) 2014å¹´ Hori,Masaki. All rights reserved. +// + +#import "HMJSONCommand.h" + +@interface HMCreateSlotItemCommand : HMJSONCommand + +@end diff --git a/KCD/HMCreateSlotItemCommand.m b/KCD/HMCreateSlotItemCommand.m new file mode 100644 index 00000000..eb538fc9 --- /dev/null +++ b/KCD/HMCreateSlotItemCommand.m @@ -0,0 +1,71 @@ +// +// HMCreateSlotItemCommand.m +// KCD +// +// Created by Hori,Masaki on 2014/03/22. +// Copyright (c) 2014å¹´ Hori,Masaki. All rights reserved. +// + +#import "HMCreateSlotItemCommand.h" + +#import "HMCoreDataManager.h" +#import "HMLocalDataStore.h" +#import "HMKaihatuHistory.h" + + +@implementation HMCreateSlotItemCommand ++ (void)load +{ + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + [HMJSONCommand registerClass:self]; + }); +} + ++ (BOOL)canExcuteAPI:(NSString *)api +{ + if([api isEqualToString:@"/kcsapi/api_req_kousyou/createitem"]) return YES; + + return NO; +} +- (void)execute +{ + id data = [self.json valueForKey:@"api_data"]; + BOOL created = [[data valueForKey:@"api_create_flag"] boolValue]; + NSString *name = nil; + NSNumber *numberOfUsedKaihatuSizai = nil; + + if(created) { + NSManagedObjectContext *context = [[HMCoreDataManager defaultManager] managedObjectContext]; + + NSNumber *slotItemID = [data valueForKey:@"api_slotitem_id"]; + NSFetchRequest *req = [NSFetchRequest fetchRequestWithEntityName:@"MasterSlotItem"]; + NSPredicate *predicate = [NSPredicate predicateWithFormat:@"id = %@", slotItemID]; + [req setPredicate:predicate]; + + NSArray *array = [context executeFetchRequest:req error:NULL]; + if([array count] == 0) { + NSLog(@"MasterSlotItem data is invalid or ship_id is invalid."); + return; + } + name = [array[0] valueForKey:@"name"]; + numberOfUsedKaihatuSizai = @1; + } else { + name = NSLocalizedString(@"fail to develop", @""); + numberOfUsedKaihatuSizai = @0; + } + + HMLocalDataStore *lds = [HMLocalDataStore oneTimeEditor]; + NSManagedObjectContext *localStoreContext = [lds managedObjectContext]; + HMKaihatuHistory *newObejct = [NSEntityDescription insertNewObjectForEntityForName:@"KaihatuHistory" + inManagedObjectContext:localStoreContext]; + newObejct.name = name; + newObejct.fuel = @([[self.arguments valueForKey:@"api_item1"] integerValue]); + newObejct.bull = @([[self.arguments valueForKey:@"api_item2"] integerValue]); + newObejct.steel = @([[self.arguments valueForKey:@"api_item3"] integerValue]); + newObejct.bauxite = @([[self.arguments valueForKey:@"api_item4"] integerValue]); + newObejct.kaihatusizai = numberOfUsedKaihatuSizai; + newObejct.date = [NSDate date]; +} + +@end diff --git a/KCD/HMKaihatuHistory.h b/KCD/HMKaihatuHistory.h new file mode 100644 index 00000000..708ade56 --- /dev/null +++ b/KCD/HMKaihatuHistory.h @@ -0,0 +1,23 @@ +// +// HMKaihatuHistory.h +// KCD +// +// Created by Hori,Masaki on 2014/03/22. +// Copyright (c) 2014å¹´ Hori,Masaki. All rights reserved. +// + +#import +#import + + +@interface HMKaihatuHistory : NSManagedObject + +@property (nonatomic, retain) NSNumber *bull; +@property (nonatomic, retain) NSNumber *bauxite; +@property (nonatomic, retain) NSDate *date; +@property (nonatomic, retain) NSNumber *fuel; +@property (nonatomic, retain) NSString *name; +@property (nonatomic, retain) NSNumber *steel; +@property (nonatomic, retain) NSNumber *kaihatusizai; + +@end diff --git a/KCD/HMKaihatuHistory.m b/KCD/HMKaihatuHistory.m new file mode 100644 index 00000000..a54e7aa1 --- /dev/null +++ b/KCD/HMKaihatuHistory.m @@ -0,0 +1,22 @@ +// +// HMKaihatuHistory.m +// KCD +// +// Created by Hori,Masaki on 2014/03/22. +// Copyright (c) 2014å¹´ Hori,Masaki. All rights reserved. +// + +#import "HMKaihatuHistory.h" + + +@implementation HMKaihatuHistory + +@dynamic bull; +@dynamic bauxite; +@dynamic date; +@dynamic fuel; +@dynamic name; +@dynamic steel; +@dynamic kaihatusizai; + +@end diff --git a/KCD/LocalData.xcdatamodeld/LocalData.xcdatamodel/contents b/KCD/LocalData.xcdatamodeld/LocalData.xcdatamodel/contents index af2542f8..3ece2317 100644 --- a/KCD/LocalData.xcdatamodeld/LocalData.xcdatamodel/contents +++ b/KCD/LocalData.xcdatamodeld/LocalData.xcdatamodel/contents @@ -1,16 +1,26 @@ + + + + + + + + + - + - + + \ No newline at end of file -- 2.11.0