Add track weights

This commit is contained in:
Ategon 2024-08-27 19:49:56 -04:00
parent f3dfc02119
commit 66117d14aa

View file

@ -52,7 +52,18 @@ func _get_track():
if _tracks.size() == 0:
return null
return _tracks.pick_random()
var weight = _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:
current_weight += track.weight if track.has("weight") else 1
if current_weight >= rand:
return track
return null