Minor fixes

This commit is contained in:
Aldin Duraki 2020-05-21 02:44:38 +02:00
parent ad44ba8302
commit 9fd34d9a6c
4 changed files with 33 additions and 30 deletions

View File

@ -31,9 +31,10 @@ class Base: GKEntity{
self.position = position self.position = position
super.init() super.init()
addComponent(DefaultBaseComponent(texture: SKTexture(imageNamed: "Base"), position: position)) let spritePos = position
addComponent(DefaultBaseComponent(texture: SKTexture(imageNamed: "Base"), position: spritePos))
if(team != nil && player != nil){ if(team != nil && player != nil){
addComponent(TeamComponent(team: team!, player: player!, position: position)) addComponent(TeamComponent(team: team!, player: player!, position: spritePos))
self.unitCount = 500 self.unitCount = 500
} }
} }

View File

@ -43,10 +43,10 @@ class EntityManager {
scene.addChild(modal.header) scene.addChild(modal.header)
scene.addChild(modal.body) scene.addChild(modal.body)
scene.addChild(modal.footer) scene.addChild(modal.footer)
isModal = true
} }
if let skillButtonNode = entity.component(ofType: AtkBoostSkillComponent.self)?.skillButtonNode { if let skillButtonNode = entity.component(ofType: AtkBoostSkillComponent.self)?.skillButtonNode {
scene.addChild(skillButtonNode) scene.addChild(skillButtonNode)
isModal = true
} }
if let skillButtonNode = entity.component(ofType: DefBoostSkillComponent.self)?.skillButtonNode { if let skillButtonNode = entity.component(ofType: DefBoostSkillComponent.self)?.skillButtonNode {
scene.addChild(skillButtonNode) scene.addChild(skillButtonNode)
@ -60,7 +60,6 @@ class EntityManager {
} }
if let buttonNode = entity.component(ofType: ButtonComponent.self)?.buttonNode { if let buttonNode = entity.component(ofType: ButtonComponent.self)?.buttonNode {
scene.addChild(buttonNode) scene.addChild(buttonNode)
isModal = true
} }
if let nodes = entity.component(ofType: BackgroundComponent.self)?.nodes { if let nodes = entity.component(ofType: BackgroundComponent.self)?.nodes {
for node in nodes { for node in nodes {
@ -76,7 +75,6 @@ class EntityManager {
} }
if let cancelBtnNode = entity.component(ofType: CancelBtnComponent.self)?.cancelBtnNode { if let cancelBtnNode = entity.component(ofType: CancelBtnComponent.self)?.cancelBtnNode {
scene.addChild(cancelBtnNode) scene.addChild(cancelBtnNode)
isModal = true
} }
if let node = entity.component(ofType: SpinningLogoComponent.self)?.node { if let node = entity.component(ofType: SpinningLogoComponent.self)?.node {
scene.addChild(node) scene.addChild(node)
@ -97,6 +95,7 @@ class EntityManager {
modal.header.removeFromParent() modal.header.removeFromParent()
modal.body.removeFromParent() modal.body.removeFromParent()
modal.footer.removeFromParent() modal.footer.removeFromParent()
isModal = false
} }
if let sliderNode = entity.component(ofType: SliderComponent.self)?.sliderNode { if let sliderNode = entity.component(ofType: SliderComponent.self)?.sliderNode {
sliderNode.sliderKnob.removeFromParent() sliderNode.sliderKnob.removeFromParent()
@ -104,11 +103,9 @@ class EntityManager {
} }
if let modalButton = entity.component(ofType: ButtonComponent.self) { if let modalButton = entity.component(ofType: ButtonComponent.self) {
modalButton.buttonNode.removeFromParent() modalButton.buttonNode.removeFromParent()
isModal = false
} }
if let cancelBtnNode = entity.component(ofType: CancelBtnComponent.self)?.cancelBtnNode { if let cancelBtnNode = entity.component(ofType: CancelBtnComponent.self)?.cancelBtnNode {
cancelBtnNode.removeFromParent() cancelBtnNode.removeFromParent()
isModal = false
} }
entities.remove(entity) entities.remove(entity)
} }
@ -147,6 +144,8 @@ class EntityManager {
if snapBase.ownership != nil { if snapBase.ownership != nil {
getOwnerBySnapBase = MatchmakingHelper.sharedInstance.getGKPlayerByUsername(displayName: snapBase.ownership!) getOwnerBySnapBase = MatchmakingHelper.sharedInstance.getGKPlayerByUsername(displayName: snapBase.ownership!)
} else {
entity.removeComponent(ofType: TeamComponent.self)
} }
if getOwnerBySnapBase != nil { if getOwnerBySnapBase != nil {
base.changeOwnership = true base.changeOwnership = true

View File

@ -111,7 +111,6 @@ class RoundCalculatorService {
MultiplayerNetwork.sharedInstance.sendSnapshotModelToPlayers() MultiplayerNetwork.sharedInstance.sendSnapshotModelToPlayers()
DataService.sharedInstance.snapshotModel = currentSnapshotModel DataService.sharedInstance.snapshotModel = currentSnapshotModel
EntityManager.sharedInstance.updateSnapshotModel(snapshotModel: currentSnapshotModel!) EntityManager.sharedInstance.updateSnapshotModel(snapshotModel: currentSnapshotModel!)
sleep(1)
EntityManager.sharedInstance.getTimer().startWithDuration(duration: 31) EntityManager.sharedInstance.getTimer().startWithDuration(duration: 31)
os_log("Finished calculating Round", log: RoundCalculatorService.LOG, type: .info) os_log("Finished calculating Round", log: RoundCalculatorService.LOG, type: .info)
} }

View File

@ -13,7 +13,6 @@ import GameKit
class GameScene: SKScene{ class GameScene: SKScene{
var isMoveTouch = false var isMoveTouch = false
var currentDraggedBasePos = CGPoint()
var currentDraggedBase : Base? var currentDraggedBase : Base?
static var sendUnits: CGFloat = 0 static var sendUnits: CGFloat = 0
var collisionBase: Base? var collisionBase: Base?
@ -42,8 +41,8 @@ class GameScene: SKScene{
if isMoveTouch{ if isMoveTouch{
isMoveTouch = false isMoveTouch = false
currentDraggedBase!.component(ofType: DefaultBaseComponent.self)?.spriteNode.position = currentDraggedBasePos currentDraggedBase!.component(ofType: DefaultBaseComponent.self)?.spriteNode.position = currentDraggedBase!.position
currentDraggedBase!.component(ofType: TeamComponent.self)?.fire.position = currentDraggedBasePos currentDraggedBase!.component(ofType: TeamComponent.self)?.fire.position = currentDraggedBase!.position
addAttackDetails(touchLocation: touchLocation) addAttackDetails(touchLocation: touchLocation)
} }
@ -51,6 +50,7 @@ class GameScene: SKScene{
for entity in EntityManager.sharedInstance.entities { for entity in EntityManager.sharedInstance.entities {
let spriteNode = entity.component(ofType: DefaultBaseComponent.self)?.spriteNode let spriteNode = entity.component(ofType: DefaultBaseComponent.self)?.spriteNode
//FIXME: this is confusing
addBaseDetails(touchLocation: touchLocation, spriteNode: spriteNode, touches: touches, event: event, entity: entity) addBaseDetails(touchLocation: touchLocation, spriteNode: spriteNode, touches: touches, event: event, entity: entity)
} }
} }
@ -83,7 +83,8 @@ class GameScene: SKScene{
func addBaseDetails(touchLocation: CGPoint, spriteNode: SKNode?, touches: Set<UITouch>, event: UIEvent?, entity: GKEntity){ func addBaseDetails(touchLocation: CGPoint, spriteNode: SKNode?, touches: Set<UITouch>, event: UIEvent?, entity: GKEntity){
if atPoint(touchLocation) == spriteNode && !EntityManager.sharedInstance.isModal { if atPoint(touchLocation) == spriteNode && !EntityManager.sharedInstance.isModal {
spriteNode?.touchesBegan(touches, with: event) spriteNode?.touchesBegan(touches, with: event)
if !EntityManager.sharedInstance.isModal { if let baseEntity = entity as? Base {
if baseEntity.ownershipPlayer == GKLocalPlayer.local {
for child in self.children { for child in self.children {
if(child.name != "fire"){ if(child.name != "fire"){
child.alpha = 0.3 child.alpha = 0.3
@ -92,23 +93,26 @@ class GameScene: SKScene{
EntityManager.sharedInstance.add(Modal(modaltype: .BaseDetails, EntityManager.sharedInstance.add(Modal(modaltype: .BaseDetails,
base: entity as! Base, base: entity as! Base,
anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2), anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2),
gameScene: self, currentDraggedBase: currentDraggedBase, touchLocation: touchLocation, collisionBase: collisionBase)) gameScene: self,
currentDraggedBase: currentDraggedBase, touchLocation: touchLocation, collisionBase: collisionBase))
} }
} }
} }
}
func addAttackDetails(touchLocation: CGPoint){ func addAttackDetails(touchLocation: CGPoint){
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 {
collisionBase = base collisionBase = base
// TODO: change interaction based on collision instead of touchlocation // TODO: change interaction based on collision instead of touchlocation
if currentDraggedBase!.unitCount > 1 {
EntityManager.sharedInstance.add(Modal(modaltype: .BaseAttack, EntityManager.sharedInstance.add(Modal(modaltype: .BaseAttack,
base: currentDraggedBase!, base: currentDraggedBase!,
anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2), anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2),
gameScene: self, currentDraggedBase: currentDraggedBase, touchLocation: touchLocation, collisionBase: collisionBase)) gameScene: self, currentDraggedBase: currentDraggedBase, touchLocation: touchLocation, collisionBase: collisionBase))
GameScene.sendUnits = CGFloat(currentDraggedBase!.unitCount / 2) GameScene.sendUnits = CGFloat(currentDraggedBase!.unitCount / 2)
}
} }
} }
} }
@ -118,7 +122,7 @@ class GameScene: SKScene{
if let body = e.component(ofType: ModalContentComponent.self)?.body{ if let body = e.component(ofType: ModalContentComponent.self)?.body{
GameScene.sendUnits = ((e.component(ofType: SliderComponent.self)?.sliderNode.getValue ?? 0) * CGFloat((e as! Modal).unitCount)).rounded(.up) GameScene.sendUnits = ((e.component(ofType: SliderComponent.self)?.sliderNode.getValue ?? 0) * CGFloat((e as! Modal).unitCount)).rounded(.up)
//TODO: quick fix chauntalle die olle mach augen auf //TODO: refactor this quick and dirty fix
if GameScene.sendUnits == 0 { if GameScene.sendUnits == 0 {
GameScene.sendUnits = 1 GameScene.sendUnits = 1
} else if Int(GameScene.sendUnits) == currentDraggedBase?.unitCount { } else if Int(GameScene.sendUnits) == currentDraggedBase?.unitCount {
@ -131,8 +135,8 @@ class GameScene: SKScene{
func checkBases(bases: Set<Base>, touchLocation: CGPoint){ func checkBases(bases: Set<Base>, touchLocation: CGPoint){
for base in bases { for base in bases {
if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode{ if !isMoveTouch { if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode{
currentDraggedBasePos = base.component(ofType: DefaultBaseComponent.self)!.spriteNode.position if !isMoveTouch {
currentDraggedBase = base currentDraggedBase = base
} }
isMoveTouch = true isMoveTouch = true