OSDN Git Service

integerArrayプロパティを使用するようにした
authormasakih <masakih@users.sourceforge.jp>
Mon, 11 Dec 2017 15:30:30 +0000 (00:30 +0900)
committermasakih <masakih@users.sourceforge.jp>
Mon, 11 Dec 2017 15:30:30 +0000 (00:30 +0900)
KCD/AirCorpsSupplyCommand.swift
KCD/DestroyItem2Command.swift
KCD/RealDestroyShipCommand.swift
KCD/RealPowerUpCommand.swift
KCD/SetActionCommand.swift

index 072d2dc..db02726 100644 (file)
@@ -21,28 +21,27 @@ final class AirCorpsSupplyCommand: JSONCommand {
         
         guard let areaId = parameter["api_area_id"].int else { return }
         guard let rId = parameter["api_base_id"].int else { return }
-        guard let squadronIdsString = parameter["api_squadron_id"].string else { return }
         guard let airBase = store.airBase(area: areaId, base: rId) else { return }
         
         let planeInfos = data["api_plane_info"]
         let planes = airBase.planeInfo
-        let squadronIds = squadronIdsString
-            .components(separatedBy: ",")
-            .flatMap { Int($0) }
-        
-        squadronIds.enumerated().forEach {
-            
-            guard planes.count >= $0.element else { return }
-            guard planeInfos.count > $0.offset else { return }
-            guard let plane = planes[$0.element - 1] as? AirBasePlaneInfo else { return }
-            
-            let planeInfo = planeInfos[$0.offset]
-            
-            if let v = planeInfo["api_cond"].int { plane.cond = v }
-            if let v = planeInfo["api_slotid"].int { plane.slotid = v }
-            if let v = planeInfo["api_state"].int { plane.state = v }
-            if let v = planeInfo["api_count"].int { plane.count = v }
-            if let v = planeInfo["api_max_count"].int { plane.max_count = v }
+        
+        parameter["api_squadron_id"]
+            .integerArray
+            .enumerated()
+            .forEach {
+                
+                guard planes.count >= $0.element else { return }
+                guard planeInfos.count > $0.offset else { return }
+                guard let plane = planes[$0.element - 1] as? AirBasePlaneInfo else { return }
+                
+                let planeInfo = planeInfos[$0.offset]
+                
+                if let v = planeInfo["api_cond"].int { plane.cond = v }
+                if let v = planeInfo["api_slotid"].int { plane.slotid = v }
+                if let v = planeInfo["api_state"].int { plane.state = v }
+                if let v = planeInfo["api_count"].int { plane.count = v }
+                if let v = planeInfo["api_max_count"].int { plane.max_count = v }
         }
         
         if let v = data["api_distance"].int { airBase.distance = v }
index 8ae214b..4a0c3ad 100644 (file)
@@ -17,17 +17,9 @@ final class DestroyItem2Command: JSONCommand {
     
     override func execute() {
         
-        guard let itemIds = parameter["api_slotitem_ids"]
-            .string?
-            .components(separatedBy: ",")
-            .flatMap({ Int($0) }) else {
-                
-                return Logger.shared.log("api_slotitem_ids is wrong")
-        }
-        
         let store = ServerDataStore.oneTimeEditor()
         
-        store.slotItems(in: itemIds).forEach(store.delete)
+        store.slotItems(in: parameter["api_slotitem_ids"].integerArray).forEach(store.delete)
         
         guard let material = store.material() else {
             
index 1b28580..530346f 100644 (file)
@@ -15,8 +15,7 @@ final class RealDestroyShipCommand: JSONCommand {
         let store = ServerDataStore.oneTimeEditor()
         
         let ships = parameter["api_ship_id"]
-            .array
-            .flatMap { $0.int }
+            .integerArray
             .flatMap(store.ship(by:))
         
         if parameter["api_slot_dest_flag"].int == 0 {
index 29f099b..7e0fa82 100644 (file)
@@ -15,9 +15,7 @@ final class RealPowerUpCommand: JSONCommand {
         let store = ServerDataStore.oneTimeEditor()
         
         parameter["api_id_items"]
-            .string?
-            .components(separatedBy: ",")
-            .flatMap { Int($0) }
+            .integerArray
             .flatMap(store.ship(by:))
             .forEach(store.delete)
     }
index 7e874ae..a9d4989 100644 (file)
@@ -21,21 +21,9 @@ final class SetActionCommand: JSONCommand {
             
             return Logger.shared.log("api_area_id is wrong.")
         }
-        guard let rIds = parameter["api_base_id"]
-            .string?
-            .components(separatedBy: ",")
-            .map({ Int($0) ?? -1 }) else {
-                
-                return Logger.shared.log("api_base_id is wrong.")
-        }
-        guard let actions = parameter["api_action_kind"]
-            .string?
-            .components(separatedBy: ",")
-            .map({ Int($0) ?? -1 }) else {
-                
-                return Logger.shared.log("api_action_kind is rwong")
-        }
         
+        let rIds = parameter["api_base_id"].integerArray
+        let actions = parameter["api_action_kind"].integerArray
         if rIds.count != actions.count { print("missmatch count") }
         
         let store = ServerDataStore.oneTimeEditor()