//
//  DefaultTestMap.swift
//  GoldWars
//
//  Created by Marcel Schwarz on 02.05.20.
//  Copyright © 2020 SP2. All rights reserved.
//

import Foundation
import SpriteKit

class TwoPlayerDefaultTestMap: MapProtocol {
    
    var entityManager: EntityManager!
    var size: CGSize!
    
    required init(scene: SKScene, entityManager: EntityManager) {
        self.entityManager = entityManager;
        self.size = scene.size
    }
    
    func load() {
        
        // Create Bases
        let basePlayerOne = Base(
            position: CGPoint(x: self.size.width * 0.1, y: self.size.height / 2),
            team: .team1
        )
        
        let column1 = [
            Base(position: CGPoint(x: self.size.width * 0.25, y: self.size.height * 0.25)),
            Base(position: CGPoint(x: self.size.width * 0.25, y: self.size.height * 0.5)),
            Base(position: CGPoint(x: self.size.width * 0.25, y: self.size.height * 0.75))
        ]
        
        let column2 = [
            Base(position: CGPoint(x: self.size.width * 0.5, y: self.size.height * 0.333)),
            Base(position: CGPoint(x: self.size.width * 0.5, y: self.size.height * 0.666))
        ]
        
        let column3 = [
            Base(position: CGPoint(x: self.size.width * 0.75, y: self.size.height * 0.25)),
            Base(position: CGPoint(x: self.size.width * 0.75, y: self.size.height * 0.5)),
            Base(position: CGPoint(x: self.size.width * 0.75, y: self.size.height * 0.75))
        ]
        
        let basePlayerTwo = Base(
            position: CGPoint(x: self.size.width * 0.9, y: self.size.height / 2),
            team: .team2
        )
        
        // Create adjacency Mapping
        basePlayerOne.adjacencyList.append(contentsOf: column1)
        
        column1.forEach({currBase in
            currBase.adjacencyList.append(contentsOf: column2)
            currBase.adjacencyList.append(basePlayerOne)
        })
        
        column2.forEach({currBase in
            currBase.adjacencyList.append(contentsOf: column3)
            currBase.adjacencyList.append(contentsOf: column1)
        })
        
        column3.forEach({currBase in
            currBase.adjacencyList.append(basePlayerTwo)
            currBase.adjacencyList.append(contentsOf: column3)
        })
        
        basePlayerTwo.adjacencyList.append(contentsOf: column3)
        
        // Register bases with the EntityManager
        entityManager.add(basePlayerOne)
        
        column1.forEach({base in entityManager.add(base)})
        column2.forEach({base in entityManager.add(base)})
        column3.forEach({base in entityManager.add(base)})
        
        entityManager.add(basePlayerTwo)
    }
}
