diff --git a/FullStackCodingBot/FullStackCodingBot.xcodeproj/project.pbxproj b/FullStackCodingBot/FullStackCodingBot.xcodeproj/project.pbxproj index 5436b2e..43e370a 100644 --- a/FullStackCodingBot/FullStackCodingBot.xcodeproj/project.pbxproj +++ b/FullStackCodingBot/FullStackCodingBot.xcodeproj/project.pbxproj @@ -13,6 +13,7 @@ 710D0D422693EA3200244A16 /* GameViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 710D0D412693EA3200244A16 /* GameViewController.swift */; }; 710D0D442693EA6900244A16 /* GameViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 710D0D432693EA6900244A16 /* GameViewModel.swift */; }; 710D0D4F2693F6E500244A16 /* ItemCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 710D0D4D2693F6E500244A16 /* ItemCell.swift */; }; + 7123C74026FD79A70049E6DC /* AlertScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7123C73F26FD79A70049E6DC /* AlertScene.swift */; }; 712F500A26A831D900186948 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 712F500926A831D900186948 /* GoogleService-Info.plist */; }; 712F500B26A831D900186948 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 712F500926A831D900186948 /* GoogleService-Info.plist */; }; 71307A8926A529F400C3191F /* LevelUpButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71307A8826A529F400C3191F /* LevelUpButton.swift */; }; @@ -40,6 +41,10 @@ 718F224926C377B700B2648C /* ErrorManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 718F224826C377B700B2648C /* ErrorManager.swift */; }; 719A6A9B26B11208006AC991 /* NetworkDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 719A6A9A26B11208006AC991 /* NetworkDTO.swift */; }; 719AB9DE26B7ADF2001B5913 /* SettingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 719AB9DD26B7ADF2001B5913 /* SettingViewController.swift */; }; + 719D0D9026F1863200913BBE /* MainScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = 719D0D8F26F1863200913BBE /* MainScene.swift */; }; + 719D0D9226F186F100913BBE /* GameScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = 719D0D9126F186F100913BBE /* GameScene.swift */; }; + 719D0D9426F1875100913BBE /* GameHelperScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = 719D0D9326F1875100913BBE /* GameHelperScene.swift */; }; + 719D0D9626F1889700913BBE /* SceneType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 719D0D9526F1889700913BBE /* SceneType.swift */; }; 719DA2B126A7FC9900624C61 /* JoystixMonospace-Regular.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 719DA2B026A7FC9800624C61 /* JoystixMonospace-Regular.ttf */; }; 71A5518026A91C280083A4B0 /* FirebaseManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71A5517F26A91C280083A4B0 /* FirebaseManager.swift */; }; 71A5518226A9277C0083A4B0 /* FirebaseManagerType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71A5518126A9277C0083A4B0 /* FirebaseManagerType.swift */; }; @@ -48,7 +53,6 @@ 71DF64BD2692C18F00557693 /* RankViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71DF64BC2692C18F00557693 /* RankViewController.swift */; }; 71DF64BF2692C1C600557693 /* ItemViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71DF64BE2692C1C600557693 /* ItemViewController.swift */; }; 71DF653C2692F90100557693 /* TransitionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71DF653B2692F90100557693 /* TransitionModel.swift */; }; - 71DF653E2692F92700557693 /* Scene.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71DF653D2692F92700557693 /* Scene.swift */; }; 71DF65412692F94E00557693 /* MainViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71DF65402692F94E00557693 /* MainViewModel.swift */; }; 71DF65432692F95800557693 /* ShopViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71DF65422692F95800557693 /* ShopViewModel.swift */; }; 71DF65472692F97000557693 /* RankViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71DF65462692F97000557693 /* RankViewModel.swift */; }; @@ -168,6 +172,7 @@ 710D0D412693EA3200244A16 /* GameViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameViewController.swift; sourceTree = ""; }; 710D0D432693EA6900244A16 /* GameViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameViewModel.swift; sourceTree = ""; }; 710D0D4D2693F6E500244A16 /* ItemCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemCell.swift; sourceTree = ""; }; + 7123C73F26FD79A70049E6DC /* AlertScene.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertScene.swift; sourceTree = ""; }; 712F500926A831D900186948 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = ""; }; 71307A8826A529F400C3191F /* LevelUpButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LevelUpButton.swift; sourceTree = ""; }; 71307A8A26A52A1F00C3191F /* LevelUpButton.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = LevelUpButton.xib; sourceTree = ""; }; @@ -194,6 +199,10 @@ 718F224826C377B700B2648C /* ErrorManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ErrorManager.swift; sourceTree = ""; }; 719A6A9A26B11208006AC991 /* NetworkDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkDTO.swift; sourceTree = ""; }; 719AB9DD26B7ADF2001B5913 /* SettingViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingViewController.swift; sourceTree = ""; }; + 719D0D8F26F1863200913BBE /* MainScene.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainScene.swift; sourceTree = ""; }; + 719D0D9126F186F100913BBE /* GameScene.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameScene.swift; sourceTree = ""; }; + 719D0D9326F1875100913BBE /* GameHelperScene.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameHelperScene.swift; sourceTree = ""; }; + 719D0D9526F1889700913BBE /* SceneType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneType.swift; sourceTree = ""; }; 719DA2B026A7FC9800624C61 /* JoystixMonospace-Regular.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "JoystixMonospace-Regular.ttf"; sourceTree = ""; }; 71A5517F26A91C280083A4B0 /* FirebaseManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirebaseManager.swift; sourceTree = ""; }; 71A5518126A9277C0083A4B0 /* FirebaseManagerType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirebaseManagerType.swift; sourceTree = ""; }; @@ -202,7 +211,6 @@ 71DF64BC2692C18F00557693 /* RankViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RankViewController.swift; sourceTree = ""; }; 71DF64BE2692C1C600557693 /* ItemViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemViewController.swift; sourceTree = ""; }; 71DF653B2692F90100557693 /* TransitionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransitionModel.swift; sourceTree = ""; }; - 71DF653D2692F92700557693 /* Scene.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Scene.swift; sourceTree = ""; }; 71DF65402692F94E00557693 /* MainViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainViewModel.swift; sourceTree = ""; }; 71DF65422692F95800557693 /* ShopViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShopViewModel.swift; sourceTree = ""; }; 71DF65462692F97000557693 /* RankViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RankViewModel.swift; sourceTree = ""; }; @@ -429,6 +437,27 @@ path = ErrorManager; sourceTree = ""; }; + 719D0D9726F18C0700913BBE /* SceneType */ = { + isa = PBXGroup; + children = ( + 719D0D8F26F1863200913BBE /* MainScene.swift */, + 719D0D9126F186F100913BBE /* GameScene.swift */, + 719D0D9326F1875100913BBE /* GameHelperScene.swift */, + 7123C73F26FD79A70049E6DC /* AlertScene.swift */, + 719D0D9526F1889700913BBE /* SceneType.swift */, + ); + path = SceneType; + sourceTree = ""; + }; + 71A5517E26A91C160083A4B0 /* FirebaseStorage */ = { + isa = PBXGroup; + children = ( + 71A5517F26A91C280083A4B0 /* DatabaseManager.swift */, + 71A5518126A9277C0083A4B0 /* DatabaseManagerType.swift */, + ); + path = FirebaseStorage; + sourceTree = ""; + }; 71BC752C26A940870021BA1A /* DataFormatManager */ = { isa = PBXGroup; children = ( @@ -449,8 +478,8 @@ 71DF653A2692F8D400557693 /* Scene */ = { isa = PBXGroup; children = ( + 719D0D9726F18C0700913BBE /* SceneType */, 71DF653B2692F90100557693 /* TransitionModel.swift */, - 71DF653D2692F92700557693 /* Scene.swift */, 71DF65502692FBCC00557693 /* SceneCoordinatorType.swift */, 71DF65522692FBE500557693 /* SceneCoordinator.swift */, ); @@ -1034,6 +1063,7 @@ buildActionMask = 2147483647; files = ( 719A6A9B26B11208006AC991 /* NetworkDTO.swift in Sources */, + 7123C74026FD79A70049E6DC /* AlertScene.swift in Sources */, E418F37526DC985B00F35AFB /* AverageColor.swift in Sources */, E43B64A226ABD81C001D9896 /* GameBackgroundView.swift in Sources */, E4C2C34D26A24666007BDF81 /* SkyView.swift in Sources */, @@ -1044,7 +1074,9 @@ E4BF710526AFD45A00E8645F /* TimeManagerType.swift in Sources */, E4336F5F26F083840049A5D8 /* BackUpCenterType.swift in Sources */, 710D0D4F2693F6E500244A16 /* ItemCell.swift in Sources */, + 719D0D9226F186F100913BBE /* GameScene.swift in Sources */, E4D7C63E2693E79800D58BA2 /* AppDelegate.swift in Sources */, + 719D0D9626F1889700913BBE /* SceneType.swift in Sources */, 715C1C9426BCF9FF0025C681 /* StoryViewController.swift in Sources */, E45B0AC92692F9CF006FDE3D /* Unit.swift in Sources */, E45B0AC72692F42D006FDE3D /* UnitPerspectiveView.swift in Sources */, @@ -1066,7 +1098,6 @@ E41C85DA269C4E8F008F2E91 /* PauseViewController.swift in Sources */, E4DF613D26A845DA0061F6E9 /* AdStorage.swift in Sources */, E4D7C64B26953C6200D58BA2 /* ScreenSize.swift in Sources */, - 71DF653E2692F92700557693 /* Scene.swift in Sources */, E4BF714326B7E23A00E8645F /* GameSoundEffectStation.swift in Sources */, 71DF64BF2692C1C600557693 /* ItemViewController.swift in Sources */, E4336F5D26F083650049A5D8 /* GameStorageType.swift in Sources */, @@ -1114,9 +1145,11 @@ E418F36D26DC8BAC00F35AFB /* BackgroundAnimation.swift in Sources */, E4A40F9926C1038F003E40B2 /* StoryManager.swift in Sources */, 715A83EE269FE96300C9CEFF /* StoryboardType.swift in Sources */, + 719D0D9426F1875100913BBE /* GameHelperScene.swift in Sources */, 71307AB126A53C7B00C3191F /* AlertMessage.swift in Sources */, 71E91E1726BA33190016386E /* Extension.swift in Sources */, 7170CD4526B266BE00F03248 /* VersionErrorViewController.swift in Sources */, + 719D0D9026F1863200913BBE /* MainScene.swift in Sources */, E4CA08B926A8287B00AA6F03 /* Font.swift in Sources */, E4BF710B26B1324500E8645F /* ReadyView.swift in Sources */, 71DF64B92692C13A00557693 /* ShopViewController.swift in Sources */, diff --git a/FullStackCodingBot/FullStackCodingBot/AppCycle/AppDelegate.swift b/FullStackCodingBot/FullStackCodingBot/AppCycle/AppDelegate.swift index a3a6687..84d86c8 100644 --- a/FullStackCodingBot/FullStackCodingBot/AppCycle/AppDelegate.swift +++ b/FullStackCodingBot/FullStackCodingBot/AppCycle/AppDelegate.swift @@ -54,18 +54,18 @@ private extension AppDelegate { private func getFirstScene(_ hasLaunchedOnce: Bool, _ sceneCoordinator: SceneCoordinator, - _ settings: SettingInformation) -> Scene { - + _ database: DatabaseManager, + _ settings: SettingInformation) -> SceneType { switch hasLaunchedOnce { case true: let mainViewModel = MainViewModel(sceneCoordinator: sceneCoordinator, storage: storage!, settings: settings) - let mainScene = Scene.main(mainViewModel) + let mainScene = MainScene.main(mainViewModel) return mainScene case false: let storyViewModel = StoryViewModel(sceneCoordinator: sceneCoordinator, storage: storage!, settings: settings) - let storyScene = Scene.story(storyViewModel) + let storyScene = GameHelperScene.story(storyViewModel) return storyScene } diff --git a/FullStackCodingBot/FullStackCodingBot/View/Scene/Scene.swift b/FullStackCodingBot/FullStackCodingBot/View/Scene/Scene.swift deleted file mode 100644 index 5f9c4c8..0000000 --- a/FullStackCodingBot/FullStackCodingBot/View/Scene/Scene.swift +++ /dev/null @@ -1,121 +0,0 @@ -import UIKit -import GameKit -import Firebase - -enum Scene { - case main(MainViewModel) - case setting(MainViewModel) - case howToPlay(HowToPlayViewModel) - case story(StoryViewModel) - case shop(ShopViewModel) - case rank(RankViewModel) - case item(ItemViewModel) - case game(GameViewModel) - case pause(PauseViewModel) - case gameOver(GameOverViewModel) - case alert(AlertMessage) - case gameCenter(UIViewController) -} - -extension Scene { - - // swiftlint:disable:next cyclomatic_complexity - func instantiate(from identifier: String) -> UIViewController { - let storyboard = UIStoryboard(name: identifier, bundle: nil) - switch self { - - case .main(let viewModel): - guard var mainVC = storyboard.instantiateViewController(withIdentifier: IdentifierVC.main) as? MainViewController else { - Firebase.Analytics.logEvent("ViewControllerError", parameters: nil) - fatalError() - } - mainVC.bind(viewModel: viewModel) - return mainVC - - case .shop(let viewModel): - guard var shopVC = storyboard.instantiateViewController(withIdentifier: IdentifierVC.shop) as? ShopViewController else { - Firebase.Analytics.logEvent("ViewControllerError", parameters: nil) - fatalError() - } - shopVC.bind(viewModel: viewModel) - return shopVC - - case .rank(let viewModel): - guard var rankVC = storyboard.instantiateViewController(withIdentifier: IdentifierVC.rank) as? RankViewController else { - Firebase.Analytics.logEvent("ViewControllerError", parameters: nil) - fatalError() - } - rankVC.gameCenterDelegate = viewModel - rankVC.leaderboardIdentifier = IdentifierGC.leaderboard - rankVC.viewState = .leaderboards - rankVC.bind(viewModel: viewModel) - return rankVC - - case .item(let viewModel): - guard var itemVC = storyboard.instantiateViewController(withIdentifier: IdentifierVC.item) as? ItemViewController else { - Firebase.Analytics.logEvent("ViewControllerError", parameters: nil) - fatalError() - } - itemVC.bind(viewModel: viewModel) - return itemVC - - case .game(let viewModel): - guard var gameVC = storyboard.instantiateViewController(withIdentifier: IdentifierVC.game) as? GameViewController else { - Firebase.Analytics.logEvent("ViewControllerError", parameters: nil) - fatalError() - } - gameVC.bind(viewModel: viewModel) - return gameVC - - case .pause(let viewModel): - guard var pauseVC = storyboard.instantiateViewController(withIdentifier: IdentifierVC.pause) as? PauseViewController else { - Firebase.Analytics.logEvent("ViewControllerError", parameters: nil) - fatalError() - } - pauseVC.bind(viewModel: viewModel) - return pauseVC - - case .gameOver(let viewModel): - guard var gameOverVC = storyboard.instantiateViewController(withIdentifier: IdentifierVC.gameOver) as? GameOverViewController else { - Firebase.Analytics.logEvent("ViewControllerError", parameters: nil) - fatalError() - } - gameOverVC.bind(viewModel: viewModel) - return gameOverVC - - case .alert(let message): - let alerMessage = message.content.message - let alertScene = UIAlertController(title: alerMessage.title, message: alerMessage.content, preferredStyle: .alert) - let confirmAction = UIAlertAction(title: message.content.confirm, style: .cancel) - alertScene.addAction(confirmAction) - return alertScene - - case .setting(let viewModel): - guard var settingVC = storyboard.instantiateViewController(withIdentifier: IdentifierVC.setting) as? SettingViewController else { - Firebase.Analytics.logEvent("ViewControllerError", parameters: nil) - fatalError() - } - settingVC.bind(viewModel: viewModel) - return settingVC - - case .story(let viewModel): - guard var storyVC = storyboard.instantiateViewController(withIdentifier: IdentifierVC.story) as? StoryViewController else { - Firebase.Analytics.logEvent("ViewControllerError", parameters: nil) - fatalError() - } - storyVC.bind(viewModel: viewModel) - return storyVC - - case .howToPlay(let viewModel): - guard var howToVC = storyboard.instantiateViewController(withIdentifier: IdentifierVC.howTo) as? HowToPlayViewController else { - Firebase.Analytics.logEvent("ViewControllerError", parameters: nil) - fatalError() - } - howToVC.bind(viewModel: viewModel) - return howToVC - - case .gameCenter(let viewController): - return viewController - } - } -} diff --git a/FullStackCodingBot/FullStackCodingBot/View/Scene/SceneCoordinator.swift b/FullStackCodingBot/FullStackCodingBot/View/Scene/SceneCoordinator.swift index 715178a..ca0c70e 100644 --- a/FullStackCodingBot/FullStackCodingBot/View/Scene/SceneCoordinator.swift +++ b/FullStackCodingBot/FullStackCodingBot/View/Scene/SceneCoordinator.swift @@ -14,7 +14,7 @@ final class SceneCoordinator: SceneCoordinatorType { } @discardableResult - func transition(to scene: Scene, using style: TransitionStyle, with type: StoryboardType, animated: Bool) -> Completable { + func transition(to scene: SceneType, using style: TransitionStyle, with type: StoryboardType, animated: Bool) -> Completable { let subject = PublishSubject() let target = scene.instantiate(from: type.name) diff --git a/FullStackCodingBot/FullStackCodingBot/View/Scene/SceneCoordinatorType.swift b/FullStackCodingBot/FullStackCodingBot/View/Scene/SceneCoordinatorType.swift index 90c1ec0..a3a50f5 100644 --- a/FullStackCodingBot/FullStackCodingBot/View/Scene/SceneCoordinatorType.swift +++ b/FullStackCodingBot/FullStackCodingBot/View/Scene/SceneCoordinatorType.swift @@ -4,7 +4,7 @@ import RxSwift protocol SceneCoordinatorType { @discardableResult - func transition(to scene: Scene, using style: TransitionStyle, with type: StoryboardType, animated: Bool) -> Completable + func transition(to scene: SceneType, using style: TransitionStyle, with type: StoryboardType, animated: Bool) -> Completable @discardableResult func close(animated: Bool) -> Completable diff --git a/FullStackCodingBot/FullStackCodingBot/View/Scene/SceneType/AlertScene.swift b/FullStackCodingBot/FullStackCodingBot/View/Scene/SceneType/AlertScene.swift new file mode 100644 index 0000000..789513c --- /dev/null +++ b/FullStackCodingBot/FullStackCodingBot/View/Scene/SceneType/AlertScene.swift @@ -0,0 +1,24 @@ +import UIKit +import GameKit +import Firebase + +enum AlertScene { + case alert(AlertMessage) +} + +extension AlertScene: SceneType { + + func instantiate(from identifier: String) -> UIViewController { + + switch self { + + case .alert(let message): + let alerMessage = message.content.message + let alertScene = UIAlertController(title: alerMessage.title, message: alerMessage.content, preferredStyle: .alert) + let confirmAction = UIAlertAction(title: message.content.confirm, style: .cancel) + alertScene.addAction(confirmAction) + return alertScene + + } + } +} diff --git a/FullStackCodingBot/FullStackCodingBot/View/Scene/SceneType/GameHelperScene.swift b/FullStackCodingBot/FullStackCodingBot/View/Scene/SceneType/GameHelperScene.swift new file mode 100644 index 0000000..ea8a2ec --- /dev/null +++ b/FullStackCodingBot/FullStackCodingBot/View/Scene/SceneType/GameHelperScene.swift @@ -0,0 +1,43 @@ +import UIKit +import GameKit +import Firebase + +enum GameHelperScene { + case setting(MainViewModel) + case howToPlay(HowToPlayViewModel) + case story(StoryViewModel) +} + +extension GameHelperScene: SceneType { + + func instantiate(from identifier: String) -> UIViewController { + let storyboard = UIStoryboard(name: identifier, bundle: nil) + switch self { + + case .setting(let viewModel): + guard var settingVC = storyboard.instantiateViewController(withIdentifier: IdentifierVC.setting) as? SettingViewController else { + Firebase.Analytics.logEvent("ViewControllerError", parameters: nil) + fatalError() + } + settingVC.bind(viewModel: viewModel) + return settingVC + + case .howToPlay(let viewModel): + guard var howToVC = storyboard.instantiateViewController(withIdentifier: IdentifierVC.howTo) as? HowToPlayViewController else { + Firebase.Analytics.logEvent("ViewControllerError", parameters: nil) + fatalError() + } + howToVC.bind(viewModel: viewModel) + return howToVC + + case .story(let viewModel): + guard var storyVC = storyboard.instantiateViewController(withIdentifier: IdentifierVC.story) as? StoryViewController else { + Firebase.Analytics.logEvent("ViewControllerError", parameters: nil) + fatalError() + } + storyVC.bind(viewModel: viewModel) + return storyVC + + } + } +} diff --git a/FullStackCodingBot/FullStackCodingBot/View/Scene/SceneType/GameScene.swift b/FullStackCodingBot/FullStackCodingBot/View/Scene/SceneType/GameScene.swift new file mode 100644 index 0000000..5b6b42b --- /dev/null +++ b/FullStackCodingBot/FullStackCodingBot/View/Scene/SceneType/GameScene.swift @@ -0,0 +1,43 @@ +import UIKit +import GameKit +import Firebase + +enum GameScene { + case game(GameViewModel) + case pause(PauseViewModel) + case gameOver(GameOverViewModel) +} + +extension GameScene: SceneType { + + func instantiate(from identifier: String) -> UIViewController { + let storyboard = UIStoryboard(name: identifier, bundle: nil) + switch self { + + case .game(let viewModel): + guard var gameVC = storyboard.instantiateViewController(withIdentifier: IdentifierVC.game) as? GameViewController else { + Firebase.Analytics.logEvent("ViewControllerError", parameters: nil) + fatalError() + } + gameVC.bind(viewModel: viewModel) + return gameVC + + case .pause(let viewModel): + guard var pauseVC = storyboard.instantiateViewController(withIdentifier: IdentifierVC.pause) as? PauseViewController else { + Firebase.Analytics.logEvent("ViewControllerError", parameters: nil) + fatalError() + } + pauseVC.bind(viewModel: viewModel) + return pauseVC + + case .gameOver(let viewModel): + guard var gameOverVC = storyboard.instantiateViewController(withIdentifier: IdentifierVC.gameOver) as? GameOverViewController else { + Firebase.Analytics.logEvent("ViewControllerError", parameters: nil) + fatalError() + } + gameOverVC.bind(viewModel: viewModel) + return gameOverVC + + } + } +} diff --git a/FullStackCodingBot/FullStackCodingBot/View/Scene/SceneType/MainScene.swift b/FullStackCodingBot/FullStackCodingBot/View/Scene/SceneType/MainScene.swift new file mode 100644 index 0000000..f25673f --- /dev/null +++ b/FullStackCodingBot/FullStackCodingBot/View/Scene/SceneType/MainScene.swift @@ -0,0 +1,59 @@ +import UIKit +import GameKit +import Firebase + +enum MainScene { + case main(MainViewModel) + case shop(ShopViewModel) + case rank(RankViewModel) + case item(ItemViewModel) + case gameCenter(UIViewController) +} + +extension MainScene: SceneType { + + func instantiate(from identifier: String) -> UIViewController { + let storyboard = UIStoryboard(name: identifier, bundle: nil) + switch self { + + case .main(let viewModel): + guard var mainVC = storyboard.instantiateViewController(withIdentifier: IdentifierVC.main) as? MainViewController else { + Firebase.Analytics.logEvent("ViewControllerError", parameters: nil) + fatalError() + } + mainVC.bind(viewModel: viewModel) + return mainVC + + case .shop(let viewModel): + guard var shopVC = storyboard.instantiateViewController(withIdentifier: IdentifierVC.shop) as? ShopViewController else { + Firebase.Analytics.logEvent("ViewControllerError", parameters: nil) + fatalError() + } + shopVC.bind(viewModel: viewModel) + return shopVC + + case .rank(let viewModel): + guard var rankVC = storyboard.instantiateViewController(withIdentifier: IdentifierVC.rank) as? RankViewController else { + Firebase.Analytics.logEvent("ViewControllerError", parameters: nil) + fatalError() + } + rankVC.gameCenterDelegate = viewModel + rankVC.leaderboardIdentifier = IdentifierGC.leaderboard + rankVC.viewState = .leaderboards + rankVC.bind(viewModel: viewModel) + return rankVC + + case .item(let viewModel): + guard var itemVC = storyboard.instantiateViewController(withIdentifier: IdentifierVC.item) as? ItemViewController else { + Firebase.Analytics.logEvent("ViewControllerError", parameters: nil) + fatalError() + } + itemVC.bind(viewModel: viewModel) + return itemVC + + case .gameCenter(let viewController): + return viewController + + } + } +} diff --git a/FullStackCodingBot/FullStackCodingBot/View/Scene/SceneType/SceneType.swift b/FullStackCodingBot/FullStackCodingBot/View/Scene/SceneType/SceneType.swift new file mode 100644 index 0000000..fb28ae1 --- /dev/null +++ b/FullStackCodingBot/FullStackCodingBot/View/Scene/SceneType/SceneType.swift @@ -0,0 +1,5 @@ +import UIKit + +protocol SceneType { + func instantiate(from identifier: String) -> UIViewController +} diff --git a/FullStackCodingBot/FullStackCodingBot/ViewModel/GameViewModel.swift b/FullStackCodingBot/FullStackCodingBot/ViewModel/GameViewModel.swift index d736ffd..40a9ff9 100644 --- a/FullStackCodingBot/FullStackCodingBot/ViewModel/GameViewModel.swift +++ b/FullStackCodingBot/FullStackCodingBot/ViewModel/GameViewModel.swift @@ -205,7 +205,7 @@ private extension GameViewModel { private func toGameOverScene() -> Completable { let currentScore = try? currentScore.value() let gameOverViewModel = GameOverViewModel(sceneCoordinator: sceneCoordinator, storage: storage, finalScore: currentScore ?? 0, newGameStatus: newGameStatus) - let gameOverScene = Scene.gameOver(gameOverViewModel) + let gameOverScene = GameScene.gameOver(gameOverViewModel) return self.sceneCoordinator.transition(to: gameOverScene, using: .pop, with: StoryboardType.game, animated: true) } @@ -213,7 +213,7 @@ private extension GameViewModel { private func toPauseScene() -> Completable { let currentScore = try? currentScore.value() let pauseViewModel = PauseViewModel(sceneCoordinator: sceneCoordinator, storage: storage, currentScore: currentScore ?? 0, newGameStatus: newGameStatus) - let pauseScene = Scene.pause(pauseViewModel) + let pauseScene = GameScene.pause(pauseViewModel) return self.sceneCoordinator.transition(to: pauseScene, using: .fullScreen, with: StoryboardType.game, animated: false) } } diff --git a/FullStackCodingBot/FullStackCodingBot/ViewModel/MainViewModel.swift b/FullStackCodingBot/FullStackCodingBot/ViewModel/MainViewModel.swift index ec00680..30b27f9 100644 --- a/FullStackCodingBot/FullStackCodingBot/ViewModel/MainViewModel.swift +++ b/FullStackCodingBot/FullStackCodingBot/ViewModel/MainViewModel.swift @@ -36,37 +36,37 @@ final class MainViewModel: AdViewModel { switch viewController { case .giftVC: let shopViewModel = ShopViewModel(sceneCoordinator: self.sceneCoordinator, storage: self.storage) - let shopScene = Scene.shop(shopViewModel) + let shopScene = MainScene.shop(shopViewModel) self.sceneCoordinator.transition(to: shopScene, using: .fullScreen, with: StoryboardType.main, animated: true) case .rankVC: let rankViewModel = RankViewModel(sceneCoordinator: self.sceneCoordinator, storage: self.storage) - let rankScene = Scene.rank(rankViewModel) + let rankScene = MainScene.rank(rankViewModel) self.sceneCoordinator.transition(to: rankScene, using: .fullScreen, with: StoryboardType.main, animated: true) case .itemVC: let itemViewModel = ItemViewModel(sceneCoordinator: self.sceneCoordinator, storage: self.storage) - let itemScene = Scene.item(itemViewModel) + let itemScene = MainScene.item(itemViewModel) self.sceneCoordinator.transition(to: itemScene, using: .fullScreen, with: StoryboardType.main, animated: true) case .gameVC: let gameUnitManager = GameUnitManager(allKinds: Unit.initialValues()) let gameViewModel = GameViewModel(sceneCoordinator: self.sceneCoordinator, storage: self.storage, gameUnitManager: gameUnitManager) - let gameScene = Scene.game(gameViewModel) + let gameScene = GameScene.game(gameViewModel) self.sceneCoordinator.transition(to: gameScene, using: .fullScreen, with: StoryboardType.game, animated: true) case .settingVC: - let settingScene = Scene.setting(self) + let settingScene = GameHelperScene.setting(self) self.sceneCoordinator.transition(to: settingScene, using: .overCurrent, with: StoryboardType.main, animated: true) case .storyVC: let storyViewModel = StoryViewModel(sceneCoordinator: sceneCoordinator, storage: storage, settings: settingInfo, isFirstTimePlay: false) - let storyScene = Scene.story(storyViewModel) + let storyScene = GameHelperScene.story(storyViewModel) self.sceneCoordinator.transition(to: storyScene, using: .fullScreen, with: StoryboardType.main, animated: true) case .howToVC: let howToViewModel = HowToPlayViewModel(sceneCoordinator: sceneCoordinator, storage: storage) - let howToScene = Scene.howToPlay(howToViewModel) + let howToScene = GameHelperScene.howToPlay(howToViewModel) self.sceneCoordinator.transition(to: howToScene, using: .fullScreen, with: StoryboardType.main, animated: true) } } @@ -100,7 +100,7 @@ extension MainViewModel: GKGameCenterControllerDelegate { private func setupAppleGameCenterLogin() { GKLocalPlayer.local.authenticateHandler = { [unowned self] gcViewController, error in if let gcViewController = gcViewController { - let scene = Scene.gameCenter(gcViewController) + let scene = MainScene.gameCenter(gcViewController) self.sceneCoordinator.transition(to: scene, using: .fullScreen, with: StoryboardType.main, animated: false) } else if let error = error { Firebase.Analytics.logEvent("CancelGameCenter", parameters: ["ErrorMessage": "\(error.localizedDescription)"]) diff --git a/FullStackCodingBot/FullStackCodingBot/ViewModel/StoryViewModel.swift b/FullStackCodingBot/FullStackCodingBot/ViewModel/StoryViewModel.swift index 55d11f5..878b771 100644 --- a/FullStackCodingBot/FullStackCodingBot/ViewModel/StoryViewModel.swift +++ b/FullStackCodingBot/FullStackCodingBot/ViewModel/StoryViewModel.swift @@ -45,7 +45,7 @@ final class StoryViewModel: AdViewModel { private func makeMoveActionToMain() { let mainViewModel = MainViewModel(sceneCoordinator: sceneCoordinator, storage: storage, settings: settings) - let mainScene = Scene.main(mainViewModel) + let mainScene = MainScene.main(mainViewModel) self.sceneCoordinator.transition(to: mainScene, using: .root, with: StoryboardType.main, animated: true) } diff --git a/FullStackCodingBot/Podfile.lock b/FullStackCodingBot/Podfile.lock index c26b996..2e039b1 100644 --- a/FullStackCodingBot/Podfile.lock +++ b/FullStackCodingBot/Podfile.lock @@ -2,19 +2,19 @@ PODS: - Action (5.0.0): - RxCocoa (~> 6.0) - RxSwift (~> 6.0) - - Firebase/Auth (8.6.1): + - Firebase/Auth (8.7.0): - Firebase/CoreOnly - - FirebaseAuth (~> 8.6.0) - - Firebase/Core (8.6.1): + - FirebaseAuth (~> 8.7.0) + - Firebase/Core (8.7.0): - Firebase/CoreOnly - - FirebaseAnalytics (~> 8.6.0) - - Firebase/CoreOnly (8.6.1): - - FirebaseCore (= 8.6.1) - - Firebase/Database (8.6.1): + - FirebaseAnalytics (~> 8.7.0) + - Firebase/CoreOnly (8.7.0): + - FirebaseCore (= 8.7.0) + - Firebase/Database (8.7.0): - Firebase/CoreOnly - - FirebaseDatabase (~> 8.6.0) - - FirebaseAnalytics (8.6.0): - - FirebaseAnalytics/AdIdSupport (= 8.6.0) + - FirebaseDatabase (~> 8.7.0) + - FirebaseAnalytics (8.7.0): + - FirebaseAnalytics/AdIdSupport (= 8.7.0) - FirebaseCore (~> 8.0) - FirebaseInstallations (~> 8.0) - GoogleUtilities/AppDelegateSwizzler (~> 7.4) @@ -22,48 +22,48 @@ PODS: - GoogleUtilities/Network (~> 7.4) - "GoogleUtilities/NSData+zlib (~> 7.4)" - nanopb (~> 2.30908.0) - - FirebaseAnalytics/AdIdSupport (8.6.0): + - FirebaseAnalytics/AdIdSupport (8.7.0): - FirebaseCore (~> 8.0) - FirebaseInstallations (~> 8.0) - - GoogleAppMeasurement (= 8.6.0) + - GoogleAppMeasurement (= 8.7.0) - GoogleUtilities/AppDelegateSwizzler (~> 7.4) - GoogleUtilities/MethodSwizzler (~> 7.4) - GoogleUtilities/Network (~> 7.4) - "GoogleUtilities/NSData+zlib (~> 7.4)" - nanopb (~> 2.30908.0) - - FirebaseAuth (8.6.0): + - FirebaseAuth (8.7.0): - FirebaseCore (~> 8.0) - GoogleUtilities/AppDelegateSwizzler (~> 7.4) - GoogleUtilities/Environment (~> 7.4) - GTMSessionFetcher/Core (~> 1.5) - - FirebaseCore (8.6.1): + - FirebaseCore (8.7.0): - FirebaseCoreDiagnostics (~> 8.0) - GoogleUtilities/Environment (~> 7.4) - GoogleUtilities/Logger (~> 7.4) - - FirebaseCoreDiagnostics (8.6.0): + - FirebaseCoreDiagnostics (8.7.0): - GoogleDataTransport (~> 9.0) - GoogleUtilities/Environment (~> 7.4) - GoogleUtilities/Logger (~> 7.4) - nanopb (~> 2.30908.0) - - FirebaseDatabase (8.6.0): + - FirebaseDatabase (8.7.0): - FirebaseCore (~> 8.0) - leveldb-library (~> 1.22) - - FirebaseInstallations (8.6.0): + - FirebaseInstallations (8.7.0): - FirebaseCore (~> 8.0) - GoogleUtilities/Environment (~> 7.4) - GoogleUtilities/UserDefaults (~> 7.4) - PromisesObjC (< 3.0, >= 1.2) - - Google-Mobile-Ads-SDK (8.9.0): + - Google-Mobile-Ads-SDK (8.10.0): - GoogleAppMeasurement (< 9.0, >= 7.0) - GoogleUserMessagingPlatform (>= 1.1) - - GoogleAppMeasurement (8.6.0): - - GoogleAppMeasurement/AdIdSupport (= 8.6.0) + - GoogleAppMeasurement (8.7.0): + - GoogleAppMeasurement/AdIdSupport (= 8.7.0) - GoogleUtilities/AppDelegateSwizzler (~> 7.4) - GoogleUtilities/MethodSwizzler (~> 7.4) - GoogleUtilities/Network (~> 7.4) - "GoogleUtilities/NSData+zlib (~> 7.4)" - nanopb (~> 2.30908.0) - - GoogleAppMeasurement/AdIdSupport (8.6.0): + - GoogleAppMeasurement/AdIdSupport (8.7.0): - GoogleUtilities/AppDelegateSwizzler (~> 7.4) - GoogleUtilities/MethodSwizzler (~> 7.4) - GoogleUtilities/Network (~> 7.4) @@ -74,26 +74,26 @@ PODS: - nanopb (~> 2.30908.0) - PromisesObjC (< 3.0, >= 1.2) - GoogleUserMessagingPlatform (2.0.0) - - GoogleUtilities/AppDelegateSwizzler (7.5.1): + - GoogleUtilities/AppDelegateSwizzler (7.5.2): - GoogleUtilities/Environment - GoogleUtilities/Logger - GoogleUtilities/Network - - GoogleUtilities/Environment (7.5.1): + - GoogleUtilities/Environment (7.5.2): - PromisesObjC (< 3.0, >= 1.2) - - GoogleUtilities/Logger (7.5.1): + - GoogleUtilities/Logger (7.5.2): - GoogleUtilities/Environment - - GoogleUtilities/MethodSwizzler (7.5.1): + - GoogleUtilities/MethodSwizzler (7.5.2): - GoogleUtilities/Logger - - GoogleUtilities/Network (7.5.1): + - GoogleUtilities/Network (7.5.2): - GoogleUtilities/Logger - "GoogleUtilities/NSData+zlib" - GoogleUtilities/Reachability - - "GoogleUtilities/NSData+zlib (7.5.1)" - - GoogleUtilities/Reachability (7.5.1): + - "GoogleUtilities/NSData+zlib (7.5.2)" + - GoogleUtilities/Reachability (7.5.2): - GoogleUtilities/Logger - - GoogleUtilities/UserDefaults (7.5.1): + - GoogleUtilities/UserDefaults (7.5.2): - GoogleUtilities/Logger - - GTMSessionFetcher/Core (1.6.1) + - GTMSessionFetcher/Core (1.7.0) - leveldb-library (1.22.1) - nanopb (2.30908.0): - nanopb/decode (= 2.30908.0) @@ -109,7 +109,7 @@ PODS: - RxRelay (6.2.0): - RxSwift (= 6.2.0) - RxSwift (6.2.0) - - SwiftLint (0.43.1) + - SwiftLint (0.44.0) DEPENDENCIES: - Action @@ -160,8 +160,8 @@ SPEC CHECKSUMS: GoogleAppMeasurement: 2c0c6e2a7ab3fe730ade6379f732bdefb46f50b0 GoogleDataTransport: 85fd18ff3019bb85d3f2c551d04c481dedf71fc9 GoogleUserMessagingPlatform: ab890ce5f6620f293a21b6bdd82e416a2c73aeca - GoogleUtilities: 3df19e3c24f7bbc291d8b5809aa6b0d41e642437 - GTMSessionFetcher: 36689134877faeb055b27dfa4ccc9ceaa42e029e + GoogleUtilities: 8de2a97a17e15b6b98e38e8770e2d129a57c0040 + GTMSessionFetcher: 43748f93435c2aa068b1cbe39655aaf600652e91 leveldb-library: 50c7b45cbd7bf543c81a468fe557a16ae3db8729 nanopb: a0ba3315591a9ae0a16a309ee504766e90db0c96 "NSObject+Rx": 61cf1f7306a73dcef8b36649198af0813ec18dfd @@ -169,7 +169,7 @@ SPEC CHECKSUMS: RxCocoa: 4baf94bb35f2c0ab31bc0cb9f1900155f646ba42 RxRelay: e72dbfd157807478401ef1982e1c61c945c94b2f RxSwift: d356ab7bee873611322f134c5f9ef379fa183d8f - SwiftLint: 99f82d07b837b942dd563c668de129a03fc3fb52 + SwiftLint: e96c0a8c770c7ebbc4d36c55baf9096bb65c4584 PODFILE CHECKSUM: bdce34f2ae6ceca45889e75fa0818ccb2cad524f