class_name ShotSFX extends Node3D
## SFX controller for golf shots

const BASE_VOLUME := -6.0
const MAX_VOLUME := -1.0

@onready var good_drive_sfx_player: AudioStreamPlayer3D = %GoodDriveSFXPlayer
@onready var bad_drive_sfx_player: AudioStreamPlayer3D = %BadDriveSFXPlayer
@onready var putt_sfx_player: AudioStreamPlayer3D = %PuttSFXPlayer


func _attenuate_volume(power: float) -> float:
	return lerpf(BASE_VOLUME, MAX_VOLUME, power)


func play_shot_sfx(club_type: Club.Type, good: bool, power: float) -> void:
	var player: AudioStreamPlayer3D
	match club_type:
		Club.Type.PUTTER:
			player = putt_sfx_player
		_:
			# TODO more varied SFX maybe?
			player = good_drive_sfx_player if good else bad_drive_sfx_player

	player.volume_db = _attenuate_volume(power)
	print_debug("Playing ", player)
	player.play()
