extends PointLight2D

@export_range(0.0, 1.0, 0.01, "suffix:%") var to_intensity: float;
@export_range(0.1, 5.0, 0.1, "or_greater", "suffix:s") var duration: float;
var tween: Tween;

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	assert(duration >= 0.0);
	var current: float = energy;
	tween = get_tree().create_tween();
	tween.tween_interval(randf_range(0.75, 1.25));
	for i in range(4):	
		tween.tween_property(self, "energy", current * to_intensity, duration * randf_range(0.8, 1.22)).set_trans(Tween.TRANS_CUBIC);
		tween.tween_property(self, "energy", current, duration * randf_range(0.8, 1.22)).set_trans(Tween.TRANS_CUBIC);
	tween.set_loops();
	
	tween.play();

func _exit_tree() -> void:
	if tween:
		tween.kill();
