TEST: Change dependencies of optional types

This commit is contained in:
Aldin Duraki 2020-05-18 01:03:25 +02:00
parent e08d40dd4a
commit 4a1b43a70d
4 changed files with 23 additions and 14 deletions

View File

@ -9,11 +9,11 @@
import GameplayKit
class TimerComponent: GKComponent {
let labelNode :SKLabelNode
var endTime :Date!
var duration :Double
init(text: String, anchorPoint: CGPoint, duration: TimeInterval) {
self.labelNode = SKLabelNode(text: text)
self.labelNode.fontColor = UIColor.black
@ -49,7 +49,8 @@ class TimerComponent: GKComponent {
MultiplayerNetwork.sharedInstance.sendPlayerMoves(playerMoves: DataService.sharedInstance.localPlayerMoves)
}
if !RoundCalculatorServie.sharedInstance.isCalculating
&& DataService.sharedInstance.didReceiveAllData(){
&& DataService.sharedInstance.didReceiveAllData()
&& MatchmakingHelper.sharedInstance.isServer {
RoundCalculatorServie.sharedInstance.calculateRound()
}
}
@ -58,6 +59,6 @@ class TimerComponent: GKComponent {
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

View File

@ -16,8 +16,16 @@ struct Host: Codable {
let playerName: String
}
struct SnapshotModel: Codable {
var baseEntites: [BaseEntityModel]?
class SnapshotModel: Codable {
var baseEntites: [BaseEntityModel]
//
// init() {
// self.baseEntites = []
// }
//
init(baseEntites: [BaseEntityModel]) {
self.baseEntites = baseEntites
}
}
class BaseEntityModel: Codable {
@ -36,7 +44,7 @@ class DataService {
static let sharedInstance = DataService()
var localPlayerMoves: [PlayerMove] = []
var remotePlayerMoves: [String: [PlayerMove]] = [:]
var snapshotModel = SnapshotModel()
var snapshotModel: SnapshotModel?
var gameHost: Host?

View File

@ -142,7 +142,7 @@ class EntityManager {
}
func getSnapshotBaseById(baseId: Int, snapshotModel: SnapshotModel) -> BaseEntityModel{
return (snapshotModel.baseEntites?.filter { $0.baseId == baseId }[0])!
return snapshotModel.baseEntites.filter { $0.baseId == baseId }[0]
}
func getBaseByPlayer(for player: GKPlayer) -> GKEntity? {

View File

@ -42,12 +42,12 @@ class RoundCalculatorServie {
let baseId = key
var playerMovesByBase = value
let targetBase = currentSnapshotModel.baseEntites?.filter { $0.baseId == baseId }[0]
let targetBase = currentSnapshotModel?.baseEntites.filter { $0.baseId == baseId }[0]
let possiblyOwnershipMoves = playerMovesByBase.filter { $0.key == targetBase?.ownership}
// spieler verschiebt einheiten beim schieben
for (playerName, playerMove) in possiblyOwnershipMoves {
for var base in currentSnapshotModel.baseEntites! {
for var base in currentSnapshotModel!.baseEntites {
if base.baseId == playerMove.fromBase {
base.unitCount -= playerMove.unitCount
}
@ -59,7 +59,7 @@ class RoundCalculatorServie {
}
for (_, playerMove) in playerMovesByBase {
for var base in currentSnapshotModel.baseEntites! {
for var base in currentSnapshotModel!.baseEntites {
if base.baseId == playerMove.fromBase {
base.unitCount -= playerMove.unitCount
}
@ -78,7 +78,7 @@ class RoundCalculatorServie {
}
for var base in currentSnapshotModel.baseEntites! {
for var base in currentSnapshotModel!.baseEntites {
if base.baseId == max.value.toBase {
base.unitCount += max.value.unitCount
if max.value.unitCount == 0 {
@ -95,9 +95,9 @@ class RoundCalculatorServie {
print(currentSnapshotModel)
MultiplayerNetwork.sharedInstance.sendSnapshotModelToPlayers()
EntityManager.sharedInstance.updateSnapshotModel(snapshotModel: currentSnapshotModel)
EntityManager.sharedInstance.updateSnapshotModel(snapshotModel: currentSnapshotModel!)
let calcTime = CFAbsoluteTimeGetCurrent() - startTime
os_log("Finished calculating Round in %@", log: OSLog.default, type: .info, calcTime)
os_log("Finished calculating Round in %@", log: OSLog.default, type: .info)
}
func addPlayerMove(playerName: String, playerMoves: [PlayerMove]) {