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/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/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) { 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] +} diff --git a/GoldWars/GoldWars/GameCenterHelper.swift b/GoldWars/GoldWars/GameCenterHelper.swift new file mode 100644 index 0000000..abf9578 --- /dev/null +++ b/GoldWars/GoldWars/GameCenterHelper.swift @@ -0,0 +1,45 @@ +// +// 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 + + static let helper = GameCenterHelper() + + 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") +} 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 { 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 diff --git a/GoldWars/GoldWars/Scenes/MenuScene.swift b/GoldWars/GoldWars/Scenes/MenuScene.swift index 46b4af3..38e4f64 100644 --- a/GoldWars/GoldWars/Scenes/MenuScene.swift +++ b/GoldWars/GoldWars/Scenes/MenuScene.swift @@ -46,14 +46,24 @@ 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 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) + self.addChild(authLabel) + } else { + self.childNode(withName: "authLabel")?.removeFromParent() + } + } }