Test: Receiving Data on Hostdevice

This commit is contained in:
Aldin Duraki 2020-05-13 21:15:44 +02:00
parent 917769ac24
commit 570099911f
6 changed files with 54 additions and 11 deletions

View File

@ -21,6 +21,7 @@
3EBD242C245D8044003CECE7 /* GameCenterHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EBD242B245D8044003CECE7 /* GameCenterHelper.swift */; }; 3EBD242C245D8044003CECE7 /* GameCenterHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EBD242B245D8044003CECE7 /* GameCenterHelper.swift */; };
3EBD242E245D9332003CECE7 /* Team.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EBD242D245D9332003CECE7 /* Team.swift */; }; 3EBD242E245D9332003CECE7 /* Team.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EBD242D245D9332003CECE7 /* Team.swift */; };
3FE19DB3246C690B004827AB /* RoundSimulatorService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FE19DB2246C690B004827AB /* RoundSimulatorService.swift */; }; 3FE19DB3246C690B004827AB /* RoundSimulatorService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FE19DB2246C690B004827AB /* RoundSimulatorService.swift */; };
3FE19DB5246C7A22004827AB /* RoundCalculatorService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FE19DB4246C7A22004827AB /* RoundCalculatorService.swift */; };
9E04AFAF245E2B73002D5CFC /* AttackActionComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E04AFAE245E2B73002D5CFC /* AttackActionComponent.swift */; }; 9E04AFAF245E2B73002D5CFC /* AttackActionComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E04AFAE245E2B73002D5CFC /* AttackActionComponent.swift */; };
9E11FF79245CD81100EED3BE /* Fire.sks in Resources */ = {isa = PBXBuildFile; fileRef = 9E11FF77245CD81100EED3BE /* Fire.sks */; }; 9E11FF79245CD81100EED3BE /* Fire.sks in Resources */ = {isa = PBXBuildFile; fileRef = 9E11FF77245CD81100EED3BE /* Fire.sks */; };
9E174C82245DD81D00209FF0 /* ButtonNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E174C81245DD81D00209FF0 /* ButtonNode.swift */; }; 9E174C82245DD81D00209FF0 /* ButtonNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E174C81245DD81D00209FF0 /* ButtonNode.swift */; };
@ -86,6 +87,7 @@
3EBD242B245D8044003CECE7 /* GameCenterHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameCenterHelper.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>"; }; 3EBD242D245D9332003CECE7 /* Team.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Team.swift; sourceTree = "<group>"; };
3FE19DB2246C690B004827AB /* RoundSimulatorService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoundSimulatorService.swift; sourceTree = "<group>"; }; 3FE19DB2246C690B004827AB /* RoundSimulatorService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoundSimulatorService.swift; sourceTree = "<group>"; };
3FE19DB4246C7A22004827AB /* RoundCalculatorService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoundCalculatorService.swift; sourceTree = "<group>"; };
9E04AFAE245E2B73002D5CFC /* AttackActionComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttackActionComponent.swift; sourceTree = "<group>"; }; 9E04AFAE245E2B73002D5CFC /* AttackActionComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttackActionComponent.swift; sourceTree = "<group>"; };
9E11FF77245CD81100EED3BE /* Fire.sks */ = {isa = PBXFileReference; lastKnownFileType = file.sks; path = Fire.sks; sourceTree = "<group>"; }; 9E11FF77245CD81100EED3BE /* Fire.sks */ = {isa = PBXFileReference; lastKnownFileType = file.sks; path = Fire.sks; sourceTree = "<group>"; };
9E174C81245DD81D00209FF0 /* ButtonNode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ButtonNode.swift; sourceTree = "<group>"; }; 9E174C81245DD81D00209FF0 /* ButtonNode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ButtonNode.swift; sourceTree = "<group>"; };
@ -181,6 +183,7 @@
C099579B246C5E5C0016AA22 /* DataService.swift */, C099579B246C5E5C0016AA22 /* DataService.swift */,
110360E4244B101B008610AF /* Info.plist */, 110360E4244B101B008610AF /* Info.plist */,
AE151588245F18EF001D363E /* MatchmakingHelper.swift */, AE151588245F18EF001D363E /* MatchmakingHelper.swift */,
3FE19DB4246C7A22004827AB /* RoundCalculatorService.swift */,
3EBD242B245D8044003CECE7 /* GameCenterHelper.swift */, 3EBD242B245D8044003CECE7 /* GameCenterHelper.swift */,
C04783EF24685995004961FB /* SettingsScene.swift */, C04783EF24685995004961FB /* SettingsScene.swift */,
C064E9A7246C0EA50022B228 /* LabelNode.swift */, C064E9A7246C0EA50022B228 /* LabelNode.swift */,
@ -394,6 +397,7 @@
files = ( files = (
9E78ACB8245CB75B00526FF7 /* TeamComponent.swift in Sources */, 9E78ACB8245CB75B00526FF7 /* TeamComponent.swift in Sources */,
9EA3ABEF245C834B006BC61D /* ModalContentComponent.swift in Sources */, 9EA3ABEF245C834B006BC61D /* ModalContentComponent.swift in Sources */,
3FE19DB5246C7A22004827AB /* RoundCalculatorService.swift in Sources */,
9EC86BA6245C8AD000796EF3 /* ModalType.swift in Sources */, 9EC86BA6245C8AD000796EF3 /* ModalType.swift in Sources */,
9EC239E1246878A900952F74 /* MultiplayerNetwork.swift in Sources */, 9EC239E1246878A900952F74 /* MultiplayerNetwork.swift in Sources */,
9E78ACBE245CC9C000526FF7 /* AtkBoostSkillComponent.swift in Sources */, 9E78ACBE245CC9C000526FF7 /* AtkBoostSkillComponent.swift in Sources */,

View File

@ -44,9 +44,8 @@ class TimerComponent: GKComponent {
self.labelNode.text = String(timeLeft()) self.labelNode.text = String(timeLeft())
if(isFinished()){ if(isFinished()){
MatchmakingHelper.shar
self.labelNode.text = "Synching" self.labelNode.text = "Synching"
MultiplayerNetwork.sharedInstance.sendPlayerMoves(playerMoves: DataService.sharedInstance.playerMoves) MultiplayerNetwork.sharedInstance.sendPlayerMoves(playerMoves: DataService.sharedInstance.localPlayerMoves)
} }
} }

View File

@ -18,12 +18,25 @@ struct Host: Codable {
class DataService { class DataService {
static let sharedInstance = DataService() static let sharedInstance = DataService()
var playerMoves: [PlayerMove] = [] var localPlayerMoves: [PlayerMove] = []
var remotePlayerMoves: [String: [PlayerMove]] = [:]
var gameHost: Host? var gameHost: Host?
func addMove(playerMove: PlayerMove) { func addMove(playerMove: PlayerMove) {
self.playerMoves.append(playerMove) self.localPlayerMoves.append(playerMove)
}
func addRemotePlayerMoves(playerID: String, playerMoves: [PlayerMove]) {
self.remotePlayerMoves[playerID] = playerMoves
//test
var size = self.remotePlayerMoves.count
if size == 1 {
for (key, value) in remotePlayerMoves {
print("\(key) : \(value)")
}
}
} }
func setGameHost(host: Host) { func setGameHost(host: Host) {

View File

@ -109,13 +109,12 @@ class MatchmakingHelper: NSObject, GKMatchmakerViewControllerDelegate, GKMatchDe
*/ */
func match(_ match: GKMatch, didReceive data: Data, fromRemotePlayer player: GKPlayer) { func match(_ match: GKMatch, didReceive data: Data, fromRemotePlayer player: GKPlayer) {
print("Daten empfangen!")
if mpMatch != match { return } if mpMatch != match { return }
let jsonDecoder = JSONDecoder() let jsonDecoder = JSONDecoder()
if let message = try? jsonDecoder.decode(PlayerMove.self, from: data) { if let playerMoves = try? jsonDecoder.decode([PlayerMove].self, from: data) {
//TODO: impl logic DataService.sharedInstance.addRemotePlayerMoves(playerID: player.gamePlayerID, playerMoves: playerMoves)
} }
if let message = try? jsonDecoder.decode(Host.self, from: data) { if let message = try? jsonDecoder.decode(Host.self, from: data) {

View File

@ -11,7 +11,7 @@ import Foundation
class MultiplayerNetwork{ class MultiplayerNetwork{
static let sharedInstance = MultiplayerNetwork() static let sharedInstance = MultiplayerNetwork()
func sendData(data: Data) { func sendData(data: Data) {
let mmHelper = MatchmakingHelper.sharedInstance let mmHelper = MatchmakingHelper.sharedInstance
if let multiplayerMatch = mmHelper.mpMatch { if let multiplayerMatch = mmHelper.mpMatch {
@ -22,11 +22,26 @@ class MultiplayerNetwork{
} }
} }
} }
func sendDataToHost(data: Data) {
let mmHelper = MatchmakingHelper.sharedInstance
let hostGKPlayer = MatchmakingHelper.sharedInstance.mpMatch?.players.filter{ $0.gamePlayerID == DataService.sharedInstance.gameHost?.playerID}
if let multiplayerMatch = mmHelper.mpMatch{
do {
try multiplayerMatch.send(data, to: hostGKPlayer!, dataMode: .reliable)
} catch {
print("Tim war mal wieder am Werk der Krasse")
}
}
}
func sendPlayerMoves(playerMoves: [PlayerMove]) { func sendPlayerMoves(playerMoves: [PlayerMove]) {
let encoder = JSONEncoder() if !MatchmakingHelper.sharedInstance.isServer {
let encoded = (try? encoder.encode(playerMoves))! let encoder = JSONEncoder()
sendData(data: encoded) let encoded = (try? encoder.encode(playerMoves))!
sendDataToHost(data: encoded)
}
} }
func sendHostIdentifier() { func sendHostIdentifier() {

View File

@ -0,0 +1,13 @@
//
// RoundCalculatorService.swift
// GoldWars
//
// Created by student on 13.05.20.
// Copyright © 2020 SP2. All rights reserved.
//
import Foundation
class RoundCalculatorServie {
}