From: masakih Date: Sun, 10 Dec 2017 07:26:20 +0000 (+0900) Subject: ShipMapperにslotDepriveの時用のイニシャライザを追加 X-Git-Tag: 1.9b35~7 X-Git-Url: http://git.osdn.net/view?p=kcd%2FKCD.git;a=commitdiff_plain;h=61da9915cbf5655728974da84b62a4508df673c9 ShipMapperにslotDepriveの時用のイニシャライザを追加 --- diff --git a/KCD/ShipMapper.swift b/KCD/ShipMapper.swift index 3a655d3a..bb742313 100644 --- a/KCD/ShipMapper.swift +++ b/KCD/ShipMapper.swift @@ -9,20 +9,17 @@ import Cocoa import SwiftyJSON -extension MappingConfiguration { - - func change(dataKeys: [String]) -> MappingConfiguration { - - return MappingConfiguration(entity: self.entity, - dataKeys: dataKeys, - primaryKeys: self.primaryKeys, - editorStore: self.editorStore, - ignoreKeys: self.ignoreKeys) - } -} - final class ShipMapper: JSONMapper { + private static let ignoreKeys = ["api_gomes", "api_gomes2", "api_broken", "api_powup", + "api_voicef", "api_afterlv", "api_aftershipid", "api_backs", + "api_slotnum", "api_stype", "api_name", "api_yomi", + "api_raig", "api_luck", "api_saku", "api_raim", "api_baku", + "api_taik", "api_houg", "api_houm", "api_tyku", + "api_ndock_item", "api_star", + "api_ndock_time_str", "api_member_id", + "api_fuel_max", "api_bull_max"] + let apiResponse: APIResponse let configuration: MappingConfiguration @@ -32,28 +29,17 @@ final class ShipMapper: JSONMapper { self.configuration = MappingConfiguration(entity: Ship.entity, dataKeys: ShipMapper.dataKeys(apiResponse), editorStore: ServerDataStore.oneTimeEditor(), - ignoreKeys: - ["api_gomes", "api_gomes2", "api_broken", "api_powup", - "api_voicef", "api_afterlv", "api_aftershipid", "api_backs", - "api_slotnum", "api_stype", "api_name", "api_yomi", - "api_raig", "api_luck", "api_saku", "api_raim", "api_baku", - "api_taik", "api_houg", "api_houm", "api_tyku", - "api_ndock_item", "api_star", - "api_ndock_time_str", "api_member_id", - "api_fuel_max", "api_bull_max"]) - - // kaisouSlotDepriveでは同時に2種類のデータが入る - if apiResponse.api.endpoint == .slotDeprive { - - let conf = self.configuration.change(dataKeys: ["api_data", "api_ship_data", "api_unset_ship"]) - ShipMapper(apiResponse, configuration: conf).commit() - } + ignoreKeys: ShipMapper.ignoreKeys) } - private init(_ apiResponse: APIResponse, configuration: MappingConfiguration) { + // slotDepriveの時に2種類のデータが来るため + init(forSlotDepriveUnset apiResponse: APIResponse) { self.apiResponse = apiResponse - self.configuration = configuration + self.configuration = MappingConfiguration(entity: Ship.entity, + dataKeys: ["api_data", "api_ship_data", "api_unset_ship"], + editorStore: ServerDataStore.oneTimeEditor(), + ignoreKeys: ShipMapper.ignoreKeys) } private class func dataKeys(_ apiResponse: APIResponse) -> [String] { diff --git a/KCD/SlotDepriveCommand.swift b/KCD/SlotDepriveCommand.swift index ec60d459..47a1b09e 100644 --- a/KCD/SlotDepriveCommand.swift +++ b/KCD/SlotDepriveCommand.swift @@ -18,5 +18,8 @@ final class SlotDepriveCommand: JSONCommand { override func execute() { ShipMapper(apiResponse).commit() + + // 2種類のデータが来るため + ShipMapper(forSlotDepriveUnset: apiResponse).commit() } }