/**
 * Created by rockyl on 2018/11/15.
 *
 */

import {engine} from 'scilla';
import ScillaComponent from "../base/ScillaComponent";

/**
 * 全舞台尺寸组件
 */
export default class FullStageSize extends ScillaComponent {
	once: boolean = true;
	applyWidth: boolean = true;
	applyHeight: boolean = true;

	private _stageSize;

	get stageSize(){
		if(!this._stageSize){
			this._stageSize = engine.renderContext.stageSize;
		}

		return this._stageSize;
	}

	onCreate() {
		super.onCreate();
	}

	onAwake() {
		super.onAwake();

		this.execute();
	}

	onUpdate(t) {
		super.onUpdate(t);

		if(!this.once){
			this.execute();
		}
	}

	onEditorUpdate(t) {
		super.onEditorUpdate(t);

		this.execute();
	}

	execute() {
		const {width, height} = this.stageSize;

		if(this.applyWidth){
			this.transform.width = width;
		}

		if(this.applyHeight){
			this.transform.height = height;
		}
	}
}
