2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
|
|
* @copyright 2018 Photon Storm Ltd.
|
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
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.
|
|
|
|
*
|
2018-02-08 01:08:59 +00:00
|
|
|
* @function Phaser.Tilemaps.Components.SwapByIndex
|
2018-04-16 14:25:22 +00:00
|
|
|
* @private
|
2018-02-08 01:08:59 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2017-11-29 21:07:56 +00:00
|
|
|
* @param {integer} tileA - First tile index.
|
|
|
|
* @param {integer} tileB - Second tile index.
|
2018-09-28 13:32:36 +00:00
|
|
|
* @param {integer} [tileX=0] - The left most tile index (in tile coordinates) to use as the origin of the area.
|
|
|
|
* @param {integer} [tileY=0] - The top most tile index (in tile coordinates) to use as the origin of the area.
|
|
|
|
* @param {integer} [width=max width based on tileX] - How many tiles wide from the `tileX` index the area will be.
|
|
|
|
* @param {integer} [height=max height based on tileY] - How many tiles tall from the `tileY` index the area will be.
|
2018-02-08 02:02:37 +00:00
|
|
|
* @param {Phaser.Tilemaps.LayerData} layer - The Tilemap Layer to act upon.
|
2017-11-27 13:33:30 +00:00
|
|
|
*/
|
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;
|