extends Node
class_name ReedSFXSystem

# =========================
# 可选：统一音频 Bus
# =========================
@export var default_bus := "SFX"


# =========================
# 在世界坐标播放音效
# =========================
func play_sfx_at_pos(
	stream: AudioStream,
	world_pos: Vector2,
	volume_db: float = 0.0,
	pitch_scale: float = 1.0
) -> void:
	if not stream:
		return

	var player := AudioStreamPlayer2D.new()
	player.stream = stream
	player.bus = default_bus
	player.volume_db = volume_db
	player.pitch_scale = pitch_scale
	player.global_position = world_pos

	add_child(player)
	player.play()

	# 播放完自动回收
	player.finished.connect(player.queue_free)


# =========================
# 全局 / UI 音效（不受 位置 影响）
# =========================
func play_sfx_global(
	stream: AudioStream,
	volume_db: float = 0.0,
	pitch_scale: float = 1.0
) -> void:
	if not stream:
		return

	var player := AudioStreamPlayer.new()
	player.stream = stream
	player.bus = default_bus
	player.volume_db = volume_db
	player.pitch_scale = pitch_scale

	add_child(player)
	player.play()

	player.finished.connect(player.queue_free)
