OSDN Git Service

Localizableを使ってローカライズするように変更
[kcd/KCD.git] / KCD / StoreCreateSlotItemHistoryCommand.swift
1 //
2 //  StoreCreateSlotItemHistoryCommand.swift
3 //  KCD
4 //
5 //  Created by Hori,Masaki on 2017/01/11.
6 //  Copyright © 2017年 Hori,Masaki. All rights reserved.
7 //
8
9 import Cocoa
10 import SwiftyJSON
11
12 final class StoreCreateSlotItemHistoryCommand: JSONCommand {
13     
14     override func execute() {
15         
16         guard let fuel = parameter["api_item1"].int,
17             let bull = parameter["api_item2"].int,
18             let steel = parameter["api_item3"].int,
19             let bauxite = parameter["api_item4"].int else {
20                 
21                 print("Parameter is Wrong")
22                 return
23         }
24         
25         let success = data["api_create_flag"].int ?? 0
26         let name = masterSlotItemName(sccess: success, data: data)
27         let numberOfUsedKaihatuSizai = success != 0 ? 1 : 0
28         
29         let store = ServerDataStore.default
30         
31         guard let flagShip = store.deck(by: 1).map({ $0.ship_0 }).flatMap({ store.ship(by: $0) }) else {
32             
33             print("Flagship is not found")
34             return
35         }
36         
37         guard let basic = store.basic() else { return print("Basic is wrong") }
38         
39         let localStore = LocalDataStore.oneTimeEditor()
40         
41         guard let newHistory = localStore.createKaihatuHistory() else {
42             
43             print("Can not create new KaihatuHistory entry")
44             return
45         }
46         
47         newHistory.name = name
48         newHistory.fuel = fuel
49         newHistory.bull = bull
50         newHistory.steel = steel
51         newHistory.bauxite = bauxite
52         newHistory.kaihatusizai = numberOfUsedKaihatuSizai
53         newHistory.flagShipLv = flagShip.lv
54         newHistory.flagShipName = flagShip.name
55         newHistory.commanderLv = basic.level
56         newHistory.date = Date()
57     }
58     
59     private func masterSlotItemName(sccess: Int, data: JSON) -> String {
60         
61         if sccess == 0 {
62             
63             return LocalizedStrings.failDevelop.string
64             
65         }
66         
67         guard let slotItemId = data["api_slot_item"]["api_slotitem_id"].int else {
68             
69             print("api_slotitem_id is wrong")
70             return ""
71         }
72         
73         return ServerDataStore.default.masterSlotItem(by: slotItemId)?.name ?? ""
74     }
75 }