add method getBaseByPlayer to entityManager

This commit is contained in:
Jakob Haag 2020-05-11 18:05:05 +02:00
parent 276d2cfa2e
commit 5b11dacbaa

View File

@ -8,6 +8,7 @@
import SpriteKit import SpriteKit
import GameplayKit import GameplayKit
import GameKit
class EntityManager { class EntityManager {
@ -92,13 +93,22 @@ class EntityManager {
let base = (entity as! Base) let base = (entity as! Base)
if base.changeOwnerShip { if base.changeOwnerShip {
base.addComponent(TeamComponent(team: (entities[0] as! Base).component(ofType: TeamComponent.self)!.team, position: (base.component(ofType: DefaultBaseComponent.self)?.spriteNode.position)!)) base.addComponent(
TeamComponent(
team: (entities[0] as! Base).component(ofType: TeamComponent.self)!.team,
position: (base.component(ofType: DefaultBaseComponent.self)?.spriteNode.position)!,
player: (entities[0] as! Base).component(ofType: TeamComponent.self)!.player))
base.changeOwnerShip = false base.changeOwnerShip = false
scene.addChild(base.component(ofType: TeamComponent.self)!.fire) scene.addChild(base.component(ofType: TeamComponent.self)!.fire)
} }
} }
} }
func getBaseByPlayer(for player: GKPlayer) -> Set<Base> {
return entities.filter{$0 is Base && ($0 as! Base).component(ofType: TeamComponent.self)?.player == player } as! Set<Base>
}
func getBaseByTeam(for team: Team) -> GKEntity? { func getBaseByTeam(for team: Team) -> GKEntity? {
for entity in entities { for entity in entities {
if let teamComponent = entity.component(ofType: TeamComponent.self), if let teamComponent = entity.component(ofType: TeamComponent.self),