Skip to content

Commit e128733

Browse files
authored
Update WeightedRandomize() to support index arrays
1 parent 15c45bd commit e128733

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/gameobjects/tilemap/components/WeightedRandomize.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ var WeightedRandomize = function (tileX, tileY, width, height, weightedIndexes,
4848
sum += weightedIndexes[j].weight;
4949
if (rand <= sum)
5050
{
51-
randomIndex = weightedIndexes[j].index;
52-
break;
51+
var chosen = weightedIndexes[j].index
52+
randomIndex = Array.isArray(chosen)
53+
? chosen[Math.floor(Math.random() * chosen.length)]
54+
: chosen
5355
}
5456
}
5557

0 commit comments

Comments
 (0)