FIXME solved by extending the TeamComponent behavior
This commit is contained in:
parent
604001a365
commit
458d50e4b3
@ -23,20 +23,29 @@ class TeamComponent: GKComponent {
|
|||||||
fire.particleColorSequence = nil
|
fire.particleColorSequence = nil
|
||||||
fire.particleColorBlendFactor = 1.0
|
fire.particleColorBlendFactor = 1.0
|
||||||
|
|
||||||
switch team {
|
|
||||||
case .team1: fire.particleColor = SKColor.red
|
|
||||||
case .team2: fire.particleColor = SKColor.purple
|
|
||||||
case .team3: fire.particleColor = SKColor.green
|
|
||||||
case .team4: fire.particleColor = SKColor.gray
|
|
||||||
}
|
|
||||||
|
|
||||||
self.team = team
|
self.team = team
|
||||||
self.player = player
|
self.player = player
|
||||||
super.init()
|
super.init()
|
||||||
|
fire.particleColor = getColor(by: team)
|
||||||
}
|
}
|
||||||
|
|
||||||
required init?(coder aDecoder: NSCoder) {
|
required init?(coder aDecoder: NSCoder) {
|
||||||
fatalError("init(coder:) has not been implemented")
|
fatalError("init(coder:) has not been implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getColor(by team: Team) -> SKColor {
|
||||||
|
switch team {
|
||||||
|
case .team1: return SKColor.red
|
||||||
|
case .team2: return SKColor.purple
|
||||||
|
case .team3: return SKColor.green
|
||||||
|
case .team4: return SKColor.gray
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func change(to team: Team, to player: GKPlayer) -> Void {
|
||||||
|
self.team = team
|
||||||
|
self.player = player
|
||||||
|
self.fire.particleColor = getColor(by: team)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,17 +119,18 @@ class EntityManager {
|
|||||||
let base = (entity as! Base)
|
let base = (entity as! Base)
|
||||||
|
|
||||||
if base.changeOwnership {
|
if base.changeOwnership {
|
||||||
//FIX-ME: Find a way to update the Component without deleting it upfront
|
if (entity.component(ofType: TeamComponent.self) != nil) {
|
||||||
//TODO: outsource component handling to a generic function
|
entity.component(ofType: TeamComponent.self)!.change(to: (entities[0] as! Base).component(ofType: TeamComponent.self)!.team, to: (entities[0] as! Base).component(ofType: TeamComponent.self)!.player)
|
||||||
//base.removeComponent(ofType: TeamComponent.self)
|
} else {
|
||||||
base.addComponent(TeamComponent(
|
base.addComponent(TeamComponent(
|
||||||
team: (entities[0] as! Base).component(ofType: TeamComponent.self)!.team,
|
team: (entities[0] as! Base).component(ofType: TeamComponent.self)!.team,
|
||||||
player: (entities[0] as! Base).component(ofType: TeamComponent.self)!.player,
|
player: (entities[0] as! Base).component(ofType: TeamComponent.self)!.player,
|
||||||
position: (base.component(ofType: DefaultBaseComponent.self)?.spriteNode.position)!
|
position: (base.component(ofType: DefaultBaseComponent.self)?.spriteNode.position)!
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
if let fire = entity.component(ofType: TeamComponent.self)?.fire{
|
||||||
if let fire = entity.component(ofType: TeamComponent.self)?.fire{
|
scene.addChild(fire)
|
||||||
scene.addChild(fire)
|
}
|
||||||
}
|
}
|
||||||
base.changeOwnership = false
|
base.changeOwnership = false
|
||||||
}
|
}
|
||||||
@ -150,17 +151,18 @@ class EntityManager {
|
|||||||
if getOwnerBySnapBase != nil {
|
if getOwnerBySnapBase != nil {
|
||||||
base.changeOwnership = true
|
base.changeOwnership = true
|
||||||
base.ownershipPlayer = getOwnerBySnapBase
|
base.ownershipPlayer = getOwnerBySnapBase
|
||||||
//FIX-ME: Find a way to update the Component without deleting it upfront
|
if (entity.component(ofType: TeamComponent.self) != nil) {
|
||||||
//TODO: outsource component handling to a generic function
|
entity.component(ofType: TeamComponent.self)!.change(to: getTeamByPlayer(playerName: snapBase.ownership!), to: getOwnerBySnapBase!)
|
||||||
//entity.removeComponent(ofType: TeamComponent.self)
|
} else {
|
||||||
entity.addComponent(TeamComponent(
|
entity.addComponent(TeamComponent(
|
||||||
team: getTeamByPlayer(playerName: snapBase.ownership!),
|
team: getTeamByPlayer(playerName: snapBase.ownership!),
|
||||||
player: getOwnerBySnapBase!,
|
player: getOwnerBySnapBase!,
|
||||||
position: (entity.component(ofType: DefaultBaseComponent.self)?.spriteNode.position)!
|
position: (entity.component(ofType: DefaultBaseComponent.self)?.spriteNode.position)!
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
if let fire = entity.component(ofType: TeamComponent.self)?.fire{
|
||||||
if let fire = entity.component(ofType: TeamComponent.self)?.fire{
|
scene.addChild(fire)
|
||||||
scene.addChild(fire)
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user