2017-11-16 02:06:07 +00:00
|
|
|
var GetTilesWithin = require('./GetTilesWithin');
|
2017-11-26 15:19:57 +00:00
|
|
|
var CalculateFacesWithin = require('./CalculateFacesWithin');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the tiles in the given rectangular area (in tile coordinates) with the specified index.
|
|
|
|
* Tiles will be set to collide if the given index is a colliding index. Interesting tile faces in
|
|
|
|
* the region will be recalculated.
|
|
|
|
*
|
|
|
|
* @param {number} index - [description]
|
|
|
|
* @param {number} tileX - [description]
|
|
|
|
* @param {number} tileY - [description]
|
|
|
|
* @param {number} width - [description]
|
|
|
|
* @param {number} height - [description]
|
|
|
|
* @param {boolean} [recalculateFaces=true] - [description]
|
|
|
|
* @param {LayerData} layer - [description]
|
|
|
|
*/
|
2017-11-16 02:06:07 +00:00
|
|
|
|
2017-11-22 01:19:13 +00:00
|
|
|
// Fills indices, not other properties. Does not modify collisions. Matches v2 functionality.
|
2017-11-26 15:19:57 +00:00
|
|
|
var Fill = function (index, tileX, tileY, width, height, recalculateFaces, layer)
|
2017-11-16 02:06:07 +00:00
|
|
|
{
|
2017-11-26 15:19:57 +00:00
|
|
|
if (recalculateFaces === undefined) { recalculateFaces = true; }
|
|
|
|
|
|
|
|
var doesIndexCollide = (layer.collideIndexes.indexOf(index) !== -1);
|
|
|
|
|
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
|
|
|
for (var i = 0; i < tiles.length; i++)
|
|
|
|
{
|
|
|
|
tiles[i].index = index;
|
2017-11-26 15:19:57 +00:00
|
|
|
|
|
|
|
if (doesIndexCollide)
|
|
|
|
{
|
|
|
|
tiles[i].setCollision(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tiles[i].resetCollision();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (recalculateFaces)
|
|
|
|
{
|
|
|
|
// Recalculate the faces within the area and neighboring tiles
|
|
|
|
CalculateFacesWithin(tileX - 1, tileY - 1, width + 2, height + 2, layer);
|
2017-11-16 02:06:07 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Fill;
|