OSDN Git Service

guard の書き方を統一した
[kcd/KCD.git] / KCD / ApplySuppliesCommand.swift
1 //
2 //  ApplySuppliesCommand.swift
3 //  KCD
4 //
5 //  Created by Hori,Masaki on 2017/01/08.
6 //  Copyright © 2017年 Hori,Masaki. All rights reserved.
7 //
8
9 import Cocoa
10
11 final class ApplySuppliesCommand: JSONCommand {
12     
13     override func execute() {
14         
15         let store = ServerDataStore.oneTimeEditor()
16         
17         data["api_ship"]
18             .forEach { (_, json) in
19                 
20                 guard let i = json["api_id"].int else { return }
21                 guard let ship = store.ship(by: i) else { return }
22                 guard let bull = json["api_bull"].int else { return }
23                 guard let fuel = json["api_fuel"].int else { return }
24                 guard let slots = json["api_onslot"].arrayObject as? [Int] else { return }
25                 guard slots.count > 4 else { return }
26                 
27                 ship.bull = bull
28                 ship.fuel = fuel
29                 ship.onslot_0 = slots[0]
30                 ship.onslot_1 = slots[1]
31                 ship.onslot_2 = slots[2]
32                 ship.onslot_3 = slots[3]
33                 ship.onslot_4 = slots[4]
34         }
35     }
36 }