diff --git a/src/main.gd b/src/main.gd index 18d8b0d..928b95f 100644 --- a/src/main.gd +++ b/src/main.gd @@ -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: + 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) - 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) - - if temp_tracks.size() > 0: - reduced_tracks = temp_tracks + 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)