2017-11-16 02:06:07 +00:00
|
|
|
var GetTilesWithin = require('./GetTilesWithin');
|
2017-11-26 14:58:38 +00:00
|
|
|
var CalculateFacesWithin = require('./CalculateFacesWithin');
|
2017-11-16 02:06:07 +00:00
|
|
|
|
2017-11-26 15:05:19 +00:00
|
|
|
/**
|
|
|
|
* Copies the tiles in the source rectangular area to a new destination (all specified in tile
|
2017-11-27 13:33:30 +00:00
|
|
|
* coordinates) within the layer. This copies all tile properties & recalculates collision
|
|
|
|
* information in the destination region.
|
2017-11-26 15:05:19 +00:00
|
|
|
*
|
2018-02-08 01:08:59 +00:00
|
|
|
* @function Phaser.Tilemaps.Components.Copy
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2017-11-29 21:07:56 +00:00
|
|
|
* @param {integer} srcTileX - [description]
|
|
|
|
* @param {integer} srcTileY - [description]
|
|
|
|
* @param {integer} width - [description]
|
|
|
|
* @param {integer} height - [description]
|
|
|
|
* @param {integer} destTileX - [description]
|
|
|
|
* @param {integer} destTileY - [description]
|
|
|
|
* @param {integer} destTileY - [description]
|
2017-11-26 15:05:19 +00:00
|
|
|
* @param {boolean} [recalculateFaces=true] - [description]
|
2018-02-08 02:02:37 +00:00
|
|
|
* @param {Phaser.Tilemaps.LayerData} layer - The Tilemap Layer to act upon.
|
2017-11-26 15:05:19 +00:00
|
|
|
*/
|
2017-11-26 14:58:38 +00:00
|
|
|
var Copy = function (srcTileX, srcTileY, width, height, destTileX, destTileY, recalculateFaces, layer)
|
2017-11-16 02:06:07 +00:00
|
|
|
{
|
2017-11-26 14:58:38 +00:00
|
|
|
if (srcTileX < 0) { srcTileX = 0; }
|
|
|
|
if (srcTileY < 0) { srcTileY = 0; }
|
|
|
|
if (recalculateFaces === undefined) { recalculateFaces = true; }
|
2017-11-16 02:06:07 +00:00
|
|
|
|
2017-11-26 00:03:21 +00:00
|
|
|
var srcTiles = GetTilesWithin(srcTileX, srcTileY, width, height, null, layer);
|
2017-11-16 02:06:07 +00:00
|
|
|
|
|
|
|
var offsetX = destTileX - srcTileX;
|
|
|
|
var offsetY = destTileY - srcTileY;
|
|
|
|
|
|
|
|
for (var i = 0; i < srcTiles.length; i++)
|
|
|
|
{
|
|
|
|
var tileX = srcTiles[i].x + offsetX;
|
|
|
|
var tileY = srcTiles[i].y + offsetY;
|
|
|
|
if (tileX >= 0 && tileX < layer.width && tileY >= 0 && tileY < layer.height)
|
|
|
|
{
|
2017-11-26 14:58:38 +00:00
|
|
|
if (layer.data[tileY][tileX])
|
|
|
|
{
|
|
|
|
layer.data[tileY][tileX].copy(srcTiles[i]);
|
|
|
|
}
|
2017-11-16 02:06:07 +00:00
|
|
|
}
|
|
|
|
}
|
2017-11-26 14:58:38 +00:00
|
|
|
|
|
|
|
if (recalculateFaces)
|
|
|
|
{
|
|
|
|
// Recalculate the faces within the destination area and neighboring tiles
|
|
|
|
CalculateFacesWithin(destTileX - 1, destTileY - 1, width + 2, height + 2, layer);
|
|
|
|
}
|
2017-11-16 02:06:07 +00:00
|
|
|
};
|
|
|
|
|
2017-11-22 01:07:22 +00:00
|
|
|
module.exports = Copy;
|