2017-11-17 01:08:58 +00:00
|
|
|
var GetTilesWithin = require('./GetTilesWithin');
|
|
|
|
|
2017-11-27 13:33:30 +00:00
|
|
|
/**
|
|
|
|
* Scans the given rectangular area (given in tile coordinates) for tiles with an index matching
|
|
|
|
* `indexA` and swaps then with `indexB`. This only modifies the index and does not change collision
|
|
|
|
* information.
|
|
|
|
*
|
|
|
|
* @param {number} tileA - First tile index.
|
|
|
|
* @param {number} tileB - Second tile index.
|
|
|
|
* @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-17 01:08:58 +00:00
|
|
|
var SwapByIndex = function (indexA, indexB, tileX, tileY, width, height, layer)
|
|
|
|
{
|
2017-11-26 00:03:21 +00:00
|
|
|
var tiles = GetTilesWithin(tileX, tileY, width, height, null, layer);
|
2017-11-17 01:08:58 +00:00
|
|
|
for (var i = 0; i < tiles.length; i++)
|
|
|
|
{
|
|
|
|
if (tiles[i])
|
|
|
|
{
|
|
|
|
if (tiles[i].index === indexA)
|
|
|
|
{
|
|
|
|
tiles[i].index = indexB;
|
|
|
|
}
|
|
|
|
else if (tiles[i].index === indexB)
|
|
|
|
{
|
|
|
|
tiles[i].index = indexA;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = SwapByIndex;
|