Change Datamodel to JSON
This commit is contained in:
parent
fb01faa1e5
commit
d553b72daf
@ -102,37 +102,24 @@ class MatchmakingHelper: NSObject, GKMatchmakerViewControllerDelegate, GKMatchDe
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func decode<T>(data: NSData) -> T {
|
|
||||||
let pointer = UnsafeMutablePointer<T>.allocate(capacity: MemoryLayout<T>.size)
|
|
||||||
data.getBytes(pointer, length: MemoryLayout<T>.size)
|
|
||||||
return pointer.move()
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Vom match erhaltene Spielerdaten
|
Vom match erhaltene Spielerdaten
|
||||||
|
|
||||||
*/
|
*/
|
||||||
private func match(match: GKMatch!, didReceiveData data: Data,fromPlayer playerID: String!) {
|
|
||||||
|
func match(_ match: GKMatch, didReceive data: Data, fromRemotePlayer player: GKPlayer) {
|
||||||
print("Daten empfangen!")
|
print("Daten empfangen!")
|
||||||
if mpMatch != match { return }
|
if mpMatch != match { return }
|
||||||
|
|
||||||
|
let jsonDecoder = JSONDecoder()
|
||||||
|
|
||||||
let pointer = UnsafeMutablePointer<Message>.allocate(capacity: MemoryLayout<Message>.size)
|
if let message = try? jsonDecoder.decode(PlayerMove.self, from: data) {
|
||||||
|
let count = message.unitCount
|
||||||
let message = pointer.move()
|
print("Angekommen \(count)")
|
||||||
|
|
||||||
switch message.messageType{
|
|
||||||
case MessageType.PlayerMove:
|
|
||||||
let playerMove = message as! PlayerMove
|
|
||||||
let count = playerMove.unitCount
|
|
||||||
print("Angekommen \(count)")
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//delegate?.matchReceivedData(match: match, data: data, fromPlayer: playerID)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Verbindung/Matchmaking ist fehlgeschlagen
|
Verbindung/Matchmaking ist fehlgeschlagen
|
||||||
*/
|
*/
|
||||||
@ -147,6 +134,7 @@ class MatchmakingHelper: NSObject, GKMatchmakerViewControllerDelegate, GKMatchDe
|
|||||||
/*
|
/*
|
||||||
Wird beim ändern des States/Zustands des Spielers aufgerufen udn gibt dessen Zustand zurück.
|
Wird beim ändern des States/Zustands des Spielers aufgerufen udn gibt dessen Zustand zurück.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
func match(_ match: GKMatch, player: GKPlayer, didChange state: GKPlayerConnectionState) {
|
func match(_ match: GKMatch, player: GKPlayer, didChange state: GKPlayerConnectionState) {
|
||||||
if mpMatch != match {
|
if mpMatch != match {
|
||||||
return
|
return
|
||||||
|
@ -9,22 +9,17 @@
|
|||||||
import GameplayKit
|
import GameplayKit
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
|
enum MessageType : Int,Codable{
|
||||||
protocol MultiplayerProtocol {
|
|
||||||
|
|
||||||
}
|
|
||||||
enum MessageType : Int{
|
|
||||||
case PlayerMove
|
case PlayerMove
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protocol Message {
|
protocol Message :Codable{
|
||||||
var messageType:MessageType { get }
|
var messageType:MessageType { get }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct PlayerMove : Message,Codable{
|
||||||
|
|
||||||
|
|
||||||
struct PlayerMove : Message{
|
|
||||||
let messageType: MessageType
|
let messageType: MessageType
|
||||||
|
|
||||||
// let message: Message
|
// let message: Message
|
||||||
|
Loading…
Reference in New Issue
Block a user