OSDN Git Service

バージョンを1.9b33に更新
[kcd/KCD.git] / KCD / SetActionCommand.swift
1 //
2 //  SetActionCommand.swift
3 //  KCD
4 //
5 //  Created by Hori,Masaki on 2017/01/14.
6 //  Copyright © 2017年 Hori,Masaki. All rights reserved.
7 //
8
9 import Cocoa
10
11 final class SetActionCommand: JSONCommand {
12     
13     override class func canExecuteAPI(_ api: String) -> Bool {
14         
15         if api == "/kcsapi/api_req_air_corps/set_action" { return true }
16         
17         return false
18     }
19     
20     override func execute() {
21         
22         guard let areaId = parameter["api_area_id"].int else {
23             
24             return Logger.shared.log("api_area_id is wrong.")
25         }
26         guard let rIds = parameter["api_base_id"]
27             .string?
28             .components(separatedBy: ",")
29             .map({ Int($0) ?? -1 }) else {
30                 
31                 return Logger.shared.log("api_base_id is wrong.")
32         }
33         guard let actions = parameter["api_action_kind"]
34             .string?
35             .components(separatedBy: ",")
36             .map({ Int($0) ?? -1 }) else {
37                 
38                 return Logger.shared.log("api_action_kind is rwong")
39         }
40         
41         if rIds.count != actions.count { print("missmatch count") }
42         
43         let store = ServerDataStore.oneTimeEditor()
44         
45         zip(rIds, actions).forEach { (rId, action) in
46             
47             store.airBase(area: areaId, base: rId)?.action_kind = action
48         }
49     }
50 }