class_name HUDParticles extends GPUParticles2D
## 2D particle emitter with spatial logic, for emitting particles in the HUD.


## Emit the given number of particles in one shot.
func emit(_amount: int) -> void:
	amount = _amount
	emitting = true


## Emit the given number of particles from the given screen location.
func emit_at_location(_amount: int, source_location: Vector2) -> void:
	var particle_mat: ParticleProcessMaterial = process_material
	particle_mat.emission_shape_offset = Vector3(source_location.x, source_location.y, 0)
	emit(_amount)


## Emit the given number of particles from the screen location of the given point in 3D space.
func emit_spatial(_amount: int, source_location: Vector3) -> void:
	var screen_location := (
		get_viewport().get_camera_3d().unproject_position(source_location) - global_position
	)
	# TODO: what to do if this is outside the viewport?
	emit_at_location(_amount, screen_location)
