Update WeightedRandomize() to support index arrays

This commit is contained in:
Hal Helms 2018-01-09 22:05:34 -08:00 committed by GitHub
parent 15c45bda0e
commit e128733f02
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -48,8 +48,10 @@ var WeightedRandomize = function (tileX, tileY, width, height, weightedIndexes,
sum += weightedIndexes[j].weight;
if (rand <= sum)
{
randomIndex = weightedIndexes[j].index;
break;
var chosen = weightedIndexes[j].index
randomIndex = Array.isArray(chosen)
? chosen[Math.floor(Math.random() * chosen.length)]
: chosen
}
}