cleaned up modal, added func for sending units

This commit is contained in:
Chauntalle Schüle 2020-05-16 18:25:22 +02:00
parent a7e6cd9f10
commit 25c57ceb74

View File

@ -11,7 +11,6 @@ import GameplayKit
class Modal: GKEntity{
var unitCount:Int
//var currentDraggedBase: Base?
init(modaltype: ModalType, base: Base, anchorPoint: CGPoint, entityManager: EntityManager, gameScene: GameScene, currentDraggedBase: Base?, touchLocation: CGPoint) {
unitCount = base.unitCount
@ -29,22 +28,8 @@ class Modal: GKEntity{
addComponent(ModalContentComponent(header: "Angriff", body: "Schicke \(unitCount / 2) Einheiten",
footer: "", anchorPoint: anchorPoint))
addComponent(ButtonComponent(iconName: "", text: "Senden", position: CGPoint(x: anchorPoint.x , y: anchorPoint.y - 120), isEnabled: true, onButtonPress: {
//on Button press: sollen einheiten verrechnet werden,bei einheiten größer 0 feuer, entities removed werden
// self.currentDraggedBase!.component(ofType: TeamComponent.self)?.fire.position = currentDraggedBasePos
for base in currentDraggedBase!.adjacencyList {
print("in here")
if gameScene.atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode {
print("in here 2")
if !(entityManager.getTeamByBase(base: currentDraggedBase!) == entityManager.getTeamByBase(base: base)){
print("sendUnits \(Int(GameScene.sendUnits))")
entityManager.update((currentDraggedBase?.attackBase(base: base, units: Int(GameScene.sendUnits)))!)
// print("in here 3")
// sendUnits = 0
}
}
}
self.sendUnits(currentDraggedBase: currentDraggedBase, touchLocation: touchLocation, entityManager: entityManager, gameScene: gameScene)
self.removeModalEntities(entityManager: entityManager, gameScene: gameScene)
}))
addComponent(CancelBtnComponent(iconName: "", text: "", position: CGPoint(x: anchorPoint.x + 160, y: anchorPoint.y + 140), isEnabled: true, onButtonPress: {
self.removeModalEntities(entityManager: entityManager, gameScene: gameScene)
@ -68,4 +53,14 @@ class Modal: GKEntity{
}
}
}
func sendUnits(currentDraggedBase: Base?, touchLocation: CGPoint, entityManager: EntityManager, gameScene: GameScene){
for base in currentDraggedBase!.adjacencyList {
if gameScene.atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode {
if !(entityManager.getTeamByBase(base: currentDraggedBase!) == entityManager.getTeamByBase(base: base)){
entityManager.update((currentDraggedBase?.attackBase(base: base, units: Int(GameScene.sendUnits)))!)
}
}
}
}
}