Fade in and out music

This commit is contained in:
Ategon 2024-08-28 20:22:52 -04:00
parent abeb696804
commit 261510de9c

View file

@ -7,6 +7,8 @@ var music_bus = AudioServer.get_bus_index("Music")
var _tracks = []
var current_track
var volume_tween
var keep_chain = 0
func _ready():
@ -35,7 +37,18 @@ func _play():
print("NO SONG COULD BE FOUND")
return
audio_stream_player.stream = load(song.track)
if volume_tween:
volume_tween.kill()
volume_tween = create_tween()
volume_tween.tween_property(audio_stream_player, "volume_db", -30, 3)
volume_tween.tween_callback(func():
audio_stream_player.stream = load(song.track)
)
volume_tween.tween_property(audio_stream_player, "volume_db", 0, 3)
audio_stream_player.play()
music_display.show_song(song)
current_track = song
@ -58,18 +71,22 @@ func _get_track():
var random_type_split = randf()
if reduced_tracks.size() > 1:
reduced_tracks = reduced_tracks.filter(func(track): return track.track != current_track.track)
var temp_tracks
if current_track:
if random_type_split < 0.4:
temp_tracks = reduced_tracks.filter(func(track): return track.artist == current_track.artist)
elif random_type_split < 0.8:
temp_tracks = reduced_tracks.filter(func(track): return track.definition_file == current_track.definition_file)
reduced_tracks = reduced_tracks.filter(func(track): return track.track != current_track.track)
if temp_tracks.size() > 0:
reduced_tracks = temp_tracks
var temp_tracks
if random_type_split < 0.4 and keep_chain <= 5:
temp_tracks = reduced_tracks.filter(func(track): return track.artist == current_track.artist)
keep_chain += 1
elif random_type_split < 0.8 and keep_chain <= 5:
temp_tracks = reduced_tracks.filter(func(track): return track.definition_file == current_track.definition_file)
keep_chain += 1
else:
keep_chain = 0
if temp_tracks and temp_tracks.size() > 0:
reduced_tracks = temp_tracks
var weight = reduced_tracks.reduce(func(accum, track): return accum + (track.weight if track.has("weight") else 1), 0)