From 288438884e70fd0731bcb09665d684029f1e49c3 Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Sun, 24 May 2020 22:43:34 +0200 Subject: [PATCH] Refactor complete entity component model --- GoldWars/GoldWars.xcodeproj/project.pbxproj | 66 +++++---------- GoldWars/GoldWars/CancelBtnComponent.swift | 28 ------- GoldWars/GoldWars/CancelBtnNode.swift | 57 ------------- .../Components/AtkBoostSkillComponent.swift | 38 --------- .../GoldWars/Components/ButtonComponent.swift | 4 +- GoldWars/GoldWars/Components/ButtonNode.swift | 15 +--- .../Components/DefBoostSkillComponent.swift | 37 -------- .../Components/DefaultBaseComponent.swift | 18 ++-- .../{ => Components}/LabelComponent.swift | 0 .../GoldWars/{ => Components}/LabelNode.swift | 0 .../Components/ModalBackgroundComponent.swift | 27 ------ .../Components/ModalContentComponent.swift | 45 ---------- .../Components/SingeClickButtonNode.swift | 18 ++++ .../GoldWars/Components/SkillButtonNode.swift | 76 ----------------- .../GoldWars/Components/SkillComponent.swift | 71 ++++++++++++++++ .../GoldWars/Components/SliderComponent.swift | 19 +++-- .../Components/SpySkillComponent.swift | 34 -------- GoldWars/GoldWars/Entities/Base.swift | 10 +-- GoldWars/GoldWars/Entities/Button.swift | 4 +- .../GoldWars/Entities/EntityManager.swift | 84 +++++++++++-------- GoldWars/GoldWars/Entities/HUD.swift | 14 +--- GoldWars/GoldWars/{ => Entities}/Label.swift | 0 GoldWars/GoldWars/Entities/Modal.swift | 73 +++++++++++++--- GoldWars/GoldWars/Enums/ModalType.swift | 5 +- GoldWars/GoldWars/Enums/UnitType.swift | 14 ---- GoldWars/GoldWars/Scenes/GameScene.swift | 12 ++- GoldWars/GoldWars/Scenes/MenuScene.swift | 4 +- GoldWars/GoldWars/SettingsScene.swift | 6 +- 28 files changed, 266 insertions(+), 513 deletions(-) delete mode 100644 GoldWars/GoldWars/CancelBtnComponent.swift delete mode 100644 GoldWars/GoldWars/CancelBtnNode.swift delete mode 100644 GoldWars/GoldWars/Components/AtkBoostSkillComponent.swift delete mode 100644 GoldWars/GoldWars/Components/DefBoostSkillComponent.swift rename GoldWars/GoldWars/{ => Components}/LabelComponent.swift (100%) rename GoldWars/GoldWars/{ => Components}/LabelNode.swift (100%) delete mode 100644 GoldWars/GoldWars/Components/ModalBackgroundComponent.swift delete mode 100644 GoldWars/GoldWars/Components/ModalContentComponent.swift create mode 100644 GoldWars/GoldWars/Components/SingeClickButtonNode.swift delete mode 100644 GoldWars/GoldWars/Components/SkillButtonNode.swift create mode 100644 GoldWars/GoldWars/Components/SkillComponent.swift delete mode 100644 GoldWars/GoldWars/Components/SpySkillComponent.swift rename GoldWars/GoldWars/{ => Entities}/Label.swift (100%) delete mode 100644 GoldWars/GoldWars/Enums/UnitType.swift diff --git a/GoldWars/GoldWars.xcodeproj/project.pbxproj b/GoldWars/GoldWars.xcodeproj/project.pbxproj index 186e912..b1e5e03 100644 --- a/GoldWars/GoldWars.xcodeproj/project.pbxproj +++ b/GoldWars/GoldWars.xcodeproj/project.pbxproj @@ -16,7 +16,6 @@ 110360EE244B101B008610AF /* GoldWarsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 110360ED244B101B008610AF /* GoldWarsTests.swift */; }; 11036113244B3E30008610AF /* MenuScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11036112244B3E30008610AF /* MenuScene.swift */; }; 116060F7245C57D2004E5A36 /* EntityManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 116060F6245C57D2004E5A36 /* EntityManager.swift */; }; - 11738A3B24508F68004426F1 /* UnitType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11738A3A24508F68004426F1 /* UnitType.swift */; }; 2086465C2461B66200817C23 /* TimerComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2086465B2461B66200817C23 /* TimerComponent.swift */; }; 3E67854024728368007B9DE4 /* CElements.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E67853F24728368007B9DE4 /* CElements.swift */; }; 3E6785422472CBEC007B9DE4 /* Way.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E6785412472CBEC007B9DE4 /* Way.swift */; }; @@ -25,7 +24,7 @@ 3EBD242E245D9332003CECE7 /* Team.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EBD242D245D9332003CECE7 /* Team.swift */; }; 3F745DF0246F48FC00CE7375 /* PlayerMoveType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F745DEF246F48FC00CE7375 /* PlayerMoveType.swift */; }; 3FE19DB5246C7A22004827AB /* RoundCalculatorService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FE19DB4246C7A22004827AB /* RoundCalculatorService.swift */; }; - 8BB6FF402472B8F000162BBD /* SkillButtonNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8BB6FF3F2472B8F000162BBD /* SkillButtonNode.swift */; }; + 8BB6FF402472B8F000162BBD /* SingeClickButtonNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8BB6FF3F2472B8F000162BBD /* SingeClickButtonNode.swift */; }; 9E04AFAF245E2B73002D5CFC /* AttackActionComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E04AFAE245E2B73002D5CFC /* AttackActionComponent.swift */; }; 9E11FF79245CD81100EED3BE /* Fire.sks in Resources */ = {isa = PBXBuildFile; fileRef = 9E11FF77245CD81100EED3BE /* Fire.sks */; }; 9E174C82245DD81D00209FF0 /* ButtonNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E174C81245DD81D00209FF0 /* ButtonNode.swift */; }; @@ -36,14 +35,8 @@ 9E78ACB6245C9A5300526FF7 /* GameKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9E78ACB5245C9A5300526FF7 /* GameKit.framework */; }; 9E78ACB8245CB75B00526FF7 /* TeamComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E78ACB7245CB75B00526FF7 /* TeamComponent.swift */; }; 9E78ACBA245CBDAF00526FF7 /* HUD.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E78ACB9245CBDAF00526FF7 /* HUD.swift */; }; - 9E78ACBE245CC9C000526FF7 /* AtkBoostSkillComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E78ACBD245CC9C000526FF7 /* AtkBoostSkillComponent.swift */; }; - 9E78ACC2245CC9EE00526FF7 /* DefBoostSkillComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E78ACC1245CC9EE00526FF7 /* DefBoostSkillComponent.swift */; }; - 9E78ACC4245CCA3600526FF7 /* SpySkillComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E78ACC3245CCA3600526FF7 /* SpySkillComponent.swift */; }; 9EA3ABE9245C6DAA006BC61D /* DefaultBaseComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EA3ABE8245C6DAA006BC61D /* DefaultBaseComponent.swift */; }; 9EA3ABEB245C6DFA006BC61D /* BaseNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EA3ABEA245C6DFA006BC61D /* BaseNode.swift */; }; - 9EA3ABED245C8143006BC61D /* ModalBackgroundComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EA3ABEC245C8143006BC61D /* ModalBackgroundComponent.swift */; }; - 9EA3ABEF245C834B006BC61D /* ModalContentComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EA3ABEE245C834B006BC61D /* ModalContentComponent.swift */; }; - 9EBFD7552462CF5A00E1E219 /* SliderComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EBFD7542462CF5A00E1E219 /* SliderComponent.swift */; }; 9EC239E1246878A900952F74 /* MultiplayerNetwork.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC239E0246878A900952F74 /* MultiplayerNetwork.swift */; }; 9EC2FBA72476B1EC00ABF11F /* PlayerInfoComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC2FBA62476B1EC00ABF11F /* PlayerInfoComponent.swift */; }; 9EC7E48B2461FBF700396BCD /* SliderNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC7E48A2461FBF700396BCD /* SliderNode.swift */; }; @@ -51,13 +44,13 @@ 9EC86BA6245C8AD000796EF3 /* ModalType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC86BA5245C8AD000796EF3 /* ModalType.swift */; }; 9EEDE02D246FCD770096C735 /* SpinningLogoEntity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EEDE02C246FCD770096C735 /* SpinningLogoEntity.swift */; }; 9EEDE02F246FCD800096C735 /* SpinningLogoComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EEDE02E246FCD800096C735 /* SpinningLogoComponent.swift */; }; + AB0B88F6247AD89200C8DF66 /* SkillComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB0B88F5247AD89200C8DF66 /* SkillComponent.swift */; }; AB1D759D245DD18100671525 /* TwoPlayerDefaultTestMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB1D759B245DD18100671525 /* TwoPlayerDefaultTestMap.swift */; }; AB1D75A0245DEC0500671525 /* MapFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB1D759F245DEC0500671525 /* MapFactory.swift */; }; AB21D7D5246C748A00B09CBA /* TwoPlayerMapGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB21D7D4246C748A00B09CBA /* TwoPlayerMapGenerator.swift */; }; ABA03DA0244BD54F00A66916 /* Base.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABA03D9F244BD54F00A66916 /* Base.swift */; }; + ABB8A40E247B195500B901BE /* SliderComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB8A40D247B195500B901BE /* SliderComponent.swift */; }; AE151589245F18EF001D363E /* MatchmakingHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE151588245F18EF001D363E /* MatchmakingHelper.swift */; }; - AEBF3AFF246EB146004F7CD5 /* CancelBtnNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEBF3AFE246EB146004F7CD5 /* CancelBtnNode.swift */; }; - AEBF3B01246EB187004F7CD5 /* CancelBtnComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEBF3B00246EB187004F7CD5 /* CancelBtnComponent.swift */; }; C04783EE2468583F004961FB /* intro-music.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = C04783ED2468583F004961FB /* intro-music.mp3 */; }; C04783F024685995004961FB /* SettingsScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = C04783EF24685995004961FB /* SettingsScene.swift */; }; C05FAED62468559D0006AF2E /* SoundManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = C05FAED52468559D0006AF2E /* SoundManager.swift */; }; @@ -91,7 +84,6 @@ 110360EF244B101B008610AF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 11036112244B3E30008610AF /* MenuScene.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuScene.swift; sourceTree = ""; }; 116060F6245C57D2004E5A36 /* EntityManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EntityManager.swift; sourceTree = ""; }; - 11738A3A24508F68004426F1 /* UnitType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UnitType.swift; sourceTree = ""; }; 2086465B2461B66200817C23 /* TimerComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimerComponent.swift; sourceTree = ""; }; 3E67853F24728368007B9DE4 /* CElements.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CElements.swift; sourceTree = ""; }; 3E6785412472CBEC007B9DE4 /* Way.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Way.swift; sourceTree = ""; }; @@ -100,7 +92,7 @@ 3EBD242D245D9332003CECE7 /* Team.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Team.swift; sourceTree = ""; }; 3F745DEF246F48FC00CE7375 /* PlayerMoveType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerMoveType.swift; sourceTree = ""; }; 3FE19DB4246C7A22004827AB /* RoundCalculatorService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoundCalculatorService.swift; sourceTree = ""; }; - 8BB6FF3F2472B8F000162BBD /* SkillButtonNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SkillButtonNode.swift; sourceTree = ""; }; + 8BB6FF3F2472B8F000162BBD /* SingeClickButtonNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingeClickButtonNode.swift; sourceTree = ""; }; 9E04AFAE245E2B73002D5CFC /* AttackActionComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttackActionComponent.swift; sourceTree = ""; }; 9E11FF77245CD81100EED3BE /* Fire.sks */ = {isa = PBXFileReference; lastKnownFileType = file.sks; path = Fire.sks; sourceTree = ""; }; 9E174C81245DD81D00209FF0 /* ButtonNode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ButtonNode.swift; sourceTree = ""; }; @@ -111,14 +103,8 @@ 9E78ACB5245C9A5300526FF7 /* GameKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GameKit.framework; path = System/Library/Frameworks/GameKit.framework; sourceTree = SDKROOT; }; 9E78ACB7245CB75B00526FF7 /* TeamComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TeamComponent.swift; sourceTree = ""; }; 9E78ACB9245CBDAF00526FF7 /* HUD.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HUD.swift; sourceTree = ""; }; - 9E78ACBD245CC9C000526FF7 /* AtkBoostSkillComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AtkBoostSkillComponent.swift; sourceTree = ""; }; - 9E78ACC1245CC9EE00526FF7 /* DefBoostSkillComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefBoostSkillComponent.swift; sourceTree = ""; }; - 9E78ACC3245CCA3600526FF7 /* SpySkillComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpySkillComponent.swift; sourceTree = ""; }; 9EA3ABE8245C6DAA006BC61D /* DefaultBaseComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultBaseComponent.swift; sourceTree = ""; wrapsLines = 1; }; 9EA3ABEA245C6DFA006BC61D /* BaseNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseNode.swift; sourceTree = ""; }; - 9EA3ABEC245C8143006BC61D /* ModalBackgroundComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModalBackgroundComponent.swift; sourceTree = ""; }; - 9EA3ABEE245C834B006BC61D /* ModalContentComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModalContentComponent.swift; sourceTree = ""; }; - 9EBFD7542462CF5A00E1E219 /* SliderComponent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SliderComponent.swift; sourceTree = ""; }; 9EC239E0246878A900952F74 /* MultiplayerNetwork.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MultiplayerNetwork.swift; sourceTree = ""; }; 9EC2FBA62476B1EC00ABF11F /* PlayerInfoComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerInfoComponent.swift; sourceTree = ""; }; 9EC7E48A2461FBF700396BCD /* SliderNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SliderNode.swift; sourceTree = ""; }; @@ -127,13 +113,13 @@ 9ECD3699245C91F7008DEEBD /* GoldWars.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = GoldWars.entitlements; sourceTree = ""; }; 9EEDE02C246FCD770096C735 /* SpinningLogoEntity.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpinningLogoEntity.swift; sourceTree = ""; }; 9EEDE02E246FCD800096C735 /* SpinningLogoComponent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpinningLogoComponent.swift; sourceTree = ""; }; + AB0B88F5247AD89200C8DF66 /* SkillComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SkillComponent.swift; sourceTree = ""; }; AB1D759B245DD18100671525 /* TwoPlayerDefaultTestMap.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TwoPlayerDefaultTestMap.swift; sourceTree = ""; }; AB1D759F245DEC0500671525 /* MapFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapFactory.swift; sourceTree = ""; }; AB21D7D4246C748A00B09CBA /* TwoPlayerMapGenerator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TwoPlayerMapGenerator.swift; sourceTree = ""; }; ABA03D9F244BD54F00A66916 /* Base.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Base.swift; sourceTree = ""; }; + ABB8A40D247B195500B901BE /* SliderComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SliderComponent.swift; sourceTree = ""; }; AE151588245F18EF001D363E /* MatchmakingHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MatchmakingHelper.swift; sourceTree = ""; }; - AEBF3AFE246EB146004F7CD5 /* CancelBtnNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CancelBtnNode.swift; sourceTree = ""; }; - AEBF3B00246EB187004F7CD5 /* CancelBtnComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CancelBtnComponent.swift; sourceTree = ""; }; C04783ED2468583F004961FB /* intro-music.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = "intro-music.mp3"; sourceTree = ""; }; C04783EF24685995004961FB /* SettingsScene.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsScene.swift; sourceTree = ""; }; C05FAED52468559D0006AF2E /* SoundManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SoundManager.swift; sourceTree = ""; }; @@ -203,12 +189,7 @@ AE151588245F18EF001D363E /* MatchmakingHelper.swift */, 3FE19DB4246C7A22004827AB /* RoundCalculatorService.swift */, 3EBD242B245D8044003CECE7 /* GameCenterHelper.swift */, - AEBF3B00246EB187004F7CD5 /* CancelBtnComponent.swift */, - AEBF3AFE246EB146004F7CD5 /* CancelBtnNode.swift */, C04783EF24685995004961FB /* SettingsScene.swift */, - C064E9A7246C0EA50022B228 /* LabelNode.swift */, - C064E9A9246C114C0022B228 /* LabelComponent.swift */, - C064E9AB246C151F0022B228 /* Label.swift */, ); path = GoldWars; sourceTree = ""; @@ -225,24 +206,22 @@ 116060F4245C56EA004E5A36 /* Components */ = { isa = PBXGroup; children = ( - 9EEDE02E246FCD800096C735 /* SpinningLogoComponent.swift */, + C064E9A7246C0EA50022B228 /* LabelNode.swift */, 9E174C81245DD81D00209FF0 /* ButtonNode.swift */, - 9EA3ABE8245C6DAA006BC61D /* DefaultBaseComponent.swift */, - 9EA3ABEC245C8143006BC61D /* ModalBackgroundComponent.swift */, - 9EA3ABEE245C834B006BC61D /* ModalContentComponent.swift */, + 8BB6FF3F2472B8F000162BBD /* SingeClickButtonNode.swift */, 9EA3ABEA245C6DFA006BC61D /* BaseNode.swift */, - 9E78ACB7245CB75B00526FF7 /* TeamComponent.swift */, - 9E78ACBD245CC9C000526FF7 /* AtkBoostSkillComponent.swift */, - 9E78ACC3245CCA3600526FF7 /* SpySkillComponent.swift */, - 9E78ACC1245CC9EE00526FF7 /* DefBoostSkillComponent.swift */, + 9EC7E48A2461FBF700396BCD /* SliderNode.swift */, + C064E9A9246C114C0022B228 /* LabelComponent.swift */, + AB0B88F5247AD89200C8DF66 /* SkillComponent.swift */, + 9EEDE02E246FCD800096C735 /* SpinningLogoComponent.swift */, 9E174C85245DD91500209FF0 /* ButtonComponent.swift */, + 9EA3ABE8245C6DAA006BC61D /* DefaultBaseComponent.swift */, + 9E78ACB7245CB75B00526FF7 /* TeamComponent.swift */, 9E174C87245DF1FF00209FF0 /* BackgroundComponent.swift */, 9E04AFAE245E2B73002D5CFC /* AttackActionComponent.swift */, 2086465B2461B66200817C23 /* TimerComponent.swift */, - 9EBFD7542462CF5A00E1E219 /* SliderComponent.swift */, - 9EC7E48A2461FBF700396BCD /* SliderNode.swift */, + ABB8A40D247B195500B901BE /* SliderComponent.swift */, 3E6785432472CC27007B9DE4 /* DefaultWayComponent.swift */, - 8BB6FF3F2472B8F000162BBD /* SkillButtonNode.swift */, 9EC2FBA62476B1EC00ABF11F /* PlayerInfoComponent.swift */, ); path = Components; @@ -259,6 +238,7 @@ 9EC86B9E245C88A300796EF3 /* Modal.swift */, 9EEDE02C246FCD770096C735 /* SpinningLogoEntity.swift */, 3E6785412472CBEC007B9DE4 /* Way.swift */, + C064E9AB246C151F0022B228 /* Label.swift */, ); path = Entities; sourceTree = ""; @@ -282,7 +262,6 @@ 9EC86BA2245C89B200796EF3 /* Enums */ = { isa = PBXGroup; children = ( - 11738A3A24508F68004426F1 /* UnitType.swift */, 9EC86BA5245C8AD000796EF3 /* ModalType.swift */, 3EBD242D245D9332003CECE7 /* Team.swift */, 3F745DEF246F48FC00CE7375 /* PlayerMoveType.swift */, @@ -423,12 +402,9 @@ buildActionMask = 2147483647; files = ( 9E78ACB8245CB75B00526FF7 /* TeamComponent.swift in Sources */, - 9EA3ABEF245C834B006BC61D /* ModalContentComponent.swift in Sources */, 3FE19DB5246C7A22004827AB /* RoundCalculatorService.swift in Sources */, 9EC86BA6245C8AD000796EF3 /* ModalType.swift in Sources */, 9EC239E1246878A900952F74 /* MultiplayerNetwork.swift in Sources */, - 9E78ACBE245CC9C000526FF7 /* AtkBoostSkillComponent.swift in Sources */, - 9E78ACC4245CCA3600526FF7 /* SpySkillComponent.swift in Sources */, 9EA3ABEB245C6DFA006BC61D /* BaseNode.swift in Sources */, 9E04AFAF245E2B73002D5CFC /* AttackActionComponent.swift in Sources */, 3E6785422472CBEC007B9DE4 /* Way.swift in Sources */, @@ -441,23 +417,21 @@ 9E78ACBA245CBDAF00526FF7 /* HUD.swift in Sources */, 9EC2FBA72476B1EC00ABF11F /* PlayerInfoComponent.swift in Sources */, 9EEDE02D246FCD770096C735 /* SpinningLogoEntity.swift in Sources */, - 11738A3B24508F68004426F1 /* UnitType.swift in Sources */, 9E174C86245DD91500209FF0 /* ButtonComponent.swift in Sources */, AE151589245F18EF001D363E /* MatchmakingHelper.swift in Sources */, + ABB8A40E247B195500B901BE /* SliderComponent.swift in Sources */, 11036113244B3E30008610AF /* MenuScene.swift in Sources */, C099579C246C5E5C0016AA22 /* DataService.swift in Sources */, AB21D7D5246C748A00B09CBA /* TwoPlayerMapGenerator.swift in Sources */, 9EA3ABE9245C6DAA006BC61D /* DefaultBaseComponent.swift in Sources */, 9E174C8A245E1A0A00209FF0 /* Background.swift in Sources */, - 8BB6FF402472B8F000162BBD /* SkillButtonNode.swift in Sources */, - 9EA3ABED245C8143006BC61D /* ModalBackgroundComponent.swift in Sources */, + 8BB6FF402472B8F000162BBD /* SingeClickButtonNode.swift in Sources */, + AB0B88F6247AD89200C8DF66 /* SkillComponent.swift in Sources */, C064E9A8246C0EA50022B228 /* LabelNode.swift in Sources */, 3EBD242C245D8044003CECE7 /* GameCenterHelper.swift in Sources */, 3F745DF0246F48FC00CE7375 /* PlayerMoveType.swift in Sources */, - AEBF3B01246EB187004F7CD5 /* CancelBtnComponent.swift in Sources */, AB1D75A0245DEC0500671525 /* MapFactory.swift in Sources */, AB1D759D245DD18100671525 /* TwoPlayerDefaultTestMap.swift in Sources */, - 9EBFD7552462CF5A00E1E219 /* SliderComponent.swift in Sources */, 3E67854024728368007B9DE4 /* CElements.swift in Sources */, ABA03DA0244BD54F00A66916 /* Base.swift in Sources */, C064E9AC246C151F0022B228 /* Label.swift in Sources */, @@ -465,13 +439,11 @@ 9EC7E48B2461FBF700396BCD /* SliderNode.swift in Sources */, 9EEDE02F246FCD800096C735 /* SpinningLogoComponent.swift in Sources */, 9E174C84245DD8CE00209FF0 /* Button.swift in Sources */, - AEBF3AFF246EB146004F7CD5 /* CancelBtnNode.swift in Sources */, 110360DB244B101A008610AF /* GameViewController.swift in Sources */, 3E6785442472CC27007B9DE4 /* DefaultWayComponent.swift in Sources */, 2086465C2461B66200817C23 /* TimerComponent.swift in Sources */, 110360D3244B101A008610AF /* AppDelegate.swift in Sources */, 9EC86B9F245C88A300796EF3 /* Modal.swift in Sources */, - 9E78ACC2245CC9EE00526FF7 /* DefBoostSkillComponent.swift in Sources */, C05FAED62468559D0006AF2E /* SoundManager.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/GoldWars/GoldWars/CancelBtnComponent.swift b/GoldWars/GoldWars/CancelBtnComponent.swift deleted file mode 100644 index ae7d6a2..0000000 --- a/GoldWars/GoldWars/CancelBtnComponent.swift +++ /dev/null @@ -1,28 +0,0 @@ -// -// CancelBtnComponent.swift -// GoldWars -// -// Created by Chauntalle Schüle on 15.05.20. -// Copyright © 2020 SP2. All rights reserved. -// -import GameplayKit -import SpriteKit - -class CancelBtnComponent: GKComponent { - - var cancelBtnNode: CancelBtnNode - - init(iconName: String, text: String, position: CGPoint, isEnabled:Bool, onButtonPress: @escaping () -> ()) { - cancelBtnNode = CancelBtnNode(iconName: iconName, - text: text, - isEnabled: isEnabled, - position: position, - onButtonPress: onButtonPress) - cancelBtnNode.zPosition = 4 - super.init() - } - - required init?(coder aDecoder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } -} diff --git a/GoldWars/GoldWars/CancelBtnNode.swift b/GoldWars/GoldWars/CancelBtnNode.swift deleted file mode 100644 index 770baa5..0000000 --- a/GoldWars/GoldWars/CancelBtnNode.swift +++ /dev/null @@ -1,57 +0,0 @@ -// -// CancelBtnNode.swift -// GoldWars -// -// Created by Chauntalle Schüle on 15.05.20. -// Copyright © 2020 SP2. All rights reserved. -// - -import SpriteKit - -class CancelBtnNode: SKSpriteNode { - - var isEnabled: Bool{ - didSet{ - if isEnabled { - self.alpha = 1 - self.childNode(withName: "label")?.alpha = 1 - } else { - self.alpha = 0.3 - self.childNode(withName: "label")?.alpha = 0.3 - } - } - } - - let onButtonPress: () -> () - - init(iconName: String, text: String, isEnabled: Bool, position: CGPoint, onButtonPress: @escaping () -> ()) { - self.onButtonPress = onButtonPress - self.isEnabled = isEnabled - let texture = SKTexture(imageNamed: "yellow_cross") - super.init(texture: texture, color: SKColor.white, size: texture.size()) - self.size = CGSize(width: 30, height: 30) - self.position = position - isUserInteractionEnabled = true - } - - override func touchesBegan(_ touches: Set, with event: UIEvent?) { - if isEnabled { - let action = SKAction.sequence( - [ - SKAction.scale(by: (3/4), duration: 0.3), - SKAction.scale(by: (4/3), duration: 0.3), - ] - ) - - self.childNode(withName: "label")?.run(action) - self.run(action) - onButtonPress() - } - } - - - required init?(coder aDecoder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - -} diff --git a/GoldWars/GoldWars/Components/AtkBoostSkillComponent.swift b/GoldWars/GoldWars/Components/AtkBoostSkillComponent.swift deleted file mode 100644 index facd9b3..0000000 --- a/GoldWars/GoldWars/Components/AtkBoostSkillComponent.swift +++ /dev/null @@ -1,38 +0,0 @@ -// -// AtkBoostSkillComponent.swift -// GoldWars -// -// Created by Niko Jochim on 01.05.20. -// Copyright © 2020 SP2. All rights reserved. -// - -import GameplayKit - -class AtkBoostSkillComponent: GKComponent{ - - var skillButtonNode: SkillButtonNode - - init(iconName: String, text: String, position: CGPoint, isEnabled:Bool) { - skillButtonNode = SkillButtonNode(iconName: iconName, - text: text, - isEnabled: isEnabled, - position: position, - onButtonPress: { - var bases: Set = EntityManager.gameEMInstance.getBasesByTeam(for: .team2) - bases.forEach{ base in - if(base.unitType == .Defence){ - base.unitType = .AttackDefence - }else { - base.unitType = .Attack - } - }}) - super.init() - } - - - - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - -} diff --git a/GoldWars/GoldWars/Components/ButtonComponent.swift b/GoldWars/GoldWars/Components/ButtonComponent.swift index 2c2d82a..0597f40 100644 --- a/GoldWars/GoldWars/Components/ButtonComponent.swift +++ b/GoldWars/GoldWars/Components/ButtonComponent.swift @@ -12,8 +12,8 @@ class ButtonComponent: GKComponent { var buttonNode: ButtonNode - init(iconName: String, text: String, position: CGPoint, isEnabled:Bool, onButtonPress: @escaping () -> ()) { - buttonNode = ButtonNode(iconName: iconName, + init(textureName: String, text: String, position: CGPoint, isEnabled:Bool, onButtonPress: @escaping () -> ()) { + buttonNode = ButtonNode(textureName: textureName, text: text, isEnabled: isEnabled, position: position, diff --git a/GoldWars/GoldWars/Components/ButtonNode.swift b/GoldWars/GoldWars/Components/ButtonNode.swift index 2ebd012..ab92e38 100644 --- a/GoldWars/GoldWars/Components/ButtonNode.swift +++ b/GoldWars/GoldWars/Components/ButtonNode.swift @@ -24,10 +24,10 @@ class ButtonNode: SKSpriteNode { let onButtonPress: () -> () - init(iconName: String, text: String, isEnabled: Bool, position: CGPoint, onButtonPress: @escaping () -> ()) { + init(textureName: String, text: String, isEnabled: Bool, position: CGPoint, onButtonPress: @escaping () -> ()) { self.onButtonPress = onButtonPress self.isEnabled = isEnabled - let texture = SKTexture(imageNamed: "yellow_button04") + let texture = SKTexture(imageNamed: textureName) super.init(texture: texture, color: SKColor.white, size: texture.size()) self.position = position @@ -38,16 +38,7 @@ class ButtonNode: SKSpriteNode { label.verticalAlignmentMode = .center label.text = text label.name = "label" - - if iconName.isEmpty { - label.position = CGPoint(x: 0, y: 0) - } else { - label.position = CGPoint(x: size.width * 0.25, y: 0) - let icon = SKSpriteNode(imageNamed: iconName) - icon.position = CGPoint(x: -size.width * 0.25, y: 0) - icon.zPosition = 1 - self.addChild(icon) - } + self.addChild(label) isUserInteractionEnabled = true } diff --git a/GoldWars/GoldWars/Components/DefBoostSkillComponent.swift b/GoldWars/GoldWars/Components/DefBoostSkillComponent.swift deleted file mode 100644 index 1e46ee2..0000000 --- a/GoldWars/GoldWars/Components/DefBoostSkillComponent.swift +++ /dev/null @@ -1,37 +0,0 @@ -// -// DefBoostSkillComponent.swift -// GoldWars -// -// Created by Niko Jochim on 01.05.20. -// Copyright © 2020 SP2. All rights reserved. -// - -import GameplayKit - -class DefBoostSkillComponent: GKComponent{ - - var skillButtonNode: SkillButtonNode - - init(iconName: String, text: String, position: CGPoint, isEnabled:Bool) { - skillButtonNode = SkillButtonNode(iconName: iconName, - text: text, - isEnabled: isEnabled, - position: position, - onButtonPress: { - var bases: Set = EntityManager.gameEMInstance.getBasesByTeam(for: .team2) - bases.forEach{ base in - if(base.unitType == .Attack){ - base.unitType = .AttackDefence - }else { - base.unitType = .Defence - } - } - }) - super.init() - } - - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - -} diff --git a/GoldWars/GoldWars/Components/DefaultBaseComponent.swift b/GoldWars/GoldWars/Components/DefaultBaseComponent.swift index 2510ad8..bc63dbc 100644 --- a/GoldWars/GoldWars/Components/DefaultBaseComponent.swift +++ b/GoldWars/GoldWars/Components/DefaultBaseComponent.swift @@ -12,21 +12,21 @@ import GameKit class DefaultBaseComponent: GKComponent { var spriteNode: BaseNode - var labelNode : SKLabelNode? + var labelNode : SKLabelNode init(texture: SKTexture, position: CGPoint) { spriteNode = BaseNode(texture: texture, size: CGSize(width: 80, height: 80)) spriteNode.position = position spriteNode.zPosition = 2 - super.init() labelNode = SKLabelNode(text: "") - labelNode?.fontColor = SKColor.black - labelNode?.horizontalAlignmentMode = .left - labelNode?.verticalAlignmentMode = .center - labelNode?.fontName = "AvenirNext-Bold" - labelNode?.fontSize = 15 - labelNode?.position = CGPoint(x: position.x + 30 , y: position.y - 50 ) - labelNode?.zPosition = spriteNode.zPosition - 1 + labelNode.fontColor = SKColor.black + labelNode.horizontalAlignmentMode = .left + labelNode.verticalAlignmentMode = .center + labelNode.fontName = "AvenirNext-Bold" + labelNode.fontSize = 15 + labelNode.position = CGPoint(x: position.x + 30 , y: position.y - 50 ) + labelNode.zPosition = spriteNode.zPosition - 1 + super.init() } required init?(coder aDecoder: NSCoder) { diff --git a/GoldWars/GoldWars/LabelComponent.swift b/GoldWars/GoldWars/Components/LabelComponent.swift similarity index 100% rename from GoldWars/GoldWars/LabelComponent.swift rename to GoldWars/GoldWars/Components/LabelComponent.swift diff --git a/GoldWars/GoldWars/LabelNode.swift b/GoldWars/GoldWars/Components/LabelNode.swift similarity index 100% rename from GoldWars/GoldWars/LabelNode.swift rename to GoldWars/GoldWars/Components/LabelNode.swift diff --git a/GoldWars/GoldWars/Components/ModalBackgroundComponent.swift b/GoldWars/GoldWars/Components/ModalBackgroundComponent.swift deleted file mode 100644 index c7edfae..0000000 --- a/GoldWars/GoldWars/Components/ModalBackgroundComponent.swift +++ /dev/null @@ -1,27 +0,0 @@ -// -// ModalBackgroundComponent.swift -// GoldWars -// -// Created by Niko Jochim on 01.05.20. -// Copyright © 2020 SP2. All rights reserved. -// - -import GameplayKit -import SpriteKit - -class ModalBackgroundComponent: GKComponent { - let spriteNode: SKSpriteNode - - init(anchorPoint: CGPoint) { - let texture = SKTexture(imageNamed:"ModalBackground") - spriteNode = SKSpriteNode(texture: texture, size: texture.size()) - spriteNode.setScale(2) - spriteNode.position = anchorPoint - spriteNode.zPosition = 3 - super.init() - } - - required init?(coder aDecoder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } -} diff --git a/GoldWars/GoldWars/Components/ModalContentComponent.swift b/GoldWars/GoldWars/Components/ModalContentComponent.swift deleted file mode 100644 index 23c301e..0000000 --- a/GoldWars/GoldWars/Components/ModalContentComponent.swift +++ /dev/null @@ -1,45 +0,0 @@ -// -// ModalComponent.swift -// GoldWars -// -// Created by Niko Jochim on 01.05.20. -// Copyright © 2020 SP2. All rights reserved. -// - -import GameplayKit -import SpriteKit - -class ModalContentComponent: GKComponent{ - - var header: SKLabelNode - var body: SKLabelNode - var footer: SKLabelNode - - init(header: String, body: String, footer: String , anchorPoint: CGPoint) { - self.header = SKLabelNode(text: header) - self.header.position = CGPoint(x: anchorPoint.x, y: anchorPoint.y + 125) - self.header.fontName = "HelveticaNeue-Bold" - self.header.fontSize = 40 - self.header.zPosition = 4 - - self.body = SKLabelNode(text: body) - self.body.position = CGPoint(x: anchorPoint.x, y: anchorPoint.y - 20) - self.body.numberOfLines = 2 - self.body.preferredMaxLayoutWidth = 390 - self.body.horizontalAlignmentMode = SKLabelHorizontalAlignmentMode.center - self.body.fontName = "HelveticaNeue-Bold" - self.body.fontSize = 40 - self.body.zPosition = 4 - - self.footer = SKLabelNode(text: footer) - self.footer.position = CGPoint(x: anchorPoint.x, y: anchorPoint.y - 40) - self.footer.fontName = "HelveticaNeue-Bold" - self.footer.fontSize = 40 - self.footer.zPosition = 4 - super.init() - } - - required init?(coder aDecoder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } -} diff --git a/GoldWars/GoldWars/Components/SingeClickButtonNode.swift b/GoldWars/GoldWars/Components/SingeClickButtonNode.swift new file mode 100644 index 0000000..8b10a71 --- /dev/null +++ b/GoldWars/GoldWars/Components/SingeClickButtonNode.swift @@ -0,0 +1,18 @@ +// +// SkillButtonNode.swift +// GoldWars +// +// Created by Simon Kellner on 18.05.20. +// Copyright © 2020 SP2. All rights reserved. +// + +import SpriteKit + +class SingeClickButtonNode: ButtonNode { + + override func touchesBegan(_ touches: Set, with event: UIEvent?) { + super.touchesBegan(touches, with: event) + self.isEnabled = false + } + +} diff --git a/GoldWars/GoldWars/Components/SkillButtonNode.swift b/GoldWars/GoldWars/Components/SkillButtonNode.swift deleted file mode 100644 index 1decb06..0000000 --- a/GoldWars/GoldWars/Components/SkillButtonNode.swift +++ /dev/null @@ -1,76 +0,0 @@ -// -// SkillButtonNode.swift -// GoldWars -// -// Created by Simon Kellner on 18.05.20. -// Copyright © 2020 SP2. All rights reserved. -// - -import SpriteKit - -class SkillButtonNode: SKSpriteNode { - - var isEnabled: Bool{ - didSet{ - if isEnabled { - self.alpha = 1 - self.childNode(withName: "label")?.alpha = 1 - } else { - self.alpha = 0.3 - self.childNode(withName: "label")?.alpha = 0.3 - } - } - } - - let onButtonPress: () -> () - - init(iconName: String, text: String, isEnabled: Bool, position: CGPoint, onButtonPress: @escaping () -> ()) { - self.onButtonPress = onButtonPress - self.isEnabled = isEnabled - let texture = SKTexture(imageNamed: "yellow_circle") - super.init(texture: texture, color: SKColor.white, size: texture.size()) - self.position = position - - let label = SKLabelNode(fontNamed: "Courier-Bold") - label.fontSize = 30 - label.fontColor = SKColor.black - label.zPosition = 1 - label.verticalAlignmentMode = .center - label.text = text - label.name = "label" - - if iconName.isEmpty { - label.position = CGPoint(x: 0, y: 0) - } else { - label.position = CGPoint(x: size.width * 0.5, y: 0) - let icon = SKSpriteNode(imageNamed: iconName) - icon.position = CGPoint(x: -size.width * 0.5, y: 0) - icon.zPosition = 1 - self.addChild(icon) - } - self.addChild(label) - isUserInteractionEnabled = true - } - - override func touchesBegan(_ touches: Set, with event: UIEvent?) { - if isEnabled { - let action = SKAction.sequence( - [ - SKAction.scale(by: (3/4), duration: 0.3), - SKAction.scale(by: (4/3), duration: 0.3), - ] - ) - - self.childNode(withName: "label")?.run(action) - self.run(action) - self.isEnabled = false - onButtonPress() - } - } - - - required init?(coder aDecoder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - -} diff --git a/GoldWars/GoldWars/Components/SkillComponent.swift b/GoldWars/GoldWars/Components/SkillComponent.swift new file mode 100644 index 0000000..27f85b5 --- /dev/null +++ b/GoldWars/GoldWars/Components/SkillComponent.swift @@ -0,0 +1,71 @@ +// +// SkillComponent.swift +// GoldWars +// +// Created by Marcel Schwarz on 24.05.20. +// Copyright © 2020 SP2. All rights reserved. +// + +import Foundation +import GameKit +import GameplayKit + +class SkillComponent: GKComponent { + var skillButtonNode: SingeClickButtonNode + + init(textureName: String, text: String, position: CGPoint, isEnabled: Bool, onButtonPress: @escaping () -> ()) { + skillButtonNode = SingeClickButtonNode(textureName: textureName, text: text, isEnabled: isEnabled, position: position, onButtonPress: onButtonPress) + super.init() + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + +} + +class AtkSkillComponent: SkillComponent { + + init() { + super.init(textureName: "yellow_circle", + text: "Atk", + position: CGPoint(x: EntityManager.gameEMInstance.scene.size.width * 0.95, y: EntityManager.gameEMInstance.scene.size.height * 0.1), + isEnabled: true, + onButtonPress: {EntityManager.gameEMInstance.getBasesByTeam(for: .team2).forEach({base in base.hasAttackBoost = true})}) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } +} + +class DefSkillComponent: SkillComponent { + + init() { + super.init(textureName: "yellow_circle", + text: "Def", + position: CGPoint(x: EntityManager.gameEMInstance.scene.size.width * 0.85, y: EntityManager.gameEMInstance.scene.size.height * 0.1), + isEnabled: true, + onButtonPress: {EntityManager.gameEMInstance.getBasesByTeam(for: .team2).forEach({base in base.hasDefenseBoost = true})}) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } +} + +class SpySkillComponent: SkillComponent { + + init() { + super.init(textureName: "yellow_circle", + text: "Spy", + position: CGPoint(x: EntityManager.gameEMInstance.scene.size.width * 0.75, y: EntityManager.gameEMInstance.scene.size.height * 0.1), + isEnabled: true, + onButtonPress: { print("Not implemented") } + ) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } +} diff --git a/GoldWars/GoldWars/Components/SliderComponent.swift b/GoldWars/GoldWars/Components/SliderComponent.swift index 9682f10..7f3a15f 100644 --- a/GoldWars/GoldWars/Components/SliderComponent.swift +++ b/GoldWars/GoldWars/Components/SliderComponent.swift @@ -2,23 +2,24 @@ // SliderComponent.swift // GoldWars // -// Created by Niko Jochim on 05.05.20. +// Created by Marcel Schwarz on 24.05.20. // Copyright © 2020 SP2. All rights reserved. // import GameplayKit + class SliderComponent: GKComponent { - var sliderNode: SliderNode + var sliderNode: SliderNode - init(width: CGFloat, position: CGPoint) { - sliderNode = SliderNode(width: width, position: position) + init(width: CGFloat, position: CGPoint) { + sliderNode = SliderNode(width: width, position: position) sliderNode.zPosition = 4 - super.init() - } + super.init() + } - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } } diff --git a/GoldWars/GoldWars/Components/SpySkillComponent.swift b/GoldWars/GoldWars/Components/SpySkillComponent.swift deleted file mode 100644 index b193de5..0000000 --- a/GoldWars/GoldWars/Components/SpySkillComponent.swift +++ /dev/null @@ -1,34 +0,0 @@ -// -// SpySkillComponent.swift -// GoldWars -// -// Created by Niko Jochim on 01.05.20. -// Copyright © 2020 SP2. All rights reserved. -// - -import GameplayKit - -class SpySkillComponent: GKComponent{ - - let shapeNode: SKShapeNode - let labelNode: SKLabelNode - - init(text: String, texture: SKTexture?, anchorPoint: CGPoint) { - self.labelNode = SKLabelNode(text: text) - self.shapeNode = SKShapeNode(circleOfRadius: 30) - self.shapeNode.position = anchorPoint - self.labelNode.position = CGPoint(x: anchorPoint.x, y: anchorPoint.y - 15) - if texture != nil { - shapeNode.fillTexture = texture - }else { - shapeNode.fillColor = SKColor.gray - } - super.init() - } - - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - -} - diff --git a/GoldWars/GoldWars/Entities/Base.swift b/GoldWars/GoldWars/Entities/Base.swift index 41078fa..817f2d6 100644 --- a/GoldWars/GoldWars/Entities/Base.swift +++ b/GoldWars/GoldWars/Entities/Base.swift @@ -13,7 +13,8 @@ import GameKit class Base: GKEntity{ static var BASE_ID_COUNT: Int = 0 var unitCount: Int - var unitType: UnitType + var hasAttackBoost = false + var hasDefenseBoost = false var adjacencyList: Array var changeOwnership: Bool var ownershipPlayer: GKPlayer? @@ -22,7 +23,6 @@ class Base: GKEntity{ init(position: CGPoint, player: GKPlayer! = nil, team: Team! = nil) { self.unitCount = 0 - self.unitType = .General self.adjacencyList = [Base]() self.changeOwnership = false self.ownershipPlayer = player @@ -38,7 +38,7 @@ class Base: GKEntity{ self.unitCount = 500 } if ownershipPlayer == GKLocalPlayer.local { - self.component(ofType: DefaultBaseComponent.self)?.labelNode?.text = "\(unitCount)" + self.component(ofType: DefaultBaseComponent.self)?.labelNode.text = "\(unitCount)" } @@ -49,8 +49,8 @@ class Base: GKEntity{ base.ownershipPlayer = self.ownershipPlayer self.unitCount -= units base.unitCount += units - self.component(ofType: DefaultBaseComponent.self)?.labelNode?.text = "\(self.unitCount)" - base.component(ofType: DefaultBaseComponent.self)?.labelNode?.text = "\(base.unitCount)" + self.component(ofType: DefaultBaseComponent.self)?.labelNode.text = "\(self.unitCount)" + base.component(ofType: DefaultBaseComponent.self)?.labelNode.text = "\(base.unitCount)" DataService.sharedInstance.addMove(playerMove: PlayerMove(fromBase: self.baseID, toBase: base.baseID, unitCount: units * playerMoveType.rawValue)) diff --git a/GoldWars/GoldWars/Entities/Button.swift b/GoldWars/GoldWars/Entities/Button.swift index 8ac174d..cbc4b34 100644 --- a/GoldWars/GoldWars/Entities/Button.swift +++ b/GoldWars/GoldWars/Entities/Button.swift @@ -13,10 +13,10 @@ class Button: GKEntity{ let name: String var isEnabled = true - init(name: String, iconName: String, text: String, position: CGPoint, onButtonPress: @escaping () -> ()) { + init(name: String, textureName: String, text: String, position: CGPoint, onButtonPress: @escaping () -> ()) { self.name = name super.init() - self.addComponent(ButtonComponent(iconName: iconName, text: text, position: position, isEnabled: isEnabled, onButtonPress: onButtonPress)) + self.addComponent(ButtonComponent(textureName: textureName, text: text, position: position, isEnabled: isEnabled, onButtonPress: onButtonPress)) } required init?(coder: NSCoder) { diff --git a/GoldWars/GoldWars/Entities/EntityManager.swift b/GoldWars/GoldWars/Entities/EntityManager.swift index 19f8a5c..9301d1e 100644 --- a/GoldWars/GoldWars/Entities/EntityManager.swift +++ b/GoldWars/GoldWars/Entities/EntityManager.swift @@ -32,33 +32,31 @@ class EntityManager { func add(_ entity: GKEntity) { entities.insert(entity) - if let spriteNode = entity.component(ofType: DefaultBaseComponent.self)?.spriteNode { - scene.addChild(spriteNode) + + if let modalEntitiy = entity as? Modal { + scene.addChild(modalEntitiy.background) + scene.addChild(modalEntitiy.closeButton) + scene.addChild(modalEntitiy.header) + scene.addChild(modalEntitiy.body) + scene.addChild(modalEntitiy.footer) + isModal = true } - if let label = entity.component(ofType: DefaultBaseComponent.self)?.labelNode { - scene.addChild(label) + + if let spriteNode = entity.component(ofType: DefaultBaseComponent.self) { + scene.addChild(spriteNode.labelNode) + scene.addChild(spriteNode.spriteNode) } if let fire = entity.component(ofType: TeamComponent.self)?.fire{ scene.addChild(fire) } - if let spriteNode = entity.component(ofType: ModalBackgroundComponent.self)?.spriteNode { - scene.addChild(spriteNode) - } - if let modal = entity.component(ofType: ModalContentComponent.self) { - scene.addChild(modal.header) - scene.addChild(modal.body) - scene.addChild(modal.footer) - isModal = true - } - if let skillButtonNode = entity.component(ofType: AtkBoostSkillComponent.self)?.skillButtonNode { + if let skillButtonNode = entity.component(ofType: AtkSkillComponent.self)?.skillButtonNode { scene.addChild(skillButtonNode) } - if let skillButtonNode = entity.component(ofType: DefBoostSkillComponent.self)?.skillButtonNode { + if let skillButtonNode = entity.component(ofType: DefSkillComponent.self)?.skillButtonNode { scene.addChild(skillButtonNode) } - if let skill = entity.component(ofType: SpySkillComponent.self) { - scene.addChild(skill.shapeNode) - scene.addChild(skill.labelNode) + if let skillButtonNode = entity.component(ofType: SpySkillComponent.self)?.skillButtonNode { + scene.addChild(skillButtonNode) } if let timer = entity.component(ofType: TimerComponent.self) { scene.addChild(timer.labelNode) @@ -78,9 +76,6 @@ class EntityManager { if let labelNode = entity.component(ofType: LabelComponent.self)?.labelNode { scene.addChild(labelNode) } - if let cancelBtnNode = entity.component(ofType: CancelBtnComponent.self)?.cancelBtnNode { - scene.addChild(cancelBtnNode) - } if let node = entity.component(ofType: SpinningLogoComponent.self)?.node { scene.addChild(node) } @@ -99,15 +94,6 @@ class EntityManager { if let spriteNode = entity.component(ofType: DefaultBaseComponent.self)?.spriteNode { spriteNode.removeFromParent() } - if let spriteNode = entity.component(ofType: ModalBackgroundComponent.self)?.spriteNode { - spriteNode.removeFromParent() - } - if let modal = entity.component(ofType: ModalContentComponent.self) { - modal.header.removeFromParent() - modal.body.removeFromParent() - modal.footer.removeFromParent() - isModal = false - } if let sliderNode = entity.component(ofType: SliderComponent.self)?.sliderNode { sliderNode.sliderKnob.removeFromParent() sliderNode.sliderLine.removeFromParent() @@ -115,9 +101,6 @@ class EntityManager { if let modalButton = entity.component(ofType: ButtonComponent.self) { modalButton.buttonNode.removeFromParent() } - if let cancelBtnNode = entity.component(ofType: CancelBtnComponent.self)?.cancelBtnNode { - cancelBtnNode.removeFromParent() - } entities.remove(entity) } @@ -160,9 +143,9 @@ class EntityManager { } if getOwnerBySnapBase != nil { if getOwnerBySnapBase == GKLocalPlayer.local { - base.component(ofType: DefaultBaseComponent.self)?.labelNode?.text = "\(base.unitCount)" + base.component(ofType: DefaultBaseComponent.self)?.labelNode.text = "\(base.unitCount)" }else { - base.component(ofType: DefaultBaseComponent.self)?.labelNode?.text = "" + base.component(ofType: DefaultBaseComponent.self)?.labelNode.text = "" } base.changeOwnership = true base.ownershipPlayer = getOwnerBySnapBase @@ -288,4 +271,35 @@ class EntityManager { } return sum } + + func removeModal() { + entities.forEach({entity in + if let modal = entity as? Modal { + modal.background.removeFromParent() + modal.closeButton.removeFromParent() + modal.header.removeFromParent() + modal.body.removeFromParent() + modal.footer.removeFromParent() + + if let slider = modal.component(ofType: SliderComponent.self) { + slider.sliderNode.removeFromParent() + slider.sliderNode.sliderKnob.removeFromParent() + slider.sliderNode.sliderLine.removeFromParent() + } + + if let button = modal.component(ofType: ButtonComponent.self) { + button.buttonNode.removeFromParent() + } + self.remove(modal) + + for child in scene.children { + if(child.name != "fire"){ + child.alpha = 1 + } + } + + isModal = false + } + }) + } } diff --git a/GoldWars/GoldWars/Entities/HUD.swift b/GoldWars/GoldWars/Entities/HUD.swift index e2da8bf..cdf9590 100644 --- a/GoldWars/GoldWars/Entities/HUD.swift +++ b/GoldWars/GoldWars/Entities/HUD.swift @@ -12,18 +12,12 @@ class HUD: GKEntity { init(size: CGSize) { super.init() - addComponent(SpySkillComponent(text: "Spy", - texture: nil, - anchorPoint: CGPoint(x: size.width * 0.75, y: size.height * 0.1))) + addComponent(DefSkillComponent()) + addComponent(AtkSkillComponent()) + addComponent(SpySkillComponent()) - addComponent(AtkBoostSkillComponent(iconName: "", text: "Atk", position: CGPoint(x: size.width * 0.85, y: size.height * 0.1), isEnabled: true)) - - - addComponent(DefBoostSkillComponent(iconName: "", text: "Def", position: CGPoint(x: size.width * 0.95, y: size.height * 0.1), isEnabled: true)) - - addComponent(TimerComponent(text: "", - anchorPoint: CGPoint(x: size.width * 0.5, y: size.height * 0.9), duration: 30)) + addComponent(TimerComponent(text: "", anchorPoint: CGPoint(x: size.width * 0.5, y: size.height * 0.9), duration: 30)) addComponent(PlayerInfoComponent(size: size)) diff --git a/GoldWars/GoldWars/Label.swift b/GoldWars/GoldWars/Entities/Label.swift similarity index 100% rename from GoldWars/GoldWars/Label.swift rename to GoldWars/GoldWars/Entities/Label.swift diff --git a/GoldWars/GoldWars/Entities/Modal.swift b/GoldWars/GoldWars/Entities/Modal.swift index d125291..1a91bf5 100644 --- a/GoldWars/GoldWars/Entities/Modal.swift +++ b/GoldWars/GoldWars/Entities/Modal.swift @@ -8,32 +8,79 @@ import GameplayKit +enum ModalType: String{ + case BaseDetails + case BaseAttack +} + class Modal: GKEntity{ var entityManager = EntityManager.gameEMInstance - var unitCount:Int + var unitCount: Int + var background: SKSpriteNode + var closeButton: ButtonNode + var header: SKLabelNode + var body: SKLabelNode + var footer: SKLabelNode + init(modaltype: ModalType, base: Base, anchorPoint: CGPoint, gameScene: GameScene, currentDraggedBase: Base?, touchLocation: CGPoint, collisionBase: Base?) { unitCount = base.unitCount + + let texture = SKTexture(imageNamed:"ModalBackground") + background = SKSpriteNode(texture: texture, size: texture.size()) + background.setScale(2) + background.position = anchorPoint + background.zPosition = 3 + + closeButton = ButtonNode(textureName: "yellow_cross", text: "", isEnabled: true, position: CGPoint(x: anchorPoint.x + 160, y: anchorPoint.y + 140), onButtonPress: { + EntityManager.gameEMInstance.removeModal() + }) + closeButton.size = CGSize(width: 30, height: 30) + closeButton.zPosition = 4 + + + switch modaltype { + case .BaseDetails: + header = SKLabelNode(text: "Information") + body = SKLabelNode(text: "Diese Basis enthält \(base.unitCount) Einheiten") + footer = SKLabelNode() + case .BaseAttack: + header = SKLabelNode(text: "Angriff") + body = SKLabelNode(text: "Schicke \(unitCount / 2) Einheiten") + footer = SKLabelNode() + } + + self.header.position = CGPoint(x: anchorPoint.x, y: anchorPoint.y + 125) + self.header.fontName = "HelveticaNeue-Bold" + self.header.fontSize = 40 + self.header.zPosition = 4 + + self.body.position = CGPoint(x: anchorPoint.x, y: anchorPoint.y - 20) + self.body.numberOfLines = 2 + self.body.preferredMaxLayoutWidth = 390 + self.body.horizontalAlignmentMode = SKLabelHorizontalAlignmentMode.center + self.body.fontName = "HelveticaNeue-Bold" + self.body.fontSize = 40 + self.body.zPosition = 4 + + self.footer.position = CGPoint(x: anchorPoint.x, y: anchorPoint.y - 40) + self.footer.fontName = "HelveticaNeue-Bold" + self.footer.fontSize = 40 + self.footer.zPosition = 4 + super.init() + switch modaltype{ case .BaseDetails: - addComponent(ModalBackgroundComponent(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: { - self.removeModalEntities(gameScene: gameScene) + addComponent(ButtonComponent(textureName: "yellow_button04", text: "Zurück", position: CGPoint(x: anchorPoint.x , y: anchorPoint.y - 120), isEnabled: true, onButtonPress: { + EntityManager.gameEMInstance.removeModal() })) case .BaseAttack: - addComponent(ModalBackgroundComponent(anchorPoint: anchorPoint)) addComponent(SliderComponent(width: 300, position: CGPoint(x: anchorPoint.x , y: anchorPoint.y - 50))) - addComponent(ModalContentComponent(header: "Angriff", body: "Schicke \(unitCount / 2) Einheiten", - footer: "", anchorPoint: anchorPoint)) - addComponent(ButtonComponent(iconName: "", text: "Senden", position: CGPoint(x: anchorPoint.x , y: anchorPoint.y - 120), isEnabled: true, onButtonPress: { + addComponent(ButtonComponent(textureName: "yellow_button04", text: "Senden", position: CGPoint(x: anchorPoint.x , y: anchorPoint.y - 120), isEnabled: true, onButtonPress: { self.sendUnits(currentDraggedBase: currentDraggedBase, touchLocation: touchLocation, gameScene: gameScene, collisionBase: collisionBase) - self.removeModalEntities(gameScene: gameScene) - })) - addComponent(CancelBtnComponent(iconName: "", text: "", position: CGPoint(x: anchorPoint.x + 160, y: anchorPoint.y + 140), isEnabled: true, onButtonPress: { - self.removeModalEntities(gameScene: gameScene) + EntityManager.gameEMInstance.removeModal() })) } } diff --git a/GoldWars/GoldWars/Enums/ModalType.swift b/GoldWars/GoldWars/Enums/ModalType.swift index 40bcedf..08faf8d 100644 --- a/GoldWars/GoldWars/Enums/ModalType.swift +++ b/GoldWars/GoldWars/Enums/ModalType.swift @@ -6,7 +6,4 @@ // Copyright © 2020 SP2. All rights reserved. // -enum ModalType: String{ - case BaseDetails - case BaseAttack -} + diff --git a/GoldWars/GoldWars/Enums/UnitType.swift b/GoldWars/GoldWars/Enums/UnitType.swift deleted file mode 100644 index aec5ccd..0000000 --- a/GoldWars/GoldWars/Enums/UnitType.swift +++ /dev/null @@ -1,14 +0,0 @@ -// -// Units.swift -// GoldWars -// -// Created by Chauntalle Schüle on 20.04.20. -// Copyright © 2020 SP2. All rights reserved. -// - -enum UnitType{ - case General - case Defence - case Attack - case AttackDefence -} diff --git a/GoldWars/GoldWars/Scenes/GameScene.swift b/GoldWars/GoldWars/Scenes/GameScene.swift index 2e26378..96be62c 100644 --- a/GoldWars/GoldWars/Scenes/GameScene.swift +++ b/GoldWars/GoldWars/Scenes/GameScene.swift @@ -118,7 +118,11 @@ class GameScene: SKScene{ entityManager.add(Modal(modaltype: .BaseAttack, base: currentDraggedBase!, 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) } } @@ -127,7 +131,7 @@ class GameScene: SKScene{ func checkSlider(){ for e in entityManager.entities{ - if let body = e.component(ofType: ModalContentComponent.self)?.body{ + if let modal = e as? Modal { GameScene.sendUnits = ((e.component(ofType: SliderComponent.self)?.sliderNode.getValue ?? 0) * CGFloat((e as! Modal).unitCount)).rounded(.up) //TODO: refactor this quick and dirty fix @@ -136,7 +140,7 @@ class GameScene: SKScene{ } else if Int(GameScene.sendUnits) == currentDraggedBase?.unitCount { GameScene.sendUnits -= 1 } - body.text = "Schicke \(GameScene.sendUnits) Einheiten " + modal.body.text = "Schicke \(GameScene.sendUnits) Einheiten " } } } @@ -157,7 +161,7 @@ class GameScene: SKScene{ func moveFireAndBase(base: Base, touchLocation: CGPoint){ base.component(ofType: DefaultBaseComponent.self)?.spriteNode.position = touchLocation base.component(ofType: TeamComponent.self)?.fire.position = touchLocation - base.component(ofType: DefaultBaseComponent.self)?.labelNode?.position = CGPoint(x:touchLocation.x + 30, y: touchLocation.y - 50) + base.component(ofType: DefaultBaseComponent.self)?.labelNode.position = CGPoint(x:touchLocation.x + 30, y: touchLocation.y - 50) } func showNearestBases(base: Base){ diff --git a/GoldWars/GoldWars/Scenes/MenuScene.swift b/GoldWars/GoldWars/Scenes/MenuScene.swift index 64699d2..22152a1 100644 --- a/GoldWars/GoldWars/Scenes/MenuScene.swift +++ b/GoldWars/GoldWars/Scenes/MenuScene.swift @@ -18,7 +18,7 @@ class MenuScene: SKScene { let midX = self.size.width / 2 let midY = self.size.height / 2 entityManager.add(Button(name: "startGameButton", - iconName: "", + textureName: "yellow_button04", text: "Start Game", position: CGPoint(x: midX, y: midY), onButtonPress: { @@ -30,7 +30,7 @@ class MenuScene: SKScene { } })) entityManager.add(Button(name: "settingsButton", - iconName: "", + textureName: "yellow_button04", text: "Settings", position: CGPoint(x: midX, y: midY - 80 ), onButtonPress: { diff --git a/GoldWars/GoldWars/SettingsScene.swift b/GoldWars/GoldWars/SettingsScene.swift index 587426d..fbd25e2 100644 --- a/GoldWars/GoldWars/SettingsScene.swift +++ b/GoldWars/GoldWars/SettingsScene.swift @@ -18,7 +18,7 @@ class SettingsScene: SKScene { let positionY = self.size.height * 0.05 print("SceneDidLoad Setting") entityManager.add(Button(name: "backToMenuScene", - iconName: "", + textureName: "yellow_button04", text: "Back", position: CGPoint(x: positionX, y: positionY), onButtonPress: { @@ -26,7 +26,7 @@ class SettingsScene: SKScene { self.loadScene(scene: scene) })) entityManager.add(Button(name: "StopMenuMusic", - iconName: "", + textureName: "yellow_button04", text: "ON/OFF", position: CGPoint(x: self.size.width * 0.6, y: self.size.height / 2), onButtonPress: { @@ -39,7 +39,7 @@ class SettingsScene: SKScene { } })) entityManager.add(Button(name: "StopMovingBackground", - iconName: "", + textureName: "", text: "MOVE/STOP", position: CGPoint(x: self.size.width * 0.6, y: self.size.height / 2 - 100), onButtonPress: {