81 lines
2.1 KiB
Swift

//
// MapFactory.swift
// GoldWars
//
// Created by Marcel Schwarz on 02.05.20.
// Copyright © 2020 SP2. All rights reserved.
//
import Foundation
import SpriteKit
import os
protocol CenterElementProtocol {
var bases: [Base] {get set}
var ways: [Way] {get set}
var id: Int { get }
init(frame: CGRect)
func getAllBases() -> [Base]
func getInternalWays() -> [Way]
func getTopConnection() -> Base?
func getRightConnection() -> Base?
func getBottomConnection() -> Base?
func getLeftConnection() -> Base?
}
class MapFactory {
let LOG = OSLog.init(subsystem: "MapGenerator", category: "MapFactory")
var twoPlayerMapGenerator: TwoPlayerMapGenerator
init(scene: SKScene, entityManager: EntityManager) {
self.twoPlayerMapGenerator = TwoPlayerMapGenerator(scene: scene, entityManager: entityManager)
}
func loadMap() -> MapGenerationModel {
let mapModel = TwoPlayerMapGenerator.getNewMapModel()
loadMap(fromModel: mapModel)
return mapModel
}
func loadMap(fromModel model: MapGenerationModel) {
os_log("Loading two player map", log: LOG, type: .info)
twoPlayerMapGenerator.load(withModel: model)
}
}
class CenterElementProvider {
static let LOG = OSLog.init(subsystem: "MapGenerator", category: "CenterElementProvider")
static let centerElements: [CenterElementProtocol.Type] = [
CElement0.self,
CElement1.self,
CElement2.self,
CElement3.self,
CElement4.self,
CElement5.self,
CElement6.self,
CElement7.self,
CElement8.self,
CElement9.self,
CElement10.self,
CElement11.self,
CElement12.self,
CElement13.self,
CElement14.self,
CElement15.self,
CElement16.self,
CElement17.self
]
static func get(inFrame frame: CGRect, withId id: Int) -> CenterElementProtocol {
os_log("Getting new predifined center element from provider", log: LOG, type: .info)
return centerElements[id].init(frame: frame)
}
}