Engine.EffectGenericFlash = class extends Engine.Drawable
{
	constructor()
	{
		super();

		this.onFinish = null
		this.speedMult = 0;

		this.blurFilter = new PIXI.filters.BlurFilter();
		this.colorizeFilter = new Engine.ColorizeFilter();//new PIXI.filters.AdjustmentFilter();
		//this.colorizeFilter.brightness = 5;
		this.colorizeFilter.init(Colors.white);
		this.flashGraphic = new Engine.Drawable();
		this.flashColorGraphic = new Engine.Drawable();
		this.currentIndex = 0;
		this.tween = new Engine.SimpleTween();
        this.alphaTargets = [0, 1, 0.38, 0];

		this.flashGraphic.additive = true;
		this.flashColorGraphic.additive = true;
		
		this.addChild(this.flashGraphic);
		this.addChild(this.flashColorGraphic);

		this.addLiveEffect(this.blurFilter);
		this.addLiveEffect(this.colorizeFilter);
		//this.addLiveEffect(this.blurFilter);
		//this.addLiveEffect(this.colorizeFilter);
	}

	init(drawable /*Drawable*/, flashTime /*float*/, color /*Color*/)
	{
		this.speedMult = flashTime / 0.7;
		//var name = Engine.Filter.applyFiltersAndCache(drawable, this.filters);
		this.flashGraphic.loadFromGraphicName(drawable.graphicData.name);
		this.flashColorGraphic.loadFromGraphicName(drawable.graphicData.name);
		//this.flashColorGraphic.tint = color;
		this.flashGraphic.scale = drawable.scale;
		this.flashColorGraphic.scale = drawable.scale;
	}

	go()
	{
		this.currentIndex = 1;
		this.tween.init((v) => this.animateFilterUpdate(v), Engine.SimpleTween.quadEaseIn, 0, 1, 0.2 * this.speedMult);
		this.tween.onFinish = () => this.flashFadeInMid();
	}

	flashFadeInMid()
	{
		this.currentIndex = 2;
		this.tween.init((v) => this.animateFilterUpdate(v), Engine.SimpleTween.quadEaseIn, 0, 1, 0.2 * this.speedMult);
		this.tween.onFinish = () => this.returnFilterToNormal();
	}

	returnFilterToNormal()
	{
		this.currentIndex = 3;
		this.tween.init((v) => this.animateFilterUpdate(v), Engine.SimpleTween.quadEaseIn, 0, 1, 0.3 * this.speedMult);
		this.tween.onFinish = () => this.finished();
	}

	finished()
	{
		if (this.onFinish != null) this.onFinish();
	}

	animateFilterUpdate(value /*float*/)
	{
		var start = this.alphaTargets[this.currentIndex - 1];
		var end = this.alphaTargets[this.currentIndex];
		this.flashGraphic.alpha = start + value * (end - start);
		this.flashColorGraphic.alpha = start + value * (end - start);
	}
}