Compare commits
4 commits
Author | SHA1 | Date | |
---|---|---|---|
|
4c066b821c | ||
|
261510de9c | ||
|
abeb696804 | ||
|
8dce1ee84b |
1 changed files with 41 additions and 3 deletions
44
src/main.gd
44
src/main.gd
|
@ -6,6 +6,9 @@ extends CanvasLayer
|
|||
var music_bus = AudioServer.get_bus_index("Music")
|
||||
|
||||
var _tracks = []
|
||||
var current_track
|
||||
var volume_tween
|
||||
var keep_chain = 0
|
||||
|
||||
|
||||
func _ready():
|
||||
|
@ -34,9 +37,19 @@ func _play():
|
|||
print("NO SONG COULD BE FOUND")
|
||||
return
|
||||
|
||||
if volume_tween:
|
||||
volume_tween.kill()
|
||||
|
||||
audio_stream_player.volume_db = -30
|
||||
audio_stream_player.stream = load(song.track)
|
||||
audio_stream_player.play()
|
||||
music_display.show_song(song)
|
||||
current_track = song
|
||||
|
||||
volume_tween = create_tween()
|
||||
volume_tween.tween_property(audio_stream_player, "volume_db", 0, 3)
|
||||
volume_tween.tween_interval(audio_stream_player.stream.get_length() - 3)
|
||||
volume_tween.tween_property(audio_stream_player, "volume_db", -30, 3)
|
||||
|
||||
|
||||
func _stop():
|
||||
|
@ -52,12 +65,33 @@ func _get_track():
|
|||
if _tracks.size() == 0:
|
||||
return null
|
||||
|
||||
var weight = _tracks.reduce(func(accum, track): return accum + (track.weight if track.has("weight") else 1), 0)
|
||||
var reduced_tracks = _tracks
|
||||
var random_type_split = randf()
|
||||
|
||||
if reduced_tracks.size() > 1:
|
||||
if current_track:
|
||||
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)
|
||||
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)
|
||||
|
||||
var rand = randf() * weight
|
||||
var current_weight = 0
|
||||
|
||||
for track in _tracks:
|
||||
for track in reduced_tracks:
|
||||
current_weight += track.weight if track.has("weight") else 1
|
||||
|
||||
if current_weight >= rand:
|
||||
|
@ -66,7 +100,6 @@ func _get_track():
|
|||
return null
|
||||
|
||||
|
||||
|
||||
func _load_tracks():
|
||||
_load_directory("res://tracks")
|
||||
print("Loaded music")
|
||||
|
@ -88,8 +121,13 @@ func _load_directory(path: String):
|
|||
for track in new_tracks:
|
||||
if track.has("disabled") and track.disabled:
|
||||
continue
|
||||
track.definition_file = "%s/%s" % [path, file_name]
|
||||
_tracks.push_back(track)
|
||||
else:
|
||||
_load_directory("res://tracks/%s" % [file_name])
|
||||
|
||||
file_name = dir.get_next()
|
||||
|
||||
|
||||
func _on_audio_stream_player_finished() -> void:
|
||||
_play()
|
||||
|
|
Loading…
Reference in a new issue