47 lines
1.3 KiB
GDScript
47 lines
1.3 KiB
GDScript
extends Node3D
|
|
|
|
#const TRAIN_WHISTLE_STREAM: AudioStream = preload("res://tgcc/train/sounds/train_whistle.mp3")
|
|
const TRAIN_WHISTLE_STREAM: AudioStream = preload("res://tgcc/train/sounds/train_whistle2.mp3")
|
|
|
|
@export_group("Whistle")
|
|
@export var whistle_volume_db: float = 1.0
|
|
@export var whistle_unit_size: float = 90.0
|
|
@export var whistle_max_distance: float = 1200.0
|
|
|
|
var _whistle_player: AudioStreamPlayer3D
|
|
|
|
|
|
func _ready() -> void:
|
|
_create_whistle_player()
|
|
|
|
if not UIEvents.toot_toot.is_connected(_on_toot_toot):
|
|
UIEvents.toot_toot.connect(_on_toot_toot)
|
|
|
|
|
|
func _exit_tree() -> void:
|
|
if UIEvents.toot_toot.is_connected(_on_toot_toot):
|
|
UIEvents.toot_toot.disconnect(_on_toot_toot)
|
|
|
|
|
|
func _create_whistle_player() -> void:
|
|
_whistle_player = AudioStreamPlayer3D.new()
|
|
_whistle_player.name = "TrainWhistlePlayer"
|
|
_whistle_player.bus = &"SFX"
|
|
_whistle_player.volume_db = whistle_volume_db
|
|
_whistle_player.unit_size = whistle_unit_size
|
|
_whistle_player.max_distance = whistle_max_distance
|
|
_whistle_player.stream = TRAIN_WHISTLE_STREAM
|
|
add_child(_whistle_player)
|
|
|
|
|
|
func _on_toot_toot() -> void:
|
|
if _whistle_player == null:
|
|
return
|
|
|
|
print("stat_toottoot_number")
|
|
StatsManager.add_int("stat_toottoot_number", 1)
|
|
StatsManager.store()
|
|
|
|
_whistle_player.stop()
|
|
_whistle_player.play()
|