From 0a94e64a25fdab54826750776e9ff7786fd3e14c Mon Sep 17 00:00:00 2001 From: Jakob Haag Date: Sat, 2 May 2020 13:59:34 +0200 Subject: [PATCH 1/9] add GameCenterHelper to login to GameCenter and recognize authenticated user --- GoldWars/GoldWars/GameCenterHelper.swift | 47 ++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 GoldWars/GoldWars/GameCenterHelper.swift diff --git a/GoldWars/GoldWars/GameCenterHelper.swift b/GoldWars/GoldWars/GameCenterHelper.swift new file mode 100644 index 0000000..988a23f --- /dev/null +++ b/GoldWars/GoldWars/GameCenterHelper.swift @@ -0,0 +1,47 @@ +// +// GameCenterHelper.swift +// GoldWars +// +// Created by Jakob Haag on 02.05.20. +// Copyright © 2020 SP2. All rights reserved. +// + +import GameKit + +final class GameCenterHelper: NSObject { + typealias CompletionBlock = (Error?) -> Void + + // 1 + static let helper = GameCenterHelper() + + // 2 + var viewController: UIViewController? + + static var isAuthenticated: Bool { + return GKLocalPlayer.local.isAuthenticated + } + + override init() { + super.init() + + GKLocalPlayer.local.authenticateHandler = { gcAuthVC, error in + NotificationCenter.default + .post(name: .authenticationChanged, object: GKLocalPlayer.local.isAuthenticated) + + if GKLocalPlayer.local.isAuthenticated { + print("Authenticated to Game Center!") + } else if let vc = gcAuthVC { + self.viewController?.present(vc, animated: true) + } + else { + print("Error authentication to GameCenter: " + + "\(error?.localizedDescription ?? "none")") + } + } + } +} + +extension Notification.Name { + static let presentGame = Notification.Name(rawValue: "presentGame") + static let authenticationChanged = Notification.Name(rawValue: "authenticationChanged") +} From cdb4d696218bb62a7711f83d30bdc3f60dbe71e9 Mon Sep 17 00:00:00 2001 From: Jakob Haag Date: Sat, 2 May 2020 14:01:05 +0200 Subject: [PATCH 2/9] Add window to menu to see if the user is authenticated (ToDo) --- GoldWars/GoldWars/Scenes/MenuScene.swift | 27 +++++++++++++++--------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/GoldWars/GoldWars/Scenes/MenuScene.swift b/GoldWars/GoldWars/Scenes/MenuScene.swift index 46b4af3..943c568 100644 --- a/GoldWars/GoldWars/Scenes/MenuScene.swift +++ b/GoldWars/GoldWars/Scenes/MenuScene.swift @@ -46,14 +46,21 @@ class MenuScene: SKScene { } } - override func update(_ currentTime: TimeInterval) { - self.enumerateChildNodes(withName: "clouds", using: ({ - (node, error) in - node.position.x -= 2 - if node.position.x < -(self.scene?.size.width)! { - node.position.x += (self.scene?.size.width)! * 3 - } - })) - } - + override func update(_ currentTime: TimeInterval) { + self.enumerateChildNodes(withName: "clouds", using: ({ + (node, error) in + node.position.x -= 2 + if node.position.x < -(self.scene?.size.width)! { + node.position.x += (self.scene?.size.width)! * 3 + } + })) + + // TODO: Notfalllösung + if(!GameCenterHelper.isAuthenticated) { + let label = SKLabelNode(text: "Authenticated") + label.zPosition = 2 + label.position = CGPoint(x: self.size.width / 2, y: self.size.height / 2) + self.addChild(label) + } + } } From e9bd05c852707d2f87920b99bfaeb98e070c377a Mon Sep 17 00:00:00 2001 From: Jakob Haag Date: Sat, 2 May 2020 14:02:24 +0200 Subject: [PATCH 3/9] add GameCenterLogin-window to the GameViewController and fix size of the MenueScene --- GoldWars/GoldWars/GameViewController.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/GoldWars/GoldWars/GameViewController.swift b/GoldWars/GoldWars/GameViewController.swift index 29f521d..158c6de 100644 --- a/GoldWars/GoldWars/GameViewController.swift +++ b/GoldWars/GoldWars/GameViewController.swift @@ -17,7 +17,6 @@ class GameViewController: UIViewController { if let view = self.view as! SKView? { if let scene = SKScene(fileNamed: "MenuScene") { - scene.size = self.view.bounds.size scene.scaleMode = .aspectFill view.presentScene(scene) //TODO: create dev profile or remove on delivery @@ -25,6 +24,8 @@ class GameViewController: UIViewController { view.showsNodeCount = true } } + + GameCenterHelper.helper.viewController = self } override var shouldAutorotate: Bool { From e8654fbf541101c446d3adb0ab27f165f9212d5e Mon Sep 17 00:00:00 2001 From: Jakob Haag Date: Sat, 2 May 2020 14:03:14 +0200 Subject: [PATCH 4/9] move team-enum out of class --- GoldWars/GoldWars/Components/TeamComponent.swift | 10 ---------- GoldWars/GoldWars/Enums/Team.swift | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 10 deletions(-) create mode 100644 GoldWars/GoldWars/Enums/Team.swift diff --git a/GoldWars/GoldWars/Components/TeamComponent.swift b/GoldWars/GoldWars/Components/TeamComponent.swift index 0509a36..dc24f45 100644 --- a/GoldWars/GoldWars/Components/TeamComponent.swift +++ b/GoldWars/GoldWars/Components/TeamComponent.swift @@ -9,16 +9,6 @@ import SpriteKit import GameplayKit -enum Team: Int { - case team1 = 1 - case team2 = 2 - case team3 = 3 - case team4 = 4 - - static let allValues = [team1, team2,team3,team4] - -} - class TeamComponent: GKComponent { let team: Team let fire:SKEmitterNode diff --git a/GoldWars/GoldWars/Enums/Team.swift b/GoldWars/GoldWars/Enums/Team.swift new file mode 100644 index 0000000..15115fa --- /dev/null +++ b/GoldWars/GoldWars/Enums/Team.swift @@ -0,0 +1,16 @@ +// +// Team.swift +// GoldWars +// +// Created by Jakob Haag on 02.05.20. +// Copyright © 2020 SP2. All rights reserved. +// + +enum Team: Int { + case team1 = 1 + case team2 = 2 + case team3 = 3 + case team4 = 4 + + static let allValues = [team1, team2,team3,team4] +} From c6d1adce9b72c682f858bd7e26f6c58380803292 Mon Sep 17 00:00:00 2001 From: Jakob Haag Date: Sat, 2 May 2020 14:03:41 +0200 Subject: [PATCH 5/9] init 100 units to the team-bases on init --- GoldWars/GoldWars/Entities/Base.swift | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/GoldWars/GoldWars/Entities/Base.swift b/GoldWars/GoldWars/Entities/Base.swift index 1358b97..75415f5 100644 --- a/GoldWars/GoldWars/Entities/Base.swift +++ b/GoldWars/GoldWars/Entities/Base.swift @@ -14,13 +14,12 @@ class Base : GKEntity{ init(textureName:String, team: Team?,position: CGPoint ) { self.unitCount = 0 - super.init() + super.init() addComponent(DefaultBaseComponent(texture: SKTexture(imageNamed: textureName), position: position)) if(team != nil){ addComponent(TeamComponent(team: team!, position: position)) - - } - + self.unitCount = 100 + } } required init?(coder: NSCoder) { From bb98c9d0a6f8d67726f7d9b79e65c6af1b87d76d Mon Sep 17 00:00:00 2001 From: Jakob Haag Date: Sat, 2 May 2020 14:04:08 +0200 Subject: [PATCH 6/9] add rest of necessary swift files --- GoldWars/GoldWars.xcodeproj/project.pbxproj | 16 ++++++++++++++-- GoldWars/GoldWars/GoldWars.entitlements | 5 ++++- GoldWars/GoldWars/Info.plist | 5 +++-- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/GoldWars/GoldWars.xcodeproj/project.pbxproj b/GoldWars/GoldWars.xcodeproj/project.pbxproj index adf2cf1..0d62603 100644 --- a/GoldWars/GoldWars.xcodeproj/project.pbxproj +++ b/GoldWars/GoldWars.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 50; + objectVersion = 53; objects = { /* Begin PBXBuildFile section */ @@ -20,6 +20,8 @@ 11036113244B3E30008610AF /* MenuScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11036112244B3E30008610AF /* MenuScene.swift */; }; 116060F7245C57D2004E5A36 /* EntityManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 116060F6245C57D2004E5A36 /* EntityManager.swift */; }; 11738A3B24508F68004426F1 /* Unit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11738A3A24508F68004426F1 /* Unit.swift */; }; + 3EBD242C245D8044003CECE7 /* GameCenterHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EBD242B245D8044003CECE7 /* GameCenterHelper.swift */; }; + 3EBD242E245D9332003CECE7 /* Team.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EBD242D245D9332003CECE7 /* Team.swift */; }; 9E11FF79245CD81100EED3BE /* Fire.sks in Resources */ = {isa = PBXBuildFile; fileRef = 9E11FF77245CD81100EED3BE /* Fire.sks */; }; 9E78ACB6245C9A5300526FF7 /* GameKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9E78ACB5245C9A5300526FF7 /* GameKit.framework */; }; 9E78ACB8245CB75B00526FF7 /* TeamComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E78ACB7245CB75B00526FF7 /* TeamComponent.swift */; }; @@ -73,6 +75,8 @@ 11036112244B3E30008610AF /* MenuScene.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuScene.swift; sourceTree = ""; }; 116060F6245C57D2004E5A36 /* EntityManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EntityManager.swift; sourceTree = ""; }; 11738A3A24508F68004426F1 /* Unit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Unit.swift; sourceTree = ""; }; + 3EBD242B245D8044003CECE7 /* GameCenterHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameCenterHelper.swift; sourceTree = ""; }; + 3EBD242D245D9332003CECE7 /* Team.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Team.swift; sourceTree = ""; }; 9E11FF77245CD81100EED3BE /* Fire.sks */ = {isa = PBXFileReference; lastKnownFileType = file.sks; path = Fire.sks; sourceTree = ""; }; 9E78ACB5245C9A5300526FF7 /* GameKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GameKit.framework; path = System/Library/Frameworks/GameKit.framework; sourceTree = SDKROOT; }; 9E78ACB7245CB75B00526FF7 /* TeamComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TeamComponent.swift; sourceTree = ""; }; @@ -151,6 +155,7 @@ 110360DA244B101A008610AF /* GameViewController.swift */, 110360DF244B101B008610AF /* Assets.xcassets */, 110360E4244B101B008610AF /* Info.plist */, + 3EBD242B245D8044003CECE7 /* GameCenterHelper.swift */, ); path = GoldWars; sourceTree = ""; @@ -220,6 +225,7 @@ children = ( 11738A3A24508F68004426F1 /* Unit.swift */, 9EC86BA5245C8AD000796EF3 /* ModalType.swift */, + 3EBD242D245D9332003CECE7 /* Team.swift */, ); path = Enums; sourceTree = ""; @@ -324,7 +330,7 @@ }; }; buildConfigurationList = 110360CA244B101A008610AF /* Build configuration list for PBXProject "GoldWars" */; - compatibilityVersion = "Xcode 9.3"; + compatibilityVersion = "Xcode 11.4"; developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( @@ -386,11 +392,13 @@ 9EA3ABEB245C6DFA006BC61D /* BaseNode.swift in Sources */, 110360D9244B101A008610AF /* GameScene.swift in Sources */, 116060F7245C57D2004E5A36 /* EntityManager.swift in Sources */, + 3EBD242E245D9332003CECE7 /* Team.swift in Sources */, 9E78ACBA245CBDAF00526FF7 /* HUD.swift in Sources */, 11738A3B24508F68004426F1 /* Unit.swift in Sources */, 11036113244B3E30008610AF /* MenuScene.swift in Sources */, 9EA3ABE9245C6DAA006BC61D /* DefaultBaseComponent.swift in Sources */, 9EA3ABED245C8143006BC61D /* ModalBackgroundComponent.swift in Sources */, + 3EBD242C245D8044003CECE7 /* GameCenterHelper.swift in Sources */, ABA03DA0244BD54F00A66916 /* Base.swift in Sources */, 110360DB244B101A008610AF /* GameViewController.swift in Sources */, 110360D3244B101A008610AF /* AppDelegate.swift in Sources */, @@ -571,12 +579,14 @@ CODE_SIGN_ENTITLEMENTS = GoldWars/GoldWars.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 2; DEVELOPMENT_TEAM = DDKFQG46BQ; INFOPLIST_FILE = GoldWars/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", ); + MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = de.hft.stuttgart.ip2.goldwars; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -592,12 +602,14 @@ CODE_SIGN_ENTITLEMENTS = GoldWars/GoldWars.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 2; DEVELOPMENT_TEAM = DDKFQG46BQ; INFOPLIST_FILE = GoldWars/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", ); + MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = de.hft.stuttgart.ip2.goldwars; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; diff --git a/GoldWars/GoldWars/GoldWars.entitlements b/GoldWars/GoldWars/GoldWars.entitlements index 0c67376..903def2 100644 --- a/GoldWars/GoldWars/GoldWars.entitlements +++ b/GoldWars/GoldWars/GoldWars.entitlements @@ -1,5 +1,8 @@ - + + aps-environment + development + diff --git a/GoldWars/GoldWars/Info.plist b/GoldWars/GoldWars/Info.plist index 11be888..13fe48d 100644 --- a/GoldWars/GoldWars/Info.plist +++ b/GoldWars/GoldWars/Info.plist @@ -15,9 +15,9 @@ CFBundlePackageType $(PRODUCT_BUNDLE_PACKAGE_TYPE) CFBundleShortVersionString - 1.0 + $(MARKETING_VERSION) CFBundleVersion - 1 + $(CURRENT_PROJECT_VERSION) LSRequiresIPhoneOS UILaunchStoryboardName @@ -27,6 +27,7 @@ UIRequiredDeviceCapabilities armv7 + gamekit UIRequiresFullScreen From cdb67f2d7cbcba48a9f5f6b0969185082c785810 Mon Sep 17 00:00:00 2001 From: Jakob Haag Date: Sat, 2 May 2020 16:14:46 +0200 Subject: [PATCH 7/9] remove unused code and format --- GoldWars/GoldWars/GameCenterHelper.swift | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/GoldWars/GoldWars/GameCenterHelper.swift b/GoldWars/GoldWars/GameCenterHelper.swift index 988a23f..abf9578 100644 --- a/GoldWars/GoldWars/GameCenterHelper.swift +++ b/GoldWars/GoldWars/GameCenterHelper.swift @@ -11,10 +11,8 @@ import GameKit final class GameCenterHelper: NSObject { typealias CompletionBlock = (Error?) -> Void - // 1 static let helper = GameCenterHelper() - // 2 var viewController: UIViewController? static var isAuthenticated: Bool { @@ -42,6 +40,6 @@ final class GameCenterHelper: NSObject { } extension Notification.Name { - static let presentGame = Notification.Name(rawValue: "presentGame") - static let authenticationChanged = Notification.Name(rawValue: "authenticationChanged") + static let presentGame = Notification.Name(rawValue: "presentGame") + static let authenticationChanged = Notification.Name(rawValue: "authenticationChanged") } From 311b19d9c2c67b3cc350d517ad24d46963de6e48 Mon Sep 17 00:00:00 2001 From: Jakob Haag Date: Sat, 2 May 2020 16:15:03 +0200 Subject: [PATCH 8/9] add label of user is not logged in to GameCenter --- GoldWars/GoldWars/Scenes/MenuScene.swift | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/GoldWars/GoldWars/Scenes/MenuScene.swift b/GoldWars/GoldWars/Scenes/MenuScene.swift index 943c568..cd5f9a8 100644 --- a/GoldWars/GoldWars/Scenes/MenuScene.swift +++ b/GoldWars/GoldWars/Scenes/MenuScene.swift @@ -57,10 +57,13 @@ class MenuScene: SKScene { // TODO: Notfalllösung if(!GameCenterHelper.isAuthenticated) { - let label = SKLabelNode(text: "Authenticated") - label.zPosition = 2 - label.position = CGPoint(x: self.size.width / 2, y: self.size.height / 2) - self.addChild(label) + let authLabel = SKLabelNode(text: "Yout are not logged in to Gamecenter. Please login via GameCenterApp") + authLabel.name = "authLabel" + authLabel.zPosition = 2 + authLabel.position = CGPoint(x: self.size.width / 2, y: self.size.height / 5) + self.addChild(authLabel) + } else { + self.childNode(withName: "authLabel")?.removeFromParent() } } } From 868e10e7a41ad4d8afe1249776f7591690c1b099 Mon Sep 17 00:00:00 2001 From: Jakob Haag Date: Sat, 2 May 2020 16:16:16 +0200 Subject: [PATCH 9/9] fix spelling --- GoldWars/GoldWars/Scenes/MenuScene.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GoldWars/GoldWars/Scenes/MenuScene.swift b/GoldWars/GoldWars/Scenes/MenuScene.swift index cd5f9a8..38e4f64 100644 --- a/GoldWars/GoldWars/Scenes/MenuScene.swift +++ b/GoldWars/GoldWars/Scenes/MenuScene.swift @@ -57,7 +57,7 @@ class MenuScene: SKScene { // TODO: Notfalllösung if(!GameCenterHelper.isAuthenticated) { - let authLabel = SKLabelNode(text: "Yout are not logged in to Gamecenter. Please login via GameCenterApp") + let authLabel = SKLabelNode(text: "You are not logged in to Gamecenter. Please login via GameCenterApp") authLabel.name = "authLabel" authLabel.zPosition = 2 authLabel.position = CGPoint(x: self.size.width / 2, y: self.size.height / 5)