Bug fixed: gameScene blieb nach beenden der Anzeige von Modal Basis Informationen dunkel

This commit is contained in:
Chauntalle Schüle 2020-05-14 14:23:44 +02:00 committed by Chauntalle Schüle
parent 5feb831873
commit 8342c2e550
2 changed files with 51 additions and 58 deletions

View File

@ -11,18 +11,16 @@ import GameplayKit
class Modal: GKEntity{ class Modal: GKEntity{
var unitCount:Int var unitCount:Int
var modalEntityManager: EntityManager
init(modaltype: ModalType, base: Base, anchorPoint: CGPoint, entityManager: EntityManager) { init(modaltype: ModalType, base: Base, anchorPoint: CGPoint, entityManager: EntityManager, gameScene: SKScene) {
unitCount = base.unitCount unitCount = base.unitCount
modalEntityManager = entityManager
super.init() super.init()
switch modaltype{ switch modaltype{
case .BaseDetails: case .BaseDetails:
addComponent(ModalBackgroundComponent(anchorPoint: anchorPoint)) addComponent(ModalBackgroundComponent(anchorPoint: anchorPoint))
addComponent(ModalContentComponent(header: "Basis Information", body: "Diese Basis enthält \(base.unitCount) Einheiten", footer: "", anchorPoint: anchorPoint)) addComponent(ModalContentComponent(header: "Basis Information", body: "Diese Basis enthält \(base.unitCount) Einheiten", footer: "", anchorPoint: anchorPoint))
addComponent(ButtonComponent(iconName: "", text: "Zurück", position: CGPoint(x: anchorPoint.x , y: anchorPoint.y - 120), isEnabled: true, onButtonPress: { addComponent(ButtonComponent(iconName: "", text: "Zurück", position: CGPoint(x: anchorPoint.x , y: anchorPoint.y - 120), isEnabled: true, onButtonPress: {
self.removeModalEntities(entityManager: self.modalEntityManager) self.removeModalEntities(entityManager: entityManager, gameScene: gameScene)
})) }))
case .BaseAttack: case .BaseAttack:
addComponent(ModalBackgroundComponent(anchorPoint: anchorPoint)) addComponent(ModalBackgroundComponent(anchorPoint: anchorPoint))
@ -30,7 +28,7 @@ class Modal: GKEntity{
addComponent(ModalContentComponent(header: "Angriff", body: "Schicke \(unitCount / 2) Einheiten", addComponent(ModalContentComponent(header: "Angriff", body: "Schicke \(unitCount / 2) Einheiten",
footer: "", anchorPoint: anchorPoint)) footer: "", anchorPoint: anchorPoint))
addComponent(ButtonComponent(iconName: "", text: "Senden", position: CGPoint(x: anchorPoint.x , y: anchorPoint.y - 120), isEnabled: true, onButtonPress: { addComponent(ButtonComponent(iconName: "", text: "Senden", position: CGPoint(x: anchorPoint.x , y: anchorPoint.y - 120), isEnabled: true, onButtonPress: {
self.removeModalEntities(entityManager: self.modalEntityManager) self.removeModalEntities(entityManager: entityManager, gameScene: gameScene)
})) }))
} }
} }
@ -39,11 +37,16 @@ class Modal: GKEntity{
fatalError("init(coder:) has not been implemented") fatalError("init(coder:) has not been implemented")
} }
func removeModalEntities(entityManager: EntityManager){ func removeModalEntities(entityManager: EntityManager, gameScene: SKScene){
for entity in entityManager.entities { for entity in entityManager.entities {
if entityManager.isModal && entity.isMember(of: Modal.self) { if entityManager.isModal && entity.isMember(of: Modal.self) {
entityManager.remove(entity) entityManager.remove(entity)
} }
for child in gameScene.children {
if(child.name != "fire"){
child.alpha = 1
}
}
} }
} }
} }

View File

@ -22,55 +22,45 @@ class GameScene: SKScene{
entityManager.add(Background(size: self.size)) entityManager.add(Background(size: self.size))
initMap() initMap()
} }
func initMap() { func initMap() {
MapFactory(scene: self, entityManager: self.entityManager).loadMap(playerCount: 2) MapFactory(scene: self, entityManager: self.entityManager).loadMap(playerCount: 2)
} }
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) { override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let touch = touches.first else { guard let touch = touches.first else {
return return
} }
let touchLocation = touch.location(in: self) let touchLocation = touch.location(in: self)
if isMoveTouch{ if isMoveTouch{
isMoveTouch = false isMoveTouch = false
currentDraggedBase!.component(ofType: DefaultBaseComponent.self)?.spriteNode.position = currentDraggedBasePos currentDraggedBase!.component(ofType: DefaultBaseComponent.self)?.spriteNode.position = currentDraggedBasePos
currentDraggedBase!.component(ofType: TeamComponent.self)?.fire.position = currentDraggedBasePos currentDraggedBase!.component(ofType: TeamComponent.self)?.fire.position = currentDraggedBasePos
for base in currentDraggedBase!.adjacencyList { for base in currentDraggedBase!.adjacencyList {
if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode { if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode {
// TODO: change interaction based on collision instead of touchlocation // TODO: change interaction based on collision instead of touchlocation
if !(entityManager.getTeamByBase(base: currentDraggedBase!) == entityManager.getTeamByBase(base: base)){ if !(entityManager.getTeamByBase(base: currentDraggedBase!) == entityManager.getTeamByBase(base: base)){
entityManager.add(Modal(modaltype: .BaseAttack, entityManager.add(Modal(modaltype: .BaseAttack,
base: currentDraggedBase!, base: currentDraggedBase!,
anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2), entityManager: entityManager)) anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2), entityManager: entityManager, gameScene: self))
entityManager.update((currentDraggedBase?.attackBase(base: base, units: 100))!) entityManager.update((currentDraggedBase?.attackBase(base: base, units: 100))!)
}else { }else {
entityManager.add(Modal(modaltype: .BaseAttack, entityManager.add(Modal(modaltype: .BaseAttack,
base: currentDraggedBase!, base: currentDraggedBase!,
anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2), entityManager: entityManager)) anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2), entityManager: entityManager, gameScene: self))
} }
} }
} }
} }
else { else {
for entity in entityManager.entities { for entity in entityManager.entities {
let spriteNode = entity.component(ofType: DefaultBaseComponent.self)?.spriteNode let spriteNode = entity.component(ofType: DefaultBaseComponent.self)?.spriteNode
if entityManager.isModal && entity.isMember(of: Modal.self) {
// entityManager.remove(entity)
for child in self.children {
if(child.name != "fire"){
child.alpha = 1
}
}
}
if atPoint(touchLocation) == spriteNode && !entityManager.isModal { if atPoint(touchLocation) == spriteNode && !entityManager.isModal {
spriteNode?.touchesBegan(touches, with: event) spriteNode?.touchesBegan(touches, with: event)
if !entityManager.isModal { if !entityManager.isModal {
@ -81,33 +71,33 @@ class GameScene: SKScene{
} }
entityManager.add(Modal(modaltype: .BaseDetails, entityManager.add(Modal(modaltype: .BaseDetails,
base: entity as! Base, base: entity as! Base,
anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2), entityManager: entityManager)) anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2), entityManager: entityManager, gameScene: self))
} }
} }
} }
} }
} }
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) { override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let touch = touches.first else { guard let touch = touches.first else {
return return
} }
let touchLocation = touch.location(in: self) let touchLocation = touch.location(in: self)
for child in children { for child in children {
if atPoint(touchLocation) == child { if atPoint(touchLocation) == child {
child.touchesMoved(touches, with: event) child.touchesMoved(touches, with: event)
} }
} }
for e in entityManager.entities{ for e in entityManager.entities{
if let body = e.component(ofType: ModalContentComponent.self)?.body{ if let body = e.component(ofType: ModalContentComponent.self)?.body{
body.text = "Schicke \( ((e.component(ofType: SliderComponent.self)?.sliderNode.getValue ?? 0) * CGFloat((e as! Modal).unitCount)).rounded(.up)) Einheiten " body.text = "Schicke \( ((e.component(ofType: SliderComponent.self)?.sliderNode.getValue ?? 0) * CGFloat((e as! Modal).unitCount)).rounded(.up)) Einheiten "
} } } }
let bases = entityManager.getBasesByTeam(for: .team1) let bases = entityManager.getBasesByTeam(for: .team1)
for base in bases { for base in bases {
if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode{ if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode{
if !isMoveTouch { if !isMoveTouch {
@ -115,7 +105,7 @@ class GameScene: SKScene{
currentDraggedBase = base currentDraggedBase = base
} }
isMoveTouch = true isMoveTouch = true
base.component(ofType: DefaultBaseComponent.self)?.spriteNode.position = touchLocation base.component(ofType: DefaultBaseComponent.self)?.spriteNode.position = touchLocation
base.component(ofType: TeamComponent.self)?.fire.position = touchLocation base.component(ofType: TeamComponent.self)?.fire.position = touchLocation
for adjacencyBase in base.adjacencyList { for adjacencyBase in base.adjacencyList {