OSDN Git Service

/kcsapi/api_get_member/materialに対応
authormasakih <masakih@users.sourceforge.jp>
Sat, 22 Feb 2014 14:45:00 +0000 (23:45 +0900)
committermasakih <masakih@users.sourceforge.jp>
Sat, 22 Feb 2014 14:45:00 +0000 (23:45 +0900)
KCD.xcodeproj/project.pbxproj
KCD/HMMemberMaterialCommand.h [new file with mode: 0644]
KCD/HMMemberMaterialCommand.m [new file with mode: 0644]
KCD/KCD.xcdatamodeld/KCD.xcdatamodel/contents

index 22bb8cc..18e5e3e 100644 (file)
@@ -12,6 +12,7 @@
                F4513EE518B635EA00073552 /* HMDocksViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F4513EE318B635EA00073552 /* HMDocksViewController.xib */; };
                F4513EE818B77A5300073552 /* HMMemberKDockCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4513EE718B77A5300073552 /* HMMemberKDockCommand.m */; };
                F4513EEB18B7900A00073552 /* HMMemberDeckCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4513EEA18B7900A00073552 /* HMMemberDeckCommand.m */; };
+               F4513EEE18B8E2F600073552 /* HMMemberMaterialCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4513EED18B8E2F600073552 /* HMMemberMaterialCommand.m */; };
                F46F103618A7CE310063E503 /* HMJSONViewCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F46F103518A7CE310063E503 /* HMJSONViewCommand.m */; };
                F46F104118A9B85E0063E503 /* HMJSONNode.m in Sources */ = {isa = PBXBuildFile; fileRef = F46F104018A9B85E0063E503 /* HMJSONNode.m */; };
                F46F104518AA50730063E503 /* HMBroserWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = F46F104318AA50730063E503 /* HMBroserWindowController.m */; };
@@ -73,6 +74,8 @@
                F4513EE718B77A5300073552 /* HMMemberKDockCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMMemberKDockCommand.m; sourceTree = "<group>"; };
                F4513EE918B7900A00073552 /* HMMemberDeckCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMMemberDeckCommand.h; sourceTree = "<group>"; };
                F4513EEA18B7900A00073552 /* HMMemberDeckCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMMemberDeckCommand.m; sourceTree = "<group>"; };
+               F4513EEC18B8E2F600073552 /* HMMemberMaterialCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMMemberMaterialCommand.h; sourceTree = "<group>"; };
+               F4513EED18B8E2F600073552 /* HMMemberMaterialCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMMemberMaterialCommand.m; sourceTree = "<group>"; };
                F46F103418A7CE310063E503 /* HMJSONViewCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMJSONViewCommand.h; sourceTree = "<group>"; };
                F46F103518A7CE310063E503 /* HMJSONViewCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMJSONViewCommand.m; sourceTree = "<group>"; };
                F46F103F18A9B85E0063E503 /* HMJSONNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMJSONNode.h; sourceTree = "<group>"; };
                                F4513EE718B77A5300073552 /* HMMemberKDockCommand.m */,
                                F4513EE918B7900A00073552 /* HMMemberDeckCommand.h */,
                                F4513EEA18B7900A00073552 /* HMMemberDeckCommand.m */,
+                               F4513EEC18B8E2F600073552 /* HMMemberMaterialCommand.h */,
+                               F4513EED18B8E2F600073552 /* HMMemberMaterialCommand.m */,
                        );
                        name = Command;
                        sourceTree = "<group>";
                                F4B414F818B1D35800468DAF /* HMMasterMissionCommand.m in Sources */,
                                F4C1190B18A74DF0005D5B25 /* HMJSONCommand.m in Sources */,
                                F4B414F518B1888800468DAF /* HMMasterFurnitureCommand.m in Sources */,
+                               F4513EEE18B8E2F600073552 /* HMMemberMaterialCommand.m in Sources */,
                                F4BDEB53187252F30069D0CE /* main.m in Sources */,
                                F4513EE418B635EA00073552 /* HMDocksViewController.m in Sources */,
                                F47B78B218A7B42B0011386E /* HMJSONViewWindowController.m in Sources */,
diff --git a/KCD/HMMemberMaterialCommand.h b/KCD/HMMemberMaterialCommand.h
new file mode 100644 (file)
index 0000000..fc7af4c
--- /dev/null
@@ -0,0 +1,13 @@
+//
+//  HMMemberMaterialCommand.h
+//  KCD
+//
+//  Created by Hori,Masaki on 2014/02/22.
+//  Copyright (c) 2014年 Hori,Masaki. All rights reserved.
+//
+
+#import "HMJSONCommand.h"
+
+@interface HMMemberMaterialCommand : HMJSONCommand
+
+@end
diff --git a/KCD/HMMemberMaterialCommand.m b/KCD/HMMemberMaterialCommand.m
new file mode 100644 (file)
index 0000000..e8495ef
--- /dev/null
@@ -0,0 +1,61 @@
+//
+//  HMMemberMaterialCommand.m
+//  KCD
+//
+//  Created by Hori,Masaki on 2014/02/22.
+//  Copyright (c) 2014年 Hori,Masaki. All rights reserved.
+//
+
+#import "HMMemberMaterialCommand.h"
+
+#import "HMCoreDataManager.h"
+
+@implementation HMMemberMaterialCommand
++ (void)load
+{
+       static dispatch_once_t onceToken;
+       dispatch_once(&onceToken, ^{
+               [HMJSONCommand registerClass:self];
+       });
+}
+
++ (BOOL)canExcuteAPI:(NSString *)api
+{
+       return [api isEqualToString:@"/kcsapi/api_get_member/material"];
+}
+- (void)execute
+{
+       NSArray *api_data = [self.json objectForKey:@"api_data"];
+       if(![api_data isKindOfClass:[NSArray class]]) {
+               [self log:@"api_data is NOT NSArray."];
+               return;
+       }
+       
+       HMCoreDataManager *dm = [HMCoreDataManager oneTimeEditor];
+       NSManagedObjectContext *managedObjectContext = [dm managedObjectContext];
+       
+       NSFetchRequest *req = [NSFetchRequest fetchRequestWithEntityName:@"Material"];
+       NSError *error = nil;
+       id result = [managedObjectContext executeFetchRequest:req
+                                                                                                       error:&error];
+       if(error) {
+               [self log:@"Fetch error: %@", error];
+               return;
+       }
+       NSManagedObject *object = nil;
+       if(!result || [result count] == 0) {
+               object = [NSEntityDescription insertNewObjectForEntityForName:@"Material"
+                                                                                          inManagedObjectContext:managedObjectContext];
+       } else {
+               object = result[0];
+       }
+       
+       NSArray *keys = @[@"fuel", @"bull", @"steel", @"bauxite", @"kousokukenzo", @"kousokushuhuku", @"kaihatusizai"];
+       
+       for(NSDictionary *dict in api_data) {
+               NSNumber *idValue = [dict valueForKey:@"api_id"];
+               NSString *key = keys[[idValue integerValue] - 1];
+               [object setValue:[dict valueForKey:@"api_value"] forKey:key];
+       }
+}
+@end
index 952659a..0a97e6a 100644 (file)
         <attribute name="price" optional="YES" attributeType="Integer 32" defaultValueString="0" syncable="YES"/>
         <attribute name="usetype" optional="YES" attributeType="Integer 32" defaultValueString="0" syncable="YES"/>
     </entity>
+    <entity name="Material" representedClassName="HMKCManagedObject" syncable="YES">
+        <attribute name="bauxite" optional="YES" attributeType="Integer 32" defaultValueString="0" syncable="YES"/>
+        <attribute name="bull" optional="YES" attributeType="Integer 32" defaultValueString="0" syncable="YES"/>
+        <attribute name="fuel" optional="YES" attributeType="Integer 32" defaultValueString="0" syncable="YES"/>
+        <attribute name="kaihatusizai" optional="YES" attributeType="Integer 32" defaultValueString="0" syncable="YES"/>
+        <attribute name="kousokukenzo" optional="YES" attributeType="Integer 32" defaultValueString="0" syncable="YES"/>
+        <attribute name="kousokushuhuku" optional="YES" attributeType="Integer 32" defaultValueString="0" syncable="YES"/>
+        <attribute name="steel" optional="YES" attributeType="Integer 32" defaultValueString="0" syncable="YES"/>
+    </entity>
     <entity name="NyukyoDock" representedClassName="HMKCManagedObject" syncable="YES">
         <attribute name="complete_time" optional="YES" attributeType="Integer 64" defaultValueString="0" syncable="YES"/>
         <attribute name="complete_time_str" optional="YES" attributeType="String" syncable="YES"/>
         <element name="NyukyoDock" positionX="0" positionY="0" width="0" height="0"/>
         <element name="KenzoDock" positionX="0" positionY="0" width="0" height="0"/>
         <element name="Deck" positionX="0" positionY="0" width="0" height="0"/>
+        <element name="Material" positionX="0" positionY="0" width="0" height="0"/>
     </elements>
 </model>
\ No newline at end of file