Skip to content

Commit

Permalink
Update game to pause when app inactive on singleplayer and concede wh…
Browse files Browse the repository at this point in the history
…en multiplayer
  • Loading branch information
zheng-ze committed Apr 21, 2024
1 parent 34e5e96 commit 4653b95
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
10 changes: 10 additions & 0 deletions TowerForge/TowerForge/AppMain/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// Games should use this method to pause the game.

/// TODO: ADD PAUSE METHOD HERE
guard let navigationController = window?.rootViewController as? UINavigationController,
let gameViewController = navigationController.topViewController as? GameViewController else {
return
}

if gameViewController.roomId != nil {
gameViewController.onMenu()
} else {
gameViewController.pause()
}
}

func applicationDidEnterBackground(_ application: UIApplication) {
Expand Down
8 changes: 6 additions & 2 deletions TowerForge/TowerForge/GameViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ class GameViewController: UIViewController {

@IBOutlet private var gamePopupButton: UIButton!
@IBAction private func onStatePressed(_ sender: Any) {
isPaused = (roomId == nil && currentPlayer == nil) // Allow pausing only on singleplayer.
gameWorld?.presentStatePopup()
self.pause()
}

override func viewDidLoad() {
Expand Down Expand Up @@ -64,6 +63,11 @@ class GameViewController: UIViewController {
self.gameWorld?.delegate = self
self.gameWorld?.statePopupDelegate = self
}

func pause() {
isPaused = (roomId == nil && currentPlayer == nil) // Allow pausing only on singleplayer.
gameWorld?.presentStatePopup()
}
}

extension GameViewController: SceneUpdateDelegate {
Expand Down

0 comments on commit 4653b95

Please sign in to comment.