Pull protocols in MapFactory

Add TwoPlayerMapGenerator
Add CenterElementProvider
Introduce Logging for MapGenerator
This commit is contained in:
Marcel Schwarz 2020-05-13 22:24:15 +02:00
parent 701a56248a
commit e2bd0dc7cf
4 changed files with 87 additions and 22 deletions

View File

@ -49,6 +49,7 @@
AB1D759C245DD18100671525 /* MapProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB1D759A245DD18100671525 /* MapProtocol.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 */; };
AE151589245F18EF001D363E /* MatchmakingHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE151588245F18EF001D363E /* MatchmakingHelper.swift */; };
AEBF3AFF246EB146004F7CD5 /* CancelBtnNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEBF3AFE246EB146004F7CD5 /* CancelBtnNode.swift */; };
@ -120,6 +121,7 @@
AB1D759A245DD18100671525 /* MapProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MapProtocol.swift; sourceTree = "<group>"; };
AB1D759B245DD18100671525 /* TwoPlayerDefaultTestMap.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TwoPlayerDefaultTestMap.swift; sourceTree = "<group>"; };
AB1D759F245DEC0500671525 /* MapFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapFactory.swift; sourceTree = "<group>"; };
AB21D7D4246C748A00B09CBA /* TwoPlayerMapGenerator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TwoPlayerMapGenerator.swift; sourceTree = "<group>"; };
ABA03D9F244BD54F00A66916 /* Base.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Base.swift; sourceTree = "<group>"; };
AE151588245F18EF001D363E /* MatchmakingHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MatchmakingHelper.swift; sourceTree = "<group>"; };
AEBF3AFE246EB146004F7CD5 /* CancelBtnNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CancelBtnNode.swift; sourceTree = "<group>"; };
@ -297,9 +299,9 @@
AB1D759E245DD2EA00671525 /* Map */ = {
isa = PBXGroup;
children = (
AB1D759A245DD18100671525 /* MapProtocol.swift */,
AB1D759F245DEC0500671525 /* MapFactory.swift */,
AB1D759B245DD18100671525 /* TwoPlayerDefaultTestMap.swift */,
AB21D7D4246C748A00B09CBA /* TwoPlayerMapGenerator.swift */,
);
path = Map;
sourceTree = "<group>";
@ -429,6 +431,7 @@
AE151589245F18EF001D363E /* MatchmakingHelper.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 */,
9EA3ABED245C8143006BC61D /* ModalBackgroundComponent.swift in Sources */,

View File

@ -8,8 +8,30 @@
import Foundation
import SpriteKit
import os
protocol MapProtocol {
var size: CGSize! {get set}
var entityManager: EntityManager! {get set}
init(scene: SKScene, entityManager: EntityManager)
func load()
}
protocol CenterElementProtocol {
init(frame: CGRect)
func getAllBases() -> [Base]
func getTopConnection() -> Base
func getRightConnection() -> Base
func getBottomConnection() -> Base
func getLeftConnection() -> Base
}
class MapFactory {
let LOG = OSLog.init(subsystem: "MapGenerator", category: "MapFactory")
var twoPlayerMaps: [MapProtocol]!
var threePlayerMaps: [MapProtocol]!
@ -17,7 +39,7 @@ class MapFactory {
init(scene: SKScene, entityManager: EntityManager) {
self.twoPlayerMaps = [
TwoPlayerDefaultTestMap(scene: scene, entityManager: entityManager)
TwoPlayerMapGenerator(scene: scene, entityManager: entityManager)
]
self.threePlayerMaps = [MapProtocol]()
@ -26,11 +48,24 @@ class MapFactory {
func loadMap(playerCount: Int) {
if playerCount == 2 {
os_log("Loading two player map", log: LOG, type: .info)
twoPlayerMaps.randomElement()?.load()
} else if playerCount == 3 {
os_log("Loading three player map", log: LOG, type: .info)
threePlayerMaps.randomElement()?.load()
} else {
os_log("Loading four player map", log: LOG, type: .info)
fourPlayerMaps.randomElement()?.load()
}
}
}
class CenterElementProvider {
static let LOG = OSLog.init(subsystem: "MapGenerator", category: "CenterElementProvider")
static func get(frame: CGRect) -> CenterElementProtocol? {
// TODO: Implemented by Jakob
os_log("Getting new center from provider", log: LOG, type: .info)
return nil
}
}

View File

@ -1,20 +0,0 @@
//
// MapProtocoll.swift
// GoldWars
//
// Created by Marcel Schwarz on 02.05.20.
// Copyright © 2020 SP2. All rights reserved.
//
import Foundation
import SpriteKit
protocol MapProtocol {
var size: CGSize! {get set}
var entityManager: EntityManager! {get set}
init(scene: SKScene, entityManager: EntityManager)
func load()
}

View File

@ -0,0 +1,47 @@
//
// TwoPlayerMapGenerator.swift
// GoldWars
//
// Created by Marcel Schwarz on 13.05.20.
// Copyright © 2020 SP2. All rights reserved.
//
import Foundation
import SpriteKit
import os
class TwoPlayerMapGenerator: MapProtocol {
let LOG = OSLog.init(subsystem: "MapGenerator", category: "TwoPlayerMapGenerator")
var size: CGSize!
var entityManager: EntityManager!
required init(scene: SKScene, entityManager: EntityManager) {
self.size = scene.size
self.entityManager = entityManager
}
func load() {
os_log("Loading from TwoPlayerMapFactory", log: LOG, type: .info)
getPlayerOneAndStartbases()
getMapCenter()
getPlayerTwoAndStartbases()
}
private func getPlayerOneAndStartbases() -> [Base]{
os_log("Get player one and his startbases", log: LOG, type: .info)
return [Base]()
}
private func getPlayerTwoAndStartbases() -> [Base]{
os_log("Get player two and his startbases", log: LOG, type: .info)
return [Base]()
}
private func getMapCenter() -> [Base] {
os_log("Get centered bases", log: LOG, type: .info)
return [Base]()
}
}