/*
 * Copyright 2013-2019, kaj dijkstra , 
 * Author, Kaj Dijkstra.
 * All rights reserved.
 *
 */
 
import entity from './entity.js';
/**
 * Scene Node
**/
class scene{

	rootEntity;
	entitys = [];

	/**
	 * add entity to scene
	 * @param {(entity)} entity
	**/
	addEntity(entity){

		
		this.entitys.push(entity);
	}
	
	
	getLights(){
		
		var lightEntitys = [];
		
		for(var c = 0; c<this.entitys.length;c++) {
			if(this.entitys[c].type == "pointLight" || this.entitys[c].type == "skyLight")
				lightEntitys.push( this.entitys[c] );
		}
		
		if(lightEntitys.length == 0) {
			
			var light = new entity( );

			light.name = "skylight";
			light.transform.position = [0, 18.1, -10.01];
			light.type = "skyLight"; 
			//light.type = "pointLight"; 
			light.transform.direction = [0, -4, -0.01];
			//light.showFrustum = true;
			light.degrees = 70;
		
			lightEntitys.push( light );
			
			this.entitys.push( light );
		}
		
		return lightEntitys;
	}
	
	/**
	 * get entity's
	 * @param {(entity)} entity
	**/
	getEntitys(entity){
		return this.entitys;
	}

	getEntityByName(name){
		for(var c = 0; c<this.entitys.length;c++) {
			if(this.entitys[c].name == name)
				return this.entitys[c];
		}
	}
	getEntityByID(id){

		for(var c = 0; c<this.entitys.length;c++) {
			if(this.entitys[c].id == id)
				return this.entitys[c];
		}

	}
	
	getEntityByName(name){
		for(var c = 0; c<this.entitys.length;c++) {
			if(this.entitys[c].name == name)
				return this.entitys[c];
		}
	}

	removeEntityByName(name){
		for(var c = 0; c<this.entitys.length;c++) {
			if(this.entitys[c].name == name)
				this.entitys.splice(c, 1);
		}
		
		
		var children = kepler.system.scene.rootEntity.children[0].children;
		for(var c = 0; c<children.length;c++) {
			if(children[c].name == name)
				children.splice(c, 1);
		}
		
	}
}

export {scene as default};