Test crash bugfix

This commit is contained in:
Aldin Duraki 2020-07-02 12:48:51 +02:00
parent 5d8df46361
commit f4cd97cac7

View File

@ -13,6 +13,7 @@ class RoundTimer: Timer {
var timer: Timer?
var timeLeft: Int = 0
var isHeartbeatLocked = false
var isTimerStopped = false
var calculate = false
var roundEnded = "Syncing"
@ -31,48 +32,42 @@ class RoundTimer: Timer {
}
func stopTimer() {
guard timer != nil else { return }
timer?.invalidate()
timer = nil
isTimerStopped = true
}
func resumeTimer() {
timer = Timer.scheduledTimer(
timeInterval: 1.0,
target: self,
selector: #selector(onTimerFires),
userInfo: nil,
repeats: true
)
isTimerStopped = false
}
@objc func onTimerFires()
{
timeLeft -= 1
EntityManager.gameEMInstance.updateTime(time: (timeLeft > 0 ? String(timeLeft) : roundEnded))
if timeLeft == 0 {
EntityManager.gameEMInstance.removeModal()
RoundCalculatorService.sharedInstance.resetNumberOfAttacksAndFormats()
if !MultiplayerNetwork.sharedInstance.isSending {
MultiplayerNetwork.sharedInstance.sendPlayerMoves(localRoundData: DataService.sharedInstance.localRoundData)
if !isTimerStopped {
timeLeft -= 1
EntityManager.gameEMInstance.updateTime(time: (timeLeft > 0 ? String(timeLeft) : roundEnded))
if timeLeft == 0 {
EntityManager.gameEMInstance.removeModal()
RoundCalculatorService.sharedInstance.resetNumberOfAttacksAndFormats()
if !MultiplayerNetwork.sharedInstance.isSending {
MultiplayerNetwork.sharedInstance.sendPlayerMoves(localRoundData: DataService.sharedInstance.localRoundData)
}
calculate = true
}
calculate = true
}
if timeLeft <= 0 {
if calculate
&& !RoundCalculatorService.sharedInstance.isCalculating
&& DataService.sharedInstance.didReceiveAllData()
&& GameCenterManager.sharedInstance.isServer {
RoundCalculatorService.sharedInstance.calculateRound()
calculate = false
if timeLeft <= 0 {
if calculate
&& !RoundCalculatorService.sharedInstance.isCalculating
&& DataService.sharedInstance.didReceiveAllData()
&& GameCenterManager.sharedInstance.isServer {
RoundCalculatorService.sharedInstance.calculateRound()
calculate = false
}
}
if (!isHeartbeatLocked && (timeLeft % 7 == 0)){
MultiplayerNetwork.sharedInstance.sendHeartbeatToPlayer()
isHeartbeatLocked = true;
}
}
if (!isHeartbeatLocked && (timeLeft % 7 == 0)){
MultiplayerNetwork.sharedInstance.sendHeartbeatToPlayer()
isHeartbeatLocked = true;
}
}
}