-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvolume_slider.gd
More file actions
48 lines (36 loc) · 1.46 KB
/
volume_slider.gd
File metadata and controls
48 lines (36 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
## Copyright (C) 2025 Egor Kostan
## SPDX-License-Identifier: GPL-3.0-or-later
# New: Register as global class for testing and reuse
class_name VolumeSlider
extends HSlider
@export var bus_name: String
var bus_index: int
# New: Debounce timer for saving settings
var save_debounce_timer: Timer
func _ready() -> void:
# Get bus id by name
bus_index = AudioServer.get_bus_index(bus_name)
# Set current bus volume value first (without triggering signal yet)
value = db_to_linear(AudioServer.get_bus_volume_db(bus_index))
# Now connect signal for future changes
value_changed.connect(_on_value_changed)
# New: Initialize debounce timer (0.5s delay, one-shot)
save_debounce_timer = Timer.new()
save_debounce_timer.wait_time = 0.5
save_debounce_timer.one_shot = true
save_debounce_timer.timeout.connect(_on_debounce_timeout)
add_child(save_debounce_timer) # Add to scene tree for auto-processing
# change bus value/volume
func _on_value_changed(value: float) -> void:
AudioServer.set_bus_volume_db(bus_index, linear_to_db(value))
AudioManager.set_volume(bus_name, value)
# New: Start/restart debounce timer instead of immediate save
if save_debounce_timer.is_stopped():
save_debounce_timer.start()
else:
save_debounce_timer.stop()
save_debounce_timer.start()
# New: Called on timer timeout—perform the batched save
func _on_debounce_timeout() -> void:
AudioManager.save_volumes()
Globals.log_message("Debounced settings save triggered.", Globals.LogLevel.DEBUG)