Merge branch '18-auth-anbindung-an-gamecenter' into 'development'

Resolve "[AUTH] Anbindung an GameCenter"

Closes #18

See merge request marcel.schwarz/software-projekt-2!33
This commit is contained in:
Aldin Duraki 2020-05-02 14:17:42 +00:00
commit b8edc830fb
9 changed files with 107 additions and 30 deletions

View File

@ -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 = "<group>"; };
116060F6245C57D2004E5A36 /* EntityManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EntityManager.swift; sourceTree = "<group>"; };
11738A3A24508F68004426F1 /* Unit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Unit.swift; sourceTree = "<group>"; };
3EBD242B245D8044003CECE7 /* GameCenterHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameCenterHelper.swift; sourceTree = "<group>"; };
3EBD242D245D9332003CECE7 /* Team.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Team.swift; sourceTree = "<group>"; };
9E11FF77245CD81100EED3BE /* Fire.sks */ = {isa = PBXFileReference; lastKnownFileType = file.sks; path = Fire.sks; sourceTree = "<group>"; };
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 = "<group>"; };
@ -151,6 +155,7 @@
110360DA244B101A008610AF /* GameViewController.swift */,
110360DF244B101B008610AF /* Assets.xcassets */,
110360E4244B101B008610AF /* Info.plist */,
3EBD242B245D8044003CECE7 /* GameCenterHelper.swift */,
);
path = GoldWars;
sourceTree = "<group>";
@ -220,6 +225,7 @@
children = (
11738A3A24508F68004426F1 /* Unit.swift */,
9EC86BA5245C8AD000796EF3 /* ModalType.swift */,
3EBD242D245D9332003CECE7 /* Team.swift */,
);
path = Enums;
sourceTree = "<group>";
@ -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 = "";

View File

@ -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

View File

@ -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) {

View File

@ -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]
}

View File

@ -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")
}

View File

@ -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 {

View File

@ -1,5 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict/>
<dict>
<key>aps-environment</key>
<string>development</string>
</dict>
</plist>

View File

@ -15,9 +15,9 @@
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>1</string>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
@ -27,6 +27,7 @@
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
<string>gamekit</string>
</array>
<key>UIRequiresFullScreen</key>
<true/>

View File

@ -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()
}
}
}