2017-11-16 02:06:07 +00:00
|
|
|
var GetTilesWithin = require('./GetTilesWithin');
|
|
|
|
var ShuffleArray = require('../../../utils/array/Shuffle');
|
|
|
|
|
2017-11-27 13:33:30 +00:00
|
|
|
/**
|
|
|
|
* Shuffles the tiles in a rectangular region (specified in tile coordinates) within the given
|
|
|
|
* layer. It will only randomize the tiles in that area, so if they're all the same nothing will
|
|
|
|
* appear to have changed! This method only modifies tile indexes and does not change collision
|
|
|
|
* information.
|
|
|
|
*
|
|
|
|
* @param {number} [tileX=0] - [description]
|
|
|
|
* @param {number} [tileY=0] - [description]
|
|
|
|
* @param {number} [width=max width based on tileX] - [description]
|
|
|
|
* @param {number} [height=max height based on tileY] - [description]
|
|
|
|
* @param {LayerData} layer - [description]
|
|
|
|
*/
|
2017-11-16 02:06:07 +00:00
|
|
|
var Shuffle = function (tileX, tileY, width, height, layer)
|
|
|
|
{
|
2017-11-26 00:03:21 +00:00
|
|
|
var tiles = GetTilesWithin(tileX, tileY, width, height, null, layer);
|
2017-11-16 02:06:07 +00:00
|
|
|
|
|
|
|
var indices = tiles.map(function (tile) { return tile.index; });
|
|
|
|
ShuffleArray(indices);
|
|
|
|
|
|
|
|
for (var i = 0; i < tiles.length; i++)
|
|
|
|
{
|
|
|
|
tiles[i].index = indices[i];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Shuffle;
|