From e6d866bc7021fb16a34828f53560d9d582e40a60 Mon Sep 17 00:00:00 2001 From: Aldin Duraki Date: Sat, 6 Jun 2020 19:20:13 +0200 Subject: [PATCH] For better understanding --- GoldWars/GoldWars/Entities/Modal.swift | 3 ++- GoldWars/GoldWars/Scenes/GameScene.swift | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/GoldWars/GoldWars/Entities/Modal.swift b/GoldWars/GoldWars/Entities/Modal.swift index bed5779..3cbcf1d 100644 --- a/GoldWars/GoldWars/Entities/Modal.swift +++ b/GoldWars/GoldWars/Entities/Modal.swift @@ -25,9 +25,10 @@ class Modal: GKEntity{ var body: SKLabelNode var footer: SKLabelNode var overlay: SKSpriteNode + var type: ModalType init(modaltype: ModalType, base: Base?, anchorPoint: CGPoint, gameScene: GameScene, currentDraggedBase: Base?, touchLocation: CGPoint?, collisionBase: Base?) { - + self.type = modaltype unitCount = 0 if base != nil { unitCount = base!.unitCount diff --git a/GoldWars/GoldWars/Scenes/GameScene.swift b/GoldWars/GoldWars/Scenes/GameScene.swift index fd00f43..3158ca6 100644 --- a/GoldWars/GoldWars/Scenes/GameScene.swift +++ b/GoldWars/GoldWars/Scenes/GameScene.swift @@ -122,15 +122,17 @@ class GameScene: SKScene{ func checkSlider(){ for e in entityManager.entities{ if let modal = e as? Modal { - GameScene.sendUnits = ((e.component(ofType: SliderComponent.self)?.sliderNode.getValue ?? 0) * CGFloat((e as! Modal).unitCount)).rounded(.up) - - //TODO: refactor this quick and dirty fix - if GameScene.sendUnits == 0 { - GameScene.sendUnits = 1 - } else if Int(GameScene.sendUnits) == currentDraggedBase?.unitCount { - GameScene.sendUnits -= 1 + if modal.type == ModalType.BaseAttack || modal.type == ModalType.BaseMoveOwnUnits { + GameScene.sendUnits = ((e.component(ofType: SliderComponent.self)?.sliderNode.getValue ?? 0) * CGFloat((e as! Modal).unitCount)).rounded(.up) + + //TODO: refactor this quick and dirty fix + if GameScene.sendUnits == 0 { + GameScene.sendUnits = 1 + } else if Int(GameScene.sendUnits) == currentDraggedBase?.unitCount { + GameScene.sendUnits -= 1 + } + modal.body.text = "Schicke \(GameScene.sendUnits) Einheiten " } - modal.body.text = "Schicke \(GameScene.sendUnits) Einheiten " } } }