OSDN Git Service

HMKCDamageをSwiftに変換した
authormasakih <masakih@users.sourceforge.jp>
Thu, 2 Feb 2017 13:04:40 +0000 (22:04 +0900)
committermasakih <masakih@users.sourceforge.jp>
Thu, 2 Feb 2017 13:04:40 +0000 (22:04 +0900)
KCD.xcodeproj/project.pbxproj
KCD/HMCalculateDamageCommand.swift
KCD/HMKCDamage+CoreDataProperties.h [deleted file]
KCD/HMKCDamage+CoreDataProperties.m [deleted file]
KCD/HMKCDamage.h [deleted file]
KCD/HMKCDamage.m [deleted file]
KCD/HMKCDamage.swift [new file with mode: 0644]
KCD/KCD-Bridging-Header.h
KCD/Temporary.xcdatamodeld/Temporary.xcdatamodel/contents

index 63bc0db..669496b 100644 (file)
@@ -34,6 +34,7 @@
                F42A8FE81E422B180099DC1D /* HMKenzoHistory.swift in Sources */ = {isa = PBXBuildFile; fileRef = F42A8FE71E422B180099DC1D /* HMKenzoHistory.swift */; };
                F42A8FEA1E43476F0099DC1D /* HMKenzoMark.swift in Sources */ = {isa = PBXBuildFile; fileRef = F42A8FE91E43476F0099DC1D /* HMKenzoMark.swift */; };
                F42A8FEC1E4354F50099DC1D /* HMKCBattle.swift in Sources */ = {isa = PBXBuildFile; fileRef = F42A8FEB1E4354F50099DC1D /* HMKCBattle.swift */; };
+               F42A8FEE1E435E330099DC1D /* HMKCDamage.swift in Sources */ = {isa = PBXBuildFile; fileRef = F42A8FED1E435E330099DC1D /* HMKCDamage.swift */; };
                F42CFE161E3BA1E1000B4F9B /* HMEnhancementListItem2.plist in Resources */ = {isa = PBXBuildFile; fileRef = F42CFE151E3BA1E1000B4F9B /* HMEnhancementListItem2.plist */; };
                F42CFE181E3C12AA000B4F9B /* HMScreenshotInformation.swift in Sources */ = {isa = PBXBuildFile; fileRef = F42CFE171E3C12AA000B4F9B /* HMScreenshotInformation.swift */; };
                F42CFE1A1E3C726D000B4F9B /* UserDefaultsExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F42CFE191E3C726D000B4F9B /* UserDefaultsExtension.swift */; };
                F4F9470A1D5DBA3800F95998 /* HMEquipmentWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F4F9470C1D5DBA3800F95998 /* HMEquipmentWindowController.xib */; };
                F4F9471F1D5DBBC700F95998 /* HMRepairListViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F4F947211D5DBBC700F95998 /* HMRepairListViewController.xib */; };
                F4F947281D5DBC5500F95998 /* HMAncherageRepairTimerViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F4F9472A1D5DBC5500F95998 /* HMAncherageRepairTimerViewController.xib */; };
-               F4F9F86D1C6A306A00D0EE76 /* HMKCDamage+CoreDataProperties.m in Sources */ = {isa = PBXBuildFile; fileRef = F4F9F8621C6A306A00D0EE76 /* HMKCDamage+CoreDataProperties.m */; };
-               F4F9F86E1C6A306A00D0EE76 /* HMKCDamage.m in Sources */ = {isa = PBXBuildFile; fileRef = F4F9F8641C6A306A00D0EE76 /* HMKCDamage.m */; };
                F4F9F86F1C6A306A00D0EE76 /* HMKCGuardEscaped+CoreDataProperties.m in Sources */ = {isa = PBXBuildFile; fileRef = F4F9F8661C6A306A00D0EE76 /* HMKCGuardEscaped+CoreDataProperties.m */; };
                F4F9F8701C6A306A00D0EE76 /* HMKCGuardEscaped.m in Sources */ = {isa = PBXBuildFile; fileRef = F4F9F8681C6A306A00D0EE76 /* HMKCGuardEscaped.m */; };
 /* End PBXBuildFile section */
                F42A8FE71E422B180099DC1D /* HMKenzoHistory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMKenzoHistory.swift; sourceTree = "<group>"; };
                F42A8FE91E43476F0099DC1D /* HMKenzoMark.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMKenzoMark.swift; sourceTree = "<group>"; };
                F42A8FEB1E4354F50099DC1D /* HMKCBattle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMKCBattle.swift; sourceTree = "<group>"; };
+               F42A8FED1E435E330099DC1D /* HMKCDamage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMKCDamage.swift; sourceTree = "<group>"; };
                F42CBB201D1ED41D004C2AE2 /* LocalData 3.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "LocalData 3.xcdatamodel"; sourceTree = "<group>"; };
                F42CFE151E3BA1E1000B4F9B /* HMEnhancementListItem2.plist */ = {isa = PBXFileReference; lastKnownFileType = file.bplist; path = HMEnhancementListItem2.plist; sourceTree = "<group>"; };
                F42CFE171E3C12AA000B4F9B /* HMScreenshotInformation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMScreenshotInformation.swift; sourceTree = "<group>"; };
                F4F9472C1D5DBC7300F95998 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/HMBroserWindowController.xib; sourceTree = "<group>"; };
                F4F947331D5EB44700F95998 /* zh-Hant-TW */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant-TW"; path = "zh-Hant-TW.lproj/HMBroserWindowController.strings"; sourceTree = "<group>"; };
                F4F947351D5EBDD700F95998 /* zh-Hant-TW */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant-TW"; path = "zh-Hant-TW.lproj/HMShipViewController.strings"; sourceTree = "<group>"; };
-               F4F9F8611C6A306A00D0EE76 /* HMKCDamage+CoreDataProperties.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "HMKCDamage+CoreDataProperties.h"; sourceTree = "<group>"; };
-               F4F9F8621C6A306A00D0EE76 /* HMKCDamage+CoreDataProperties.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "HMKCDamage+CoreDataProperties.m"; sourceTree = "<group>"; };
-               F4F9F8631C6A306A00D0EE76 /* HMKCDamage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMKCDamage.h; sourceTree = "<group>"; };
-               F4F9F8641C6A306A00D0EE76 /* HMKCDamage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMKCDamage.m; sourceTree = "<group>"; };
                F4F9F8651C6A306A00D0EE76 /* HMKCGuardEscaped+CoreDataProperties.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "HMKCGuardEscaped+CoreDataProperties.h"; sourceTree = "<group>"; };
                F4F9F8661C6A306A00D0EE76 /* HMKCGuardEscaped+CoreDataProperties.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "HMKCGuardEscaped+CoreDataProperties.m"; sourceTree = "<group>"; };
                F4F9F8671C6A306A00D0EE76 /* HMKCGuardEscaped.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMKCGuardEscaped.h; sourceTree = "<group>"; };
                                F4AA05F9192B92C700844688 /* Temporary.xcdatamodeld */,
                                F47215AB1E1FA2460083D3BC /* HMTemporaryDataStore.swift */,
                                F42A8FEB1E4354F50099DC1D /* HMKCBattle.swift */,
-                               F4F9F8611C6A306A00D0EE76 /* HMKCDamage+CoreDataProperties.h */,
-                               F4F9F8621C6A306A00D0EE76 /* HMKCDamage+CoreDataProperties.m */,
-                               F4F9F8631C6A306A00D0EE76 /* HMKCDamage.h */,
-                               F4F9F8641C6A306A00D0EE76 /* HMKCDamage.m */,
+                               F42A8FED1E435E330099DC1D /* HMKCDamage.swift */,
                                F4F9F8651C6A306A00D0EE76 /* HMKCGuardEscaped+CoreDataProperties.h */,
                                F4F9F8661C6A306A00D0EE76 /* HMKCGuardEscaped+CoreDataProperties.m */,
                                F4F9F8671C6A306A00D0EE76 /* HMKCGuardEscaped.h */,
                                F44BC6E31E230577004644E3 /* HMSlotDepriveCommand.swift in Sources */,
                                F42A8FCE1E3DA7E90099DC1D /* HMKCMasterShipObject.swift in Sources */,
                                F490977B1E19C3910085A45D /* HMSuppliesView.swift in Sources */,
-                               F4F9F86D1C6A306A00D0EE76 /* HMKCDamage+CoreDataProperties.m in Sources */,
                                F4AA59341E1D2512001667AF /* HMSlotItemShortNameTransformer.swift in Sources */,
                                F44BC7311E2A247F004644E3 /* HMMasterSTypeCommand.swift in Sources */,
                                F44BC6E11E2304E3004644E3 /* HMSlotDepriveUnsetCommand.swift in Sources */,
                                F4A0D7131E2FAEF800224DCE /* HMBattleCommand.swift in Sources */,
                                F4AA59481E1E3CBA001667AF /* HMAirbasePlaneStateTransformer.swift in Sources */,
                                F4E7802E18DC3AF00011BC4C /* LocalData.xcdatamodeld in Sources */,
+                               F42A8FEE1E435E330099DC1D /* HMKCDamage.swift in Sources */,
                                F42CFE1C1E3CB495000B4F9B /* HMBookmarkItem.swift in Sources */,
                                F44BC7151E2914FE004644E3 /* HMMemberBasicCommand.swift in Sources */,
                                F47215AC1E1FA2460083D3BC /* HMTemporaryDataStore.swift in Sources */,
                                F4AA59141E1C951F001667AF /* HMTimerCountFormatter.swift in Sources */,
                                F44BC6D91E2272F6004644E3 /* HMNyukyoStartCommand.swift in Sources */,
                                F44BC7411E2B263D004644E3 /* HMGuardShelterCommand.swift in Sources */,
-                               F4F9F86E1C6A306A00D0EE76 /* HMKCDamage.m in Sources */,
                                F4D05BD21E0F3C4E00688D66 /* HMCombileViewController.swift in Sources */,
                                F42CFE241E3D8309000B4F9B /* HMKCKenzoDock.swift in Sources */,
                                F4BDEB53187252F30069D0CE /* main.m in Sources */,
index 95220dc..bb8aa6d 100644 (file)
@@ -138,12 +138,11 @@ class HMCalculateDamageCommand: HMJSONCommand {
             let cellNumber = data["api_no"] as? Int,
             let eventId = data["api_event_id"] as? Int
             else { return print("updateBattleCell JSON is wrong") }
-        let isBossCell = (eventId == 5)
         guard let battles = store?.battles,
             let battle = battles.first
             else { return print("Battle is invalid.") }
         battle.no = cellNumber
-        battle.isBossCell = isBossCell
+        battle.isBossCell = (eventId == 5)
     }
     private func buildDamagedEntity() {
         guard let battles = store?.battles,
@@ -168,10 +167,10 @@ class HMCalculateDamageCommand: HMJSONCommand {
             guard let damage = store?.insertNewObjectForEntity(forName: "Damage") as? HMKCDamage
                 else { return print("Can not create Damage") }
             damage.battle = battle
-            damage.id = $0.offset as NSNumber
+            damage.id = $0.offset
             if let ship = $0.element as? HMKCShipObject {
-                damage.hp = ship.nowhp as NSNumber
-                damage.shipID = ship.id as NSNumber
+                damage.hp = ship.nowhp
+                damage.shipID = ship.id
             }
         }
     }
@@ -233,19 +232,19 @@ class HMCalculateDamageCommand: HMJSONCommand {
                 
                 let damageObject = damages[targetPosition - 1 + shipOffset]
                 let damage = hougeki1Damages[i][j]
-                let hp = damageObject.hp ?? 0
+                let hp = damageObject.hp
                 var newHP = (hp as Int) - damage
                 if newHP <= 0 {
-                    if let shipId = damageObject.shipID as? Int,
-                        let ship = HMServerDataStore.default().ship(byId: shipId) {
+                    let shipId = damageObject.shipID
+                    if let ship = HMServerDataStore.default().ship(byId: shipId) {
                         let efectiveHP = damageControlIfPossible(nowhp: newHP, ship: ship)
                         if efectiveHP != 0 && efectiveHP != newHP {
-                            damageObject.useDamageControl = true as NSNumber
+                            damageObject.useDamageControl = true
                         }
                         newHP = efectiveHP
                     }
                 }
-                damageObject.hp = newHP as NSNumber
+                damageObject.hp = newHP
                 
                 #if DAMAGE_CHECK
                     print("Hougeki \(targetPosition + shipOffset) -> \(damage)")
@@ -271,20 +270,19 @@ class HMCalculateDamageCommand: HMJSONCommand {
             if idx == 0 { return }
             
             let damageObject = damages[ idx - 1 + shipOffset]
-            let hp = (damageObject.hp as? Int) ?? 0
-            var newHP = hp - damage
+            var newHP = damageObject.hp - damage
             if newHP <= 0 {
-                if let shipId = damageObject.shipID as? Int,
-                    let ship = HMServerDataStore.default().ship(byId: shipId) {
+                let shipId = damageObject.shipID
+                if let ship = HMServerDataStore.default().ship(byId: shipId) {
                     let efectiveHP = damageControlIfPossible(nowhp: newHP, ship: ship)
                     if efectiveHP != 0 && efectiveHP != newHP {
-                        damageObject.useDamageControl = true as NSNumber
+                        damageObject.useDamageControl = true
                     }
                     newHP = efectiveHP
                 }
-                damageObject.hp = newHP as NSNumber
+                damageObject.hp = newHP
             }
-            damageObject.hp = newHP as NSNumber
+            damageObject.hp = newHP
             
             #if DAMAGE_CHECK
                 print("FDam \(idx + shipOffset) -> \(damage)")
@@ -535,20 +533,16 @@ class HMCalculateDamageCommand: HMJSONCommand {
             else { return print("Damages count is invalid") }
         let aStore = HMServerDataStore.oneTimeEditor()
         totalDamages.forEach {
-            guard let shipId = $0.shipID as? Int,
-                let ship = aStore?.ship(byId: shipId)
+            guard let ship = aStore?.ship(byId: $0.shipID)
                 else { return }
             
             #if DAMAGE_CHECK
-                if let d = $0.hp as? Int,
-                    ship.nowhp != d
-                { print("\(ship.name)(\(ship.id)),HP \(ship.nowhp) -> \(d)") }
+                if ship.nowhp != $0.hp
+                { print("\(ship.name)(\(ship.id)),HP \(ship.nowhp) -> \($0.hp)") }
             #endif
             
-            ship.nowhp = $0.hp as? Int ?? 0
-            if let b = $0.useDamageControl as? Bool, b {
-                removeFirstDamageControl(of: ship)
-            }
+            ship.nowhp = $0.hp
+            if $0.useDamageControl { removeFirstDamageControl(of: ship) }
         }
     }
 }
diff --git a/KCD/HMKCDamage+CoreDataProperties.h b/KCD/HMKCDamage+CoreDataProperties.h
deleted file mode 100644 (file)
index 1c19bf9..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-//
-//  HMKCDamage+CoreDataProperties.h
-//  KCD
-//
-//  Created by Hori,Masaki on 2016/02/09.
-//  Copyright © 2016年 Hori,Masaki. All rights reserved.
-//
-//  Choose "Create NSManagedObject Subclass…" from the Core Data editor menu
-//  to delete and recreate this implementation file for your updated model.
-//
-
-#import "HMKCDamage.h"
-
-NS_ASSUME_NONNULL_BEGIN
-
-@interface HMKCDamage (CoreDataProperties)
-
-@property (nullable, nonatomic, retain) NSNumber *id;
-@property (nullable, nonatomic, retain) HMKCBattle *battle;
-@property (nullable, nonatomic, retain) NSNumber *hp;
-@property (nullable, nonatomic, retain) NSNumber *shipID;
-@property (nullable, nonatomic, retain) NSNumber *useDamageControl;
-
-@end
-
-NS_ASSUME_NONNULL_END
diff --git a/KCD/HMKCDamage+CoreDataProperties.m b/KCD/HMKCDamage+CoreDataProperties.m
deleted file mode 100644 (file)
index 8e248e5..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-//
-//  HMKCDamage+CoreDataProperties.m
-//  KCD
-//
-//  Created by Hori,Masaki on 2016/02/09.
-//  Copyright © 2016年 Hori,Masaki. All rights reserved.
-//
-//  Choose "Create NSManagedObject Subclass…" from the Core Data editor menu
-//  to delete and recreate this implementation file for your updated model.
-//
-
-#import "HMKCDamage+CoreDataProperties.h"
-
-@implementation HMKCDamage (CoreDataProperties)
-
-@dynamic id;
-@dynamic battle;
-@dynamic hp;
-@dynamic shipID;
-@dynamic useDamageControl;
-
-@end
diff --git a/KCD/HMKCDamage.h b/KCD/HMKCDamage.h
deleted file mode 100644 (file)
index e9415ea..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-//
-//  HMKCDamage.h
-//  KCD
-//
-//  Created by Hori,Masaki on 2016/02/09.
-//  Copyright © 2016年 Hori,Masaki. All rights reserved.
-//
-
-#import "HMKCManagedObject.h"
-
-@class HMKCBattle;
-
-NS_ASSUME_NONNULL_BEGIN
-
-@interface HMKCDamage : HMKCManagedObject
-
-// Insert code here to declare functionality of your managed object subclass
-
-@end
-
-NS_ASSUME_NONNULL_END
-
-#import "HMKCDamage+CoreDataProperties.h"
diff --git a/KCD/HMKCDamage.m b/KCD/HMKCDamage.m
deleted file mode 100644 (file)
index 966498a..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-//
-//  HMKCDamage.m
-//  KCD
-//
-//  Created by Hori,Masaki on 2016/02/09.
-//  Copyright © 2016年 Hori,Masaki. All rights reserved.
-//
-
-#import "HMKCDamage.h"
-
-@implementation HMKCDamage
-
-// Insert code here to add functionality to your managed object subclass
-
-@end
diff --git a/KCD/HMKCDamage.swift b/KCD/HMKCDamage.swift
new file mode 100644 (file)
index 0000000..445de48
--- /dev/null
@@ -0,0 +1,17 @@
+//
+//  HMKCDamage.swift
+//  KCD
+//
+//  Created by Hori,Masaki on 2017/02/02.
+//  Copyright © 2017年 Hori,Masaki. All rights reserved.
+//
+
+import Foundation
+
+class HMKCDamage: HMKCManagedObject {
+    @NSManaged var id: Int
+    @NSManaged var battle: HMKCBattle
+    @NSManaged var hp: Int
+    @NSManaged var shipID: Int
+    @NSManaged var useDamageControl: Bool
+}
index 5046966..c561e2f 100644 (file)
@@ -4,20 +4,13 @@
 
 #import "HMAppDelegate.h"
 
-
 // Other
-
 #import "HMJSONReciever.h"
 
-
 // Core Data
 #import "HMCoreDataManager.h"
-
-
-#import "HMKCDamage.h"
 #import "HMKCGuardEscaped.h"
 
-
 //
 #import "TemporaryEnumDefined.h"
 
index f9760ef..ceab6c2 100644 (file)
@@ -9,11 +9,11 @@
         <attribute name="no" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="NO" syncable="YES"/>
         <relationship name="damages" optional="YES" toMany="YES" maxCount="12" deletionRule="Cascade" ordered="YES" destinationEntity="Damage" inverseName="battle" inverseEntity="Damage" syncable="YES"/>
     </entity>
-    <entity name="Damage" representedClassName="HMKCDamage" syncable="YES">
-        <attribute name="hp" optional="YES" attributeType="Integer 64" defaultValueString="0.0" usesScalarValueType="NO" syncable="YES"/>
-        <attribute name="id" optional="YES" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="NO" syncable="YES"/>
-        <attribute name="shipID" optional="YES" attributeType="Integer 64" defaultValueString="0.0" usesScalarValueType="NO" syncable="YES"/>
-        <attribute name="useDamageControl" optional="YES" attributeType="Boolean" usesScalarValueType="NO" syncable="YES"/>
+    <entity name="Damage" representedClassName="KCD.HMKCDamage" syncable="YES">
+        <attribute name="hp" attributeType="Integer 64" defaultValueString="0.0" usesScalarValueType="NO" syncable="YES"/>
+        <attribute name="id" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="NO" syncable="YES"/>
+        <attribute name="shipID" attributeType="Integer 64" defaultValueString="0.0" usesScalarValueType="NO" syncable="YES"/>
+        <attribute name="useDamageControl" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="NO" syncable="YES"/>
         <relationship name="battle" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Battle" inverseName="damages" inverseEntity="Battle" syncable="YES"/>
     </entity>
     <entity name="GuardEscaped" representedClassName="HMKCGuardEscaped" syncable="YES">