OSDN Git Service

staticプロパティをインスタンスプロパティに変更
[kcd/KCD.git] / KCD / ApplySuppliesCommand.swift
index fce3dbd..d241816 100644 (file)
@@ -8,25 +8,50 @@
 
 import Cocoa
 
-class ApplySuppliesCommand: JSONCommand {
+final class ApplySuppliesCommand: JSONCommand {
+    
     override func execute() {
+        
         let store = ServerDataStore.oneTimeEditor()
+        
         data["api_ship"]
-            .forEach { (_, json) in
-                guard let i = json["api_id"].int,
-                    let ship = store.ship(byId: i),
-                    let bull = json["api_bull"].int,
-                    let fuel = json["api_fuel"].int,
-                    let slots = json["api_onslot"].arrayObject as? [Int],
-                    slots.count > 4
-                    else { return }
-                ship.bull = bull
-                ship.fuel = fuel
-                ship.onslot_0 = slots[0]
-                ship.onslot_1 = slots[1]
-                ship.onslot_2 = slots[2]
-                ship.onslot_3 = slots[3]
-                ship.onslot_4 = slots[4]
+            .forEach { _, json in
+                
+                guard let i = json["api_id"].int else {
+                    
+                    return
+                }
+                guard let ship = store.sync(execute: { store.ship(by: i) }) else {
+                    
+                    return
+                }
+                guard let bull = json["api_bull"].int else {
+                    
+                    return
+                }
+                guard let fuel = json["api_fuel"].int else {
+                    
+                    return
+                }
+                guard let slots = json["api_onslot"].arrayObject as? [Int] else {
+                    
+                    return
+                }
+                guard slots.count > 4 else {
+                    
+                    return
+                }
+                
+                store.sync {
+                    
+                    ship.bull = bull
+                    ship.fuel = fuel
+                    ship.onslot_0 = slots[0]
+                    ship.onslot_1 = slots[1]
+                    ship.onslot_2 = slots[2]
+                    ship.onslot_3 = slots[3]
+                    ship.onslot_4 = slots[4]
+                }
         }
     }
 }