extends Node3D

const MAX_RADIUS: float = 20.0
const DURATION: float = 1.0

signal pulse_finished()


func trigger() -> void:
	var mesh_instance := MeshInstance3D.new()
	var sphere_mesh := SphereMesh.new()
	sphere_mesh.radius = 0.1
	sphere_mesh.height = 0.2
	mesh_instance.mesh = sphere_mesh

	var mat := StandardMaterial3D.new()
	mat.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA
	mat.albedo_color = Color(0.2, 0.85, 1.0, 0.5)
	mat.emission_enabled = true
	mat.emission = Color(0.1, 0.6, 1.0)
	mat.emission_energy_multiplier = 1.5
	mat.cull_mode = BaseMaterial3D.CULL_DISABLED
	mesh_instance.material_override = mat

	add_child(mesh_instance)

	var tween: Tween = create_tween()
	tween.set_parallel(true)
	tween.tween_method(
		func(r: float) -> void:
			mesh_instance.scale = Vector3(r, r, r),
		0.1,
		MAX_RADIUS,
		DURATION
	)
	tween.tween_method(
		func(a: float) -> void:
			mat.albedo_color = Color(0.2, 0.85, 1.0, a),
		0.5,
		0.0,
		DURATION
	)
	tween.chain().tween_callback(func() -> void:
		mesh_instance.queue_free()
		pulse_finished.emit()
	)
