/**
 * Created by rockyl on 2019-04-17.
 */

import {Component} from 'scilla'
import Transform from "./Transform";
 
export default class ScillaComponent extends Component{
	get transform():Transform {
		return <Transform>this.entity.components[0]; //约定第0个组件为Transform组件
	}

	/**
	 * 根据组件名称获取指定类的组件列表
	 * @param name
	 */
	getComponentsByName<T extends Component>(name: string): T[] {
		return this.entity.getComponentsByName<T>(name);
	}

	/**
	 * 获取指定类的组件列表
	 * @param clazz
	 */
	getComponents<T extends Component>(clazz: new()=> T): T[] {
		return this.entity.getComponents<T>(clazz);
	}

	/**
	 * 获取指定类的组件
	 * @param name
	 */
	getComponentByName<T extends Component>(name: string): T {
		return this.entity.getComponentByName<T>(name);
	}

	/**
	 * 获取指定类的组件
	 * @param clazz
	 */
	getComponent<T extends Component>(clazz: new()=> T): T {
		return this.entity.getComponent<T>(clazz);
	}
}
