Refactors LaunchViewController into RSTLaunchViewController subclass
This commit is contained in:
parent
c1cfdad0a7
commit
4c913d5be0
@ -36,11 +36,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate
|
||||
gestureRecognizer.delaysTouchesBegan = false
|
||||
}
|
||||
|
||||
// Database
|
||||
DatabaseManager.shared.start { (error) in
|
||||
print("Database started with error:", error as Any)
|
||||
}
|
||||
|
||||
// Controllers
|
||||
ExternalGameControllerManager.shared.startMonitoring()
|
||||
|
||||
|
||||
@ -74,6 +74,8 @@ final class DatabaseManager: RSTPersistentContainer
|
||||
else { fatalError("Core Data model cannot be found. Aborting.") }
|
||||
|
||||
super.init(name: "Delta", managedObjectModel: harmonyModel)
|
||||
|
||||
self.shouldAddStoresAsynchronously = true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
import UIKit
|
||||
import Roxas
|
||||
|
||||
class LaunchViewController: UIViewController
|
||||
class LaunchViewController: RSTLaunchViewController
|
||||
{
|
||||
@IBOutlet private var gameViewContainerView: UIView!
|
||||
private var gameViewController: GameViewController!
|
||||
@ -37,40 +37,6 @@ class LaunchViewController: UIViewController
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(LaunchViewController.deepLinkControllerLaunchGame(with:)), name: .deepLinkControllerLaunchGame, object: nil)
|
||||
}
|
||||
|
||||
override func viewDidAppear(_ animated: Bool)
|
||||
{
|
||||
super.viewDidAppear(animated)
|
||||
|
||||
if !self.presentedGameViewController
|
||||
{
|
||||
self.presentedGameViewController = true
|
||||
|
||||
func showGameViewController()
|
||||
{
|
||||
self.view.bringSubviewToFront(self.gameViewContainerView)
|
||||
|
||||
self.setNeedsStatusBarAppearanceUpdate()
|
||||
self.setNeedsUpdateOfHomeIndicatorAutoHidden()
|
||||
}
|
||||
|
||||
if let game = self.applicationLaunchDeepLinkGame
|
||||
{
|
||||
self.gameViewController.game = game
|
||||
|
||||
UIView.transition(with: self.view, duration: 0.3, options: [.transitionCrossDissolve], animations: {
|
||||
showGameViewController()
|
||||
}, completion: nil)
|
||||
}
|
||||
else
|
||||
{
|
||||
self.gameViewController.performSegue(withIdentifier: "showInitialGamesViewController", sender: nil)
|
||||
self.transitionCoordinator?.animate(alongsideTransition: nil, completion: { (context) in
|
||||
showGameViewController()
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override func prepare(for segue: UIStoryboardSegue, sender: Any?)
|
||||
{
|
||||
guard segue.identifier == "embedGameViewController" else { return }
|
||||
@ -79,6 +45,59 @@ class LaunchViewController: UIViewController
|
||||
}
|
||||
}
|
||||
|
||||
extension LaunchViewController
|
||||
{
|
||||
override var launchConditions: [RSTLaunchCondition] {
|
||||
let isDatabaseManagerStarted = RSTLaunchCondition(condition: { DatabaseManager.shared.isStarted }) { (completionHandler) in
|
||||
DatabaseManager.shared.start(completionHandler: completionHandler)
|
||||
}
|
||||
|
||||
return [isDatabaseManagerStarted, isDatabaseManagerStarted]
|
||||
}
|
||||
|
||||
override func handleLaunchError(_ error: Error)
|
||||
{
|
||||
let alertController = UIAlertController(title: NSLocalizedString("Unable to Launch Delta", comment: ""), message: error.localizedDescription, preferredStyle: .alert)
|
||||
alertController.addAction(UIAlertAction(title: NSLocalizedString("Retry", comment: ""), style: .default, handler: { (action) in
|
||||
self.handleLaunchConditions()
|
||||
}))
|
||||
self.present(alertController, animated: true, completion: nil)
|
||||
}
|
||||
|
||||
override func finishLaunching()
|
||||
{
|
||||
super.finishLaunching()
|
||||
|
||||
guard !self.presentedGameViewController else { return }
|
||||
|
||||
self.presentedGameViewController = true
|
||||
|
||||
func showGameViewController()
|
||||
{
|
||||
self.view.bringSubviewToFront(self.gameViewContainerView)
|
||||
|
||||
self.setNeedsStatusBarAppearanceUpdate()
|
||||
self.setNeedsUpdateOfHomeIndicatorAutoHidden()
|
||||
}
|
||||
|
||||
if let game = self.applicationLaunchDeepLinkGame
|
||||
{
|
||||
self.gameViewController.game = game
|
||||
|
||||
UIView.transition(with: self.view, duration: 0.3, options: [.transitionCrossDissolve], animations: {
|
||||
showGameViewController()
|
||||
}, completion: nil)
|
||||
}
|
||||
else
|
||||
{
|
||||
self.gameViewController.performSegue(withIdentifier: "showInitialGamesViewController", sender: nil)
|
||||
self.transitionCoordinator?.animate(alongsideTransition: nil, completion: { (context) in
|
||||
showGameViewController()
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private extension LaunchViewController
|
||||
{
|
||||
@objc func deepLinkControllerLaunchGame(with notification: Notification)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user