Fade in and out music
This commit is contained in:
parent
abeb696804
commit
261510de9c
1 changed files with 27 additions and 10 deletions
37
src/main.gd
37
src/main.gd
|
@ -7,6 +7,8 @@ var music_bus = AudioServer.get_bus_index("Music")
|
||||||
|
|
||||||
var _tracks = []
|
var _tracks = []
|
||||||
var current_track
|
var current_track
|
||||||
|
var volume_tween
|
||||||
|
var keep_chain = 0
|
||||||
|
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
|
@ -35,7 +37,18 @@ func _play():
|
||||||
print("NO SONG COULD BE FOUND")
|
print("NO SONG COULD BE FOUND")
|
||||||
return
|
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()
|
audio_stream_player.play()
|
||||||
music_display.show_song(song)
|
music_display.show_song(song)
|
||||||
current_track = song
|
current_track = song
|
||||||
|
@ -58,18 +71,22 @@ func _get_track():
|
||||||
var random_type_split = randf()
|
var random_type_split = randf()
|
||||||
|
|
||||||
if reduced_tracks.size() > 1:
|
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 current_track:
|
||||||
if random_type_split < 0.4:
|
reduced_tracks = reduced_tracks.filter(func(track): return track.track != current_track.track)
|
||||||
|
|
||||||
|
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)
|
temp_tracks = reduced_tracks.filter(func(track): return track.artist == current_track.artist)
|
||||||
elif random_type_split < 0.8:
|
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)
|
temp_tracks = reduced_tracks.filter(func(track): return track.definition_file == current_track.definition_file)
|
||||||
|
keep_chain += 1
|
||||||
if temp_tracks.size() > 0:
|
else:
|
||||||
reduced_tracks = temp_tracks
|
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)
|
var weight = reduced_tracks.reduce(func(accum, track): return accum + (track.weight if track.has("weight") else 1), 0)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue