From 009b39ca1465a55d399783e899af82c133f3a2f7 Mon Sep 17 00:00:00 2001 From: Aldin Duraki Date: Fri, 15 May 2020 20:45:52 +0200 Subject: [PATCH] TEST: Get a List of overlapping moves --- GoldWars/GoldWars/Components/TimerComponent.swift | 6 +++--- GoldWars/GoldWars/RoundCalculatorService.swift | 10 +++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/GoldWars/GoldWars/Components/TimerComponent.swift b/GoldWars/GoldWars/Components/TimerComponent.swift index 894a16e..5ad2695 100644 --- a/GoldWars/GoldWars/Components/TimerComponent.swift +++ b/GoldWars/GoldWars/Components/TimerComponent.swift @@ -48,10 +48,10 @@ class TimerComponent: GKComponent { if !MultiplayerNetwork.sharedInstance.isSending { MultiplayerNetwork.sharedInstance.sendPlayerMoves(playerMoves: DataService.sharedInstance.localPlayerMoves) } - if DataService.sharedInstance.didReceiveAllData() { - RoundCalculatorServie.sharedInstance.calculateRound() + if !RoundCalculatorServie.sharedInstance.isCalculating + && DataService.sharedInstance.didReceiveAllData(){ + RoundCalculatorServie.sharedInstance.calculateRound() } - } } diff --git a/GoldWars/GoldWars/RoundCalculatorService.swift b/GoldWars/GoldWars/RoundCalculatorService.swift index 273b2b0..2032a93 100644 --- a/GoldWars/GoldWars/RoundCalculatorService.swift +++ b/GoldWars/GoldWars/RoundCalculatorService.swift @@ -13,24 +13,28 @@ import os class RoundCalculatorServie { static let sharedInstance = RoundCalculatorServie() + var allPlayerMoves: [String: [PlayerMove]] = [:] var baseSpecificMove: [Int: [(String, PlayerMove)]] = [:] + var isCalculating = false func calculateRound() { + isCalculating = true for entry in DataService.sharedInstance.remotePlayerMoves { addPlayerMove(playerID: entry.key, playerMoves: entry.value) } addPlayerMove(playerID: GKLocalPlayer.local.displayName, playerMoves: DataService.sharedInstance.localPlayerMoves) - // berechnen nach minimal substraction - for entry in allPlayerMoves { for move in entry.value { addFiltedMove(playerName: entry.key, playerMove: move) } } + // berechnen nach minimal substraction + print(baseSpecificMove) + isCalculating = false // sende an alle anderen spieler die moves } @@ -39,6 +43,6 @@ class RoundCalculatorServie { } func addFiltedMove(playerName: String, playerMove: PlayerMove) { - self.baseSpecificMove[playerMove.toBase]!.append((playerName, playerMove)) + self.baseSpecificMove.merge([playerMove.toBase : [(playerName, playerMove)]], uniquingKeysWith: +) } }