Refactors cheat usage for non-throwing EmulatorCore.deactivateCheat(_:)
This commit is contained in:
parent
fecb1396d2
commit
b2bf15a79c
@ -1 +1 @@
|
|||||||
Subproject commit a20b36f96e52bc236d243cd8b1b55fc5e1bbf76c
|
Subproject commit d8532bd184a9a1e87b48ad5ad9f4a6d24d81783f
|
||||||
@ -1 +1 @@
|
|||||||
Subproject commit cac97f68eea3eb85471a16b468ae8da6fa1038e6
|
Subproject commit 58dce561dd80baf954f487fc8fa15aae998559a6
|
||||||
@ -347,9 +347,9 @@ extension EmulationViewController: CheatsViewControllerDelegate
|
|||||||
try self.emulatorCore.activateCheat(cheat)
|
try self.emulatorCore.activateCheat(cheat)
|
||||||
}
|
}
|
||||||
|
|
||||||
func cheatsViewController(cheatsViewController: CheatsViewController, didDeactivateCheat cheat: Cheat) throws
|
func cheatsViewController(cheatsViewController: CheatsViewController, didDeactivateCheat cheat: Cheat)
|
||||||
{
|
{
|
||||||
try self.emulatorCore.deactivateCheat(cheat)
|
self.emulatorCore.deactivateCheat(cheat)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func updateCheats()
|
private func updateCheats()
|
||||||
@ -369,33 +369,28 @@ extension EmulationViewController: CheatsViewControllerDelegate
|
|||||||
|
|
||||||
let cheats = Cheat.instancesWithPredicate(predicate, inManagedObjectContext: backgroundContext, type: Cheat.self)
|
let cheats = Cheat.instancesWithPredicate(predicate, inManagedObjectContext: backgroundContext, type: Cheat.self)
|
||||||
for cheat in cheats
|
for cheat in cheats
|
||||||
{
|
|
||||||
do
|
|
||||||
{
|
{
|
||||||
if cheat.enabled
|
if cheat.enabled
|
||||||
{
|
{
|
||||||
try self.emulatorCore.activateCheat(cheat)
|
do
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
try self.emulatorCore.deactivateCheat(cheat)
|
try self.emulatorCore.activateCheat(cheat)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch EmulatorCore.CheatError.invalid
|
catch EmulatorCore.CheatError.invalid
|
||||||
{
|
{
|
||||||
print("Invalid cheat:", cheat.name, cheat.code)
|
print("Invalid cheat:", cheat.name, cheat.code)
|
||||||
}
|
}
|
||||||
catch EmulatorCore.CheatError.doesNotExist
|
|
||||||
{
|
|
||||||
// Ignore this error, because we could be deactivating a cheat that hasn't yet been activated
|
|
||||||
print("Cheat does not exist:", cheat.name, cheat.code)
|
|
||||||
}
|
|
||||||
catch let error as NSError
|
catch let error as NSError
|
||||||
{
|
{
|
||||||
print("Unknown Cheat Error:", error, cheat.name, cheat.code)
|
print("Unknown Cheat Error:", error, cheat.name, cheat.code)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
self.emulatorCore.deactivateCheat(cheat)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if running
|
if running
|
||||||
{
|
{
|
||||||
|
|||||||
@ -17,7 +17,7 @@ protocol CheatsViewControllerDelegate: class
|
|||||||
{
|
{
|
||||||
func cheatsViewControllerActiveEmulatorCore(saveStatesViewController: CheatsViewController) -> EmulatorCore
|
func cheatsViewControllerActiveEmulatorCore(saveStatesViewController: CheatsViewController) -> EmulatorCore
|
||||||
func cheatsViewController(cheatsViewController: CheatsViewController, didActivateCheat cheat: Cheat) throws
|
func cheatsViewController(cheatsViewController: CheatsViewController, didActivateCheat cheat: Cheat) throws
|
||||||
func cheatsViewController(cheatsViewController: CheatsViewController, didDeactivateCheat cheat: Cheat) throws
|
func cheatsViewController(cheatsViewController: CheatsViewController, didDeactivateCheat cheat: Cheat)
|
||||||
}
|
}
|
||||||
|
|
||||||
class CheatsViewController: UITableViewController
|
class CheatsViewController: UITableViewController
|
||||||
@ -121,7 +121,7 @@ private extension CheatsViewController
|
|||||||
|
|
||||||
func deleteCheat(cheat: Cheat)
|
func deleteCheat(cheat: Cheat)
|
||||||
{
|
{
|
||||||
let _ = try? self.delegate.cheatsViewController(self, didDeactivateCheat: cheat)
|
self.delegate.cheatsViewController(self, didDeactivateCheat: cheat)
|
||||||
|
|
||||||
let backgroundContext = DatabaseManager.sharedManager.backgroundManagedObjectContext()
|
let backgroundContext = DatabaseManager.sharedManager.backgroundManagedObjectContext()
|
||||||
backgroundContext.performBlock {
|
backgroundContext.performBlock {
|
||||||
@ -191,29 +191,26 @@ extension CheatsViewController
|
|||||||
let temporaryCheat = backgroundContext.objectWithID(cheat.objectID) as! Cheat
|
let temporaryCheat = backgroundContext.objectWithID(cheat.objectID) as! Cheat
|
||||||
temporaryCheat.enabled = !temporaryCheat.enabled
|
temporaryCheat.enabled = !temporaryCheat.enabled
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
if temporaryCheat.enabled
|
if temporaryCheat.enabled
|
||||||
{
|
{
|
||||||
try self.delegate.cheatsViewController(self, didActivateCheat: temporaryCheat)
|
do
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
try self.delegate.cheatsViewController(self, didDeactivateCheat: temporaryCheat)
|
try self.delegate.cheatsViewController(self, didActivateCheat: temporaryCheat)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch EmulatorCore.CheatError.invalid
|
catch EmulatorCore.CheatError.invalid
|
||||||
{
|
{
|
||||||
print("Invalid cheat:", cheat.name, cheat.code)
|
print("Invalid cheat:", cheat.name, cheat.code)
|
||||||
}
|
}
|
||||||
catch EmulatorCore.CheatError.doesNotExist
|
|
||||||
{
|
|
||||||
print("Cheat does not exist:", cheat.name, cheat.code)
|
|
||||||
}
|
|
||||||
catch let error as NSError
|
catch let error as NSError
|
||||||
{
|
{
|
||||||
print("Unknown Cheat Error:", error, cheat.name, cheat.code)
|
print("Unknown Cheat Error:", error, cheat.name, cheat.code)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
self.delegate.cheatsViewController(self, didDeactivateCheat: temporaryCheat)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
backgroundContext.saveWithErrorLogging()
|
backgroundContext.saveWithErrorLogging()
|
||||||
}
|
}
|
||||||
@ -281,22 +278,14 @@ extension CheatsViewController: EditCheatViewControllerDelegate
|
|||||||
|
|
||||||
guard previousCheat.code != code else { return }
|
guard previousCheat.code != code else { return }
|
||||||
|
|
||||||
do
|
self.delegate.cheatsViewController(self, didDeactivateCheat: previousCheat)
|
||||||
{
|
|
||||||
try self.delegate.cheatsViewController(self, didDeactivateCheat: previousCheat)
|
|
||||||
}
|
|
||||||
catch let error as NSError
|
|
||||||
{
|
|
||||||
print(error)
|
|
||||||
}
|
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func editCheatViewController(editCheatViewController: EditCheatViewController, deactivateCheat cheat: Cheat)
|
func editCheatViewController(editCheatViewController: EditCheatViewController, deactivateCheat cheat: Cheat)
|
||||||
{
|
{
|
||||||
let _ = try? self.delegate.cheatsViewController(self, didDeactivateCheat: cheat)
|
self.delegate.cheatsViewController(self, didDeactivateCheat: cheat)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user