refactor
This commit is contained in:
@@ -2,32 +2,40 @@ extends Node
|
||||
|
||||
const MUSIC_PATH := "res://audio/Space Horror InGame Music (Exploration) _Clement Panchout.wav"
|
||||
|
||||
@onready var music_player := AudioStreamPlayer.new()
|
||||
var music_player: AudioStreamPlayer
|
||||
|
||||
func _ready():
|
||||
music_player = AudioStreamPlayer.new()
|
||||
add_child(music_player)
|
||||
if not _load_and_configure_stream():
|
||||
|
||||
var orig_stream = _load_stream()
|
||||
if not orig_stream:
|
||||
push_error("Failed to load music stream: %s" % MUSIC_PATH)
|
||||
return
|
||||
|
||||
var stream = orig_stream.duplicate(true) as AudioStream
|
||||
|
||||
_configure_stream_loop(stream)
|
||||
music_player.stream = stream
|
||||
_configure_audio_bus()
|
||||
|
||||
if SettingsManager.get_setting("music_volume") > 0:
|
||||
_start_music()
|
||||
if SettingsManager.get_setting("music_volume") <= 0:
|
||||
return
|
||||
|
||||
func _load_and_configure_stream() -> bool:
|
||||
var stream: AudioStream = load(MUSIC_PATH)
|
||||
if not stream:
|
||||
return false
|
||||
_start_music()
|
||||
|
||||
func _load_stream() -> AudioStream:
|
||||
var res = load(MUSIC_PATH)
|
||||
if not res or not res is AudioStream:
|
||||
return null
|
||||
return res
|
||||
|
||||
func _configure_stream_loop(stream: AudioStream) -> void:
|
||||
if stream is AudioStreamWAV:
|
||||
stream.loop_mode = AudioStreamWAV.LOOP_FORWARD
|
||||
elif stream is AudioStreamOggVorbis:
|
||||
stream.loop = true
|
||||
|
||||
music_player.stream = stream
|
||||
return true
|
||||
|
||||
func _configure_audio_bus() -> void:
|
||||
music_player.bus = "Music"
|
||||
music_player.volume_db = linear_to_db(SettingsManager.get_setting("music_volume"))
|
||||
|
||||
Reference in New Issue
Block a user