Merge pull request #6537 from jorbascrumps/feat-use-seeded-random-for-tilemap-weighted-randomize

Updates `Tilemaps.Components.WeightedRandomize` to use seeded random value
This commit is contained in:
Robert Kowalski 2024-01-30 18:45:20 -05:00 committed by GitHub
commit b27e4d3744
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -5,6 +5,7 @@
*/
var GetTilesWithin = require('./GetTilesWithin');
var MATH = require('../../math');
/**
* Randomizes the indexes of a rectangular region of tiles (in tile coordinates) within the
@ -51,7 +52,7 @@ var WeightedRandomize = function (tileX, tileY, width, height, weightedIndexes,
for (i = 0; i < tiles.length; i++)
{
var rand = Math.random() * weightTotal;
var rand = MATH.RND.frac() * weightTotal;
var sum = 0;
var randomIndex = -1;
@ -64,7 +65,7 @@ var WeightedRandomize = function (tileX, tileY, width, height, weightedIndexes,
var chosen = weightedIndexes[j].index;
randomIndex = Array.isArray(chosen)
? chosen[Math.floor(Math.random() * chosen.length)]
? chosen[Math.floor(MATH.RND.frac() * chosen.length)]
: chosen;
break;
}