diff --git a/Common/Database/Model/Model.xcdatamodeld/Model.xcdatamodel/contents b/Common/Database/Model/Model.xcdatamodeld/Model.xcdatamodel/contents index 430ddf7..3c28812 100644 --- a/Common/Database/Model/Model.xcdatamodeld/Model.xcdatamodel/contents +++ b/Common/Database/Model/Model.xcdatamodeld/Model.xcdatamodel/contents @@ -1,5 +1,5 @@ - + @@ -40,6 +40,7 @@ + @@ -53,6 +54,6 @@ - + \ No newline at end of file diff --git a/Common/Database/Model/SaveState.swift b/Common/Database/Model/SaveState.swift index b1fdf53..35b40da 100644 --- a/Common/Database/Model/SaveState.swift +++ b/Common/Database/Model/SaveState.swift @@ -17,6 +17,7 @@ extension SaveState { case filename case identifier + case isPreview case name case creationDate case modifiedDate @@ -39,6 +40,7 @@ class SaveState: NSManagedObject, SaveStateType @NSManaged var name: String? @NSManaged var modifiedDate: NSDate @NSManaged var type: Type + @NSManaged var isPreview: Bool @NSManaged private(set) var filename: String @NSManaged private(set) var identifier: String diff --git a/Delta/Base.lproj/Main.storyboard b/Delta/Base.lproj/Main.storyboard index 72af4c2..b3a4500 100644 --- a/Delta/Base.lproj/Main.storyboard +++ b/Delta/Base.lproj/Main.storyboard @@ -1,7 +1,7 @@ - + - + @@ -75,7 +75,7 @@ - + @@ -210,6 +210,6 @@ - + diff --git a/Delta/Emulation/EmulationViewController.swift b/Delta/Emulation/EmulationViewController.swift index e4dfb2a..3d81d94 100644 --- a/Delta/Emulation/EmulationViewController.swift +++ b/Delta/Emulation/EmulationViewController.swift @@ -104,6 +104,7 @@ class EmulationViewController: UIViewController super.viewDidAppear(animated) self.deferredPreparationHandler?() + self.deferredPreparationHandler = nil switch self.emulatorCore.state { diff --git a/Delta/Game Selection/GamesViewController.swift b/Delta/Game Selection/GamesViewController.swift index b86bb8a..ed19235 100644 --- a/Delta/Game Selection/GamesViewController.swift +++ b/Delta/Game Selection/GamesViewController.swift @@ -125,6 +125,21 @@ class GamesViewController: UIViewController let game = sourceViewController.dataSource.fetchedResultsController.objectAtIndexPath(indexPath!) as! Game destinationViewController.game = game + + if segue.identifier == "peekEmulationViewController" + { + destinationViewController.deferredPreparationHandler = { [unowned destinationViewController] in + + let predicate = NSPredicate(format: "%K == %@ AND %K == YES", SaveState.Attributes.game.rawValue, game, SaveState.Attributes.isPreview.rawValue) + + if let saveState = SaveState.instancesWithPredicate(predicate, inManagedObjectContext: DatabaseManager.sharedManager.managedObjectContext, type: SaveState.self).first + { + destinationViewController.emulatorCore.startEmulation() + destinationViewController.emulatorCore.pauseEmulation() + destinationViewController.emulatorCore.loadSaveState(saveState) + } + } + } } @IBAction func unwindFromSettingsViewController(segue: UIStoryboardSegue) diff --git a/Delta/Pause Menu/Save States/SaveStatesViewController.swift b/Delta/Pause Menu/Save States/SaveStatesViewController.swift index 9f048e4..9895cd1 100644 --- a/Delta/Pause Menu/Save States/SaveStatesViewController.swift +++ b/Delta/Pause Menu/Save States/SaveStatesViewController.swift @@ -253,6 +253,23 @@ private extension SaveStatesViewController self.renameSaveState(saveState) })) + if self.traitCollection.forceTouchCapability == .Available + { + if !saveState.isPreview + { + alertController.addAction(UIAlertAction(title: NSLocalizedString("Set as Preview Save State", comment: ""), style: .Default, handler: { action in + self.updatePreviewSaveState(saveState) + })) + } + else + { + alertController.addAction(UIAlertAction(title: NSLocalizedString("Remove as Preview Save State", comment: ""), style: .Default, handler: { action in + self.updatePreviewSaveState(nil) + })) + } + } + + let section = self.correctedSectionForSectionIndex(indexPath.section) switch section { @@ -302,7 +319,7 @@ private extension SaveStatesViewController func deleteSaveState(saveState: SaveState) { - let confirmationAlertController = UIAlertController(title: NSLocalizedString("Confirm Deletion", comment: ""), message: NSLocalizedString("Are you sure you want to delete this save state? This cannot be undone.", comment: ""), preferredStyle: .Alert) + let confirmationAlertController = UIAlertController(title: NSLocalizedString("Delete Save State?", comment: ""), message: NSLocalizedString("Are you sure you want to delete this save state? This cannot be undone.", comment: ""), preferredStyle: .Alert) confirmationAlertController.addAction(UIAlertAction(title: NSLocalizedString("Delete", comment: ""), style: .Default, handler: { action in let backgroundContext = DatabaseManager.sharedManager.backgroundManagedObjectContext() @@ -363,6 +380,37 @@ private extension SaveStatesViewController self.selectedSaveState = nil } + func updatePreviewSaveState(saveState: SaveState?) + { + let alertController = UIAlertController(title: NSLocalizedString("Change Preview Save State?", comment: ""), message: NSLocalizedString("The Preview Save State is loaded whenever you preview this game from the Main Menu with 3D Touch. Are you sure you want to change it?", comment: ""), preferredStyle: .Alert) + alertController.addAction(UIAlertAction(title: NSLocalizedString("Cancel", comment: ""), style: .Cancel, handler: nil)) + alertController.addAction(UIAlertAction(title: NSLocalizedString("Change", comment: ""), style: .Default, handler: { (action) in + + let backgroundContext = DatabaseManager.sharedManager.backgroundManagedObjectContext() + backgroundContext.performBlock { + + var game = self.delegate.saveStatesViewControllerActiveEmulatorCore(self).game as! Game + game = backgroundContext.objectWithID(game.objectID) as! Game + + let predicate = NSPredicate(format: "%K == %@ AND %K == YES", SaveState.Attributes.game.rawValue, game, SaveState.Attributes.isPreview.rawValue) + + let previousPreviewSaveState = SaveState.instancesWithPredicate(predicate, inManagedObjectContext: backgroundContext, type: SaveState.self).first + previousPreviewSaveState?.isPreview = false + + if let saveState = saveState + { + let previewSaveState = backgroundContext.objectWithID(saveState.objectID) as! SaveState + previewSaveState.isPreview = true + } + + backgroundContext.saveWithErrorLogging() + } + + })) + + self.presentViewController(alertController, animated: true, completion: nil) + } + func lockSaveState(saveState: SaveState) { let backgroundContext = DatabaseManager.sharedManager.backgroundManagedObjectContext()