Synching players timer since playermoves would not register before calculating
This commit is contained in:
parent
5df7fd3dac
commit
ad44ba8302
@ -13,6 +13,7 @@ class TimerComponent: GKComponent {
|
||||
let labelNode :SKLabelNode
|
||||
var endTime :Date!
|
||||
var duration :Double
|
||||
var isRunning = false
|
||||
|
||||
init(text: String, anchorPoint: CGPoint, duration: TimeInterval) {
|
||||
self.labelNode = SKLabelNode(text: text)
|
||||
@ -25,18 +26,26 @@ class TimerComponent: GKComponent {
|
||||
}
|
||||
|
||||
func startWithDuration(duration: TimeInterval){
|
||||
isRunning = true
|
||||
endTime = Date().addingTimeInterval(duration)
|
||||
RoundCalculatorService.sharedInstance.isCalculating = false
|
||||
}
|
||||
|
||||
func timeLeft() -> Int {
|
||||
if isRunning {
|
||||
let remainingSeconds = Int(endTime.timeIntervalSince(Date()))
|
||||
if(remainingSeconds < 0 && DataService.sharedInstance.didReceiveAllData()){
|
||||
startWithDuration(duration: duration)
|
||||
if(remainingSeconds == 0) {
|
||||
isRunning = false
|
||||
}
|
||||
return remainingSeconds
|
||||
}
|
||||
|
||||
// if(remainingSeconds < 0){
|
||||
// startWithDuration(duration: duration)
|
||||
// }
|
||||
return 0
|
||||
}
|
||||
|
||||
func isFinished() -> Bool {
|
||||
return timeLeft() == 0
|
||||
}
|
||||
|
@ -259,4 +259,8 @@ class EntityManager {
|
||||
|
||||
return SnapshotModel(baseEntites: snapBase)
|
||||
}
|
||||
|
||||
func getTimer() -> TimerComponent {
|
||||
return entities.filter{$0 is HUD}[0].component(ofType: TimerComponent.self)!
|
||||
}
|
||||
}
|
||||
|
@ -120,6 +120,7 @@ class MatchmakingHelper: NSObject, GKMatchmakerViewControllerDelegate, GKMatchDe
|
||||
if let snapshotModel = try? jsonDecoder.decode(SnapshotModel.self, from: data) {
|
||||
DataService.sharedInstance.snapshotModel = snapshotModel
|
||||
EntityManager.sharedInstance.updateSnapshotModel(snapshotModel: snapshotModel)
|
||||
EntityManager.sharedInstance.getTimer().startWithDuration(duration: 31)
|
||||
}
|
||||
|
||||
if let mapModel = try? jsonDecoder.decode(MapGenerationModel.self, from: data) {
|
||||
|
@ -111,6 +111,8 @@ class RoundCalculatorService {
|
||||
MultiplayerNetwork.sharedInstance.sendSnapshotModelToPlayers()
|
||||
DataService.sharedInstance.snapshotModel = currentSnapshotModel
|
||||
EntityManager.sharedInstance.updateSnapshotModel(snapshotModel: currentSnapshotModel!)
|
||||
sleep(1)
|
||||
EntityManager.sharedInstance.getTimer().startWithDuration(duration: 31)
|
||||
os_log("Finished calculating Round", log: RoundCalculatorService.LOG, type: .info)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user