From 9fd34d9a6cb0fd36f5728c689a21bbdfce4f792c Mon Sep 17 00:00:00 2001 From: Aldin Duraki Date: Thu, 21 May 2020 02:44:38 +0200 Subject: [PATCH] Minor fixes --- GoldWars/GoldWars/Entities/Base.swift | 5 +- .../GoldWars/Entities/EntityManager.swift | 9 ++-- .../GoldWars/RoundCalculatorService.swift | 1 - GoldWars/GoldWars/Scenes/GameScene.swift | 48 ++++++++++--------- 4 files changed, 33 insertions(+), 30 deletions(-) diff --git a/GoldWars/GoldWars/Entities/Base.swift b/GoldWars/GoldWars/Entities/Base.swift index 4f695c9..0749085 100644 --- a/GoldWars/GoldWars/Entities/Base.swift +++ b/GoldWars/GoldWars/Entities/Base.swift @@ -31,9 +31,10 @@ class Base: GKEntity{ self.position = position super.init() - addComponent(DefaultBaseComponent(texture: SKTexture(imageNamed: "Base"), position: position)) + let spritePos = position + addComponent(DefaultBaseComponent(texture: SKTexture(imageNamed: "Base"), position: spritePos)) if(team != nil && player != nil){ - addComponent(TeamComponent(team: team!, player: player!, position: position)) + addComponent(TeamComponent(team: team!, player: player!, position: spritePos)) self.unitCount = 500 } } diff --git a/GoldWars/GoldWars/Entities/EntityManager.swift b/GoldWars/GoldWars/Entities/EntityManager.swift index f18dcf4..3cfafa7 100644 --- a/GoldWars/GoldWars/Entities/EntityManager.swift +++ b/GoldWars/GoldWars/Entities/EntityManager.swift @@ -43,10 +43,10 @@ class EntityManager { scene.addChild(modal.header) scene.addChild(modal.body) scene.addChild(modal.footer) + isModal = true } if let skillButtonNode = entity.component(ofType: AtkBoostSkillComponent.self)?.skillButtonNode { scene.addChild(skillButtonNode) - isModal = true } if let skillButtonNode = entity.component(ofType: DefBoostSkillComponent.self)?.skillButtonNode { scene.addChild(skillButtonNode) @@ -60,7 +60,6 @@ class EntityManager { } if let buttonNode = entity.component(ofType: ButtonComponent.self)?.buttonNode { scene.addChild(buttonNode) - isModal = true } if let nodes = entity.component(ofType: BackgroundComponent.self)?.nodes { for node in nodes { @@ -76,7 +75,6 @@ class EntityManager { } if let cancelBtnNode = entity.component(ofType: CancelBtnComponent.self)?.cancelBtnNode { scene.addChild(cancelBtnNode) - isModal = true } if let node = entity.component(ofType: SpinningLogoComponent.self)?.node { scene.addChild(node) @@ -97,6 +95,7 @@ class EntityManager { modal.header.removeFromParent() modal.body.removeFromParent() modal.footer.removeFromParent() + isModal = false } if let sliderNode = entity.component(ofType: SliderComponent.self)?.sliderNode { sliderNode.sliderKnob.removeFromParent() @@ -104,11 +103,9 @@ class EntityManager { } if let modalButton = entity.component(ofType: ButtonComponent.self) { modalButton.buttonNode.removeFromParent() - isModal = false } if let cancelBtnNode = entity.component(ofType: CancelBtnComponent.self)?.cancelBtnNode { cancelBtnNode.removeFromParent() - isModal = false } entities.remove(entity) } @@ -147,6 +144,8 @@ class EntityManager { if snapBase.ownership != nil { getOwnerBySnapBase = MatchmakingHelper.sharedInstance.getGKPlayerByUsername(displayName: snapBase.ownership!) + } else { + entity.removeComponent(ofType: TeamComponent.self) } if getOwnerBySnapBase != nil { base.changeOwnership = true diff --git a/GoldWars/GoldWars/RoundCalculatorService.swift b/GoldWars/GoldWars/RoundCalculatorService.swift index b9186c6..a07fa2f 100644 --- a/GoldWars/GoldWars/RoundCalculatorService.swift +++ b/GoldWars/GoldWars/RoundCalculatorService.swift @@ -111,7 +111,6 @@ 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) } diff --git a/GoldWars/GoldWars/Scenes/GameScene.swift b/GoldWars/GoldWars/Scenes/GameScene.swift index 31eec3b..962fe46 100644 --- a/GoldWars/GoldWars/Scenes/GameScene.swift +++ b/GoldWars/GoldWars/Scenes/GameScene.swift @@ -13,7 +13,6 @@ import GameKit class GameScene: SKScene{ var isMoveTouch = false - var currentDraggedBasePos = CGPoint() var currentDraggedBase : Base? static var sendUnits: CGFloat = 0 var collisionBase: Base? @@ -42,8 +41,8 @@ class GameScene: SKScene{ if isMoveTouch{ isMoveTouch = false - currentDraggedBase!.component(ofType: DefaultBaseComponent.self)?.spriteNode.position = currentDraggedBasePos - currentDraggedBase!.component(ofType: TeamComponent.self)?.fire.position = currentDraggedBasePos + currentDraggedBase!.component(ofType: DefaultBaseComponent.self)?.spriteNode.position = currentDraggedBase!.position + currentDraggedBase!.component(ofType: TeamComponent.self)?.fire.position = currentDraggedBase!.position addAttackDetails(touchLocation: touchLocation) } @@ -51,6 +50,7 @@ class GameScene: SKScene{ for entity in EntityManager.sharedInstance.entities { let spriteNode = entity.component(ofType: DefaultBaseComponent.self)?.spriteNode + //FIXME: this is confusing addBaseDetails(touchLocation: touchLocation, spriteNode: spriteNode, touches: touches, event: event, entity: entity) } } @@ -83,17 +83,20 @@ class GameScene: SKScene{ func addBaseDetails(touchLocation: CGPoint, spriteNode: SKNode?, touches: Set, event: UIEvent?, entity: GKEntity){ if atPoint(touchLocation) == spriteNode && !EntityManager.sharedInstance.isModal { spriteNode?.touchesBegan(touches, with: event) - if !EntityManager.sharedInstance.isModal { - for child in self.children { - if(child.name != "fire"){ - child.alpha = 0.3 + if let baseEntity = entity as? Base { + if baseEntity.ownershipPlayer == GKLocalPlayer.local { + for child in self.children { + if(child.name != "fire"){ + child.alpha = 0.3 + } } + EntityManager.sharedInstance.add(Modal(modaltype: .BaseDetails, + base: entity as! Base, + anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2), + gameScene: self, + currentDraggedBase: currentDraggedBase, touchLocation: touchLocation, collisionBase: collisionBase)) + } - EntityManager.sharedInstance.add(Modal(modaltype: .BaseDetails, - base: entity as! Base, - anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2), - gameScene: self, currentDraggedBase: currentDraggedBase, touchLocation: touchLocation, collisionBase: collisionBase)) - } } } @@ -103,12 +106,13 @@ class GameScene: SKScene{ if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode { collisionBase = base // TODO: change interaction based on collision instead of touchlocation - EntityManager.sharedInstance.add(Modal(modaltype: .BaseAttack, - base: currentDraggedBase!, - anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2), - gameScene: self, currentDraggedBase: currentDraggedBase, touchLocation: touchLocation, collisionBase: collisionBase)) - GameScene.sendUnits = CGFloat(currentDraggedBase!.unitCount / 2) - + if currentDraggedBase!.unitCount > 1 { + EntityManager.sharedInstance.add(Modal(modaltype: .BaseAttack, + base: currentDraggedBase!, + anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2), + gameScene: self, currentDraggedBase: currentDraggedBase, touchLocation: touchLocation, collisionBase: collisionBase)) + GameScene.sendUnits = CGFloat(currentDraggedBase!.unitCount / 2) + } } } } @@ -118,7 +122,7 @@ class GameScene: SKScene{ if let body = e.component(ofType: ModalContentComponent.self)?.body{ GameScene.sendUnits = ((e.component(ofType: SliderComponent.self)?.sliderNode.getValue ?? 0) * CGFloat((e as! Modal).unitCount)).rounded(.up) - //TODO: quick fix chauntalle die olle mach augen auf + //TODO: refactor this quick and dirty fix if GameScene.sendUnits == 0 { GameScene.sendUnits = 1 } else if Int(GameScene.sendUnits) == currentDraggedBase?.unitCount { @@ -131,9 +135,9 @@ class GameScene: SKScene{ func checkBases(bases: Set, touchLocation: CGPoint){ for base in bases { - if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode{ if !isMoveTouch { - currentDraggedBasePos = base.component(ofType: DefaultBaseComponent.self)!.spriteNode.position - currentDraggedBase = base + if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode{ + if !isMoveTouch { + currentDraggedBase = base } isMoveTouch = true moveFireAndBase(base: base, touchLocation: touchLocation)