Adds coreID to SaveState’s Harmony metadata for backwards compatibility

This commit is contained in:
Riley Testut 2020-04-27 13:03:28 -07:00
parent f0d245ef8d
commit e11e4437c5
2 changed files with 17 additions and 5 deletions

View File

@ -134,7 +134,7 @@ extension SaveState: Syncable
public var syncableMetadata: [HarmonyMetadataKey : String] { public var syncableMetadata: [HarmonyMetadataKey : String] {
guard let game = self.game else { return [:] } guard let game = self.game else { return [:] }
return [.gameID: game.identifier, .gameName: game.name] return [.gameID: game.identifier, .gameName: game.name, .coreID: self.coreIdentifier].compactMapValues { $0 }
} }
public var syncableLocalizedName: String? { public var syncableLocalizedName: String? {
@ -145,11 +145,20 @@ extension SaveState: Syncable
{ {
guard self.coreIdentifier == nil else { return } guard self.coreIdentifier == nil else { return }
guard let game = self.game, let system = System(gameType: game.type) else { return } guard let game = self.game, let system = System(gameType: game.type) else { return }
switch system if let coreIdentifier = record.remoteMetadata?[.coreID]
{ {
case .ds: self.coreIdentifier = DS.core.identifier // Assume DS save state with nil coreIdentifier is from DeSmuME core. // SaveState was synced to older version of Delta and lost its coreIdentifier,
default: self.coreIdentifier = system.deltaCore.identifier // but it remains in the remote metadata so we can reassign it.
self.coreIdentifier = coreIdentifier
}
else
{
switch system
{
case .ds: self.coreIdentifier = DS.core.identifier // Assume DS save state with nil coreIdentifier is from DeSmuME core.
default: self.coreIdentifier = system.deltaCore.identifier
}
} }
} }
} }

View File

@ -12,4 +12,7 @@ extension HarmonyMetadataKey
{ {
static let gameID = HarmonyMetadataKey("gameID") static let gameID = HarmonyMetadataKey("gameID")
static let gameName = HarmonyMetadataKey("gameName") static let gameName = HarmonyMetadataKey("gameName")
// Backwards compatibility
static let coreID = HarmonyMetadataKey("coreID")
} }