package com.isartdigital.game.sprites;

import com.isartdigital.utils.game.BoxType;
import com.isartdigital.utils.game.factory.MovieClipAnimFactory;
import com.isartdigital.utils.game.GameStage;
import com.isartdigital.utils.game.StateGraphic;
import com.isartdigital.utils.system.DeviceCapabilities;
import pixi.extras.MovieClip;

	
/**
 * ...
 * @author Nathan
 */
class CheckItem extends StateGraphic 
{	
	
	public static var arrayCheckItem : Array<CheckItem> = new Array<CheckItem>();
	
	
	public function new(pBool:Bool) 
	{
		super();
		factory = new MovieClipAnimFactory();
		boxType = BoxType.SIMPLE;
		//x = DeviceCapabilities.getScreenRect(GameStage.getInstance()).x + DeviceCapabilities.getScreenRect(GameStage.getInstance()).width / 2;
		//y = DeviceCapabilities.getScreenRect(GameStage.getInstance()).y + DeviceCapabilities.getScreenRect(GameStage.getInstance()).height / 2;
		init(pBool);
		untyped anim.animationSpeed = 0.1;
		arrayCheckItem.push(this);
	}
	
	public function init(pBool: Bool) {
		start();
		pBool ? setModeCorrect() : setModeWrong();
	}
	
	private function setModeCorrect() {
		setState("right");
		cast(anim,MovieClip).anchor.set(0.5, 0.5);
	}
	
	private function setModeWrong() {
		setState("wrong");
		cast(anim,MovieClip).anchor.set(0.5, 0.5);
	}
	
	override function doActionNormal():Void 
	{
		super.doActionNormal();
		untyped anim.onComplete = function() { finished(); }
	}
	
	public function finished ():Void {
		GameStage.getInstance().removeChild(this);
		arrayCheckItem.splice(arrayCheckItem.indexOf(this), 1);
		destroy();
	}
}