From 37fba97953f51f23845c52be44f4903b3e1f0a82 Mon Sep 17 00:00:00 2001 From: Jakob Haag Date: Thu, 28 May 2020 18:21:09 +0200 Subject: [PATCH 1/8] Add RoundTimer and adjust TimerComponent --- GoldWars/GoldWars.xcodeproj/project.pbxproj | 1 + GoldWars/GoldWars/Components/TimerComponent.swift | 0 2 files changed, 1 insertion(+) create mode 100644 GoldWars/GoldWars/Components/TimerComponent.swift diff --git a/GoldWars/GoldWars.xcodeproj/project.pbxproj b/GoldWars/GoldWars.xcodeproj/project.pbxproj index 38ce07b..4894f3b 100644 --- a/GoldWars/GoldWars.xcodeproj/project.pbxproj +++ b/GoldWars/GoldWars.xcodeproj/project.pbxproj @@ -410,6 +410,7 @@ 8BB6FF402472B8F000162BBD /* SingeClickButtonNode.swift in Sources */, C064E9A8246C0EA50022B228 /* LabelNode.swift in Sources */, 3F745DF0246F48FC00CE7375 /* PlayerMoveType.swift in Sources */, + AB1D75A0245DEC0500671525 /* MapFactory.swift in Sources */, 3EAD889524801B6A0048A10A /* RoundTimer.swift in Sources */, 3E67854024728368007B9DE4 /* CElements.swift in Sources */, ABA03DA0244BD54F00A66916 /* Base.swift in Sources */, diff --git a/GoldWars/GoldWars/Components/TimerComponent.swift b/GoldWars/GoldWars/Components/TimerComponent.swift new file mode 100644 index 0000000..e69de29 From bddd226ffd22de429d90c00071fe4b6d6f14fee3 Mon Sep 17 00:00:00 2001 From: Jakob Haag Date: Sat, 30 May 2020 14:46:42 +0200 Subject: [PATCH 2/8] Remove TimeComponent and set TimerLabel in the HUD. Reset Timer via RoundTimer --- GoldWars/GoldWars.xcodeproj/project.pbxproj | 1 - GoldWars/GoldWars/Entities/EntityManager.swift | 1 - 2 files changed, 2 deletions(-) diff --git a/GoldWars/GoldWars.xcodeproj/project.pbxproj b/GoldWars/GoldWars.xcodeproj/project.pbxproj index 4894f3b..38ce07b 100644 --- a/GoldWars/GoldWars.xcodeproj/project.pbxproj +++ b/GoldWars/GoldWars.xcodeproj/project.pbxproj @@ -410,7 +410,6 @@ 8BB6FF402472B8F000162BBD /* SingeClickButtonNode.swift in Sources */, C064E9A8246C0EA50022B228 /* LabelNode.swift in Sources */, 3F745DF0246F48FC00CE7375 /* PlayerMoveType.swift in Sources */, - AB1D75A0245DEC0500671525 /* MapFactory.swift in Sources */, 3EAD889524801B6A0048A10A /* RoundTimer.swift in Sources */, 3E67854024728368007B9DE4 /* CElements.swift in Sources */, ABA03DA0244BD54F00A66916 /* Base.swift in Sources */, diff --git a/GoldWars/GoldWars/Entities/EntityManager.swift b/GoldWars/GoldWars/Entities/EntityManager.swift index 8b95144..b115459 100644 --- a/GoldWars/GoldWars/Entities/EntityManager.swift +++ b/GoldWars/GoldWars/Entities/EntityManager.swift @@ -51,7 +51,6 @@ class EntityManager { scene.addChild(hudEntitiy.atkSkill) scene.addChild(hudEntitiy.spySkill) scene.addChild(hudEntitiy.roundTimerLabel) - isModal = true } if let spriteNode = entity.component(ofType: DefaultBaseComponent.self) { From 99b57cc4cdbea9b9356ddce958bf7fddd67f3d74 Mon Sep 17 00:00:00 2001 From: Jakob Haag Date: Thu, 28 May 2020 16:52:03 +0200 Subject: [PATCH 3/8] add finishButton to HUD --- GoldWars/GoldWars/Entities/EntityManager.swift | 1 + GoldWars/GoldWars/Entities/HUD.swift | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/GoldWars/GoldWars/Entities/EntityManager.swift b/GoldWars/GoldWars/Entities/EntityManager.swift index b115459..b739eca 100644 --- a/GoldWars/GoldWars/Entities/EntityManager.swift +++ b/GoldWars/GoldWars/Entities/EntityManager.swift @@ -51,6 +51,7 @@ class EntityManager { scene.addChild(hudEntitiy.atkSkill) scene.addChild(hudEntitiy.spySkill) scene.addChild(hudEntitiy.roundTimerLabel) + scene.addChild(hudEntitiy.finishButton) } if let spriteNode = entity.component(ofType: DefaultBaseComponent.self) { diff --git a/GoldWars/GoldWars/Entities/HUD.swift b/GoldWars/GoldWars/Entities/HUD.swift index 0d6c4f7..6c08562 100644 --- a/GoldWars/GoldWars/Entities/HUD.swift +++ b/GoldWars/GoldWars/Entities/HUD.swift @@ -27,14 +27,22 @@ class HUD: GKEntity { var roundTimerLabel: SKLabelNode let roundTimer: RoundTimer + var finishButton: ButtonNode + init(size: CGSize) { + finishButton = ButtonNode(textureName: "yellow_button04", text: "Finish Round", isEnabled: true, position: CGPoint(x: EntityManager.gameEMInstance.scene.size.width * 0.15, y: EntityManager.gameEMInstance.scene.size.height * 0.1), + onButtonPress: { print("Finish Round") } + ) + finishButton.size = CGSize(width: 225, height: 40) + finishButton.zPosition = 4 + host = GameCenterManager.sharedInstance.hostingPlayer peer = GameCenterManager.sharedInstance.peerPlayer hostLabel = SKLabelNode(text: host?.displayName) hostUnitsLabel = SKLabelNode(text: "500" ) peerLabel = SKLabelNode(text: peer?.displayName) peerUnitsLabel = SKLabelNode(text: "500") - + roundTimerLabel = SKLabelNode(text: "") roundTimerLabel.fontColor = UIColor.black roundTimerLabel.fontSize = CGFloat(45) From eadcec10d8c3ec9730a355b10f576db9d3dc11b7 Mon Sep 17 00:00:00 2001 From: Jakob Haag Date: Mon, 1 Jun 2020 16:33:52 +0200 Subject: [PATCH 4/8] init function of finish button --- GoldWars/GoldWars/Components/ButtonNode.swift | 2 +- GoldWars/GoldWars/Entities/HUD.swift | 30 ++++++++++++++----- GoldWars/GoldWars/RoundTimer.swift | 4 ++- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/GoldWars/GoldWars/Components/ButtonNode.swift b/GoldWars/GoldWars/Components/ButtonNode.swift index ab92e38..b98164a 100644 --- a/GoldWars/GoldWars/Components/ButtonNode.swift +++ b/GoldWars/GoldWars/Components/ButtonNode.swift @@ -22,7 +22,7 @@ class ButtonNode: SKSpriteNode { } } - let onButtonPress: () -> () + var onButtonPress: () -> () init(textureName: String, text: String, isEnabled: Bool, position: CGPoint, onButtonPress: @escaping () -> ()) { self.onButtonPress = onButtonPress diff --git a/GoldWars/GoldWars/Entities/HUD.swift b/GoldWars/GoldWars/Entities/HUD.swift index 6c08562..aaf2f57 100644 --- a/GoldWars/GoldWars/Entities/HUD.swift +++ b/GoldWars/GoldWars/Entities/HUD.swift @@ -30,12 +30,6 @@ class HUD: GKEntity { var finishButton: ButtonNode init(size: CGSize) { - finishButton = ButtonNode(textureName: "yellow_button04", text: "Finish Round", isEnabled: true, position: CGPoint(x: EntityManager.gameEMInstance.scene.size.width * 0.15, y: EntityManager.gameEMInstance.scene.size.height * 0.1), - onButtonPress: { print("Finish Round") } - ) - finishButton.size = CGSize(width: 225, height: 40) - finishButton.zPosition = 4 - host = GameCenterManager.sharedInstance.hostingPlayer peer = GameCenterManager.sharedInstance.peerPlayer hostLabel = SKLabelNode(text: host?.displayName) @@ -46,7 +40,8 @@ class HUD: GKEntity { roundTimerLabel = SKLabelNode(text: "") roundTimerLabel.fontColor = UIColor.black roundTimerLabel.fontSize = CGFloat(45) - roundTimerLabel.position = CGPoint(x: size.width * 0.5, y: size.height * 0.9 - 15) + roundTimerLabel.position = CGPoint(x: size.width * 0.5, y: size.height * 0.9) + roundTimerLabel.horizontalAlignmentMode = .center self.roundTimer = RoundTimer() @@ -71,7 +66,22 @@ class HUD: GKEntity { position: CGPoint(x: EntityManager.gameEMInstance.scene.size.width * 0.95, y: EntityManager.gameEMInstance.scene.size.height * 0.1), onButtonPress: {DataService.sharedInstance.localRoundData.hasAttackBoost = true} ) + + finishButton = ButtonNode( + textureName: "yellow_button04", + text: "Finish Round", + isEnabled: true, + position: CGPoint(x: EntityManager.gameEMInstance.scene.size.width * 0.15, y: EntityManager.gameEMInstance.scene.size.height * 0.1), + onButtonPress: { } + ) + finishButton.size = CGSize(width: 250, height: 40) + finishButton.zPosition = 4 super.init() + + finishButton.onButtonPress = { [unowned self] in + self.finishRound() + } + hostLabel.position = CGPoint(x: size.width * 0.02, y: size.height * 0.95) hostLabel.horizontalAlignmentMode = .left peerLabel.position = CGPoint(x: size.width * 0.98, y: size.height * 0.95) @@ -101,6 +111,12 @@ class HUD: GKEntity { func startWithDuration(){ roundTimer.startTimer() + self.roundTimer.roundEnded = "Syncing" RoundCalculatorService.sharedInstance.isCalculating = false } + + func finishRound() -> () { + self.roundTimer.timeLeft = 1; + self.roundTimer.roundEnded = "Waiting for other player..." + } } diff --git a/GoldWars/GoldWars/RoundTimer.swift b/GoldWars/GoldWars/RoundTimer.swift index 92dfb28..2faa03a 100644 --- a/GoldWars/GoldWars/RoundTimer.swift +++ b/GoldWars/GoldWars/RoundTimer.swift @@ -13,6 +13,7 @@ class RoundTimer: Timer { var timer: Timer? var timeLeft: Int = 0 var calculate = false + var roundEnded = "Syncing" func initTimer() { timer = Timer.scheduledTimer( @@ -32,7 +33,7 @@ class RoundTimer: Timer { { timeLeft = timeLeft - 1 - EntityManager.gameEMInstance.updateTime(time: (timeLeft > 0 ? String(timeLeft) : "Syncing")) + EntityManager.gameEMInstance.updateTime(time: (timeLeft > 0 ? String(timeLeft) : roundEnded)) if timeLeft == 0 { RoundCalculatorService.sharedInstance.resetNumberOfAttacksAndFormats() @@ -40,6 +41,7 @@ class RoundTimer: Timer { MultiplayerNetwork.sharedInstance.sendPlayerMoves(localRoundData: DataService.sharedInstance.localRoundData) } calculate = true + print("send Player Moves") } if timeLeft <= 0 { if calculate From a086a7779b6f8c2947f6d5ef8908efed3e1cefe6 Mon Sep 17 00:00:00 2001 From: Jakob Haag Date: Mon, 1 Jun 2020 20:34:44 +0200 Subject: [PATCH 5/8] fix rebase issues --- GoldWars/GoldWars/RoundCalculatorService.swift | 4 ++-- GoldWars/GoldWars/RoundTimer.swift | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/GoldWars/GoldWars/RoundCalculatorService.swift b/GoldWars/GoldWars/RoundCalculatorService.swift index 7372c9e..3fb1688 100644 --- a/GoldWars/GoldWars/RoundCalculatorService.swift +++ b/GoldWars/GoldWars/RoundCalculatorService.swift @@ -201,9 +201,9 @@ class RoundCalculatorService { func increaseMoveCounter(ownBase: Bool!) { if ownBase { - self.numberOfOwnUnitMoves = self.numberOfOwnUnitMoves + 1 + self.numberOfOwnUnitMoves += 1 } else { - self.numberOfAttacks = self.numberOfAttacks + 1 + self.numberOfAttacks += 1 } } } diff --git a/GoldWars/GoldWars/RoundTimer.swift b/GoldWars/GoldWars/RoundTimer.swift index 2faa03a..34c5d3d 100644 --- a/GoldWars/GoldWars/RoundTimer.swift +++ b/GoldWars/GoldWars/RoundTimer.swift @@ -31,7 +31,7 @@ class RoundTimer: Timer { @objc func onTimerFires() { - timeLeft = timeLeft - 1 + timeLeft -= 1 EntityManager.gameEMInstance.updateTime(time: (timeLeft > 0 ? String(timeLeft) : roundEnded)) From eaa71d1d7364e248c7f9f4130e0574ae3a8ebc57 Mon Sep 17 00:00:00 2001 From: Jakob Haag Date: Tue, 2 Jun 2020 09:34:32 +0200 Subject: [PATCH 6/8] fix crash on spamming finish button --- GoldWars/GoldWars/Entities/HUD.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/GoldWars/GoldWars/Entities/HUD.swift b/GoldWars/GoldWars/Entities/HUD.swift index aaf2f57..507ec4d 100644 --- a/GoldWars/GoldWars/Entities/HUD.swift +++ b/GoldWars/GoldWars/Entities/HUD.swift @@ -67,7 +67,7 @@ class HUD: GKEntity { onButtonPress: {DataService.sharedInstance.localRoundData.hasAttackBoost = true} ) - finishButton = ButtonNode( + finishButton = SingeClickButtonNode( textureName: "yellow_button04", text: "Finish Round", isEnabled: true, @@ -111,6 +111,7 @@ class HUD: GKEntity { func startWithDuration(){ roundTimer.startTimer() + finishButton.isEnabled = true self.roundTimer.roundEnded = "Syncing" RoundCalculatorService.sharedInstance.isCalculating = false } From 42f4537dc643982a9d144484db856a24c3dceeb5 Mon Sep 17 00:00:00 2001 From: Aldin Duraki Date: Tue, 2 Jun 2020 11:01:15 +0200 Subject: [PATCH 7/8] Fixed scope issue on collected playerMoves --- GoldWars/GoldWars/RoundCalculatorService.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/GoldWars/GoldWars/RoundCalculatorService.swift b/GoldWars/GoldWars/RoundCalculatorService.swift index 3fb1688..fc57f96 100644 --- a/GoldWars/GoldWars/RoundCalculatorService.swift +++ b/GoldWars/GoldWars/RoundCalculatorService.swift @@ -35,7 +35,7 @@ class RoundCalculatorService { var baseSpecificMoves = collectBaseSpecificMoves() // TODO: Refactor to a less complex way - for (baseId, var playerMovesByBase) in baseSpecificMoves { + for (baseId, playerMovesByBase) in baseSpecificMoves { let targetBase = currentSnapshotModel?.baseEntites.filter { $0.baseId == baseId }[0] let possiblyOwnershipMoves = playerMovesByBase.filter { $0.key == targetBase?.ownership} @@ -50,10 +50,10 @@ class RoundCalculatorService { } } } - playerMovesByBase.removeValue(forKey: playerName) + baseSpecificMoves[baseId]!.removeValue(forKey: playerName) } - for (_, playerMoves) in playerMovesByBase { + for playerMoves in baseSpecificMoves[baseId]!.values { for playerMove in playerMoves { for base in currentSnapshotModel!.baseEntites { if base.baseId == playerMove.fromBase { From 2ba541e369d3419e94a14149f911f5b9e850d9e0 Mon Sep 17 00:00:00 2001 From: Jakob Haag Date: Tue, 2 Jun 2020 11:06:49 +0200 Subject: [PATCH 8/8] Resize Button, adjust position and change text --- GoldWars/GoldWars/Entities/HUD.swift | 8 +++++--- GoldWars/GoldWars/RoundTimer.swift | 1 - 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/GoldWars/GoldWars/Entities/HUD.swift b/GoldWars/GoldWars/Entities/HUD.swift index 507ec4d..6ff9a2d 100644 --- a/GoldWars/GoldWars/Entities/HUD.swift +++ b/GoldWars/GoldWars/Entities/HUD.swift @@ -69,12 +69,14 @@ class HUD: GKEntity { finishButton = SingeClickButtonNode( textureName: "yellow_button04", - text: "Finish Round", + text: "Done", isEnabled: true, - position: CGPoint(x: EntityManager.gameEMInstance.scene.size.width * 0.15, y: EntityManager.gameEMInstance.scene.size.height * 0.1), + position: CGPoint( + x: EntityManager.gameEMInstance.scene.size.width * 0.1, + y: EntityManager.gameEMInstance.scene.size.height * 0.1), onButtonPress: { } ) - finishButton.size = CGSize(width: 250, height: 40) + finishButton.size = CGSize(width: 80, height: 40) finishButton.zPosition = 4 super.init() diff --git a/GoldWars/GoldWars/RoundTimer.swift b/GoldWars/GoldWars/RoundTimer.swift index 34c5d3d..8f27a60 100644 --- a/GoldWars/GoldWars/RoundTimer.swift +++ b/GoldWars/GoldWars/RoundTimer.swift @@ -41,7 +41,6 @@ class RoundTimer: Timer { MultiplayerNetwork.sharedInstance.sendPlayerMoves(localRoundData: DataService.sharedInstance.localRoundData) } calculate = true - print("send Player Moves") } if timeLeft <= 0 { if calculate