- Types on every parameter, return value and variable, and snake_case names (the player name limit is the constant MAX_NAME_LENGTH). - Spelling fixes: *_triggered, character_selected, separator, caught_errors. The server's catched_errors key stays as the server sends it. - Signals are connected with signal.connect() instead of by name. - Code is ordered signals, constants, exported vars, vars, @onready vars, functions, with @onready on one line and two blank lines between functions. - Every script starts with a ## description. Template comments, old LOC notes and commented-out code are gone, apart from the local play code. - Lines are at most 100 characters, apart from the local play path. - The screenshot tour turns off the blinking text cursor so pictures match.
25 lines
693 B
GDScript
25 lines
693 B
GDScript
class_name VolumeSlider
|
|
extends HSlider
|
|
## A slider that sets the volume of an audio bus.
|
|
|
|
## The audio bus whose volume the slider sets.
|
|
|
|
@export var audio_bus_name: String = "music"
|
|
|
|
var _bus: int
|
|
|
|
|
|
func _ready() -> void:
|
|
_bus = AudioServer.get_bus_index(audio_bus_name)
|
|
value_changed.connect(_on_value_changed)
|
|
value = db_to_linear(AudioServer.get_bus_volume_db(_bus))
|
|
|
|
|
|
## Sets the bus volume to [param changed_value], from 0 (silent) to 1 (full).
|
|
func change_volume(changed_value: float) -> void:
|
|
AudioServer.set_bus_volume_db(_bus, linear_to_db(changed_value))
|
|
|
|
|
|
func _on_value_changed(changed_value: float) -> void:
|
|
AudioServer.set_bus_volume_db(_bus, linear_to_db(changed_value))
|