Displays preview save state image even if context menu previews are disabled

This commit is contained in:
Riley Testut 2021-01-11 15:57:54 -06:00
parent 0ad0e752f8
commit 1b874ce9c1
3 changed files with 49 additions and 11 deletions

@ -1 +1 @@
Subproject commit a07abad3214a310785055eddf86bed36ae7612ca
Subproject commit 135b0532a3b17e0a970e23bdc81bf80595ed81b2

View File

@ -27,6 +27,8 @@ class PreviewGameViewController: DeltaCore.GameViewController
}
}
var isLivePreview: Bool = true
private var emulatorCoreQueue = DispatchQueue(label: "com.rileytestut.Delta.PreviewGameViewController.emulatorCoreQueue", qos: .userInitiated)
private var copiedSaveFiles = [(originalURL: URL, copyURL: URL)]()
@ -58,6 +60,20 @@ class PreviewGameViewController: DeltaCore.GameViewController
return previewActionItems
}
public required init()
{
super.init()
self.delegate = self
}
public required init?(coder aDecoder: NSCoder)
{
super.init(coder: aDecoder)
self.delegate = self
}
deinit
{
// Explicitly stop emulatorCore _before_ we remove ourselves as observer
@ -77,6 +93,7 @@ extension PreviewGameViewController
super.viewDidLoad()
self.controllerView.isHidden = true
self.controllerView.controllerSkin = nil // Skip loading controller skin from disk, which may be slow.
// Temporarily prevent emulatorCore from updating gameView to prevent flicker of black, or other visual glitches
self.emulatorCore?.remove(self.gameView)
@ -94,7 +111,7 @@ extension PreviewGameViewController
super.viewDidAppear(animated)
self.emulatorCoreQueue.async {
self.emulatorCore?.start()
self.startEmulation()
}
}
@ -264,3 +281,11 @@ private extension PreviewGameViewController
}
}
}
extension PreviewGameViewController: GameViewControllerDelegate
{
func gameViewControllerShouldResumeEmulation(_ gameViewController: DeltaCore.GameViewController) -> Bool
{
return self.isLivePreview
}
}

View File

@ -821,9 +821,16 @@ extension GameCollectionViewController: UIViewControllerPreviewingDelegate
gameViewController.pauseEmulation()
let indexPath = self.dataSource.fetchedResultsController.indexPath(forObject: game)!
let fileURL = FileManager.default.uniqueTemporaryURL()
self.activeSaveState = gameViewController.emulatorCore?.saveSaveState(to: fileURL)
if gameViewController.isLivePreview
{
self.activeSaveState = gameViewController.emulatorCore?.saveSaveState(to: fileURL)
}
else
{
self.activeSaveState = gameViewController.previewSaveState
}
gameViewController.emulatorCore?.stop()
@ -831,13 +838,16 @@ extension GameCollectionViewController: UIViewControllerPreviewingDelegate
self.launchGame(at: indexPath, clearScreen: true, ignoreAlreadyRunningError: true)
do
if gameViewController.isLivePreview
{
try FileManager.default.removeItem(at: fileURL)
}
catch
{
print(error)
do
{
try FileManager.default.removeItem(at: fileURL)
}
catch
{
print(error)
}
}
}
}
@ -926,9 +936,12 @@ extension GameCollectionViewController
let actions = self.actions(for: game)
return UIContextMenuConfiguration(identifier: indexPath as NSIndexPath, previewProvider: { [weak self] in
guard let self = self, Settings.isPreviewsEnabled else { return nil }
guard let self = self else { return nil }
let previewViewController = self.makePreviewGameViewController(for: game)
previewViewController.isLivePreview = Settings.isPreviewsEnabled
guard previewViewController.isLivePreview || previewViewController.previewSaveState != nil else { return nil }
self._previewTransitionViewController = previewViewController
return previewViewController