Remove unnecessary complexity, Reformat code
This commit is contained in:
parent
a52e4cd8d1
commit
9a041c7310
@ -67,10 +67,6 @@ class EntityManager {
|
|||||||
scene.addChild(spinningLogoEntity.warsLetteringNode)
|
scene.addChild(spinningLogoEntity.warsLetteringNode)
|
||||||
}
|
}
|
||||||
|
|
||||||
if let rulesEntity = entity as? Rules {
|
|
||||||
scene.addChild(rulesEntity.image)
|
|
||||||
}
|
|
||||||
|
|
||||||
if let wayEntity = entity as? Way {
|
if let wayEntity = entity as? Way {
|
||||||
scene.addChild(wayEntity.localWayComponent)
|
scene.addChild(wayEntity.localWayComponent)
|
||||||
}
|
}
|
||||||
@ -370,17 +366,4 @@ class EntityManager {
|
|||||||
func updateTime(time: String) {
|
func updateTime(time: String) {
|
||||||
getHUD()?.roundTimerLabel.text = time
|
getHUD()?.roundTimerLabel.text = time
|
||||||
}
|
}
|
||||||
|
|
||||||
func removeRules(){
|
|
||||||
entities.forEach({entity in
|
|
||||||
if let rules = entity as? Rules {
|
|
||||||
rules.image.removeFromParent()
|
|
||||||
|
|
||||||
if let button = rules.component(ofType: ButtonComponent.self) {
|
|
||||||
button.buttonNode.removeFromParent()
|
|
||||||
}
|
|
||||||
self.remove(rules)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -11,17 +11,27 @@ import GameplayKit
|
|||||||
|
|
||||||
class RulesScene: SKScene {
|
class RulesScene: SKScene {
|
||||||
|
|
||||||
|
var image: SKSpriteNode?
|
||||||
|
|
||||||
override func sceneDidLoad() {
|
override func sceneDidLoad() {
|
||||||
EntityManager.rulesEMInstance.setScene(scene: self)
|
EntityManager.rulesEMInstance.setScene(scene: self)
|
||||||
EntityManager.rulesEMInstance.add(Button(name: "backToMenuScene",
|
EntityManager.rulesEMInstance.add(
|
||||||
|
Button(name: "backToMenuScene",
|
||||||
textureName: "questionmark",
|
textureName: "questionmark",
|
||||||
text: "",
|
text: "",
|
||||||
position: CGPoint(x: self.size.width - 50, y: self.size.height - 50),
|
position: CGPoint(x: self.size.width - 50, y: self.size.height - 50),
|
||||||
onButtonPress: {
|
onButtonPress: {
|
||||||
let scene = MenuScene(size: self.size)
|
EntityManager.rulesEMInstance.entities.removeAll()
|
||||||
self.loadScene(scene: scene)
|
self.view?.presentScene(
|
||||||
}))
|
MenuScene(size: self.size),
|
||||||
EntityManager.rulesEMInstance.add(Label(fontnamed: "Courier-Bold",
|
transition: SKTransition.flipVertical(withDuration: 0.5)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
EntityManager.rulesEMInstance.add(
|
||||||
|
Label(fontnamed: "Courier-Bold",
|
||||||
name: "rulesLabel",
|
name: "rulesLabel",
|
||||||
text: "Regelwerk",
|
text: "Regelwerk",
|
||||||
fontSize: 90,
|
fontSize: 90,
|
||||||
@ -30,64 +40,66 @@ class RulesScene: SKScene {
|
|||||||
horizontalAlignmentMode: .center,
|
horizontalAlignmentMode: .center,
|
||||||
vertikalAligmentMode: .baseline,
|
vertikalAligmentMode: .baseline,
|
||||||
isAnimationEnabled: true,
|
isAnimationEnabled: true,
|
||||||
isAnimationInfinite: true)
|
isAnimationInfinite: true
|
||||||
)
|
)
|
||||||
EntityManager.rulesEMInstance.add(Button(name: "Spiel",
|
)
|
||||||
|
|
||||||
|
image = SKSpriteNode(imageNamed: "RulesSpiel")
|
||||||
|
image!.size = CGSize(width: size.width * 0.8, height: size.height * 0.8)
|
||||||
|
image!.position = CGPoint(x: size.width * 0.6, y: size.height * 0.6 - 150)
|
||||||
|
image!.zPosition = 4
|
||||||
|
|
||||||
|
self.addChild(image!)
|
||||||
|
|
||||||
|
EntityManager.rulesEMInstance.add(
|
||||||
|
Button(name: "Spiel",
|
||||||
textureName: "yellow_button13",
|
textureName: "yellow_button13",
|
||||||
text: "Spiel",
|
text: "Spiel",
|
||||||
position: CGPoint(x: self.size.width * 0.1, y: self.size.height * 0.5 + 150),
|
position: CGPoint(x: self.size.width * 0.1, y: self.size.height * 0.5 + 150),
|
||||||
onButtonPress: {
|
onButtonPress: { self.image!.texture = SKTexture(imageNamed: "RulesSpiel") }
|
||||||
EntityManager.rulesEMInstance.removeRules()
|
)
|
||||||
EntityManager.rulesEMInstance.add(Rules(rulesScene: self, textureName: "RulesSpiel"))
|
)
|
||||||
}))
|
EntityManager.rulesEMInstance.add(
|
||||||
EntityManager.rulesEMInstance.add(Button(name: "Basen",
|
Button(name: "Basen",
|
||||||
textureName: "yellow_button13",
|
textureName: "yellow_button13",
|
||||||
text: "Basen",
|
text: "Basen",
|
||||||
position: CGPoint(x: self.size.width * 0.1, y: self.size.height * 0.5 + 85),
|
position: CGPoint(x: self.size.width * 0.1, y: self.size.height * 0.5 + 85),
|
||||||
onButtonPress: {
|
onButtonPress: { self.image!.texture = SKTexture(imageNamed: "RulesBasen") }
|
||||||
EntityManager.rulesEMInstance.removeRules()
|
)
|
||||||
EntityManager.rulesEMInstance.add(Rules(rulesScene: self, textureName: "RulesBasen"))
|
)
|
||||||
}))
|
EntityManager.rulesEMInstance.add(
|
||||||
EntityManager.rulesEMInstance.add(Button(name: "Einheiten",
|
Button(name: "Einheiten",
|
||||||
textureName: "yellow_button13",
|
textureName: "yellow_button13",
|
||||||
text: "Einheiten",
|
text: "Einheiten",
|
||||||
position: CGPoint(x: self.size.width * 0.1, y: self.size.height * 0.5 + 20),
|
position: CGPoint(x: self.size.width * 0.1, y: self.size.height * 0.5 + 20),
|
||||||
onButtonPress: {
|
onButtonPress: { self.image!.texture = SKTexture(imageNamed: "RulesEinheiten") }
|
||||||
EntityManager.rulesEMInstance.removeRules()
|
)
|
||||||
EntityManager.rulesEMInstance.add(Rules(rulesScene: self, textureName: "RulesEinheiten"))
|
)
|
||||||
}))
|
EntityManager.rulesEMInstance.add(
|
||||||
EntityManager.rulesEMInstance.add(Button(name: "Spielende",
|
Button(name: "Spielende",
|
||||||
textureName: "yellow_button13",
|
textureName: "yellow_button13",
|
||||||
text: "Spielende",
|
text: "Spielende",
|
||||||
position: CGPoint(x: self.size.width * 0.1, y: self.size.height * 0.5 - 45),
|
position: CGPoint(x: self.size.width * 0.1, y: self.size.height * 0.5 - 45),
|
||||||
onButtonPress: {
|
onButtonPress: { self.image!.texture = SKTexture(imageNamed: "RulesSpielende") }
|
||||||
EntityManager.rulesEMInstance.removeRules()
|
)
|
||||||
EntityManager.rulesEMInstance.add(Rules(rulesScene: self, textureName: "RulesSpielende"))
|
)
|
||||||
}))
|
EntityManager.rulesEMInstance.add(
|
||||||
EntityManager.rulesEMInstance.add(Button(name: "Boost",
|
Button(name: "Boost",
|
||||||
textureName: "yellow_button13",
|
textureName: "yellow_button13",
|
||||||
text: "Boost",
|
text: "Boost",
|
||||||
position: CGPoint(x: self.size.width * 0.1, y: self.size.height * 0.5 - 110),
|
position: CGPoint(x: self.size.width * 0.1, y: self.size.height * 0.5 - 110),
|
||||||
onButtonPress: {
|
onButtonPress: { self.image!.texture = SKTexture(imageNamed: "RulesBoost") }
|
||||||
EntityManager.rulesEMInstance.removeRules()
|
)
|
||||||
EntityManager.rulesEMInstance.add(Rules(rulesScene: self, textureName: "RulesBoost"))
|
)
|
||||||
}))
|
EntityManager.rulesEMInstance.add(
|
||||||
EntityManager.rulesEMInstance.add(Button(name: "Erfolge",
|
Button(name: "Erfolge",
|
||||||
textureName: "yellow_button13",
|
textureName: "yellow_button13",
|
||||||
text: "Erfolge",
|
text: "Erfolge",
|
||||||
position: CGPoint(x: self.size.width * 0.1, y: self.size.height * 0.5 - 175),
|
position: CGPoint(x: self.size.width * 0.1, y: self.size.height * 0.5 - 175),
|
||||||
onButtonPress: {
|
onButtonPress: { self.image!.texture = SKTexture(imageNamed: "RulesErfolge") }
|
||||||
EntityManager.rulesEMInstance.removeRules()
|
)
|
||||||
EntityManager.rulesEMInstance.add(Rules(rulesScene: self, textureName: "RulesErfolge"))
|
)
|
||||||
}))
|
|
||||||
EntityManager.rulesEMInstance.add(Background(size: self.size))
|
EntityManager.rulesEMInstance.add(Background(size: self.size))
|
||||||
EntityManager.rulesEMInstance.add(Rules(rulesScene: self, textureName: "RulesSpiel"))
|
|
||||||
}
|
|
||||||
|
|
||||||
func loadScene(scene: SKScene) {
|
|
||||||
let transition = SKTransition.flipVertical(withDuration: 0.5)
|
|
||||||
EntityManager.rulesEMInstance.entities.removeAll()
|
|
||||||
self.view?.presentScene(scene, transition: transition)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override func update(_ currentTime: TimeInterval) {
|
override func update(_ currentTime: TimeInterval) {
|
||||||
@ -96,20 +108,3 @@ class RulesScene: SKScene {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Rules: GKEntity {
|
|
||||||
|
|
||||||
var image: SKSpriteNode
|
|
||||||
|
|
||||||
init(rulesScene: RulesScene, textureName: String) {
|
|
||||||
let texture = SKTexture(imageNamed: textureName)
|
|
||||||
image = SKSpriteNode(texture: texture, size: CGSize(width: rulesScene.size.width * 0.8, height: rulesScene.size.height * 0.8))
|
|
||||||
image.position = CGPoint(x: rulesScene.size.width * 0.6, y: rulesScene.size.height * 0.6 - 150)
|
|
||||||
image.zPosition = 4
|
|
||||||
super.init()
|
|
||||||
}
|
|
||||||
|
|
||||||
required init?(coder: NSCoder) {
|
|
||||||
fatalError("init(coder:) has not been implemented")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user