extends Node

#The time, in seconds, it should take for the character to fade to FadeOutValue
export var FadeOutTime = 2.0
export var InvisTime = 5.0
export var FadeInTime = 1.0

#The alpha value we aim for when fading out
export var FadeOutValue = 0.025

func AlmostFadeOutRoutine(player, delta):
	var sprite : Sprite = player.get_node("Sprite")
	var elapsed = delta	
	var origin = sprite.get_modulate().a
	while sprite.self_modulate.a > FadeOutValue:
		player.ALPHA_FACTORS.append(lerp(1, FadeOutValue, elapsed /  FadeOutTime))
		elapsed += yield()
		
	elapsed -= FadeOutTime;
	while elapsed < InvisTime:
		player.ALPHA_FACTORS.append(FadeOutValue)
		elapsed += yield()	
	elapsed -= InvisTime;
		
	while sprite.self_modulate.a < origin:
		player.ALPHA_FACTORS.append(lerp(FadeOutValue, 1, elapsed / FadeInTime))
		elapsed += yield()	
		

func StartEffect(player):
	var rout = AlmostFadeOutRoutine(player, 0)
	return rout	
	
