2017-11-16 02:06:07 +00:00
|
|
|
var GetTilesWithin = require('./GetTilesWithin');
|
|
|
|
var GetRandomElement = require('../../../utils/array/GetRandomElement');
|
|
|
|
|
2017-11-22 01:07:22 +00:00
|
|
|
// Randomizes indices, not other properties. Does not modify collisions. Matches v2 functionality.
|
|
|
|
var Randomize = function (tileX, tileY, width, height, indices, layer)
|
2017-11-16 02:06:07 +00:00
|
|
|
{
|
|
|
|
var i;
|
|
|
|
var tiles = GetTilesWithin(tileX, tileY, width, height, layer);
|
|
|
|
|
|
|
|
// If no indicies are given, then find all the unique indices within the specified region
|
|
|
|
if (indices === undefined)
|
|
|
|
{
|
|
|
|
indices = [];
|
|
|
|
for (i = 0; i < tiles.length; i++)
|
|
|
|
{
|
|
|
|
if (indices.indexOf(tiles[i].index) === -1)
|
|
|
|
{
|
|
|
|
indices.push(tiles[i].index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < tiles.length; i++)
|
|
|
|
{
|
|
|
|
tiles[i].index = GetRandomElement(indices);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-11-22 01:07:22 +00:00
|
|
|
module.exports = Randomize;
|