Skip to content

Commit

Permalink
Adapt all storyboards for all iPads + fix bug where multiplayer was b…
Browse files Browse the repository at this point in the history
…roken
  • Loading branch information
zheng-ze committed Apr 9, 2024
1 parent 91ec626 commit 21a6ca9
Show file tree
Hide file tree
Showing 11 changed files with 617 additions and 309 deletions.
827 changes: 576 additions & 251 deletions TowerForge/TowerForge/AppMain/Storyboards/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ class AuthenticationManager: AuthenticationProtocol {
}
}
}
func registerUser(email: String, username: String, password: String, onFinish: @escaping (AuthenticationData?, Error?) -> Void) {
func registerUser(email: String, username: String, password: String,
onFinish: @escaping (AuthenticationData?, Error?) -> Void) {
guard !email.isEmpty, !password.isEmpty else {
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ class DeathMatchMode: GameMode {
}
}
func getGameResults() -> [GameResult] {
let result: [GameResult] = [GameResult(variable: "Total Kill",
value: String(self.currentOwnKillCounter)),
GameResult(variable: "Opponent Kill", value: String(self.currentOpponentKillCounter))]
let result = [GameResult(variable: "Total Kill", value: String(self.currentOwnKillCounter)),
GameResult(variable: "Opponent Kill", value: String(self.currentOpponentKillCounter))]
return result
}

Expand Down
2 changes: 1 addition & 1 deletion TowerForge/TowerForge/GameModule/GameWorld.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class GameWorld {
if checkGameEnded() {
renderer?.renderMessage("You win")
print(gameMode.gameState)
delegate?.showGameOverScene(isWin: gameMode.gameState == .WIN ? true : false, results: gameMode.getGameResults())
delegate?.showGameOverScene(isWin: gameMode.gameState == .WIN, results: gameMode.getGameResults())
}
selectionNode.update()
renderer?.render()
Expand Down
17 changes: 10 additions & 7 deletions TowerForge/TowerForge/Networking/RoomNetwork/GameRoom.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,16 @@ class GameRoom {
completion(.waitingForFinalConfirmation)
}
}

func deleteRoom() {
if roomState == .gameOnGoing {
roomRef.child(roomName).removeValue { error, _ in
if let error = error {
print("Error deleting room: \(error.localizedDescription)")
} else {
print("Room deleted successfully.")
}
guard roomState == .gameOnGoing else {
return
}
roomRef.child(roomName).removeValue { error, _ in
if let error = error {
print("Error deleting room: \(error.localizedDescription)")
} else {
print("Room deleted successfully.")
}
}
}
Expand All @@ -130,6 +132,7 @@ class GameRoom {
}
}
}

func leaveRoom(player: GamePlayer, completion: @escaping (Bool) -> Void) {
let roomPlayersRef = roomRef.child(roomName).child("players")

Expand Down
17 changes: 6 additions & 11 deletions TowerForge/TowerForge/ViewControllers/GameModeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import UIKit

class GameModeViewController: UIViewController {
@IBOutlet private var rankingButton: UIButton!
@IBOutlet private var rankingView: UIView!
@IBOutlet private var loginButtonLabel: UILabel!

var selectedGameMode = Mode.captureTheFlag
Expand All @@ -24,10 +24,10 @@ class GameModeViewController: UIViewController {
authenticationProvider.addObserver(self)
if authenticationProvider.isUserLoggedIn() {
loginButtonLabel.text = "Logout"
rankingButton.isHidden = false
rankingView.isHidden = false
} else {
loginButtonLabel.text = "Login"
rankingButton.isHidden = true
rankingView.isHidden = true
}
}

Expand Down Expand Up @@ -64,12 +64,8 @@ class GameModeViewController: UIViewController {
guard !authenticationProvider.isUserLoggedIn() else {
return
}
guard let loginViewController = storyboard?.instantiateViewController(withIdentifier: "LoginViewController")
as? LoginViewController else {
return
}

present(loginViewController, animated: true, completion: nil)
performSegue(withIdentifier: "segueToLogin", sender: self)
}
}

Expand All @@ -95,12 +91,12 @@ class GameModeViewController: UIViewController {
extension GameModeViewController: AuthenticationDelegate {
func onLogin() {
loginButtonLabel.text = "Logout"
rankingButton.isHidden = false
rankingView.isHidden = false
}

func onLogout() {
loginButtonLabel.text = "Login"
rankingButton.isHidden = true
rankingView.isHidden = true
}
}

Expand All @@ -111,5 +107,4 @@ extension GameModeViewController: LevelPopupDelegate {
navigateToGameViewController()
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,7 @@ import UIKit

// Dummy still
class GameRoomViewController: UIViewController {
@IBOutlet private var MultiplayerButton: UIView!

@IBOutlet private var CreateRoom: UIButton!
@IBOutlet private var JoinRoom: UIButton!

@IBOutlet private var RoomNameInput: UITextField!

@IBOutlet private var PlayerNameInput: UITextField!

var gameRoom: GameRoom?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,6 @@ class GameWaitingRoomViewController: UIViewController {
updatePlayerList()
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
super.prepare(for: segue, sender: sender)

guard let destVC = segue.destination as? GameViewController else {
return
}
destVC.gameRoom = gameRoom
destVC.currentPlayer = currentPlayer
}

@IBAction private func onStartButtonPressed(_ sender: Any) {
gameRoom?.updatePlayerReady { _ in
self.startButton.isHidden = true
Expand Down Expand Up @@ -69,11 +59,14 @@ class GameWaitingRoomViewController: UIViewController {
let playerTwoView = createPlayerView(for: playerTwo)
ListStackView.addArrangedSubview(playerTwoView)
}

if gameRoom?.roomState == .gameOnGoing {
guard let gameViewController = self.storyboard?.instantiateViewController(withIdentifier: "GameViewController")
guard let gameViewController = storyboard?.instantiateViewController(withIdentifier: "GameViewController")
as? GameViewController else {
return
}
gameViewController.currentPlayer = currentPlayer
gameViewController.gameRoom = gameRoom
self.present(gameViewController, animated: true)
gameRoom?.deleteRoom()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,33 @@
import Foundation
import UIKit

protocol LevelPopupDelegate {
protocol LevelPopupDelegate: AnyObject {
func handleLevel(level: Int)
}

class LevelPopupViewController: UIViewController {

var delegate: LevelPopupDelegate?

@IBAction func onLevelOnePressed(_ sender: Any) {
@IBAction private func onLevelOnePressed(_ sender: Any) {
self.delegate?.handleLevel(level: 1)
self.dismiss(animated: true)
}
@IBAction func onLevelTwoPressed(_ sender: Any) {

@IBAction private func onLevelTwoPressed(_ sender: Any) {
self.delegate?.handleLevel(level: 2)
self.dismiss(animated: true)
}
@IBAction func onLevelThreePressed(_ sender: Any) {

@IBAction private func onLevelThreePressed(_ sender: Any) {
self.delegate?.handleLevel(level: 3)
self.dismiss(animated: true)
}

@IBAction func onClosePressed(_ sender: Any) {
@IBAction private func onClosePressed(_ sender: Any) {
self.dismiss(animated: true)
}

static func showDialogBox(parentVC: UIViewController) {
if let levelPopupViewController = UIStoryboard(name: "Main", bundle: nil)
.instantiateViewController(withIdentifier: "LevelPopupViewController")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,25 @@ import UIKit
class LoginViewController: UIViewController {
@IBOutlet private var emailInputField: UITextField!
@IBOutlet private var passwordInputField: UITextField!

@IBAction private func onLoginPressed(_ sender: Any) {
guard let email = emailInputField.text,
let password = passwordInputField.text else {
return
}
self.login(email: email, password: password)
}

@IBAction private func onRegisterPressed(_ sender: Any) {
performSegue(withIdentifier: "segueToRegister", sender: self)
}

private func login(email: String, password: String) {
let authentication = AuthenticationProvider()
authentication.login(email: email, password: password) { _, err in
if let error = err {
print(error)
} else {
// guard let gameModeViewController = self.storyboard?.instantiateViewController(withIdentifier: "GameModeViewController")
// as? GameModeViewController else {
// return
// }

// self.present(gameModeViewController, animated: true, completion: nil)
self.navigationController?.popViewController(animated: true)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@ class RegisterViewController: UIViewController {
authenticationProvider?.register(email: email, username: username, password: password) { _, err in
if let error = err {
print(error)
} else {
guard let gameModeViewController = self.storyboard?.instantiateViewController(withIdentifier: "GameModeViewController")
as? GameModeViewController else {
return
}

self.present(gameModeViewController, animated: true, completion: nil)
return
}
if let navigationController = self.navigationController,
let gameModeVC = navigationController.viewControllers.first(where: { $0 is GameModeViewController }) {
self.navigationController?.popToViewController(gameModeVC, animated: true)
}
}
}
Expand Down

0 comments on commit 21a6ca9

Please sign in to comment.