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

@ -49,7 +49,8 @@ class TimerComponent: GKComponent {
MultiplayerNetwork.sharedInstance.sendPlayerMoves(playerMoves: DataService.sharedInstance.localPlayerMoves) MultiplayerNetwork.sharedInstance.sendPlayerMoves(playerMoves: DataService.sharedInstance.localPlayerMoves)
} }
if !RoundCalculatorServie.sharedInstance.isCalculating if !RoundCalculatorServie.sharedInstance.isCalculating
&& DataService.sharedInstance.didReceiveAllData(){ && DataService.sharedInstance.didReceiveAllData()
&& MatchmakingHelper.sharedInstance.isServer {
RoundCalculatorServie.sharedInstance.calculateRound() RoundCalculatorServie.sharedInstance.calculateRound()
} }
} }

View File

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

View File

@ -142,7 +142,7 @@ class EntityManager {
} }
func getSnapshotBaseById(baseId: Int, snapshotModel: SnapshotModel) -> BaseEntityModel{ 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? { func getBaseByPlayer(for player: GKPlayer) -> GKEntity? {

View File

@ -42,12 +42,12 @@ class RoundCalculatorServie {
let baseId = key let baseId = key
var playerMovesByBase = value 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} let possiblyOwnershipMoves = playerMovesByBase.filter { $0.key == targetBase?.ownership}
// spieler verschiebt einheiten beim schieben // spieler verschiebt einheiten beim schieben
for (playerName, playerMove) in possiblyOwnershipMoves { for (playerName, playerMove) in possiblyOwnershipMoves {
for var base in currentSnapshotModel.baseEntites! { for var base in currentSnapshotModel!.baseEntites {
if base.baseId == playerMove.fromBase { if base.baseId == playerMove.fromBase {
base.unitCount -= playerMove.unitCount base.unitCount -= playerMove.unitCount
} }
@ -59,7 +59,7 @@ class RoundCalculatorServie {
} }
for (_, playerMove) in playerMovesByBase { for (_, playerMove) in playerMovesByBase {
for var base in currentSnapshotModel.baseEntites! { for var base in currentSnapshotModel!.baseEntites {
if base.baseId == playerMove.fromBase { if base.baseId == playerMove.fromBase {
base.unitCount -= playerMove.unitCount 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 { if base.baseId == max.value.toBase {
base.unitCount += max.value.unitCount base.unitCount += max.value.unitCount
if max.value.unitCount == 0 { if max.value.unitCount == 0 {
@ -95,9 +95,9 @@ class RoundCalculatorServie {
print(currentSnapshotModel) print(currentSnapshotModel)
MultiplayerNetwork.sharedInstance.sendSnapshotModelToPlayers() MultiplayerNetwork.sharedInstance.sendSnapshotModelToPlayers()
EntityManager.sharedInstance.updateSnapshotModel(snapshotModel: currentSnapshotModel) EntityManager.sharedInstance.updateSnapshotModel(snapshotModel: currentSnapshotModel!)
let calcTime = CFAbsoluteTimeGetCurrent() - startTime 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]) { func addPlayerMove(playerName: String, playerMoves: [PlayerMove]) {